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 =
'')
109 if ($placeholder !=
'' && $value ==
'') {
111 $out .=
' type="text" placeholder="' . $placeholder .
'" onfocus="(this.type=\'date\')"';
113 $out .=
' type="date"';
115 $out .= ($morecss ?
' class="' . $morecss .
'"' :
'');
117 $out .=
' id="' .
$id .
'"';
119 $out .=
' name="' . $name .
'"';
120 $out .=
' value="' . $value .
'"';
121 $out .= ($moreparam ?
' ' . $moreparam :
'');
150 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)
155 $array = array_combine($array, $array);
160 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
161 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' class="' . ($morecss ?
' ' . $morecss :
'') .
'"';
162 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'"' . ($moreparam ?
' ' . $moreparam :
'');
167 if (!is_numeric($show_empty)) {
168 $textforempty = $show_empty;
170 $out .=
'<option value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
173 if (is_array($array)) {
176 foreach ($array as $key => $value) {
177 if (!is_array($value)) {
178 $array[$key] = $langs->trans($value);
180 $array[$key][
'label'] = $langs->trans($value[
'label']);
186 if ($sort ==
'ASC') {
188 } elseif ($sort ==
'DESC') {
192 foreach ($array as $key => $tmpvalue) {
193 if (is_array($tmpvalue)) {
194 $value = $tmpvalue[
'label'];
195 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
205 if ($value ==
'' || $value ==
'-') {
206 $selectOptionValue =
' ';
210 $out .=
'<option value="' . $key .
'"';
213 if (in_array($key,
$id) && !$disabled) {
218 if (
$id !=
'' && (
$id == $key || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
222 if (is_array($tmpvalue)) {
223 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
224 if (preg_match(
'/^data-/', $keyforvalue)) {
230 $out .= $selectOptionValue;
231 $out .=
"</option>\n";
253 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter =
'', $morecss =
'', $allfiles = 0)
255 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
264 $this->infofiles = array(
'nboffiles' => 0,
'extensions' => array(),
'files' => array());
269 if (isModEnabled(
'multicompany')) {
271 preg_match(
'/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir,
'/') .
'$/', $filedir, $regs);
272 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1);
277 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/');
279 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/') .
'\.';
281 $file_list =
dol_dir_list($filedir,
'files', 0, $filterforfilesearch,
'\.meta$|\.png$');
285 $out .=
'<!-- html.formwebportal::getDocumentsLink -->' .
"\n";
286 if (!empty($file_list)) {
292 foreach ($file_list as $file) {
294 if ($filter && !preg_match(
'/' . $filter .
'/i', $file[
"name"])) {
300 $relativepath = $file[
"name"];
302 $relativepath = $modulesubdir .
"/" . $file[
"name"];
305 if ($modulepart ==
'donation') {
306 $relativepath =
get_exdir($modulesubdir, 2, 0, 0,
null,
'donation') . $file[
"name"];
308 if ($modulepart ==
'export') {
309 $relativepath = $file[
"name"];
312 $this->infofiles[
'nboffiles']++;
313 $this->infofiles[
'files'][] = $file[
'fullname'];
314 $ext = pathinfo($file[
"name"], PATHINFO_EXTENSION);
315 if (empty($this->infofiles[$ext])) {
316 $this->infofiles[
'extensions'][$ext] = 1;
318 $this->infofiles[
'extensions'][$ext]++;
322 $url = $context->getControllerUrl(
'document') .
'&modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($relativepath) .
'&soc_id=' . $context->logged_thirdparty->id;
323 $tmpout .=
'<a href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="downloadlink"';
325 if (preg_match(
'/text/', $mime)) {
326 $tmpout .=
' target="_blank" rel="noopener noreferrer"';
329 $tmpout .=
img_mime($relativepath, $file[
"name"]);
330 $tmpout .= strtoupper($ext);
355 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
356 $out =
'<!-- html.formwebportal::getSignatureLink -->' .
"\n";
357 $url = getOnlineSignatureUrl(0, $modulepart,
$object->ref, 1,
$object);
359 $out .=
'<a target="_blank" rel="noopener noreferrer" href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="signaturelink">';
360 $out .=
'<i class="fa fa-file-signature"></i>';
361 $out .= $langs->trans(
"Sign");
387 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $disabled = 0, $selected_input_value =
'', $objectfield =
'')
397 $InfoFieldList = explode(
":", $objectdesc, 4);
398 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
400 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
401 $InfoFieldList[4] = $reg[1];
403 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
405 $classname = $InfoFieldList[0];
406 $classpath = $InfoFieldList[1];
407 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
408 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
410 if (!empty($classpath)) {
413 if ($classname && class_exists($classname)) {
414 $objecttmp =
new $classname($this->db);
417 $sharedentities =
getEntity(strtolower($classname));
418 $filter = str_replace(
419 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
420 array($conf->entity, $sharedentities),
425 if (!is_object($objecttmp)) {
426 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
427 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
430 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
433 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
458 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'')
460 global $conf, $langs, $hookmanager;
462 $prefixforautocompletemode = $objecttmp->element;
463 if ($prefixforautocompletemode ==
'societe') {
464 $prefixforautocompletemode =
'company';
466 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
468 if (in_array($objecttmp->element, array(
'adherent_type'))) {
469 $fieldstoshow =
't.libelle';
471 if (!empty($objecttmp->fields)) {
472 $tmpfieldstoshow =
'';
473 foreach ($objecttmp->fields as $key => $val) {
474 if (! (
int)
dol_eval($val[
'enabled'], 1, 1,
'1')) {
477 if (!empty($val[
'showoncombobox'])) {
478 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
481 if ($tmpfieldstoshow) {
482 $fieldstoshow = $tmpfieldstoshow;
484 } elseif (!in_array($objecttmp->element, array(
'adherent_type'))) {
486 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'showoncombobox' => 1);
489 if (empty($fieldstoshow)) {
490 if (isset($objecttmp->fields[
'ref'])) {
491 $fieldstoshow =
't.ref';
493 $langs->load(
"errors");
494 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
495 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
506 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $objecttmp->table_element .
" as t";
507 if (isset($objecttmp->ismultientitymanaged)) {
508 if (!is_numeric($objecttmp->ismultientitymanaged)) {
509 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
510 $sql .=
" INNER JOIN " . $this->db->prefix() . $tmparray[1] .
" as parenttable ON parenttable.rowid = t." . $tmparray[0];
516 'object' => $objecttmp,
517 'htmlname' => $htmlname,
519 'searchkey' => $searchkey
522 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
523 if (!empty($hookmanager->resPrint)) {
524 $sql .= $hookmanager->resPrint;
526 $sql .=
" WHERE 1=1";
527 if (isset($objecttmp->ismultientitymanaged)) {
528 if ($objecttmp->ismultientitymanaged == 1) {
529 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->table_element) .
")";
531 if (!is_numeric($objecttmp->ismultientitymanaged)) {
532 $sql .=
" AND parenttable.entity = t." . $tmparray[0];
535 if ($searchkey !=
'') {
543 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
547 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow,
"ASC");
550 $resql = $this->db->query($sql);
553 $out .=
'<select id="' . $htmlname .
'" class="' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
556 $textifempty =
' ';
560 if ($showempty && !is_numeric($showempty)) {
561 $textifempty = $langs->trans($showempty);
563 $textifempty .= $langs->trans(
"All");
567 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
570 $num = $this->db->num_rows($resql);
574 $obj = $this->db->fetch_object($resql);
577 $tmparray = explode(
',', $fieldstoshow);
578 $oldvalueforshowoncombobox = 0;
579 foreach ($tmparray as $key => $val) {
580 $val = preg_replace(
'/t\./',
'', $val);
581 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
582 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
583 $label .= $obj->$val;
584 $labelhtml .= $obj->$val;
586 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
588 if (empty($outputmode)) {
589 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
590 $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>';
592 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
595 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
599 if (($i % 10) == 0) {
605 $out .=
'</select>' .
"\n";
610 $this->result = array(
'nbofelement' => $num);
632 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
634 global $conf, $langs;
639 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
641 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
642 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
644 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
645 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
647 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
648 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
650 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
651 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
653 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
654 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
656 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
657 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
659 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
660 $param[
'options'] = array();
663 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
664 $param[
'options'] = array();
666 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
667 $param[
'options'] = array();
670 $param[
'options'] = array();
671 $type = $val[
'type'];
675 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
676 $param[
'options'] = $val[
'arrayofkeyval'];
677 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
681 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
682 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
684 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
685 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
689 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
694 if (!preg_match(
'/^search_/', $keyprefix)) {
695 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
702 if (empty($morecss) && !empty($val[
'css'])) {
703 $morecss = $val[
'css'];
706 $htmlName = $keyprefix . $key . $keysuffix;
715 $dateArr = explode(
' ', $value);
716 if (count($dateArr) > 0) {
717 $valueDate = $dateArr[0];
718 if (isset($dateArr[1])) {
719 $valueTime = $dateArr[1];
722 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
724 if ($type ==
'datetime') {
726 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
736 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
753 if (!empty($value)) {
754 $value =
price($value);
756 $addInputLabel =
' ' . $langs->getCurrencySymbol($conf->currency);
757 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
761 if (!empty($value)) {
762 $value =
price($value);
764 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
768 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
772 foreach ($param[
'options'] as $keyopt => $valopt) {
773 $htmlId = $htmlName .
'_' . $keyopt;
774 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
775 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
780 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
781 if ($default ==
'' || $notNull != 1) {
782 $out .=
'<option value="0"> </option>';
784 foreach ($param[
'options'] as $keyb => $valb) {
788 if (strpos($valb,
"|") !==
false) {
789 list($valb, $parent) = explode(
'|', $valb);
791 $out .=
'<option value="' . $keyb .
'"';
792 $out .= (((string) $value == $keyb) ?
' selected' :
'');
793 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
794 $out .=
'>' . $valb .
'</option>';
799 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
801 $param_list = array_keys($param[
'options']);
802 $InfoFieldList = explode(
":", $param_list[0]);
812 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
814 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
815 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
816 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
818 $keyList = $InfoFieldList[2] .
' as rowid';
821 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
822 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
823 $keyList .=
', ' . $parentField;
826 $filter_categorie =
false;
827 if (count($InfoFieldList) > 5) {
828 if ($InfoFieldList[0] ==
'categorie') {
829 $filter_categorie =
true;
833 if (!$filter_categorie) {
834 $fields_label = explode(
'|', $InfoFieldList[1]);
835 if (is_array($fields_label)) {
837 $keyList .= implode(
', ', $fields_label);
841 $sql =
"SELECT " . $keyList;
842 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
843 if (!empty($InfoFieldList[4])) {
845 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
846 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
850 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
853 if (strpos($InfoFieldList[4],
'extra') !==
false) {
854 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
855 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
857 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
860 $sqlwhere .=
' WHERE 1=1';
863 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
864 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
869 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
871 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
872 $resql = $this->db->query($sql);
874 $out .=
'<option value="0"> </option>';
875 $num = $this->db->num_rows($resql);
879 $obj = $this->db->fetch_object($resql);
883 $fields_label = explode(
'|', $InfoFieldList[1]);
884 if (count($fields_label) > 1) {
886 foreach ($fields_label as $field_toshow) {
887 $labeltoshow .= $obj->$field_toshow .
' ';
890 $labeltoshow = $obj->{$InfoFieldList[1]};
892 $labeltoshow =
dol_trunc($labeltoshow, 45);
894 if ($value == $obj->rowid) {
895 foreach ($fields_label as $field_toshow) {
896 $translabel = $langs->trans($obj->$field_toshow);
897 if ($translabel != $obj->$field_toshow) {
898 $labeltoshow =
dol_trunc($translabel) .
' ';
900 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
903 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
906 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
907 if ($translabel != $obj->{$InfoFieldList[1]}) {
908 $labeltoshow =
dol_trunc($translabel, 18);
910 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
913 if (empty($labeltoshow)) {
914 $labeltoshow =
'(not defined)';
916 if ($value == $obj->rowid) {
917 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
920 if (!empty($InfoFieldList[3]) && $parentField) {
921 $parent = $parentName .
':' . $obj->{$parentField};
925 $out .=
'<option value="' . $obj->rowid .
'"';
926 $out .= ($value == $obj->rowid ?
' selected' :
'');
927 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
928 $out .=
'>' . $labeltoshow .
'</option>';
933 $this->db->free($resql);
935 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
938 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
939 $categorytype = $InfoFieldList[5];
940 if (is_numeric($categorytype)) {
941 $categorytype = Categorie::$MAP_ID_TO_CODE[$categorytype];
943 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
944 $out .=
'<option value="0"> </option>';
945 foreach ($data as $data_key => $data_value) {
946 $out .=
'<option value="' . $data_key .
'"';
947 $out .= ($value == $data_key ?
' selected' :
'');
948 $out .=
'>' . $data_value .
'</option>';
955 $param_list = array_keys($param[
'options']);
956 $showempty = (($required && $default !=
'') ? 0 : 1);
958 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
963 if (!empty($hidden)) {
964 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
987 global $conf, $langs;
989 $label = empty($val[
'label']) ?
'' : $val[
'label'];
990 $type = empty($val[
'type']) ?
'' : $val[
'type'];
991 $css = empty($val[
'css']) ?
'' : $val[
'css'];
992 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
996 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
999 } elseif (preg_match(
'/varchar/', $type)) {
1002 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1003 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
1005 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1009 $default = empty($val[
'default']) ?
'' : $val[
'default'];
1010 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
1011 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
1012 $required = empty($val[
'required']) ?
'' : $val[
'required'];
1014 $param[
'options'] = array();
1016 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1017 $param[
'options'] = $val[
'arrayofkeyval'];
1019 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1021 $stringforoptions = $reg[1] .
':' . $reg[2];
1022 if ($reg[1] ==
'User') {
1023 $stringforoptions .=
':-1';
1025 $param[
'options'] = array($stringforoptions => $stringforoptions);
1026 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1027 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
1029 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1030 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
1032 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
1033 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
1035 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
1036 $param[
'options'] = array($reg[1] =>
'N');
1040 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
1041 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
1042 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
1043 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
1053 $value = (string)
dol_eval($computed, 1, 0,
'2');
1060 if (in_array($key, array(
'rowid',
'ref'))) {
1061 if (property_exists(
$object,
'ref')) {
1063 } elseif (property_exists(
$object,
'id')) {
1068 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
1069 $value =
$object->getLibStatut(3);
1073 } elseif (is_array($value)) {
1076 if ($type ==
'array') {
1077 $value = implode(
'<br>', $value);
1079 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
1084 } elseif ($type ==
'date') {
1085 if (!empty($value)) {
1090 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
1091 if (!empty($value)) {
1096 } elseif ($type ==
'duration') {
1097 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
1098 if (!is_null($value) && $value !==
'') {
1101 } elseif ($type ==
'double' || $type ==
'real') {
1102 if (!is_null($value) && $value !==
'') {
1103 $value =
price($value);
1105 } elseif ($type ==
'boolean') {
1107 if (!empty($value)) {
1108 $checked =
' checked ';
1110 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
1111 } elseif ($type ==
'mail' || $type ==
'email') {
1113 } elseif ($type ==
'url') {
1115 } elseif ($type ==
'phone') {
1117 } elseif ($type ==
'ip') {
1119 } elseif ($type ==
'price') {
1120 if (!is_null($value) && $value !==
'') {
1121 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
1123 } elseif ($type ==
'select') {
1124 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
1125 } elseif ($type ==
'sellist') {
1126 $param_list = array_keys($param[
'options']);
1127 $InfoFieldList = explode(
":", $param_list[0]);
1129 $selectkey =
"rowid";
1132 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1133 $selectkey = $InfoFieldList[2];
1134 $keyList = $InfoFieldList[2] .
' as rowid';
1137 $fields_label = explode(
'|', $InfoFieldList[1]);
1138 if (is_array($fields_label)) {
1140 $keyList .= implode(
', ', $fields_label);
1143 $filter_categorie =
false;
1144 if (count($InfoFieldList) > 5) {
1145 if ($InfoFieldList[0] ==
'categorie') {
1146 $filter_categorie =
true;
1150 $sql =
"SELECT " . $keyList;
1151 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1152 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1155 if ($selectkey ==
'rowid' && empty($value)) {
1156 $sql .=
" WHERE " . $selectkey .
" = 0";
1157 } elseif ($selectkey ==
'rowid') {
1158 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
1160 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
1163 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
1164 $resql = $this->db->query($sql);
1166 if (!$filter_categorie) {
1168 $numrows = $this->db->num_rows($resql);
1170 $obj = $this->db->fetch_object($resql);
1173 $fields_label = explode(
'|', $InfoFieldList[1]);
1175 if (is_array($fields_label) && count($fields_label) > 1) {
1176 foreach ($fields_label as $field_toshow) {
1178 if (!empty($obj->$field_toshow)) {
1179 $translabel = $langs->trans($obj->$field_toshow);
1181 if ($translabel != $field_toshow) {
1182 $value .=
dol_trunc($translabel, 18) .
' ';
1184 $value .= $obj->$field_toshow .
' ';
1189 if (!empty($obj->{$InfoFieldList[1]})) {
1190 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1192 if ($translabel != $obj->{$InfoFieldList[1]}) {
1195 $value = $obj->{$InfoFieldList[1]};
1200 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1203 $obj = $this->db->fetch_object($resql);
1205 $c->fetch($obj->rowid);
1206 $ways = $c->print_all_ways();
1207 foreach ($ways as $way) {
1208 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1210 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1213 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1215 } elseif ($type ==
'radio') {
1216 $value = $param[
'options'][$value];
1217 } elseif ($type ==
'checkbox') {
1218 $value_arr = explode(
',', $value);
1220 if (is_array($value_arr) && count($value_arr) > 0) {
1222 foreach ($value_arr as $valueval) {
1223 if (!empty($valueval)) {
1224 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1227 if (!empty($toprint)) {
1228 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1231 } elseif ($type ==
'chkbxlst') {
1232 $value_arr = explode(
',', $value);
1234 $param_list = array_keys($param[
'options']);
1235 $InfoFieldList = explode(
":", $param_list[0]);
1237 $selectkey =
"rowid";
1240 if (count($InfoFieldList) >= 3) {
1241 $selectkey = $InfoFieldList[2];
1242 $keyList = $InfoFieldList[2] .
' as rowid';
1245 $fields_label = explode(
'|', $InfoFieldList[1]);
1246 if (is_array($fields_label)) {
1248 $keyList .= implode(
', ', $fields_label);
1251 $filter_categorie =
false;
1252 if (count($InfoFieldList) > 5) {
1253 if ($InfoFieldList[0] ==
'categorie') {
1254 $filter_categorie =
true;
1258 $sql =
"SELECT " . $keyList;
1259 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1260 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1266 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1267 $resql = $this->db->query($sql);
1269 if (!$filter_categorie) {
1272 while ($obj = $this->db->fetch_object($resql)) {
1274 $fields_label = explode(
'|', $InfoFieldList[1]);
1275 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1276 if (is_array($fields_label) && count($fields_label) > 1) {
1277 foreach ($fields_label as $field_toshow) {
1279 if (!empty($obj->$field_toshow)) {
1280 $translabel = $langs->trans($obj->$field_toshow);
1282 if ($translabel != $field_toshow) {
1283 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1285 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1290 if (!empty($obj->{$InfoFieldList[1]})) {
1291 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1293 if ($translabel != $obj->{$InfoFieldList[1]}) {
1294 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1296 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1302 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1305 while ($obj = $this->db->fetch_object($resql)) {
1306 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1308 $c->fetch($obj->rowid);
1309 $ways = $c->print_all_ways();
1310 foreach ($ways as $way) {
1311 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1316 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1318 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1320 } elseif ($type ==
'link') {
1323 $param_list = array_keys($param[
'options']);
1325 $InfoFieldList = explode(
":", $param_list[0]);
1326 $classname = $InfoFieldList[0];
1327 $classpath = $InfoFieldList[1];
1328 if (!empty($classpath)) {
1330 if ($classname && class_exists($classname)) {
1331 $object =
new $classname($this->db);
1332 $result =
$object->fetch($value);
1335 if (property_exists(
$object,
'label')) {
1337 } elseif (property_exists(
$object,
'libelle')) {
1339 } elseif (property_exists(
$object,
'nom')) {
1345 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1346 return 'Error bad setup of field';
1351 } elseif ($type ==
'password') {
1352 $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_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_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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
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_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
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 a 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...