FIX assign member cateogry to a member

This commit is contained in:
Laurent Destailleur 2022-05-03 21:54:34 +02:00
parent c55da219d9
commit ae282245fe
3 changed files with 30 additions and 25 deletions

View File

@ -734,9 +734,9 @@ if ($type == Categorie::TYPE_MEMBER) {
print '<input type="hidden" name="action" value="addintocategory">'; print '<input type="hidden" name="action" value="addintocategory">';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>'; print '<tr class="liste_titre"><td>';
print $langs->trans("AddMemberIntoCategory").' &nbsp;'; print $langs->trans("AssignCategoryTo").' &nbsp;';
print $form->selectMembers('', 'elemid'); print $form->selectMembers('', 'elemid');
print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>'; print '<input type="submit" class="button buttongen" value="'.$langs->trans("Save").'"></td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';
print '</form>'; print '</form>';

View File

@ -7101,12 +7101,14 @@ class Form
if ($selected && empty($selected_input_value)) { if ($selected && empty($selected_input_value)) {
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$adherenttmpselect = new Member($this->db); $adherenttmpselect = new Adherent($this->db);
$adherenttmpselect->fetch($selected); $adherenttmpselect->fetch($selected);
$selected_input_value = $adherenttmpselect->ref; $selected_input_value = $adherenttmpselect->ref;
unset($adherenttmpselect); unset($adherenttmpselect);
} }
$urloption = '';
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions); $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel").' : '; if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel").' : ';
@ -7121,7 +7123,9 @@ class Form
$out .= img_picto($langs->trans("Search"), 'search'); $out .= img_picto($langs->trans("Search"), 'search');
} }
} else { } else {
$out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); $filterkey = '';
$out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
} }
if (empty($nooutput)) print $out; if (empty($nooutput)) print $out;
@ -7136,8 +7140,8 @@ class Form
* @param string $htmlname Name of select html * @param string $htmlname Name of select html
* @param string $filtertype Filter on adherent type * @param string $filtertype Filter on adherent type
* @param int $limit Limit on number of returned lines * @param int $limit Limit on number of returned lines
* @param string $filterkey Filter on adherent ref or subject * @param string $filterkey Filter on member status
* @param int $status Ticket status * @param int $status Member status
* @param int $outputmode 0=HTML select string, 1=Array * @param int $outputmode 0=HTML select string, 1=Array
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
@ -7151,7 +7155,7 @@ class Form
$out = ''; $out = '';
$outarray = array(); $outarray = array();
$selectFields = " p.rowid, p.ref"; $selectFields = " p.rowid, p.ref, p.firstname, p.lastname";
$sql = "SELECT "; $sql = "SELECT ";
$sql .= $selectFields; $sql .= $selectFields;
@ -7161,21 +7165,23 @@ class Form
// Add criteria on ref/label // Add criteria on ref/label
if ($filterkey != '') { if ($filterkey != '') {
$sql .= ' AND ('; $sql .= ' AND (';
$prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on $prefix = empty($conf->global->MEMBER_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
// For natural search // For natural search
$scrit = explode(' ', $filterkey); $scrit = explode(' ', $filterkey);
$i = 0; $i = 0;
if (count($scrit) > 1) $sql .= "("; if (count($scrit) > 1) $sql .= "(";
foreach ($scrit as $crit) { foreach ($scrit as $crit) {
if ($i > 0) $sql .= " AND "; if ($i > 0) $sql .= " AND ";
$sql .= "p.ref LIKE '".$this->db->escape($prefix.$crit)."%'"; $sql .= "(p.firstname LIKE '".$this->db->escape($prefix.$crit)."%'";
$sql .= ""; $sql .= " OR p.lastname LIKE '".$this->db->escape($prefix.$crit)."%')";
$i++; $i++;
} }
if (count($scrit) > 1) $sql .= ")"; if (count($scrit) > 1) $sql .= ")";
$sql .= ')'; $sql .= ')';
} }
if ($status != -1) {
$sql .= ' AND statut = '.((int) $status);
}
$sql .= $this->db->plimit($limit, 0); $sql .= $this->db->plimit($limit, 0);
// Build output string // Build output string
@ -7205,7 +7211,9 @@ class Form
} else { } else {
if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty); if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
} }
if ($showempty) $out .= '<option value="0" selected>'.$textifempty.'</option>'; if ($showempty) {
$out .= '<option value="-1" selected>'.$textifempty.'</option>';
}
$i = 0; $i = 0;
while ($num && $i < $num) { while ($num && $i < $num) {
@ -7214,6 +7222,7 @@ class Form
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
$this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey); $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
// Add new entry // Add new entry
// "key" value of json key array is used by jQuery automatically as selected value // "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box // "label" value of json key array is used by jQuery automatically as text for combo box
@ -7250,28 +7259,23 @@ class Form
global $langs, $conf, $user, $db; global $langs, $conf, $user, $db;
$outkey = ''; $outkey = '';
$outval = '';
$outref = '';
$outlabel = ''; $outlabel = '';
$outtype = ''; $outtype = '';
$label = $objp->label;
$outkey = $objp->rowid; $outkey = $objp->rowid;
$outref = $objp->ref; $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
$outlabel = $objp->label; $outtype = $objp->fk_adherent_type;
$outtype = $objp->fk_product_type;
$opt = '<option value="'.$objp->rowid.'"'; $opt = '<option value="'.$objp->rowid.'"';
$opt .= ($objp->rowid == $selected) ? ' selected' : ''; $opt .= ($objp->rowid == $selected) ? ' selected' : '';
$opt .= '>'; $opt .= '>';
$opt .= $objp->ref; if (!empty($filterkey) && $filterkey != '') {
$objRef = $objp->ref; $outlabel = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $outlabel, 1);
if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1); }
$outval .= $objRef; $opt .= $outlabel;
$opt .= "</option>\n"; $opt .= "</option>\n";
$optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem);
$optJson = array('key'=>$outkey, 'value'=>$outlabel, 'type'=>$outtype);
} }
/** /**

View File

@ -90,6 +90,7 @@ CategorieRecursivHelp=If option is on, when you add a product into a subcategory
AddProductServiceIntoCategory=Add the following product/service AddProductServiceIntoCategory=Add the following product/service
AddCustomerIntoCategory=Assign category to customer AddCustomerIntoCategory=Assign category to customer
AddSupplierIntoCategory=Assign category to supplier AddSupplierIntoCategory=Assign category to supplier
AssignCategoryTo=Assign category to
ShowCategory=Show tag/category ShowCategory=Show tag/category
ByDefaultInList=By default in list ByDefaultInList=By default in list
ChooseCategory=Choose category ChooseCategory=Choose category