add hook to add sql filter in where clause on select users

This commit is contained in:
florian HENRY 2020-03-16 11:49:03 +01:00
parent a6f8608ffd
commit 117ff5f4eb
2 changed files with 17 additions and 2 deletions

View File

@ -1618,7 +1618,7 @@ class Form
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $noactive = 0, $outputmode = 0, $multiple = false)
{
// phpcs:enable
global $conf, $user, $langs;
global $conf, $user, $langs, $hookmanager;
// If no preselected user defined, we take current user
if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected = $user->id;
@ -1679,6 +1679,10 @@ class Form
if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) $sql .= " AND u.statut <> 0";
if (!empty($morefilter)) $sql .= " ".$morefilter;
//Add hook to filter on user (for exemple on usergroup define in custom modules)
$reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectUsers', array(), $this, $action);
if (!empty($reshook)) $sql .= $hookmanager->resPrint;
if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
{
$sql .= " ORDER BY u.firstname ASC";

View File

@ -424,7 +424,7 @@ class FormOther
public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
{
// phpcs:enable
global $conf, $langs;
global $conf, $langs, $hookmanager;
$langs->load('users');
@ -440,6 +440,9 @@ class FormOther
$out.=$comboenhancement;
}
}
$reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
// Select each sales and print them in a select input
$out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
if ($showempty) $out.='<option value="0">&nbsp;</option>';
@ -464,6 +467,10 @@ class FormOther
if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
if (! empty($user->socid)) $sql_usr.=" AND u.fk_soc = ".$user->socid;
//Add hook to filter on user (for exemple on usergroup define in custom modules)
if (!empty($reshook)) $sql_usr .= $hookmanager->resArray[0];
// Add existing sales representatives of thirdparty of external user
if (empty($user->rights->user->user->lire) && $user->socid)
{
@ -485,7 +492,11 @@ class FormOther
}
$sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->socid;
//Add hook to filter on user (for exemple on usergroup define in custom modules)
if (!empty($reshook)) $sql_usr .= $hookmanager->resArray[1];
}
$sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
//print $sql_usr;exit;