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[
'extensions'][$ext])) {
322 $this->infofiles[
'extensions'][$ext] = 1;
325 $this->infofiles[
'extensions'][$ext]++;
329 $url =
$context->getControllerUrl(
'document') .
'&modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($relativepath) .
'&soc_id=' .
$context->logged_thirdparty->id;
330 $tmpout .=
'<a href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="downloadlink"';
332 if (preg_match(
'/text/', $mime)) {
333 $tmpout .=
' target="_blank" rel="noopener noreferrer"';
336 $tmpout .=
img_mime($relativepath, $file[
"name"]);
337 $tmpout .= strtoupper($ext);
362 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
363 $out =
'<!-- html.formwebportal::getSignatureLink -->' .
"\n";
364 $url = getOnlineSignatureUrl(0, $modulepart,
$object->ref, 1,
$object);
366 $out .=
'<a target="_blank" rel="noopener noreferrer" href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="signaturelink">';
367 $out .=
'<i class="fa fa-file-signature"></i>';
368 $out .= $langs->trans(
"Sign");
394 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $disabled = 0, $selected_input_value =
'', $objectfield =
'')
404 $InfoFieldList = explode(
":", $objectdesc, 4);
405 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
407 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
408 $InfoFieldList[4] = $reg[1];
410 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
412 $classname = $InfoFieldList[0];
413 $classpath = $InfoFieldList[1];
414 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
415 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
417 if (!empty($classpath)) {
420 if ($classname && class_exists($classname)) {
421 $objecttmp =
new $classname($this->db);
424 $sharedentities =
getEntity(strtolower($classname));
425 $filter = str_replace(
426 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
427 array(
$conf->entity, $sharedentities),
432 if (!is_object($objecttmp)) {
433 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
434 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
437 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
440 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
465 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'')
467 global
$conf, $langs, $hookmanager;
469 $prefixforautocompletemode = $objecttmp->element;
470 if ($prefixforautocompletemode ==
'societe') {
471 $prefixforautocompletemode =
'company';
473 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
475 if (in_array($objecttmp->element, array(
'adherent_type'))) {
476 $fieldstoshow =
't.libelle';
478 if (!empty($objecttmp->fields)) {
479 $tmpfieldstoshow =
'';
480 foreach ($objecttmp->fields as $key => $val) {
481 if (! (
int)
dol_eval($val[
'enabled'], 1, 1,
'1')) {
484 if (!empty($val[
'showoncombobox'])) {
485 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
488 if ($tmpfieldstoshow) {
489 $fieldstoshow = $tmpfieldstoshow;
491 } elseif (!in_array($objecttmp->element, array(
'adherent_type'))) {
493 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'showoncombobox' => 1);
496 if (empty($fieldstoshow)) {
497 if (isset($objecttmp->fields[
'ref'])) {
498 $fieldstoshow =
't.ref';
500 $langs->load(
"errors");
501 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
502 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
513 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $objecttmp->table_element .
" as t";
514 if (isset($objecttmp->ismultientitymanaged)) {
515 if (!is_numeric($objecttmp->ismultientitymanaged)) {
516 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
517 $sql .=
" INNER JOIN " . $this->db->prefix() . $tmparray[1] .
" as parenttable ON parenttable.rowid = t." . $tmparray[0];
523 'object' => $objecttmp,
524 'htmlname' => $htmlname,
526 'searchkey' => $searchkey
529 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
530 if (!empty($hookmanager->resPrint)) {
531 $sql .= $hookmanager->resPrint;
533 $sql .=
" WHERE 1=1";
534 if (isset($objecttmp->ismultientitymanaged)) {
535 if ($objecttmp->ismultientitymanaged == 1) {
536 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->table_element) .
")";
538 if (!is_numeric($objecttmp->ismultientitymanaged)) {
539 $sql .=
" AND parenttable.entity = t." . $tmparray[0];
542 if ($searchkey !=
'') {
550 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
554 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow,
"ASC");
557 $resql = $this->db->query($sql);
560 $out .=
'<select id="' . $htmlname .
'" class="' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
563 $textifempty =
' ';
567 if ($showempty && !is_numeric($showempty)) {
568 $textifempty = $langs->trans($showempty);
570 $textifempty .= $langs->trans(
"All");
574 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
577 $num = $this->db->num_rows($resql);
581 $obj = $this->db->fetch_object($resql);
584 $tmparray = explode(
',', $fieldstoshow);
585 $oldvalueforshowoncombobox = 0;
586 foreach ($tmparray as $key => $val) {
587 $val = preg_replace(
'/t\./',
'', $val);
588 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
589 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
590 $label .= $obj->$val;
591 $labelhtml .= $obj->$val;
593 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
595 if (empty($outputmode)) {
596 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
597 $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>';
599 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
602 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
606 if (($i % 10) == 0) {
612 $out .=
'</select>' .
"\n";
617 $this->result = array(
'nbofelement' => $num);
639 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
641 global
$conf, $langs;
646 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
648 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
649 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
651 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
652 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
654 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
655 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
657 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
658 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
660 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
661 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
663 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
664 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
666 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
667 $param[
'options'] = array();
670 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
671 $param[
'options'] = array();
673 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
674 $param[
'options'] = array();
677 $param[
'options'] = array();
678 $type = $val[
'type'];
682 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
683 $param[
'options'] = $val[
'arrayofkeyval'];
684 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
688 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
689 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
691 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
692 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
696 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
701 if (!preg_match(
'/^search_/', $keyprefix)) {
702 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
709 if (empty($morecss) && !empty($val[
'css'])) {
710 $morecss = $val[
'css'];
713 $htmlName = $keyprefix . $key . $keysuffix;
722 $dateArr = explode(
' ', $value);
723 if (count($dateArr) > 0) {
724 $valueDate = $dateArr[0];
725 if (isset($dateArr[1])) {
726 $valueTime = $dateArr[1];
729 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
731 if ($type ==
'datetime') {
733 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
743 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
760 if (!empty($value)) {
761 $value =
price($value);
763 $addInputLabel =
' ' . $langs->getCurrencySymbol(
$conf->currency);
764 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
768 if (!empty($value)) {
769 $value =
price($value);
771 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
775 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
779 foreach ($param[
'options'] as $keyopt => $valopt) {
780 $htmlId = $htmlName .
'_' . $keyopt;
781 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
782 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
787 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
788 if ($default ==
'' || $notNull != 1) {
789 $out .=
'<option value="0"> </option>';
791 foreach ($param[
'options'] as $keyb => $valb) {
795 if (strpos($valb,
"|") !==
false) {
796 list($valb, $parent) = explode(
'|', $valb);
798 $out .=
'<option value="' . $keyb .
'"';
799 $out .= (((string) $value == $keyb) ?
' selected' :
'');
800 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
801 $out .=
'>' . $valb .
'</option>';
806 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
808 $param_list = array_keys($param[
'options']);
809 $InfoFieldList = explode(
":", $param_list[0]);
819 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
821 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
822 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
823 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
825 $keyList = $InfoFieldList[2] .
' as rowid';
828 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
829 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
830 $keyList .=
', ' . $parentField;
833 $filter_categorie =
false;
834 if (count($InfoFieldList) > 5) {
835 if ($InfoFieldList[0] ==
'categorie') {
836 $filter_categorie =
true;
840 if (!$filter_categorie) {
841 $fields_label = explode(
'|', $InfoFieldList[1]);
842 if (is_array($fields_label)) {
844 $keyList .= implode(
', ', $fields_label);
848 $sql =
"SELECT " . $keyList;
849 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
850 if (!empty($InfoFieldList[4])) {
852 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
853 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
857 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
860 if (strpos($InfoFieldList[4],
'extra') !==
false) {
861 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
862 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
864 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
867 $sqlwhere .=
' WHERE 1=1';
870 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
871 $sqlwhere .=
" AND entity = " . ((int)
$conf->entity);
876 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
878 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
879 $resql = $this->db->query($sql);
881 $out .=
'<option value="0"> </option>';
882 $num = $this->db->num_rows($resql);
886 $obj = $this->db->fetch_object($resql);
890 $fields_label = explode(
'|', $InfoFieldList[1]);
891 if (count($fields_label) > 1) {
893 foreach ($fields_label as $field_toshow) {
894 $labeltoshow .= $obj->$field_toshow .
' ';
897 $labeltoshow = $obj->{$InfoFieldList[1]};
899 $labeltoshow =
dol_trunc($labeltoshow, 45);
901 if ($value == $obj->rowid) {
902 foreach ($fields_label as $field_toshow) {
903 $translabel = $langs->trans($obj->$field_toshow);
904 if ($translabel != $obj->$field_toshow) {
905 $labeltoshow =
dol_trunc($translabel) .
' ';
907 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
910 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
913 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
914 if ($translabel != $obj->{$InfoFieldList[1]}) {
915 $labeltoshow =
dol_trunc($translabel, 18);
917 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
920 if (empty($labeltoshow)) {
921 $labeltoshow =
'(not defined)';
923 if ($value == $obj->rowid) {
924 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
927 if (!empty($InfoFieldList[3]) && $parentField) {
928 $parent = $parentName .
':' . $obj->{$parentField};
932 $out .=
'<option value="' . $obj->rowid .
'"';
933 $out .= ($value == $obj->rowid ?
' selected' :
'');
934 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
935 $out .=
'>' . $labeltoshow .
'</option>';
940 $this->db->free($resql);
942 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
945 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
946 $categorytype = $InfoFieldList[5];
947 if (is_numeric($categorytype)) {
948 $categorytype = Categorie::$MAP_ID_TO_CODE[(int) $categorytype];
950 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
951 $out .=
'<option value="0"> </option>';
952 foreach ($data as $data_key => $data_value) {
953 $out .=
'<option value="' . $data_key .
'"';
954 $out .= ($value == $data_key ?
' selected' :
'');
955 $out .=
'>' . $data_value .
'</option>';
962 $param_list = array_keys($param[
'options']);
963 $showempty = (($required && $default !=
'') ?
'0' :
'1');
965 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
970 if (!empty($hidden)) {
971 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
994 global
$conf, $langs;
996 $label = empty($val[
'label']) ?
'' : $val[
'label'];
997 $type = empty($val[
'type']) ?
'' : $val[
'type'];
998 $css = empty($val[
'css']) ?
'' : $val[
'css'];
999 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
1003 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
1006 } elseif (preg_match(
'/varchar/', $type)) {
1009 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1010 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
1012 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1016 $default = empty($val[
'default']) ?
'' : $val[
'default'];
1017 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
1018 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
1019 $required = empty($val[
'required']) ?
'' : $val[
'required'];
1021 $param[
'options'] = array();
1023 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1024 $param[
'options'] = $val[
'arrayofkeyval'];
1026 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
1028 $stringforoptions = $reg[1] .
':' . $reg[2];
1029 if ($reg[1] ==
'User') {
1030 $stringforoptions .=
':-1';
1032 $param[
'options'] = array($stringforoptions => $stringforoptions);
1033 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1034 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
1036 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1037 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
1039 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
1040 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
1042 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
1043 $param[
'options'] = array($reg[1] =>
'N');
1047 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
1048 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
1049 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
1050 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
1060 $value = (string)
dol_eval($computed, 1, 0,
'2');
1067 if (in_array($key, array(
'rowid',
'ref'))) {
1068 if (property_exists(
$object,
'ref')) {
1070 } elseif (property_exists(
$object,
'id')) {
1075 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
1076 $value =
$object->getLibStatut(3);
1080 } elseif (is_array($value)) {
1083 if ($type ==
'array') {
1084 $value = implode(
'<br>', $value);
1086 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
1091 } elseif ($type ==
'date') {
1092 if (!empty($value)) {
1097 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
1098 if (!empty($value)) {
1103 } elseif ($type ==
'duration') {
1104 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
1105 if (!is_null($value) && $value !==
'') {
1111 } elseif ($type ==
'double' || $type ==
'real') {
1112 if (!is_null($value) && $value !==
'') {
1113 $value =
price($value);
1118 } elseif ($type ==
'boolean') {
1120 if (!empty($value)) {
1121 $checked =
' checked ';
1123 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
1124 } elseif ($type ==
'mail' || $type ==
'email') {
1126 } elseif ($type ==
'url') {
1128 } elseif ($type ==
'phone') {
1130 } elseif ($type ==
'ip') {
1132 } elseif ($type ==
'price') {
1133 if (!is_null($value) && $value !==
'') {
1134 $value =
price($value, 0, $langs, 0, 0, -1,
$conf->currency);
1139 } elseif ($type ==
'select') {
1140 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
1141 } elseif ($type ==
'sellist') {
1142 $param_list = array_keys($param[
'options']);
1143 $InfoFieldList = explode(
":", $param_list[0]);
1145 $selectkey =
"rowid";
1148 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1149 $selectkey = $InfoFieldList[2];
1150 $keyList = $InfoFieldList[2] .
' as rowid';
1153 $fields_label = explode(
'|', $InfoFieldList[1]);
1154 if (is_array($fields_label)) {
1156 $keyList .= implode(
', ', $fields_label);
1159 $filter_categorie =
false;
1160 if (count($InfoFieldList) > 5) {
1161 if ($InfoFieldList[0] ==
'categorie') {
1162 $filter_categorie =
true;
1166 $sql =
"SELECT " . $keyList;
1167 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1168 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1171 if ($selectkey ==
'rowid' && empty($value)) {
1172 $sql .=
" WHERE " . $selectkey .
" = 0";
1173 } elseif ($selectkey ==
'rowid') {
1174 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
1176 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
1179 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
1180 $resql = $this->db->query($sql);
1182 if (!$filter_categorie) {
1184 $numrows = $this->db->num_rows($resql);
1186 $obj = $this->db->fetch_object($resql);
1189 $fields_label = explode(
'|', $InfoFieldList[1]);
1191 if (is_array($fields_label) && count($fields_label) > 1) {
1192 foreach ($fields_label as $field_toshow) {
1194 if (!empty($obj->$field_toshow)) {
1195 $translabel = $langs->trans($obj->$field_toshow);
1197 if ($translabel != $field_toshow) {
1198 $value .=
dol_trunc($translabel, 18) .
' ';
1200 $value .= $obj->$field_toshow .
' ';
1205 if (!empty($obj->{$InfoFieldList[1]})) {
1206 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1208 if ($translabel != $obj->{$InfoFieldList[1]}) {
1211 $value = $obj->{$InfoFieldList[1]};
1216 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1219 $obj = $this->db->fetch_object($resql);
1221 $c->fetch($obj->rowid);
1222 $ways = $c->print_all_ways();
1223 foreach ($ways as $way) {
1224 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1226 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1229 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1231 } elseif ($type ==
'radio') {
1232 $value = (string) $param[
'options'][$value];
1233 } elseif ($type ==
'checkbox') {
1234 $value_arr = explode(
',', $value);
1236 if (is_array($value_arr) && count($value_arr) > 0) {
1238 foreach ($value_arr as $valueval) {
1239 if (!empty($valueval)) {
1240 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1243 if (!empty($toprint)) {
1244 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1247 } elseif ($type ==
'chkbxlst') {
1248 $value_arr = explode(
',', $value);
1250 $param_list = array_keys($param[
'options']);
1251 $InfoFieldList = explode(
":", $param_list[0]);
1253 $selectkey =
"rowid";
1256 if (count($InfoFieldList) >= 3) {
1257 $selectkey = $InfoFieldList[2];
1258 $keyList = $InfoFieldList[2] .
' as rowid';
1261 $fields_label = explode(
'|', $InfoFieldList[1]);
1262 if (is_array($fields_label)) {
1264 $keyList .= implode(
', ', $fields_label);
1267 $filter_categorie =
false;
1268 if (count($InfoFieldList) > 5) {
1269 if ($InfoFieldList[0] ==
'categorie') {
1270 $filter_categorie =
true;
1274 $sql =
"SELECT " . $keyList;
1275 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1276 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1282 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1283 $resql = $this->db->query($sql);
1285 if (!$filter_categorie) {
1288 while ($obj = $this->db->fetch_object($resql)) {
1290 $fields_label = explode(
'|', $InfoFieldList[1]);
1291 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1292 if (is_array($fields_label) && count($fields_label) > 1) {
1293 foreach ($fields_label as $field_toshow) {
1295 if (!empty($obj->$field_toshow)) {
1296 $translabel = $langs->trans($obj->$field_toshow);
1298 if ($translabel != $field_toshow) {
1299 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1301 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1306 if (!empty($obj->{$InfoFieldList[1]})) {
1307 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1309 if ($translabel != $obj->{$InfoFieldList[1]}) {
1310 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1312 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1318 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1321 while ($obj = $this->db->fetch_object($resql)) {
1322 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1324 $c->fetch($obj->rowid);
1325 $ways = $c->print_all_ways();
1326 foreach ($ways as $way) {
1327 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1332 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1334 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1336 } elseif ($type ==
'link') {
1339 $param_list = array_keys($param[
'options']);
1341 $InfoFieldList = explode(
":", $param_list[0]);
1342 $classname = $InfoFieldList[0];
1343 $classpath = $InfoFieldList[1];
1344 if (!empty($classpath)) {
1346 if ($classname && class_exists($classname)) {
1347 $object =
new $classname($this->db);
1348 '@phan-var-force CommonObject $object';
1349 $result =
$object->fetch($value);
1352 if (property_exists(
$object,
'label')) {
1354 } elseif (property_exists(
$object,
'libelle')) {
1356 } elseif (property_exists(
$object,
'nom')) {
1362 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1363 return 'Error bad setup of field';
1368 } elseif ($type ==
'password') {
1369 $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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$context
@method int call_trigger(string $triggerName, User $user)