28require_once DOL_DOCUMENT_ROOT.
"/core/class/html.form.class.php";
29require_once DOL_DOCUMENT_ROOT.
"/resource/class/dolresource.class.php";
48 public $substit = array();
53 public $param = array();
90 public function select_resource_list($selected = 0, $htmlname =
'fk_resource', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = [], $filterkey =
'', $outputmode = 0, $limit = 20, $morecss =
'minwidth100', $multiple =
false)
100 $resources_used = $resourcestat->fetchAll(
'ASC',
't.rowid', $limit, 0, $filter);
102 if (!empty($selected) && !is_array($selected)) {
103 $selected = array($selected);
106 if ($outputmode != 2) {
107 $out =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
108 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
113 $out .=
'<select id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.($multiple ?
'[]' :
'').
'" '.($multiple ?
'multiple' :
'').
'>'.
"\n";
115 $out .=
'<option value="-1"> </option>'.
"\n";
119 if (is_array($resourcestat->lines)) {
120 $num = count($resourcestat->lines);
127 $resourceclass = ucfirst($resourcestat->lines[$i]->element);
129 $label = $resourcestat->lines[$i]->ref ? $resourcestat->lines[$i]->ref :
''.$resourcestat->lines[$i]->label;
130 if ($resourceclass !=
'Dolresource') {
131 $label .=
' ('.$langs->trans($resourceclass).
')';
136 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))) {
137 $out .=
'<option value="'.$resourcestat->lines[$i]->id.
'" selected>'.$label.
'</option>';
139 $out .=
'<option value="'.$resourcestat->lines[$i]->id.
'">'.$label.
'</option>';
142 array_push($outarray, array(
'key' => (
int) $resourcestat->lines[$i]->id,
'value' => (
int) $resourcestat->lines[$i]->id,
'label' => (
string) $label));
145 if (($i % 10) == 0) {
150 $out .=
'</select>'.
"\n";
152 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'RESOURCE_USE_SEARCH_TO_SELECT') && !$forcecombo) {
154 $out .=
ajax_combobox($htmlname, $event,
$conf->global->RESOURCE_USE_SEARCH_TO_SELECT);
159 if ($outputmode != 2) {
160 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
"Search").
'"> ';
168 if ($outputmode && $outputmode != 2) {
189 public function select_types_resource($selected =
'', $htmlname =
'type_resource', $filtertype =
'', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $usejscombo = 0, $morecss =
'minwidth100')
192 global $langs, $user;
196 dol_syslog(get_class($this).
"::select_types_resource ".$selected.
", ".$htmlname.
", ".$filtertype.
", ".$format, LOG_DEBUG);
198 $filterarray = array();
200 if ($filtertype !=
'' && $filtertype !=
'-1') {
201 $filterarray = explode(
',', $filtertype);
204 $resourcestat->loadCacheCodeTypeResource();
205 print
'<select id="select'.$htmlname.
'" class="flat maxwidthonsmartphone select_'.$htmlname.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
207 print
'<option value=""> </option>';
209 if (is_array($resourcestat->cache_code_type_resource) && count($resourcestat->cache_code_type_resource)) {
210 foreach ($resourcestat->cache_code_type_resource as
$id => $arraytypes) {
212 if ($empty && empty($arraytypes[
'code'])) {
217 print
'<option value="'.$id.
'"';
218 } elseif ($format == 1) {
219 print
'<option value="'.$arraytypes[
'code'].
'"';
220 } elseif ($format == 2) {
221 print
'<option value="'.$arraytypes[
'code'].
'"';
222 } elseif ($format == 3) {
223 print
'<option value="'.$id.
'"';
226 if (!empty($selected) && preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
228 } elseif ($selected ==
$id) {
233 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
234 } elseif ($format == 1) {
235 $value = $arraytypes[
'code'];
236 } elseif ($format == 2) {
237 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
238 } elseif ($format == 3) {
239 $value = $arraytypes[
'code'];
253 if ($user->admin && !$noadmininfo) {
254 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
271 public function select_ziptown($selected =
'', $htmlname =
'zipcode', $fields = array(), $fieldsize = 0, $disableautocomplete = 0, $moreattrib =
'', $morecss =
'')
279 if (!empty($fieldsize)) {
280 $size =
'size="' . $fieldsize .
'"';
283 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
285 $moreattrib .=
' autocomplete="off"';
287 $out .=
'<input id="' . $htmlname .
'" class="maxwidthonsmartphone' . ($morecss ?
' ' . $morecss :
'') .
'" type="text"' . ($moreattrib ?
' ' . $moreattrib :
'') .
' name="' . $htmlname .
'" ' . $size .
' value="' . $selected .
'">' .
"\n";
306 public function select_state($selected = 0, $country_codeid = 0, $htmlname =
'state_id', $morecss =
'maxwidth200onsmartphone minwidth300')
309 global
$conf, $langs, $user;
311 dol_syslog(get_class($this) .
"::select_departement selected=" . $selected .
", country_codeid=" . $country_codeid, LOG_DEBUG);
313 $langs->load(
"dict");
318 $sql =
"SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
319 $sql .=
" " . $this->db->prefix() .
"c_departements as d, " . $this->db->prefix() .
"c_regions as r," . $this->db->prefix() .
"c_country as c";
320 $sql .=
" WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
321 $sql .=
" AND d.active = 1 AND r.active = 1 AND c.active = 1";
322 if ($country_codeid && is_numeric($country_codeid)) {
323 $sql .=
" AND c.rowid = '" . $this->db->escape($country_codeid) .
"'";
325 if ($country_codeid && !is_numeric($country_codeid)) {
326 $sql .=
" AND c.code = '" . $this->db->escape($country_codeid) .
"'";
328 $sql .=
" ORDER BY c.code, d.code_departement";
330 $result = $this->db->query($sql);
332 if (!empty($htmlname)) {
333 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
335 if ($country_codeid) {
336 $out .=
'<option value="0"> </option>';
338 $num = $this->db->num_rows($result);
340 dol_syslog(get_class($this) .
"::select_departement num=" . $num, LOG_DEBUG);
344 $obj = $this->db->fetch_object($result);
345 if ($obj->code ==
'0') {
346 $out .=
'<option value="0"> </option>';
348 if (!$country || $country != $obj->country) {
350 if (!$country_codeid && $obj->country_code) {
351 $out .=
'<option value="-1" disabled data-html="----- ' . $obj->country .
' -----">----- ' . $obj->country .
" -----</option>\n";
352 $country = $obj->country;
356 if (!empty($selected) && $selected == $obj->rowid) {
357 $out .=
'<option value="' . $obj->rowid .
'" selected>';
359 $out .=
'<option value="' . $obj->rowid .
'">';
368 $out .= $obj->region_name .
' - ' . $obj->code .
' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name !=
'-' ? $obj->name :
''));
370 $out .= $obj->code .
' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name !=
'-' ? $obj->name :
''));
374 $out .= $obj->region_name .
' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name !=
'-' ? $obj->name :
''));
376 $out .= ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name !=
'-' ? $obj->name :
''));
385 if (!empty($htmlname)) {
388 if (!empty($htmlname) && $user->admin) {
389 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
396 if (!empty($htmlname)) {
397 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...