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);
362 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $disabled = 0, $selected_input_value =
'', $objectfield =
'')
372 $InfoFieldList = explode(
":", $objectdesc, 4);
373 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
375 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
376 $InfoFieldList[4] = $reg[1];
378 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
380 $classname = $InfoFieldList[0];
381 $classpath = $InfoFieldList[1];
382 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
383 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
385 if (!empty($classpath)) {
388 if ($classname && class_exists($classname)) {
389 $objecttmp =
new $classname($this->db);
392 $sharedentities =
getEntity(strtolower($classname));
393 $filter = str_replace(
394 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
395 array($conf->entity, $sharedentities),
400 if (!is_object($objecttmp)) {
401 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
402 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
405 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
408 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
433 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'')
435 global $conf, $langs, $hookmanager;
437 $prefixforautocompletemode = $objecttmp->element;
438 if ($prefixforautocompletemode ==
'societe') {
439 $prefixforautocompletemode =
'company';
441 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
443 if (in_array($objecttmp->element, array(
'adherent_type'))) {
444 $fieldstoshow =
't.libelle';
446 if (!empty($objecttmp->fields)) {
447 $tmpfieldstoshow =
'';
448 foreach ($objecttmp->fields as $key => $val) {
449 if (! (
int)
dol_eval($val[
'enabled'], 1, 1,
'1')) {
452 if (!empty($val[
'showoncombobox'])) {
453 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
456 if ($tmpfieldstoshow) {
457 $fieldstoshow = $tmpfieldstoshow;
459 } elseif (!in_array($objecttmp->element, array(
'adherent_type'))) {
461 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'showoncombobox' => 1);
464 if (empty($fieldstoshow)) {
465 if (isset($objecttmp->fields[
'ref'])) {
466 $fieldstoshow =
't.ref';
468 $langs->load(
"errors");
469 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
470 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
481 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $objecttmp->table_element .
" as t";
482 if (isset($objecttmp->ismultientitymanaged)) {
483 if (!is_numeric($objecttmp->ismultientitymanaged)) {
484 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
485 $sql .=
" INNER JOIN " . $this->db->prefix() . $tmparray[1] .
" as parenttable ON parenttable.rowid = t." . $tmparray[0];
491 'object' => $objecttmp,
492 'htmlname' => $htmlname,
494 'searchkey' => $searchkey
497 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
498 if (!empty($hookmanager->resPrint)) {
499 $sql .= $hookmanager->resPrint;
501 $sql .=
" WHERE 1=1";
502 if (isset($objecttmp->ismultientitymanaged)) {
503 if ($objecttmp->ismultientitymanaged == 1) {
504 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->table_element) .
")";
506 if (!is_numeric($objecttmp->ismultientitymanaged)) {
507 $sql .=
" AND parenttable.entity = t." . $tmparray[0];
510 if ($searchkey !=
'') {
518 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
522 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow,
"ASC");
525 $resql = $this->db->query($sql);
528 $out .=
'<select id="' . $htmlname .
'" class="' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
531 $textifempty =
' ';
534 if (!empty($conf->global->$confkeyforautocompletemode)) {
535 if ($showempty && !is_numeric($showempty)) {
536 $textifempty = $langs->trans($showempty);
538 $textifempty .= $langs->trans(
"All");
542 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
545 $num = $this->db->num_rows($resql);
549 $obj = $this->db->fetch_object($resql);
552 $tmparray = explode(
',', $fieldstoshow);
553 $oldvalueforshowoncombobox = 0;
554 foreach ($tmparray as $key => $val) {
555 $val = preg_replace(
'/t\./',
'', $val);
556 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
557 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
558 $label .= $obj->$val;
559 $labelhtml .= $obj->$val;
561 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
563 if (empty($outputmode)) {
564 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
565 $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>';
567 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
570 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
574 if (($i % 10) == 0) {
580 $out .=
'</select>' .
"\n";
585 $this->result = array(
'nbofelement' => $num);
607 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
609 global $conf, $langs;
614 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
616 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
617 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
619 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
620 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
622 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
623 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
625 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
626 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
628 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
629 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
631 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
632 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
634 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
635 $param[
'options'] = array();
638 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
639 $param[
'options'] = array();
641 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
642 $param[
'options'] = array();
645 $param[
'options'] = array();
646 $type = $val[
'type'];
650 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
651 $param[
'options'] = $val[
'arrayofkeyval'];
652 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
656 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
657 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
659 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
660 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
664 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
669 if (!preg_match(
'/^search_/', $keyprefix)) {
670 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
677 if (empty($morecss) && !empty($val[
'css'])) {
678 $morecss = $val[
'css'];
681 $htmlName = $keyprefix . $key . $keysuffix;
690 $dateArr = explode(
' ', $value);
691 if (count($dateArr) > 0) {
692 $valueDate = $dateArr[0];
693 if (isset($dateArr[1])) {
694 $valueTime = $dateArr[1];
697 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
699 if ($type ==
'datetime') {
701 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
711 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
728 if (!empty($value)) {
729 $value =
price($value);
731 $addInputLabel =
' ' . $langs->getCurrencySymbol($conf->currency);
732 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
736 if (!empty($value)) {
737 $value =
price($value);
739 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
743 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
747 foreach ($param[
'options'] as $keyopt => $valopt) {
748 $htmlId = $htmlName .
'_' . $keyopt;
749 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
750 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
755 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
756 if ($default ==
'' || $notNull != 1) {
757 $out .=
'<option value="0"> </option>';
759 foreach ($param[
'options'] as $keyb => $valb) {
763 if (strpos($valb,
"|") !==
false) {
764 list($valb, $parent) = explode(
'|', $valb);
766 $out .=
'<option value="' . $keyb .
'"';
767 $out .= (((string) $value == $keyb) ?
' selected' :
'');
768 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
769 $out .=
'>' . $valb .
'</option>';
774 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
776 $param_list = array_keys($param[
'options']);
777 $InfoFieldList = explode(
":", $param_list[0]);
787 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
789 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
790 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
791 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
793 $keyList = $InfoFieldList[2] .
' as rowid';
796 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
797 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
798 $keyList .=
', ' . $parentField;
801 $filter_categorie =
false;
802 if (count($InfoFieldList) > 5) {
803 if ($InfoFieldList[0] ==
'categorie') {
804 $filter_categorie =
true;
808 if ($filter_categorie ===
false) {
809 $fields_label = explode(
'|', $InfoFieldList[1]);
810 if (is_array($fields_label)) {
812 $keyList .= implode(
', ', $fields_label);
816 $sql =
"SELECT " . $keyList;
817 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
818 if (!empty($InfoFieldList[4])) {
820 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
821 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
825 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
828 if (strpos($InfoFieldList[4],
'extra') !==
false) {
829 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
830 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
832 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
835 $sqlwhere .=
' WHERE 1=1';
838 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
839 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
844 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
846 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
847 $resql = $this->db->query($sql);
849 $out .=
'<option value="0"> </option>';
850 $num = $this->db->num_rows($resql);
854 $obj = $this->db->fetch_object($resql);
858 $fields_label = explode(
'|', $InfoFieldList[1]);
859 if (count($fields_label) > 1) {
861 foreach ($fields_label as $field_toshow) {
862 $labeltoshow .= $obj->$field_toshow .
' ';
865 $labeltoshow = $obj->{$InfoFieldList[1]};
867 $labeltoshow =
dol_trunc($labeltoshow, 45);
869 if ($value == $obj->rowid) {
870 foreach ($fields_label as $field_toshow) {
871 $translabel = $langs->trans($obj->$field_toshow);
872 if ($translabel != $obj->$field_toshow) {
873 $labeltoshow =
dol_trunc($translabel) .
' ';
875 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
878 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
881 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
882 if ($translabel != $obj->{$InfoFieldList[1]}) {
883 $labeltoshow =
dol_trunc($translabel, 18);
885 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
888 if (empty($labeltoshow)) {
889 $labeltoshow =
'(not defined)';
891 if ($value == $obj->rowid) {
892 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
895 if (!empty($InfoFieldList[3]) && $parentField) {
896 $parent = $parentName .
':' . $obj->{$parentField};
900 $out .=
'<option value="' . $obj->rowid .
'"';
901 $out .= ($value == $obj->rowid ?
' selected' :
'');
902 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
903 $out .=
'>' . $labeltoshow .
'</option>';
908 $this->db->free($resql);
910 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
913 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
914 $categorytype = $InfoFieldList[5];
915 if (is_numeric($categorytype)) {
916 $categorytype = Categorie::$MAP_ID_TO_CODE[$categorytype];
918 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
919 $out .=
'<option value="0"> </option>';
920 foreach ($data as $data_key => $data_value) {
921 $out .=
'<option value="' . $data_key .
'"';
922 $out .= ($value == $data_key ?
' selected' :
'');
923 $out .=
'>' . $data_value .
'</option>';
930 $param_list = array_keys($param[
'options']);
931 $showempty = (($required && $default !=
'') ? 0 : 1);
933 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
938 if (!empty($hidden)) {
939 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
962 global $conf, $langs;
964 $label = empty($val[
'label']) ?
'' : $val[
'label'];
965 $type = empty($val[
'type']) ?
'' : $val[
'type'];
966 $css = empty($val[
'css']) ?
'' : $val[
'css'];
967 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
971 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
974 } elseif (preg_match(
'/varchar/', $type)) {
977 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
978 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
980 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
984 $default = empty($val[
'default']) ?
'' : $val[
'default'];
985 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
986 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
987 $required = empty($val[
'required']) ?
'' : $val[
'required'];
989 $param[
'options'] = array();
991 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
992 $param[
'options'] = $val[
'arrayofkeyval'];
994 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
996 $stringforoptions = $reg[1] .
':' . $reg[2];
997 if ($reg[1] ==
'User') {
998 $stringforoptions .=
':-1';
1000 $param[
'options'] = array($stringforoptions => $stringforoptions);
1001 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1002 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
1004 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
1005 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
1007 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
1008 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
1010 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
1011 $param[
'options'] = array($reg[1] =>
'N');
1015 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
1016 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
1017 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
1018 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
1028 $value = (string)
dol_eval($computed, 1, 0,
'2');
1035 if (in_array($key, array(
'rowid',
'ref'))) {
1036 if (property_exists(
$object,
'ref')) {
1038 } elseif (property_exists(
$object,
'id')) {
1043 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
1044 $value =
$object->getLibStatut(3);
1048 } elseif (is_array($value)) {
1051 if ($type ==
'array') {
1052 $value = implode(
'<br>', $value);
1054 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
1059 } elseif ($type ==
'date') {
1060 if (!empty($value)) {
1065 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
1066 if (!empty($value)) {
1071 } elseif ($type ==
'duration') {
1072 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
1073 if (!is_null($value) && $value !==
'') {
1076 } elseif ($type ==
'double' || $type ==
'real') {
1077 if (!is_null($value) && $value !==
'') {
1078 $value =
price($value);
1080 } elseif ($type ==
'boolean') {
1082 if (!empty($value)) {
1083 $checked =
' checked ';
1085 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
1086 } elseif ($type ==
'mail' || $type ==
'email') {
1088 } elseif ($type ==
'url') {
1090 } elseif ($type ==
'phone') {
1092 } elseif ($type ==
'ip') {
1094 } elseif ($type ==
'price') {
1095 if (!is_null($value) && $value !==
'') {
1096 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
1098 } elseif ($type ==
'select') {
1099 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
1100 } elseif ($type ==
'sellist') {
1101 $param_list = array_keys($param[
'options']);
1102 $InfoFieldList = explode(
":", $param_list[0]);
1104 $selectkey =
"rowid";
1107 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1108 $selectkey = $InfoFieldList[2];
1109 $keyList = $InfoFieldList[2] .
' as rowid';
1112 $fields_label = explode(
'|', $InfoFieldList[1]);
1113 if (is_array($fields_label)) {
1115 $keyList .= implode(
', ', $fields_label);
1118 $filter_categorie =
false;
1119 if (count($InfoFieldList) > 5) {
1120 if ($InfoFieldList[0] ==
'categorie') {
1121 $filter_categorie =
true;
1125 $sql =
"SELECT " . $keyList;
1126 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1127 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1130 if ($selectkey ==
'rowid' && empty($value)) {
1131 $sql .=
" WHERE " . $selectkey .
" = 0";
1132 } elseif ($selectkey ==
'rowid') {
1133 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
1135 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
1138 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
1139 $resql = $this->db->query($sql);
1141 if ($filter_categorie ===
false) {
1143 $numrows = $this->db->num_rows($resql);
1145 $obj = $this->db->fetch_object($resql);
1148 $fields_label = explode(
'|', $InfoFieldList[1]);
1150 if (is_array($fields_label) && count($fields_label) > 1) {
1151 foreach ($fields_label as $field_toshow) {
1153 if (!empty($obj->$field_toshow)) {
1154 $translabel = $langs->trans($obj->$field_toshow);
1156 if ($translabel != $field_toshow) {
1157 $value .=
dol_trunc($translabel, 18) .
' ';
1159 $value .= $obj->$field_toshow .
' ';
1164 if (!empty($obj->{$InfoFieldList[1]})) {
1165 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1167 if ($translabel != $obj->{$InfoFieldList[1]}) {
1170 $value = $obj->{$InfoFieldList[1]};
1175 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1178 $obj = $this->db->fetch_object($resql);
1180 $c->fetch($obj->rowid);
1181 $ways = $c->print_all_ways();
1182 foreach ($ways as $way) {
1183 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1185 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1188 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1190 } elseif ($type ==
'radio') {
1191 $value = $param[
'options'][$value];
1192 } elseif ($type ==
'checkbox') {
1193 $value_arr = explode(
',', $value);
1195 if (is_array($value_arr) && count($value_arr) > 0) {
1197 foreach ($value_arr as $valueval) {
1198 if (!empty($valueval)) {
1199 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1202 if (!empty($toprint)) {
1203 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1206 } elseif ($type ==
'chkbxlst') {
1207 $value_arr = explode(
',', $value);
1209 $param_list = array_keys($param[
'options']);
1210 $InfoFieldList = explode(
":", $param_list[0]);
1212 $selectkey =
"rowid";
1215 if (count($InfoFieldList) >= 3) {
1216 $selectkey = $InfoFieldList[2];
1217 $keyList = $InfoFieldList[2] .
' as rowid';
1220 $fields_label = explode(
'|', $InfoFieldList[1]);
1221 if (is_array($fields_label)) {
1223 $keyList .= implode(
', ', $fields_label);
1226 $filter_categorie =
false;
1227 if (count($InfoFieldList) > 5) {
1228 if ($InfoFieldList[0] ==
'categorie') {
1229 $filter_categorie =
true;
1233 $sql =
"SELECT " . $keyList;
1234 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1235 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1241 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1242 $resql = $this->db->query($sql);
1244 if ($filter_categorie ===
false) {
1247 while ($obj = $this->db->fetch_object($resql)) {
1249 $fields_label = explode(
'|', $InfoFieldList[1]);
1250 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1251 if (is_array($fields_label) && count($fields_label) > 1) {
1252 foreach ($fields_label as $field_toshow) {
1254 if (!empty($obj->$field_toshow)) {
1255 $translabel = $langs->trans($obj->$field_toshow);
1257 if ($translabel != $field_toshow) {
1258 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1260 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1265 if (!empty($obj->{$InfoFieldList[1]})) {
1266 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1268 if ($translabel != $obj->{$InfoFieldList[1]}) {
1269 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1271 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1277 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1280 while ($obj = $this->db->fetch_object($resql)) {
1281 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1283 $c->fetch($obj->rowid);
1284 $ways = $c->print_all_ways();
1285 foreach ($ways as $way) {
1286 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1291 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1293 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1295 } elseif ($type ==
'link') {
1298 $param_list = array_keys($param[
'options']);
1300 $InfoFieldList = explode(
":", $param_list[0]);
1301 $classname = $InfoFieldList[0];
1302 $classpath = $InfoFieldList[1];
1303 if (!empty($classpath)) {
1305 if ($classname && class_exists($classname)) {
1306 $object =
new $classname($this->db);
1307 $result =
$object->fetch($value);
1310 if (property_exists(
$object,
'label')) {
1312 } elseif (property_exists(
$object,
'libelle')) {
1314 } elseif (property_exists(
$object,
'nom')) {
1320 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1321 return 'Error bad setup of field';
1326 } elseif ($type ==
'password') {
1327 $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...