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];
391 if (!empty($classpath)) {
394 if ($classname && class_exists($classname)) {
395 $objecttmp =
new $classname($this->db);
398 $sharedentities =
getEntity(strtolower($classname));
399 $filter = str_replace(
400 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
401 array($conf->entity, $sharedentities),
406 if (!is_object($objecttmp)) {
407 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
408 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
411 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
414 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
439 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'')
441 global $conf, $langs, $hookmanager;
443 $prefixforautocompletemode = $objecttmp->element;
444 if ($prefixforautocompletemode ==
'societe') {
445 $prefixforautocompletemode =
'company';
447 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
449 if (in_array($objecttmp->element, array(
'adherent_type'))) {
450 $fieldstoshow =
't.libelle';
452 if (!empty($objecttmp->fields)) {
453 $tmpfieldstoshow =
'';
454 foreach ($objecttmp->fields as $key => $val) {
455 if (! (
int)
dol_eval($val[
'enabled'], 1, 1,
'1')) {
458 if (!empty($val[
'showoncombobox'])) {
459 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
462 if ($tmpfieldstoshow) {
463 $fieldstoshow = $tmpfieldstoshow;
465 } elseif (!in_array($objecttmp->element, array(
'adherent_type'))) {
467 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'showoncombobox' => 1);
470 if (empty($fieldstoshow)) {
471 if (isset($objecttmp->fields[
'ref'])) {
472 $fieldstoshow =
't.ref';
474 $langs->load(
"errors");
475 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
476 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
487 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $objecttmp->table_element .
" as t";
488 if (isset($objecttmp->ismultientitymanaged)) {
489 if (!is_numeric($objecttmp->ismultientitymanaged)) {
490 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
491 $sql .=
" INNER JOIN " . $this->db->prefix() . $tmparray[1] .
" as parenttable ON parenttable.rowid = t." . $tmparray[0];
497 'object' => $objecttmp,
498 'htmlname' => $htmlname,
500 'searchkey' => $searchkey
503 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
504 if (!empty($hookmanager->resPrint)) {
505 $sql .= $hookmanager->resPrint;
507 $sql .=
" WHERE 1=1";
508 if (isset($objecttmp->ismultientitymanaged)) {
509 if ($objecttmp->ismultientitymanaged == 1) {
510 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->table_element) .
")";
512 if (!is_numeric($objecttmp->ismultientitymanaged)) {
513 $sql .=
" AND parenttable.entity = t." . $tmparray[0];
516 if ($searchkey !=
'') {
524 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
528 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow,
"ASC");
531 $resql = $this->db->query($sql);
534 $out .=
'<select id="' . $htmlname .
'" class="' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
537 $textifempty =
' ';
540 if (!empty($conf->global->$confkeyforautocompletemode)) {
541 if ($showempty && !is_numeric($showempty)) {
542 $textifempty = $langs->trans($showempty);
544 $textifempty .= $langs->trans(
"All");
548 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
551 $num = $this->db->num_rows($resql);
555 $obj = $this->db->fetch_object($resql);
558 $tmparray = explode(
',', $fieldstoshow);
559 $oldvalueforshowoncombobox = 0;
560 foreach ($tmparray as $key => $val) {
561 $val = preg_replace(
'/t\./',
'', $val);
562 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
563 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
564 $label .= $obj->$val;
565 $labelhtml .= $obj->$val;
567 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
569 if (empty($outputmode)) {
570 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
571 $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>';
573 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
576 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
580 if (($i % 10) == 0) {
586 $out .=
'</select>' .
"\n";
591 $this->result = array(
'nbofelement' => $num);
613 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
615 global $conf, $langs;
620 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
622 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
623 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
625 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
626 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
628 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
629 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
631 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
632 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
634 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
635 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
637 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
638 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
640 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
641 $param[
'options'] = array();
644 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
645 $param[
'options'] = array();
647 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
648 $param[
'options'] = array();
651 $param[
'options'] = array();
652 $type = $val[
'type'];
656 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
657 $param[
'options'] = $val[
'arrayofkeyval'];
658 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
662 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
663 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
665 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
666 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
670 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
675 if (!preg_match(
'/^search_/', $keyprefix)) {
676 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
683 if (empty($morecss) && !empty($val[
'css'])) {
684 $morecss = $val[
'css'];
687 $htmlName = $keyprefix . $key . $keysuffix;
696 $dateArr = explode(
' ', $value);
697 if (count($dateArr) > 0) {
698 $valueDate = $dateArr[0];
699 if (isset($dateArr[1])) {
700 $valueTime = $dateArr[1];
703 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
705 if ($type ==
'datetime') {
707 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
717 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
734 if (!empty($value)) {
735 $value =
price($value);
737 $addInputLabel =
' ' . $langs->getCurrencySymbol($conf->currency);
738 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
742 if (!empty($value)) {
743 $value =
price($value);
745 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
749 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
753 foreach ($param[
'options'] as $keyopt => $valopt) {
754 $htmlId = $htmlName .
'_' . $keyopt;
755 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
756 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
761 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
762 if ($default ==
'' || $notNull != 1) {
763 $out .=
'<option value="0"> </option>';
765 foreach ($param[
'options'] as $keyb => $valb) {
769 if (strpos($valb,
"|") !==
false) {
770 list($valb, $parent) = explode(
'|', $valb);
772 $out .=
'<option value="' . $keyb .
'"';
773 $out .= (((string) $value == $keyb) ?
' selected' :
'');
774 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
775 $out .=
'>' . $valb .
'</option>';
780 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
782 $param_list = array_keys($param[
'options']);
783 $InfoFieldList = explode(
":", $param_list[0]);
793 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
795 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
796 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
797 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
799 $keyList = $InfoFieldList[2] .
' as rowid';
802 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
803 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
804 $keyList .=
', ' . $parentField;
807 $filter_categorie =
false;
808 if (count($InfoFieldList) > 5) {
809 if ($InfoFieldList[0] ==
'categorie') {
810 $filter_categorie =
true;
814 if ($filter_categorie ===
false) {
815 $fields_label = explode(
'|', $InfoFieldList[1]);
816 if (is_array($fields_label)) {
818 $keyList .= implode(
', ', $fields_label);
822 $sql =
"SELECT " . $keyList;
823 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
824 if (!empty($InfoFieldList[4])) {
826 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
827 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
831 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
834 if (strpos($InfoFieldList[4],
'extra') !==
false) {
835 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
836 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
838 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
841 $sqlwhere .=
' WHERE 1=1';
844 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
845 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
850 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
852 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
853 $resql = $this->db->query($sql);
855 $out .=
'<option value="0"> </option>';
856 $num = $this->db->num_rows($resql);
860 $obj = $this->db->fetch_object($resql);
864 $fields_label = explode(
'|', $InfoFieldList[1]);
865 if (count($fields_label) > 1) {
867 foreach ($fields_label as $field_toshow) {
868 $labeltoshow .= $obj->$field_toshow .
' ';
871 $labeltoshow = $obj->{$InfoFieldList[1]};
873 $labeltoshow =
dol_trunc($labeltoshow, 45);
875 if ($value == $obj->rowid) {
876 foreach ($fields_label as $field_toshow) {
877 $translabel = $langs->trans($obj->$field_toshow);
878 if ($translabel != $obj->$field_toshow) {
879 $labeltoshow =
dol_trunc($translabel) .
' ';
881 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
884 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
887 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
888 if ($translabel != $obj->{$InfoFieldList[1]}) {
889 $labeltoshow =
dol_trunc($translabel, 18);
891 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
894 if (empty($labeltoshow)) {
895 $labeltoshow =
'(not defined)';
897 if ($value == $obj->rowid) {
898 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
901 if (!empty($InfoFieldList[3]) && $parentField) {
902 $parent = $parentName .
':' . $obj->{$parentField};
906 $out .=
'<option value="' . $obj->rowid .
'"';
907 $out .= ($value == $obj->rowid ?
' selected' :
'');
908 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
909 $out .=
'>' . $labeltoshow .
'</option>';
914 $this->db->free($resql);
916 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
919 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
920 $categorytype = $InfoFieldList[5];
921 if (is_numeric($categorytype)) {
922 $categorytype = Categorie::$MAP_ID_TO_CODE[$categorytype];
924 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
925 $out .=
'<option value="0"> </option>';
926 foreach ($data as $data_key => $data_value) {
927 $out .=
'<option value="' . $data_key .
'"';
928 $out .= ($value == $data_key ?
' selected' :
'');
929 $out .=
'>' . $data_value .
'</option>';
936 $param_list = array_keys($param[
'options']);
937 $showempty = (($required && $default !=
'') ? 0 : 1);
939 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
944 if (!empty($hidden)) {
945 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
968 global $conf, $langs;
970 $label = empty($val[
'label']) ?
'' : $val[
'label'];
971 $type = empty($val[
'type']) ?
'' : $val[
'type'];
972 $css = empty($val[
'css']) ?
'' : $val[
'css'];
973 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
977 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
980 } elseif (preg_match(
'/varchar/', $type)) {
983 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
984 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
986 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
990 $default = empty($val[
'default']) ?
'' : $val[
'default'];
991 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
992 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
993 $required = empty($val[
'required']) ?
'' : $val[
'required'];
995 $param[
'options'] = array();
997 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
998 $param[
'options'] = $val[
'arrayofkeyval'];
1000 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1002 $stringforoptions = $reg[1] .
':' . $reg[2];
1003 if ($reg[1] ==
'User') {
1004 $stringforoptions .=
':-1';
1006 $param[
'options'] = array($stringforoptions => $stringforoptions);
1007 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1008 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
1010 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1011 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
1013 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
1014 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
1016 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
1017 $param[
'options'] = array($reg[1] =>
'N');
1021 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
1022 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
1023 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
1024 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
1034 $value = (string)
dol_eval($computed, 1, 0,
'2');
1041 if (in_array($key, array(
'rowid',
'ref'))) {
1042 if (property_exists(
$object,
'ref')) {
1044 } elseif (property_exists(
$object,
'id')) {
1049 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
1050 $value =
$object->getLibStatut(3);
1054 } elseif (is_array($value)) {
1057 if ($type ==
'array') {
1058 $value = implode(
'<br>', $value);
1060 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
1065 } elseif ($type ==
'date') {
1066 if (!empty($value)) {
1071 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
1072 if (!empty($value)) {
1077 } elseif ($type ==
'duration') {
1078 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
1079 if (!is_null($value) && $value !==
'') {
1082 } elseif ($type ==
'double' || $type ==
'real') {
1083 if (!is_null($value) && $value !==
'') {
1084 $value =
price($value);
1086 } elseif ($type ==
'boolean') {
1088 if (!empty($value)) {
1089 $checked =
' checked ';
1091 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
1092 } elseif ($type ==
'mail' || $type ==
'email') {
1094 } elseif ($type ==
'url') {
1096 } elseif ($type ==
'phone') {
1098 } elseif ($type ==
'ip') {
1100 } elseif ($type ==
'price') {
1101 if (!is_null($value) && $value !==
'') {
1102 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
1104 } elseif ($type ==
'select') {
1105 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
1106 } elseif ($type ==
'sellist') {
1107 $param_list = array_keys($param[
'options']);
1108 $InfoFieldList = explode(
":", $param_list[0]);
1110 $selectkey =
"rowid";
1113 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1114 $selectkey = $InfoFieldList[2];
1115 $keyList = $InfoFieldList[2] .
' as rowid';
1118 $fields_label = explode(
'|', $InfoFieldList[1]);
1119 if (is_array($fields_label)) {
1121 $keyList .= implode(
', ', $fields_label);
1124 $filter_categorie =
false;
1125 if (count($InfoFieldList) > 5) {
1126 if ($InfoFieldList[0] ==
'categorie') {
1127 $filter_categorie =
true;
1131 $sql =
"SELECT " . $keyList;
1132 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1133 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1136 if ($selectkey ==
'rowid' && empty($value)) {
1137 $sql .=
" WHERE " . $selectkey .
" = 0";
1138 } elseif ($selectkey ==
'rowid') {
1139 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
1141 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
1144 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
1145 $resql = $this->db->query($sql);
1147 if ($filter_categorie ===
false) {
1149 $numrows = $this->db->num_rows($resql);
1151 $obj = $this->db->fetch_object($resql);
1154 $fields_label = explode(
'|', $InfoFieldList[1]);
1156 if (is_array($fields_label) && count($fields_label) > 1) {
1157 foreach ($fields_label as $field_toshow) {
1159 if (!empty($obj->$field_toshow)) {
1160 $translabel = $langs->trans($obj->$field_toshow);
1162 if ($translabel != $field_toshow) {
1163 $value .=
dol_trunc($translabel, 18) .
' ';
1165 $value .= $obj->$field_toshow .
' ';
1170 if (!empty($obj->{$InfoFieldList[1]})) {
1171 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1173 if ($translabel != $obj->{$InfoFieldList[1]}) {
1176 $value = $obj->{$InfoFieldList[1]};
1181 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1184 $obj = $this->db->fetch_object($resql);
1186 $c->fetch($obj->rowid);
1187 $ways = $c->print_all_ways();
1188 foreach ($ways as $way) {
1189 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1191 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1194 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1196 } elseif ($type ==
'radio') {
1197 $value = $param[
'options'][$value];
1198 } elseif ($type ==
'checkbox') {
1199 $value_arr = explode(
',', $value);
1201 if (is_array($value_arr) && count($value_arr) > 0) {
1203 foreach ($value_arr as $valueval) {
1204 if (!empty($valueval)) {
1205 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1208 if (!empty($toprint)) {
1209 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1212 } elseif ($type ==
'chkbxlst') {
1213 $value_arr = explode(
',', $value);
1215 $param_list = array_keys($param[
'options']);
1216 $InfoFieldList = explode(
":", $param_list[0]);
1218 $selectkey =
"rowid";
1221 if (count($InfoFieldList) >= 3) {
1222 $selectkey = $InfoFieldList[2];
1223 $keyList = $InfoFieldList[2] .
' as rowid';
1226 $fields_label = explode(
'|', $InfoFieldList[1]);
1227 if (is_array($fields_label)) {
1229 $keyList .= implode(
', ', $fields_label);
1232 $filter_categorie =
false;
1233 if (count($InfoFieldList) > 5) {
1234 if ($InfoFieldList[0] ==
'categorie') {
1235 $filter_categorie =
true;
1239 $sql =
"SELECT " . $keyList;
1240 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1241 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1247 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1248 $resql = $this->db->query($sql);
1250 if ($filter_categorie ===
false) {
1253 while ($obj = $this->db->fetch_object($resql)) {
1255 $fields_label = explode(
'|', $InfoFieldList[1]);
1256 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1257 if (is_array($fields_label) && count($fields_label) > 1) {
1258 foreach ($fields_label as $field_toshow) {
1260 if (!empty($obj->$field_toshow)) {
1261 $translabel = $langs->trans($obj->$field_toshow);
1263 if ($translabel != $field_toshow) {
1264 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1266 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1271 if (!empty($obj->{$InfoFieldList[1]})) {
1272 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1274 if ($translabel != $obj->{$InfoFieldList[1]}) {
1275 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1277 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1283 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1286 while ($obj = $this->db->fetch_object($resql)) {
1287 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1289 $c->fetch($obj->rowid);
1290 $ways = $c->print_all_ways();
1291 foreach ($ways as $way) {
1292 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1297 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1299 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1301 } elseif ($type ==
'link') {
1304 $param_list = array_keys($param[
'options']);
1306 $InfoFieldList = explode(
":", $param_list[0]);
1307 $classname = $InfoFieldList[0];
1308 $classpath = $InfoFieldList[1];
1309 if (!empty($classpath)) {
1311 if ($classname && class_exists($classname)) {
1312 $object =
new $classname($this->db);
1313 $result =
$object->fetch($value);
1316 if (property_exists(
$object,
'label')) {
1318 } elseif (property_exists(
$object,
'libelle')) {
1320 } elseif (property_exists(
$object,
'nom')) {
1326 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1327 return 'Error bad setup of field';
1332 } elseif ($type ==
'password') {
1333 $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...