New parameter to transform select into multiselect
This commit is contained in:
parent
20c72c1ae4
commit
41a516f1c4
@ -1001,9 +1001,10 @@ class Form
|
||||
* @param string $selected_input_value Value of preselected input text (for use with ajax)
|
||||
* @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after)
|
||||
* @param array $ajaxoptions Options for ajax_autocompleter
|
||||
* @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter)
|
||||
* @return string HTML string with select box for thirdparty.
|
||||
*/
|
||||
function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='', $selected_input_value='', $hidelabel=1, $ajaxoptions=array())
|
||||
function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='', $selected_input_value='', $hidelabel=1, $ajaxoptions=array(), $multiple=false)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
@ -1040,7 +1041,7 @@ class Form
|
||||
else
|
||||
{
|
||||
// Immediate load of all database
|
||||
$out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam);
|
||||
$out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple);
|
||||
}
|
||||
|
||||
return $out;
|
||||
@ -1062,16 +1063,20 @@ class Form
|
||||
* @param int $limit Limit number of answers
|
||||
* @param string $morecss Add more css styles to the SELECT component
|
||||
* @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
|
||||
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
|
||||
* @return string HTML string with
|
||||
*/
|
||||
function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty='', $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=0, $morecss='minwidth100', $moreparam='')
|
||||
function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty='', $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=0, $morecss='minwidth100', $moreparam='', $multiple=false)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
$out='';
|
||||
$num=0;
|
||||
$outarray=array();
|
||||
|
||||
|
||||
if ($selected === '') $selected = array();
|
||||
else if (!is_array($selected)) $selected = array($selected);
|
||||
|
||||
// Clean $filter that may contains sql conditions so sql code
|
||||
if (function_exists('test_sql_and_script_inject')) $filter = test_sql_and_script_inject($filter, 3);
|
||||
|
||||
@ -1120,7 +1125,7 @@ class Form
|
||||
}
|
||||
|
||||
// Construct $out and $outarray
|
||||
$out.= '<select id="'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'"'.($moreparam?' '.$moreparam:'').' name="'.$htmlname.'">'."\n";
|
||||
$out.= '<select id="'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'"'.($moreparam?' '.$moreparam:'').' name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').'>'."\n";
|
||||
|
||||
$textifempty='';
|
||||
// Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
|
||||
@ -1169,7 +1174,7 @@ class Form
|
||||
|
||||
if (empty($outputmode))
|
||||
{
|
||||
if ($selected > 0 && $selected == $obj->rowid)
|
||||
if (in_array($obj->rowid,$selected))
|
||||
{
|
||||
$out.= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>';
|
||||
}
|
||||
@ -1320,15 +1325,19 @@ class Form
|
||||
* @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
|
||||
* @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
|
||||
* @param string $htmlid Html id to use instead of htmlname
|
||||
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
|
||||
* @return int <0 if KO, Nb of contact in list if OK
|
||||
*/
|
||||
function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=0, $exclude='', $limitto='', $showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array(), $moreparam='', $htmlid='')
|
||||
function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=0, $exclude='', $limitto='', $showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array(), $moreparam='', $htmlid='', $multiple=false)
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$langs->load('companies');
|
||||
|
||||
if (empty($htmlid)) $htmlid = $htmlname;
|
||||
|
||||
if ($selected === '') $selected = array();
|
||||
else if (!is_array($selected)) $selected = array($selected);
|
||||
$out='';
|
||||
|
||||
// On recherche les societes
|
||||
@ -1353,9 +1362,9 @@ class Form
|
||||
$out .= ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT);
|
||||
}
|
||||
|
||||
if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlid.'" name="'.$htmlname.'" '.(!empty($moreparam) ? $moreparam : '').'>';
|
||||
if ($showempty == 1) $out.= '<option value="0"'.($selected=='0'?' selected':'').'> </option>';
|
||||
if ($showempty == 2) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans("Internal").'</option>';
|
||||
if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>';
|
||||
if ($showempty == 1 && !$multiple) $out.= '<option value="0"'.(in_array(0,$selected)?' selected':'').'> </option>';
|
||||
if ($showempty == 2) $out.= '<option value="0"'.(in_array(0,$selected)?' selected':'').'>'.$langs->trans("Internal").'</option>';
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
@ -1363,7 +1372,6 @@ class Form
|
||||
include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
$contactstatic=new Contact($this->db);
|
||||
|
||||
if (!is_array($selected)) $selected = array($selected);
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
@ -1413,7 +1421,7 @@ class Form
|
||||
}
|
||||
else
|
||||
{
|
||||
$out.= '<option value="-1"'.($showempty==2?'':' selected').' disabled>'.$langs->trans($socid?"NoContactDefinedForThirdParty":"NoContactDefined").'</option>';
|
||||
$out.= '<option value="-1"'.($showempty==2 || $multiple?'':' selected').' disabled>'.$langs->trans($socid?"NoContactDefinedForThirdParty":"NoContactDefined").'</option>';
|
||||
}
|
||||
if ($htmlname != 'none' || $options_only)
|
||||
{
|
||||
@ -1469,16 +1477,20 @@ class Form
|
||||
* @param string $morecss More css
|
||||
* @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on).
|
||||
* @param int $outputmode 0=HTML select string, 1=Array
|
||||
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
|
||||
* @return string HTML select string
|
||||
* @see select_dolgroups
|
||||
*/
|
||||
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)
|
||||
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)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
if ($selected === '') $selected = array();
|
||||
else if (!is_array($selected)) $selected = array($selected);
|
||||
|
||||
$excludeUsers=null;
|
||||
$includeUsers=null;
|
||||
|
||||
@ -1551,12 +1563,12 @@ class Form
|
||||
$out .= ajax_combobox($htmlname);
|
||||
|
||||
// do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined
|
||||
$out.= '<select class="flat'.($morecss?' minwidth100 '.$morecss:' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>';
|
||||
if ($show_empty) $out.= '<option value="-1"'.((empty($selected) || $selected==-1)?' selected':'').'> </option>'."\n";
|
||||
if ($show_every) $out.= '<option value="-2"'.(($selected==-2)?' selected':'').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
|
||||
$out.= '<select class="flat'.($morecss?' minwidth100 '.$morecss:' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled?' disabled':'').'>';
|
||||
if ($show_empty && !$multiple) $out.= '<option value="-1"'.((empty($selected) || in_array(-1,$selected))?' selected':'').'> </option>'."\n";
|
||||
if ($show_every) $out.= '<option value="-2"'.((in_array(-2,$selected))?' selected':'').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
|
||||
|
||||
$userstatic=new User($this->db);
|
||||
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
@ -1568,7 +1580,7 @@ class Form
|
||||
$disableline='';
|
||||
if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=($enableonlytext?$enableonlytext:'1');
|
||||
|
||||
if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
|
||||
if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && in_array($obj->rowid,$selected) ))
|
||||
{
|
||||
$out.= '<option value="'.$obj->rowid.'"';
|
||||
if ($disableline) $out.= ' disabled';
|
||||
@ -6727,10 +6739,11 @@ class Form
|
||||
* @param string $include Array list of groups id to include
|
||||
* @param int $enableonly Array list of groups id to be enabled. All other must be disabled
|
||||
* @param string $force_entity '0' or Ids of environment to force
|
||||
* @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter)
|
||||
* @return string
|
||||
* @see select_dolusers
|
||||
*/
|
||||
function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity='0')
|
||||
function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity='0', $multiple=false)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
@ -6739,6 +6752,8 @@ class Form
|
||||
// Permettre l'inclusion de groupes
|
||||
if (is_array($include)) $includeGroups = implode("','",$include);
|
||||
|
||||
if (!is_array($selected)) $selected = array($selected);
|
||||
|
||||
$out='';
|
||||
|
||||
// On recherche les groupes
|
||||
@ -6770,13 +6785,13 @@ class Form
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
||||
$out .= ajax_combobox($htmlname);
|
||||
|
||||
$out.= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>';
|
||||
$out.= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled?' disabled':'').'>';
|
||||
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
if ($show_empty) $out.= '<option value="-1"'.($selected==-1?' selected':'').'> </option>'."\n";
|
||||
if ($show_empty && !$multiple) $out.= '<option value="-1"'.(in_array(-1,$selected)?' selected':'').'> </option>'."\n";
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
@ -6786,7 +6801,7 @@ class Form
|
||||
|
||||
$out.= '<option value="'.$obj->rowid.'"';
|
||||
if ($disableline) $out.= ' disabled';
|
||||
if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
|
||||
if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (! is_object($selected[0]) && in_array($obj->rowid,$selected) ))
|
||||
{
|
||||
$out.= ' selected';
|
||||
}
|
||||
@ -6804,7 +6819,7 @@ class Form
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($show_empty) $out.= '<option value="-1"'.($selected==-1?' selected':'').'></option>'."\n";
|
||||
if ($show_empty) $out.= '<option value="-1"'.(in_array(-1,$selected)?' selected':'').'></option>'."\n";
|
||||
$out.= '<option value="" disabled>'.$langs->trans("NoUserGroupDefined").'</option>';
|
||||
}
|
||||
$out.= '</select>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user