29require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
71 public function inputType($type, $name, $value =
'', $id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
75 $out .=
'<label for="' . $id .
'">';
77 $out .=
'<input type="' . $type .
'"';
78 $out .= ($morecss ?
' class="' . $morecss .
'"' :
'');
80 $out .=
' id="' . $id .
'"';
82 $out .=
' name="' . $name .
'"';
83 $out .=
' value="' . $value .
'"';
84 $out .= ($moreparam ?
' ' . $moreparam :
'');
85 $out .=
' />' . $addInputLabel;
87 $out .= $label .
'</label>';
104 public function inputDate($name, $value =
'', $placeholder =
'', $id =
'', $morecss =
'', $moreparam =
'')
129 $out = $this->
selectDate($value ===
'' ? -1 : $value, $name, 0, 0, 0,
"", 1, 0, 0,
'');
156 public static function selectarray($htmlname, $array, $id =
'', $show_empty = 0, $key_in_label = 0, $value_as_key = 0, $moreparam =
'', $translate = 0, $maxlen = 0, $disabled = 0, $sort =
'', $morecss =
'minwidth75', $addjscombo = 1, $moreparamonempty =
'', $disablebademail = 0, $nohtmlescape = 0)
161 $array = array_combine($array, $array);
166 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
167 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' class="' . ($morecss ?
' ' . $morecss :
'') .
'"';
168 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'"' . ($moreparam ?
' ' . $moreparam :
'');
173 if (!is_numeric($show_empty)) {
174 $textforempty = $show_empty;
176 $out .=
'<option value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ($id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
179 if (is_array($array)) {
182 foreach ($array as $key => $value) {
183 if (!is_array($value)) {
184 $array[$key] = $langs->trans($value);
186 $array[$key][
'label'] = $langs->trans($value[
'label']);
192 if ($sort ==
'ASC') {
194 } elseif ($sort ==
'DESC') {
198 foreach ($array as $key => $tmpvalue) {
199 if (is_array($tmpvalue)) {
200 $value = $tmpvalue[
'label'];
201 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
211 if ($value ==
'' || $value ==
'-') {
212 $selectOptionValue =
' ';
216 $out .=
'<option value="' . $key .
'"';
219 if (in_array($key, $id) && !$disabled) {
224 if ($id !=
'' && ($id == $key || ($id ==
'ifone' && count($array) == 1)) && !$disabled) {
228 if (is_array($tmpvalue)) {
229 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
230 if (preg_match(
'/^data-/', $keyforvalue)) {
236 $out .= $selectOptionValue;
237 $out .=
"</option>\n";
259 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter =
'', $morecss =
'', $allfiles = 0)
261 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
270 $this->infofiles = array(
'nboffiles' => 0,
'extensions' => array(),
'files' => array());
275 if (isModEnabled(
'multicompany')) {
277 preg_match(
'/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir,
'/') .
'$/', $filedir, $regs);
278 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1);
283 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/');
285 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/') .
'\.';
287 $file_list =
dol_dir_list($filedir,
'files', 0, $filterforfilesearch,
'\.meta$|\.png$');
291 $out .=
'<!-- html.formwebportal::getDocumentsLink -->' .
"\n";
292 if (!empty($file_list)) {
298 foreach ($file_list as $file) {
300 if ($filter && !preg_match(
'/' . $filter .
'/i', $file[
"name"])) {
306 $relativepath = $file[
"name"];
308 $relativepath = $modulesubdir .
"/" . $file[
"name"];
311 if ($modulepart ==
'donation') {
312 $relativepath =
get_exdir($modulesubdir, 2, 0, 0,
null,
'donation') . $file[
"name"];
314 if ($modulepart ==
'export') {
315 $relativepath = $file[
"name"];
318 $this->infofiles[
'nboffiles']++;
319 $this->infofiles[
'files'][] = $file[
'fullname'];
320 $ext = pathinfo($file[
"name"], PATHINFO_EXTENSION);
321 if (empty($this->infofiles[$ext])) {
322 $this->infofiles[
'extensions'][$ext] = 1;
324 $this->infofiles[
'extensions'][$ext]++;
328 $url = $context->getControllerUrl(
'document') .
'&modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($relativepath) .
'&soc_id=' . $context->logged_thirdparty->id;
329 $tmpout .=
'<a href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="downloadlink"';
331 if (preg_match(
'/text/', $mime)) {
332 $tmpout .=
' target="_blank" rel="noopener noreferrer"';
335 $tmpout .=
img_mime($relativepath, $file[
"name"]);
336 $tmpout .= strtoupper($ext);
368 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $disabled = 0, $selected_input_value =
'', $objectfield =
'')
378 $InfoFieldList = explode(
":", $objectdesc, 4);
379 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
381 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
382 $InfoFieldList[4] = $reg[1];
384 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
386 $classname = $InfoFieldList[0];
387 $classpath = $InfoFieldList[1];
388 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
389 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
390 if (!empty($classpath)) {
393 if ($classname && class_exists($classname)) {
394 $objecttmp =
new $classname($this->db);
397 $sharedentities =
getEntity(strtolower($classname));
398 $filter = str_replace(
399 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
400 array($conf->entity, $sharedentities),
405 if (!is_object($objecttmp)) {
406 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
407 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
410 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
413 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
438 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'')
440 global $conf, $langs, $hookmanager;
442 $prefixforautocompletemode = $objecttmp->element;
443 if ($prefixforautocompletemode ==
'societe') {
444 $prefixforautocompletemode =
'company';
446 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
448 if (in_array($objecttmp->element, array(
'adherent_type'))) {
449 $fieldstoshow =
't.libelle';
451 if (!empty($objecttmp->fields)) {
452 $tmpfieldstoshow =
'';
453 foreach ($objecttmp->fields as $key => $val) {
454 if (! (
int)
dol_eval($val[
'enabled'], 1, 1,
'1')) {
457 if (!empty($val[
'showoncombobox'])) {
458 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
461 if ($tmpfieldstoshow) {
462 $fieldstoshow = $tmpfieldstoshow;
464 } elseif (!in_array($objecttmp->element, array(
'adherent_type'))) {
466 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'showoncombobox' => 1);
469 if (empty($fieldstoshow)) {
470 if (isset($objecttmp->fields[
'ref'])) {
471 $fieldstoshow =
't.ref';
473 $langs->load(
"errors");
474 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
475 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
486 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $objecttmp->table_element .
" as t";
487 if (isset($objecttmp->ismultientitymanaged)) {
488 if (!is_numeric($objecttmp->ismultientitymanaged)) {
489 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
490 $sql .=
" INNER JOIN " . $this->db->prefix() . $tmparray[1] .
" as parenttable ON parenttable.rowid = t." . $tmparray[0];
494 if (!empty($objecttmp->isextrafieldmanaged)) {
495 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
"_extrafields as e ON t.rowid = e.fk_object";
500 'object' => $objecttmp,
501 'htmlname' => $htmlname,
503 'searchkey' => $searchkey
506 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
507 if (!empty($hookmanager->resPrint)) {
508 $sql .= $hookmanager->resPrint;
510 $sql .=
" WHERE 1=1";
511 if (isset($objecttmp->ismultientitymanaged)) {
512 if ($objecttmp->ismultientitymanaged == 1) {
513 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->table_element) .
")";
515 if (!is_numeric($objecttmp->ismultientitymanaged)) {
516 $sql .=
" AND parenttable.entity = t." . $tmparray[0];
519 if ($searchkey !=
'') {
527 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
531 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow,
"ASC");
534 $resql = $this->db->query($sql);
537 $out .=
'<select id="' . $htmlname .
'" class="' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
540 $textifempty =
' ';
543 if (!empty($conf->global->$confkeyforautocompletemode)) {
544 if ($showempty && !is_numeric($showempty)) {
545 $textifempty = $langs->trans($showempty);
547 $textifempty .= $langs->trans(
"All");
551 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
554 $num = $this->db->num_rows($resql);
558 $obj = $this->db->fetch_object($resql);
561 $tmparray = explode(
',', $fieldstoshow);
562 $oldvalueforshowoncombobox = 0;
563 foreach ($tmparray as $key => $val) {
564 $val = preg_replace(
'/t\./',
'', $val);
565 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
566 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
567 $label .= $obj->$val;
568 $labelhtml .= $obj->$val;
570 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
572 if (empty($outputmode)) {
573 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
574 $out .=
'<option value="' . $obj->rowid .
'" selected data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
576 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
579 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
583 if (($i % 10) == 0) {
589 $out .=
'</select>' .
"\n";
594 $this->result = array(
'nbofelement' => $num);
616 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
618 global $conf, $langs;
623 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
625 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
626 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
628 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
629 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
631 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
632 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
634 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
635 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
637 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
638 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
640 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
641 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
643 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
644 $param[
'options'] = array();
647 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
648 $param[
'options'] = array();
650 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
651 $param[
'options'] = array();
654 $param[
'options'] = array();
655 $type = $val[
'type'];
659 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
660 $param[
'options'] = $val[
'arrayofkeyval'];
661 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
665 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
666 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
668 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
669 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
673 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
678 if (!preg_match(
'/^search_/', $keyprefix)) {
679 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
686 if (empty($morecss) && !empty($val[
'css'])) {
687 $morecss = $val[
'css'];
690 $htmlName = $keyprefix . $key . $keysuffix;
699 $dateArr = explode(
' ', $value);
700 if (count($dateArr) > 0) {
701 $valueDate = $dateArr[0];
702 if (isset($dateArr[1])) {
703 $valueTime = $dateArr[1];
706 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
708 if ($type ==
'datetime') {
710 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
720 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
737 if (!empty($value)) {
738 $value =
price($value);
740 $addInputLabel =
' ' . $langs->getCurrencySymbol($conf->currency);
741 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
745 if (!empty($value)) {
746 $value =
price($value);
748 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
752 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
756 foreach ($param[
'options'] as $keyopt => $valopt) {
757 $htmlId = $htmlName .
'_' . $keyopt;
758 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
759 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
764 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
765 if ($default ==
'' || $notNull != 1) {
766 $out .=
'<option value="0"> </option>';
768 foreach ($param[
'options'] as $keyb => $valb) {
772 if (strpos($valb,
"|") !==
false) {
773 list($valb, $parent) = explode(
'|', $valb);
775 $out .=
'<option value="' . $keyb .
'"';
776 $out .= (((string) $value == $keyb) ?
' selected' :
'');
777 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
778 $out .=
'>' . $valb .
'</option>';
783 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
785 $param_list = array_keys($param[
'options']);
786 $InfoFieldList = explode(
":", $param_list[0]);
796 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
798 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
799 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
800 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
802 $keyList = $InfoFieldList[2] .
' as rowid';
805 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
806 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
807 $keyList .=
', ' . $parentField;
810 $filter_categorie =
false;
811 if (count($InfoFieldList) > 5) {
812 if ($InfoFieldList[0] ==
'categorie') {
813 $filter_categorie =
true;
817 if ($filter_categorie ===
false) {
818 $fields_label = explode(
'|', $InfoFieldList[1]);
819 if (is_array($fields_label)) {
821 $keyList .= implode(
', ', $fields_label);
825 $sql =
"SELECT " . $keyList;
826 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
827 if (!empty($InfoFieldList[4])) {
829 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
830 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
834 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
837 if (strpos($InfoFieldList[4],
'extra') !==
false) {
838 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
839 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
841 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
844 $sqlwhere .=
' WHERE 1=1';
847 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
848 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
853 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
855 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
856 $resql = $this->db->query($sql);
858 $out .=
'<option value="0"> </option>';
859 $num = $this->db->num_rows($resql);
863 $obj = $this->db->fetch_object($resql);
867 $fields_label = explode(
'|', $InfoFieldList[1]);
868 if (count($fields_label) > 1) {
870 foreach ($fields_label as $field_toshow) {
871 $labeltoshow .= $obj->$field_toshow .
' ';
874 $labeltoshow = $obj->{$InfoFieldList[1]};
876 $labeltoshow =
dol_trunc($labeltoshow, 45);
878 if ($value == $obj->rowid) {
879 foreach ($fields_label as $field_toshow) {
880 $translabel = $langs->trans($obj->$field_toshow);
881 if ($translabel != $obj->$field_toshow) {
882 $labeltoshow =
dol_trunc($translabel) .
' ';
884 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
887 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
890 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
891 if ($translabel != $obj->{$InfoFieldList[1]}) {
892 $labeltoshow =
dol_trunc($translabel, 18);
894 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
897 if (empty($labeltoshow)) {
898 $labeltoshow =
'(not defined)';
900 if ($value == $obj->rowid) {
901 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
904 if (!empty($InfoFieldList[3]) && $parentField) {
905 $parent = $parentName .
':' . $obj->{$parentField};
909 $out .=
'<option value="' . $obj->rowid .
'"';
910 $out .= ($value == $obj->rowid ?
' selected' :
'');
911 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
912 $out .=
'>' . $labeltoshow .
'</option>';
917 $this->db->free($resql);
919 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
922 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
923 $categorytype = $InfoFieldList[5];
924 if (is_numeric($categorytype)) {
925 $categorytype = Categorie::$MAP_ID_TO_CODE[$categorytype];
927 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
928 $out .=
'<option value="0"> </option>';
929 foreach ($data as $data_key => $data_value) {
930 $out .=
'<option value="' . $data_key .
'"';
931 $out .= ($value == $data_key ?
' selected' :
'');
932 $out .=
'>' . $data_value .
'</option>';
939 $param_list = array_keys($param[
'options']);
940 $showempty = (($required && $default !=
'') ? 0 : 1);
942 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
947 if (!empty($hidden)) {
948 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
971 global $conf, $langs;
973 $label = empty($val[
'label']) ?
'' : $val[
'label'];
974 $type = empty($val[
'type']) ?
'' : $val[
'type'];
975 $css = empty($val[
'css']) ?
'' : $val[
'css'];
976 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
980 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
983 } elseif (preg_match(
'/varchar/', $type)) {
986 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
987 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
989 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
993 $default = empty($val[
'default']) ?
'' : $val[
'default'];
994 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
995 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
996 $required = empty($val[
'required']) ?
'' : $val[
'required'];
998 $param[
'options'] = array();
1000 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1001 $param[
'options'] = $val[
'arrayofkeyval'];
1003 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1005 $stringforoptions = $reg[1] .
':' . $reg[2];
1006 if ($reg[1] ==
'User') {
1007 $stringforoptions .=
':-1';
1009 $param[
'options'] = array($stringforoptions => $stringforoptions);
1010 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1011 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
1013 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1014 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
1016 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
1017 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
1019 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
1020 $param[
'options'] = array($reg[1] =>
'N');
1024 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
1025 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
1026 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
1027 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
1037 $value = (string)
dol_eval($computed, 1, 0,
'2');
1044 if (in_array($key, array(
'rowid',
'ref'))) {
1045 if (property_exists(
$object,
'ref')) {
1047 } elseif (property_exists(
$object,
'id')) {
1052 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
1053 $value =
$object->getLibStatut(3);
1057 } elseif (is_array($value)) {
1060 if ($type ==
'array') {
1061 $value = implode(
'<br>', $value);
1063 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
1068 } elseif ($type ==
'date') {
1069 if (!empty($value)) {
1074 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
1075 if (!empty($value)) {
1080 } elseif ($type ==
'duration') {
1081 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
1082 if (!is_null($value) && $value !==
'') {
1085 } elseif ($type ==
'double' || $type ==
'real') {
1086 if (!is_null($value) && $value !==
'') {
1087 $value =
price($value);
1089 } elseif ($type ==
'boolean') {
1091 if (!empty($value)) {
1092 $checked =
' checked ';
1094 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
1095 } elseif ($type ==
'mail' || $type ==
'email') {
1097 } elseif ($type ==
'url') {
1099 } elseif ($type ==
'phone') {
1101 } elseif ($type ==
'ip') {
1103 } elseif ($type ==
'price') {
1104 if (!is_null($value) && $value !==
'') {
1105 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
1107 } elseif ($type ==
'select') {
1108 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
1109 } elseif ($type ==
'sellist') {
1110 $param_list = array_keys($param[
'options']);
1111 $InfoFieldList = explode(
":", $param_list[0]);
1113 $selectkey =
"rowid";
1116 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1117 $selectkey = $InfoFieldList[2];
1118 $keyList = $InfoFieldList[2] .
' as rowid';
1121 $fields_label = explode(
'|', $InfoFieldList[1]);
1122 if (is_array($fields_label)) {
1124 $keyList .= implode(
', ', $fields_label);
1127 $filter_categorie =
false;
1128 if (count($InfoFieldList) > 5) {
1129 if ($InfoFieldList[0] ==
'categorie') {
1130 $filter_categorie =
true;
1134 $sql =
"SELECT " . $keyList;
1135 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1136 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1139 if ($selectkey ==
'rowid' && empty($value)) {
1140 $sql .=
" WHERE " . $selectkey .
" = 0";
1141 } elseif ($selectkey ==
'rowid') {
1142 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
1144 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
1147 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
1148 $resql = $this->db->query($sql);
1150 if ($filter_categorie ===
false) {
1152 $numrows = $this->db->num_rows($resql);
1154 $obj = $this->db->fetch_object($resql);
1157 $fields_label = explode(
'|', $InfoFieldList[1]);
1159 if (is_array($fields_label) && count($fields_label) > 1) {
1160 foreach ($fields_label as $field_toshow) {
1162 if (!empty($obj->$field_toshow)) {
1163 $translabel = $langs->trans($obj->$field_toshow);
1165 if ($translabel != $field_toshow) {
1166 $value .=
dol_trunc($translabel, 18) .
' ';
1168 $value .= $obj->$field_toshow .
' ';
1173 if (!empty($obj->{$InfoFieldList[1]})) {
1174 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1176 if ($translabel != $obj->{$InfoFieldList[1]}) {
1179 $value = $obj->{$InfoFieldList[1]};
1184 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1187 $obj = $this->db->fetch_object($resql);
1189 $c->fetch($obj->rowid);
1190 $ways = $c->print_all_ways();
1191 foreach ($ways as $way) {
1192 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1194 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1197 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1199 } elseif ($type ==
'radio') {
1200 $value = $param[
'options'][$value];
1201 } elseif ($type ==
'checkbox') {
1202 $value_arr = explode(
',', $value);
1204 if (is_array($value_arr) && count($value_arr) > 0) {
1206 foreach ($value_arr as $valueval) {
1207 if (!empty($valueval)) {
1208 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1211 if (!empty($toprint)) {
1212 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1215 } elseif ($type ==
'chkbxlst') {
1216 $value_arr = explode(
',', $value);
1218 $param_list = array_keys($param[
'options']);
1219 $InfoFieldList = explode(
":", $param_list[0]);
1221 $selectkey =
"rowid";
1224 if (count($InfoFieldList) >= 3) {
1225 $selectkey = $InfoFieldList[2];
1226 $keyList = $InfoFieldList[2] .
' as rowid';
1229 $fields_label = explode(
'|', $InfoFieldList[1]);
1230 if (is_array($fields_label)) {
1232 $keyList .= implode(
', ', $fields_label);
1235 $filter_categorie =
false;
1236 if (count($InfoFieldList) > 5) {
1237 if ($InfoFieldList[0] ==
'categorie') {
1238 $filter_categorie =
true;
1242 $sql =
"SELECT " . $keyList;
1243 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1244 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1250 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1251 $resql = $this->db->query($sql);
1253 if ($filter_categorie ===
false) {
1256 while ($obj = $this->db->fetch_object($resql)) {
1258 $fields_label = explode(
'|', $InfoFieldList[1]);
1259 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1260 if (is_array($fields_label) && count($fields_label) > 1) {
1261 foreach ($fields_label as $field_toshow) {
1263 if (!empty($obj->$field_toshow)) {
1264 $translabel = $langs->trans($obj->$field_toshow);
1266 if ($translabel != $field_toshow) {
1267 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1269 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1274 if (!empty($obj->{$InfoFieldList[1]})) {
1275 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1277 if ($translabel != $obj->{$InfoFieldList[1]}) {
1278 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1280 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1286 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1289 while ($obj = $this->db->fetch_object($resql)) {
1290 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1292 $c->fetch($obj->rowid);
1293 $ways = $c->print_all_ways();
1294 foreach ($ways as $way) {
1295 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1300 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1302 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1304 } elseif ($type ==
'link') {
1307 $param_list = array_keys($param[
'options']);
1309 $InfoFieldList = explode(
":", $param_list[0]);
1310 $classname = $InfoFieldList[0];
1311 $classpath = $InfoFieldList[1];
1312 if (!empty($classpath)) {
1314 if ($classname && class_exists($classname)) {
1315 $object =
new $classname($this->db);
1316 $result =
$object->fetch($value);
1319 if (property_exists(
$object,
'label')) {
1321 } elseif (property_exists(
$object,
'libelle')) {
1323 } elseif (property_exists(
$object,
'nom')) {
1329 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1330 return 'Error bad setup of field';
1335 } elseif ($type ==
'password') {
1336 $value = preg_replace(
'/./i',
'*', $value);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage categories.
static getInstance()
Singleton method to create one instance of this object.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
dol_print_ip($ip, $mode=0)
Return an IP formatted to be shown on screen.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...