26require_once DOL_DOCUMENT_ROOT.
"/core/class/html.form.class.php";
27require_once DOL_DOCUMENT_ROOT.
"/resource/class/dolresource.class.php";
43 public $substit = array();
45 public $param = array();
82 public function select_resource_list($selected =
'', $htmlname =
'fk_resource', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = array(), $filterkey =
'', $outputmode = 0, $limit = 20, $morecss =
'', $multiple =
false)
85 global $conf, $user, $langs;
92 $resources_used = $resourcestat->fetchAll(
'ASC',
't.rowid', $limit, 0, $filter);
94 if (!empty($selected) && !is_array($selected)) {
95 $selected = array($selected);
98 if ($outputmode != 2) {
99 $out =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
100 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
105 $out .=
'<select id="'.$htmlname.
'" class="flat minwidth100'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.($multiple ?
'[]' :
'').
'" '.($multiple ?
'multiple' :
'').
'>'.
"\n";
107 $out .=
'<option value="-1"> </option>'.
"\n";
111 if (is_array($resourcestat->lines)) {
112 $num = count($resourcestat->lines);
119 $resourceclass = ucfirst($resourcestat->lines[$i]->element);
121 $label = $resourcestat->lines[$i]->ref ? $resourcestat->lines[$i]->ref :
''.$resourcestat->lines[$i]->label;
122 if ($resourceclass !=
'Dolresource') {
123 $label .=
' ('.$langs->trans($resourceclass).
')';
127 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $resourcestat->lines[$i]->id) || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($resourcestat->lines[$i]->id, $selected))) {
128 $out .=
'<option value="'.$resourcestat->lines[$i]->id.
'" selected>'.$label.
'</option>';
130 $out .=
'<option value="'.$resourcestat->lines[$i]->id.
'">'.$label.
'</option>';
133 array_push($outarray, array(
'key'=>$resourcestat->lines[$i]->id,
'value'=>$resourcestat->lines[$i]->id,
'label'=>$label));
136 if (($i % 10) == 0) {
141 $out .=
'</select>'.
"\n";
143 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->RESOURCE_USE_SEARCH_TO_SELECT) && !$forcecombo) {
145 $out .=
ajax_combobox($htmlname, $event, $conf->global->RESOURCE_USE_SEARCH_TO_SELECT);
150 if ($outputmode != 2) {
151 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
"Search").
'"> ';
159 if ($outputmode && $outputmode != 2) {
178 public function select_types_resource($selected =
'', $htmlname =
'type_resource', $filtertype =
'', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0)
181 global $langs, $user;
185 dol_syslog(get_class($this).
"::select_types_resource ".$selected.
", ".$htmlname.
", ".$filtertype.
", ".$format, LOG_DEBUG);
187 $filterarray = array();
189 if ($filtertype !=
'' && $filtertype !=
'-1') {
190 $filterarray = explode(
',', $filtertype);
193 $resourcestat->load_cache_code_type_resource();
194 print
'<select id="select'.$htmlname.
'" class="flat maxwidthonsmartphone select_'.$htmlname.
'" name="'.$htmlname.
'">';
196 print
'<option value=""> </option>';
198 if (is_array($resourcestat->cache_code_type_resource) && count($resourcestat->cache_code_type_resource)) {
199 foreach ($resourcestat->cache_code_type_resource as $id => $arraytypes) {
201 if ($empty && empty($arraytypes[
'code'])) {
206 print
'<option value="'.$id.
'"';
207 } elseif ($format == 1) {
208 print
'<option value="'.$arraytypes[
'code'].
'"';
209 } elseif ($format == 2) {
210 print
'<option value="'.$arraytypes[
'code'].
'"';
211 } elseif ($format == 3) {
212 print
'<option value="'.$id.
'"';
215 if (!empty($selected) && preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
217 } elseif ($selected == $id) {
222 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
223 } elseif ($format == 1) {
224 $value = $arraytypes[
'code'];
225 } elseif ($format == 2) {
226 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
227 } elseif ($format == 3) {
228 $value = $arraytypes[
'code'];
238 if ($user->admin && !$noadmininfo) {
239 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.