29require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
69 public function inputDate($name, $value =
'', $placeholder =
'',
$id =
'', $morecss =
'', $moreparam =
'')
94 $out = $this->
selectDate($value ===
'' ? -1 : $value, $name, 0, 0, 0,
"", 1, 0, 0,
'',
'',
'',
'', 1,
'', $placeholder);
121 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)
126 $array = array_combine($array, $array);
131 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
132 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' class="' . ($morecss ?
' ' . $morecss :
'') .
'"';
133 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'"' . ($moreparam ?
' ' . $moreparam :
'');
138 if (!is_numeric($show_empty)) {
139 $textforempty = $show_empty;
141 $out .=
'<option value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
144 if (is_array($array)) {
147 foreach ($array as $key => $value) {
148 if (!is_array($value)) {
149 $array[$key] = $langs->trans($value);
151 $array[$key][
'label'] = $langs->trans($value[
'label']);
157 if ($sort ==
'ASC') {
159 } elseif ($sort ==
'DESC') {
163 foreach ($array as $key => $tmpvalue) {
164 if (is_array($tmpvalue)) {
165 $value = $tmpvalue[
'label'];
166 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
176 if ($value ==
'' || $value ==
'-') {
177 $selectOptionValue =
' ';
181 $out .=
'<option value="' . $key .
'"';
183 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
185 if (in_array($key,
$id) && !$disabled) {
190 if (
$id !=
'' && (
$id == $key || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
194 if (is_array($tmpvalue)) {
195 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
196 if (preg_match(
'/^data-/', $keyforvalue)) {
202 $out .= $selectOptionValue;
203 $out .=
"</option>\n";
225 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter =
'', $morecss =
'', $allfiles = 0)
227 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
236 $this->infofiles = array(
'nboffiles' => 0,
'extensions' => array(),
'files' => array());
243 preg_match(
'/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir,
'/') .
'$/', $filedir, $regs);
244 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1);
249 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/');
251 $filterforfilesearch =
'^' . preg_quote(basename($modulesubdir),
'/') .
'\.';
253 $file_list =
dol_dir_list($filedir,
'files', 0, $filterforfilesearch,
'\.meta$|\.png$');
257 $out .=
'<!-- html.formwebportal::getDocumentsLink -->' .
"\n";
258 if (!empty($file_list)) {
264 foreach ($file_list as $file) {
266 if ($filter && !preg_match(
'/' . $filter .
'/i', $file[
"name"])) {
272 $relativepath = $file[
"name"];
274 $relativepath = $modulesubdir .
"/" . $file[
"name"];
277 if ($modulepart ==
'donation') {
278 $relativepath =
get_exdir($modulesubdir, 2, 0, 0,
null,
'donation') . $file[
"name"];
280 if ($modulepart ==
'export') {
281 $relativepath = $file[
"name"];
284 $this->infofiles[
'nboffiles']++;
285 $this->infofiles[
'files'][] = $file[
'fullname'];
286 $ext = pathinfo($file[
"name"], PATHINFO_EXTENSION);
287 if (empty($this->infofiles[
'extensions'][$ext])) {
288 $this->infofiles[
'extensions'][$ext] = 1;
291 $this->infofiles[
'extensions'][$ext]++;
295 $url =
$context->getControllerUrl(
'document') .
'&modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($relativepath) .
'&soc_id=' .
$context->logged_thirdparty->id;
297 $tmpout .=
'<a href="' . $url .
'" class="btn-download-link ' . $morecss .
'" role="downloadlink"';
299 if (preg_match(
'/text/', $mime)) {
300 $tmpout .=
' target="_blank" rel="noopener noreferrer"';
303 $tmpout .=
img_mime($relativepath, $file[
"name"]);
304 $tmpout .= strtoupper($ext);
329 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
330 $out =
'<!-- html.formwebportal::getSignatureLink -->' .
"\n";
331 $url = getOnlineSignatureUrl(0, $modulepart,
$object->ref, 1,
$object);
333 $out .=
'<a target="_blank" rel="noopener noreferrer" href="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
' role="signaturelink">';
334 $out .=
'<i class="fa fa-file-signature"></i>';
335 $out .= $langs->trans(
"Sign");
361 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $disabled = 0, $selected_input_value =
'', $objectfield =
'')
371 $InfoFieldList = explode(
":", $objectdesc, 4);
372 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
374 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
375 $InfoFieldList[4] = $reg[1];
377 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
379 $classname = $InfoFieldList[0];
380 $classpath = $InfoFieldList[1];
381 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
382 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
383 if (!empty($classpath)) {
386 if ($classname && class_exists($classname)) {
387 $objecttmp =
new $classname($this->db);
390 $sharedentities =
getEntity(strtolower($classname));
391 $filter = str_replace(
392 array(
'__ENTITY__',
'__SHARED_ENTITIES__'),
393 array($conf->entity, $sharedentities),
398 if (!is_object($objecttmp)) {
399 dol_syslog(
'Error bad setup of type for field ' . implode(
',', $InfoFieldList), LOG_WARNING);
400 return 'Error bad setup of type for field ' . implode(
',', $InfoFieldList);
403 dol_syslog(__METHOD__ .
' filter=' . $filter, LOG_DEBUG);
406 $out .= $this->
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
430 global $conf, $langs;
435 $size = !empty($val[
'size']) ? $val[
'size'] : 0;
437 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
438 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
440 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
441 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
443 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
444 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
446 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
447 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] .
':' . $reg[5] =>
'N');
449 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
450 $param[
'options'] = array($reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
452 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
453 $param[
'options'] = array($reg[2] .
':' . $reg[3] =>
'N');
455 } elseif (preg_match(
'/^varchar\((\d+)\)/', $val[
'type'], $reg)) {
456 $param[
'options'] = array();
459 } elseif (preg_match(
'/^varchar/', $val[
'type'])) {
460 $param[
'options'] = array();
462 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $val[
'type'])) {
463 $param[
'options'] = array();
466 $param[
'options'] = array();
467 $type = $val[
'type'];
471 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
472 $param[
'options'] = $val[
'arrayofkeyval'];
473 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
477 $default = (!empty($val[
'default']) ? $val[
'default'] :
'');
478 $computed = (!empty($val[
'computed']) ? $val[
'computed'] :
'');
480 $required = (!empty($val[
'required']) ? $val[
'required'] : 0);
481 $notNull = (!empty($val[
'notnull']) ? $val[
'notnull'] : 0);
485 $hidden = (in_array(abs($val[
'visible']), array(0, 2)) ? 1 : 0);
490 if (!preg_match(
'/^search_/', $keyprefix)) {
491 return '<span>' . $langs->trans(
"AutomaticallyCalculated") .
'</span>';
498 if (empty($morecss) && !empty($val[
'css'])) {
499 $morecss = $val[
'css'];
502 $htmlName = $keyprefix . $key . $keysuffix;
511 $dateArr = explode(
' ', $value);
512 if (count($dateArr) > 0) {
513 $valueDate = $dateArr[0];
514 if (isset($dateArr[1])) {
515 $valueTime = $dateArr[1];
518 $out = $this->
inputDate($htmlName, $valueDate,
'', $htmlId, $morecss, $moreparam);
520 if ($type ==
'datetime') {
522 $out .=
' ' . $this->
inputType(
'time', $htmlName.
'_time', $valueTime, $htmlId, $morecss, $moreparam);
532 $moreparam .= ($size > 0 ?
' maxlength="' . $size .
'"' :
'');
549 if (!empty($value)) {
550 $value =
price($value);
552 $addInputLabel =
' ' . $langs->getCurrencySymbol();
553 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam,
'', $addInputLabel);
557 if (!empty($value)) {
558 $value =
price($value);
560 $out = $this->
inputType(
'text', $htmlName, $value, $htmlId, $morecss, $moreparam);
564 $out = $this->
inputType(
'password', $htmlName, $value, $htmlId, $morecss, $moreparam);
568 foreach ($param[
'options'] as $keyopt => $valopt) {
569 $htmlId = $htmlName .
'_' . $keyopt;
570 $htmlMoreParam = $moreparam . ($value == $keyopt ?
' checked' :
'');
571 $out .= $this->
inputType(
'radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) .
'<br>';
576 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' >';
577 if ($default ==
'' || $notNull != 1) {
578 $out .=
'<option value="0"> </option>';
580 foreach ($param[
'options'] as $keyb => $valb) {
584 if (strpos($valb,
"|") !==
false) {
585 list($valb, $parent) = explode(
'|', $valb);
587 $out .=
'<option value="' . $keyb .
'"';
588 $out .= (((string) $value == $keyb) ?
' selected' :
'');
589 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
590 $out .=
'>' . $valb .
'</option>';
595 $out =
'<select class="' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlId .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
'>';
597 $param_list = array_keys($param[
'options']);
598 $InfoFieldList = explode(
":", $param_list[0]);
608 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
610 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
611 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
612 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
614 $keyList = $InfoFieldList[2] .
' as rowid';
617 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
618 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
619 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
620 $keyList .=
', main.'.$parentField;
622 $keyList .=
', '.$parentField;
626 $filter_categorie =
false;
627 if (count($InfoFieldList) > 5) {
628 if ($InfoFieldList[0] ==
'categorie') {
629 $filter_categorie =
true;
633 if (!$filter_categorie) {
634 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
635 if (!empty($fields_label)) {
637 $keyList .= implode(
', ', $fields_label);
641 $sql =
"SELECT " . $keyList;
642 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
643 if (!empty($InfoFieldList[4])) {
645 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
646 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
650 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
653 if (strpos($InfoFieldList[4],
'extra') !==
false) {
654 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
655 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
657 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
660 $sqlwhere .=
' WHERE 1=1';
663 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
664 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
669 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
671 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
672 $resql = $this->db->query($sql);
674 $out .=
'<option value="0"> </option>';
675 $num = $this->db->num_rows($resql);
679 $obj = $this->db->fetch_object($resql);
683 $fields_label = explode(
'|', $InfoFieldList[1]);
684 if (count($fields_label) > 1) {
686 foreach ($fields_label as $field_toshow) {
687 $labeltoshow .= $obj->$field_toshow .
' ';
690 $labeltoshow = $obj->{$InfoFieldList[1]};
692 $labeltoshow =
dol_trunc($labeltoshow, 45);
694 if ($value == $obj->rowid) {
695 foreach ($fields_label as $field_toshow) {
696 $translabel = $langs->trans($obj->$field_toshow);
697 if ($translabel != $obj->$field_toshow) {
698 $labeltoshow =
dol_trunc($translabel) .
' ';
700 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
703 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
706 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
707 if ($translabel != $obj->{$InfoFieldList[1]}) {
708 $labeltoshow =
dol_trunc($translabel, 18);
710 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
713 if (empty($labeltoshow)) {
714 $labeltoshow =
'(not defined)';
716 if ($value == $obj->rowid) {
717 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
720 if (!empty($InfoFieldList[3]) && $parentField) {
721 $parent = $parentName .
':' . $obj->{$parentField};
725 $out .=
'<option value="' . $obj->rowid .
'"';
726 $out .= ($value == $obj->rowid ?
' selected' :
'');
727 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
728 $out .=
'>' . $labeltoshow .
'</option>';
733 $this->db->free($resql);
735 $out .=
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
738 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
739 $categorytype = $InfoFieldList[5];
740 if (is_numeric($categorytype)) {
742 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
743 $categorytype = $MAP_ID_TO_CODE[(int) $categorytype];
746 $data = $this->select_all_categories($categorytype,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
747 $out .=
'<option value="0"> </option>';
748 foreach ($data as $data_key => $data_value) {
749 $out .=
'<option value="' . $data_key .
'"';
750 $out .= ($value == $data_key ?
' selected' :
'');
751 $out .=
'>' . $data_value .
'</option>';
758 $param_list = array_keys($param[
'options']);
759 $showempty = (($required && $default !=
'') ?
'0' :
'1');
761 $out = $this->selectForForms($param_list[0], $htmlName, (
int) $value, $showempty,
'',
'', $morecss, $moreparam, 0, empty($val[
'disabled']) ? 0 : 1);
766 if (!empty($hidden)) {
767 $out = $this->inputType(
'hidden', $htmlName, $value, $htmlId);
788 public function showOutputFieldForObject(
$object, $val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
794 global $conf, $langs;
796 $label = empty($val[
'label']) ?
'' : $val[
'label'];
797 $type = empty($val[
'type']) ?
'' : $val[
'type'];
798 $css = empty($val[
'css']) ?
'' : $val[
'css'];
799 $picto = empty($val[
'picto']) ?
'' : $val[
'picto'];
803 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
806 } elseif (preg_match(
'/varchar/', $type)) {
809 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
810 $type = $val[
'type'] ==
'checkbox' ?
'checkbox' :
'select';
812 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
816 $default = empty($val[
'default']) ?
'' : $val[
'default'];
817 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
818 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
819 $required = empty($val[
'required']) ?
'' : $val[
'required'];
821 $param[
'options'] = array();
823 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
824 $param[
'options'] = $val[
'arrayofkeyval'];
826 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
828 $stringforoptions = $reg[1] .
':' . $reg[2];
829 if ($reg[1] ==
'User') {
830 $stringforoptions .=
':-1';
832 $param[
'options'] = array($stringforoptions => $stringforoptions);
833 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
834 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] .
':' . $reg[4] =>
'N');
836 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
837 $param[
'options'] = array($reg[1] .
':' . $reg[2] .
':' . $reg[3] =>
'N');
839 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
840 $param[
'options'] = array($reg[1] .
':' . $reg[2] =>
'N');
842 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
843 $param[
'options'] = array($reg[1] =>
'N');
847 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
848 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
849 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
850 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
860 $value = (string)
dol_eval((
string) $computed, 1, 0,
'2');
867 if (in_array($key, array(
'rowid',
'ref'))) {
868 if (property_exists(
$object,
'ref')) {
869 $value = (string)
$object->ref;
870 } elseif (property_exists(
$object,
'id')) {
875 } elseif ($key ==
'status' && method_exists(
$object,
'getLibStatut')) {
876 $value =
$object->getLibStatut(3);
880 } elseif (is_array($value)) {
883 if ($type ==
'array') {
884 $value = implode(
'<br>', $value);
886 dol_syslog(__METHOD__.
"Unexpected type=".$type.
" for array value=".((
string) json_encode($value)), LOG_ERR);
891 } elseif ($type ==
'date') {
892 if (!empty($value)) {
897 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
898 if (!empty($value)) {
903 } elseif ($type ==
'duration') {
904 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
905 if (!is_null($value) && $value !==
'') {
911 } elseif ($type ==
'double' || $type ==
'real') {
912 if (!is_null($value) && $value !==
'') {
913 $value =
price($value);
918 } elseif ($type ==
'boolean') {
920 if (!empty($value)) {
921 $checked =
' checked ';
923 $value =
'<input type="checkbox" ' . $checked .
' ' . ($moreparam ? $moreparam :
'') .
' readonly disabled>';
924 } elseif ($type ==
'mail' || $type ==
'email') {
926 } elseif ($type ==
'url') {
928 } elseif ($type ==
'phone') {
930 } elseif ($type ==
'ip') {
932 } elseif ($type ==
'price') {
933 if (!is_null($value) && $value !==
'') {
939 } elseif ($type ==
'select') {
940 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
941 } elseif ($type ==
'sellist') {
942 $param_list = array_keys($param[
'options']);
943 $InfoFieldList = explode(
":", $param_list[0]);
945 $selectkey =
"rowid";
948 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
949 $selectkey = $InfoFieldList[2];
950 $keyList = $InfoFieldList[2] .
' as rowid';
953 $fields_label = explode(
'|', $InfoFieldList[1]);
954 if (is_array($fields_label)) {
956 $keyList .= implode(
', ', $fields_label);
959 $filter_categorie =
false;
960 if (count($InfoFieldList) > 5) {
961 if ($InfoFieldList[0] ==
'categorie') {
962 $filter_categorie =
true;
966 $sql =
"SELECT " . $keyList;
967 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
968 if (strpos($InfoFieldList[4],
'extra') !==
false) {
971 if ($selectkey ==
'rowid' && empty($value)) {
972 $sql .=
" WHERE " . $selectkey .
" = 0";
973 } elseif ($selectkey ==
'rowid') {
974 $sql .=
" WHERE " . $selectkey .
" = " . ((int) $value);
976 $sql .=
" WHERE " . $selectkey .
" = '" . $this->db->escape($value) .
"'";
979 dol_syslog(__METHOD__ .
' type=sellist', LOG_DEBUG);
980 $resql = $this->db->query($sql);
982 if (!$filter_categorie) {
984 $numrows = $this->db->num_rows($resql);
986 $obj = $this->db->fetch_object($resql);
989 $fields_label = explode(
'|', $InfoFieldList[1]);
991 if (is_array($fields_label) && count($fields_label) > 1) {
992 foreach ($fields_label as $field_toshow) {
994 if (!empty($obj->$field_toshow)) {
995 $translabel = $langs->trans($obj->$field_toshow);
997 if ($translabel != $field_toshow) {
998 $value .=
dol_trunc($translabel, 18) .
' ';
1000 $value .= $obj->$field_toshow .
' ';
1005 if (!empty($obj->{$InfoFieldList[1]})) {
1006 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1008 if ($translabel != $obj->{$InfoFieldList[1]}) {
1011 $value = $obj->{$InfoFieldList[1]};
1016 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1019 $obj = $this->db->fetch_object($resql);
1021 $c->fetch($obj->rowid);
1022 $ways =
$c->print_all_ways();
1023 foreach ($ways as $way) {
1024 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1026 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1029 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1031 } elseif ($type ==
'radio') {
1032 $value = (string) $param[
'options'][$value];
1033 } elseif ($type ==
'checkbox') {
1034 $value_arr = explode(
',', $value);
1036 if (is_array($value_arr) && count($value_arr) > 0) {
1038 foreach ($value_arr as $valueval) {
1039 if (!empty($valueval)) {
1040 $toprint[] =
'<li>' . $param[
'options'][$valueval] .
'</li>';
1043 if (!empty($toprint)) {
1044 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1047 } elseif ($type ==
'chkbxlst') {
1048 $value_arr = explode(
',', $value);
1050 $param_list = array_keys($param[
'options']);
1051 $InfoFieldList = explode(
":", $param_list[0]);
1053 $selectkey =
"rowid";
1056 if (count($InfoFieldList) >= 3) {
1057 $selectkey = $InfoFieldList[2];
1058 $keyList = $InfoFieldList[2] .
' as rowid';
1061 $fields_label = explode(
'|', $InfoFieldList[1]);
1062 if (is_array($fields_label)) {
1064 $keyList .= implode(
', ', $fields_label);
1067 $filter_categorie =
false;
1068 if (count($InfoFieldList) > 5) {
1069 if ($InfoFieldList[0] ==
'categorie') {
1070 $filter_categorie =
true;
1074 $sql =
"SELECT " . $keyList;
1075 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1076 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1082 dol_syslog(__METHOD__ .
' type=chkbxlst', LOG_DEBUG);
1083 $resql = $this->db->query($sql);
1085 if (!$filter_categorie) {
1088 while ($obj = $this->db->fetch_object($resql)) {
1090 $fields_label = explode(
'|', $InfoFieldList[1]);
1091 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1092 if (is_array($fields_label) && count($fields_label) > 1) {
1093 foreach ($fields_label as $field_toshow) {
1095 if (!empty($obj->$field_toshow)) {
1096 $translabel = $langs->trans($obj->$field_toshow);
1098 if ($translabel != $field_toshow) {
1099 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1101 $toprint[] =
'<li>' . $obj->$field_toshow .
'</li>';
1106 if (!empty($obj->{$InfoFieldList[1]})) {
1107 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1109 if ($translabel != $obj->{$InfoFieldList[1]}) {
1110 $toprint[] =
'<li>' .
dol_trunc($translabel, 18) .
'</li>';
1112 $toprint[] =
'<li>' . $obj->{$InfoFieldList[1]} .
'</li>';
1118 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1121 while ($obj = $this->db->fetch_object($resql)) {
1122 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1124 $c->fetch($obj->rowid);
1125 $ways =
$c->print_all_ways();
1126 foreach ($ways as $way) {
1127 $toprint[] =
'<li>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1132 $value =
'<div><ul>' . implode(
' ', $toprint) .
'</ul></div>';
1134 dol_syslog(__METHOD__ .
' error ' . $this->db->lasterror(), LOG_WARNING);
1136 } elseif ($type ==
'link') {
1139 $param_list = array_keys($param[
'options']);
1141 $InfoFieldList = explode(
":", $param_list[0]);
1142 $classname = $InfoFieldList[0];
1143 $classpath = $InfoFieldList[1];
1144 if (!empty($classpath)) {
1146 if ($classname && class_exists($classname)) {
1147 $object =
new $classname($this->db);
1148 '@phan-var-force CommonObject $object';
1150 $result =
$object->fetch($value);
1153 if (property_exists(
$object,
'label')) {
1154 $value = (string)
$object->label;
1155 } elseif (property_exists(
$object,
'libelle')) {
1156 $value = (string)
$object->libelle;
1157 } elseif (property_exists(
$object,
'nom')) {
1158 $value = (string)
$object->nom;
1163 dol_syslog(__METHOD__ .
' Error bad setup of field', LOG_WARNING);
1164 return 'Error bad setup of field';
1169 } elseif ($type ==
'password') {
1170 $value = preg_replace(
'/./i',
'*', $value);
1193 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
1206 $out .= ($moreparam ?
' ' . $moreparam :
'');
1207 $out .=
' />' . $addInputLabel;
1209 $out .= $label .
'</label>';
1227 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
1231 $(document).ready(function () {
1232 $('#" . $htmlName .
"').select2({
1234 url: '" . $ajaxUrl .
"',
1236 delay: 250, // wait 250 milliseconds before triggering the request
1237 data: function (params) {
1239 search: params.term,
1240 page: params.page || 1";
1241 if (!empty($ajaxData) && is_array($ajaxData)) {
1242 foreach ($ajaxData as $key => $value) {
1243 $out .=
", " . $key .
": '" . $value .
"'";
1255 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
1269 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
1271 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
1272 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1274 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
1287 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
1292 if (!empty($options)) {
1294 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
1295 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
1298 function handlemultiinputdisabling(htmlname){
1299 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
1300 multiinput = $("#"+htmlname+"_multiinput");
1301 multiinput.find("option").each(function(){
1302 tmpval = $("#"+htmlname).val();
1303 tmpvalarray = tmpval.split("\n");
1304 valtotest = $(this).val();
1305 if(tmpvalarray.includes(valtotest)){
1306 $(this).prop("disabled",true);
1308 if($(this).prop("disabled") == true){
1309 console.log(valtotest)
1310 $(this).prop("disabled", false);
1316 $(document).ready(function () {
1317 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
1318 tmpval = $("#' . $htmlName .
'").val();
1319 tmpvalarray = tmpval.split(",");
1320 valtotest = $("#' . $htmlName .
'_multiinput").val();
1321 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
1322 console.log("We add the selected value to the text area ' . $htmlName .
'");
1326 tmpval = tmpval + "\n" + valtotest;
1328 $("#' . $htmlName .
'").val(tmpval);
1329 handlemultiinputdisabling("' . $htmlName .
'");
1330 $("#' . $htmlName .
'_multiinput").val(-1);
1332 console.log("We add nothing the text area ' . $htmlName .
'");
1335 $("#' . $htmlName .
'").on("change",function(){
1336 handlemultiinputdisabling("' . $htmlName .
'");
1338 handlemultiinputdisabling("' . $htmlName .
'");
1340 $out .=
"</script>";
1341 $value = str_replace(
',',
"\n", $value);
1344 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
1345 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1346 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
1361 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
1364 foreach ($options as $optionKey => $optionLabel) {
1365 $selected = ((string) $selectedValue) === ((string) $optionKey) ?
' checked="checked"' :
'';
1366 $optionId = $htmlName .
'_' . $optionKey;
1367 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
1383 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
1385 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
1386 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
1387 for ($i = 1; $i <= $size; $i++) {
1388 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
1392 jQuery(function($) { /* commonobject.class.php 1 */
1393 let container = $("#' . $htmlName .
'_selection");
1394 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
1395 container.find(".star").each(function() {
1396 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1398 container.find(".star").on("mouseover", function() {
1399 let selectedStar = $(this).data("value");
1400 container.find(".star").each(function() {
1401 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
1404 container.on("mouseout", function() {
1405 container.find(".star").each(function() {
1406 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1409 container.find(".star").off("click").on("click", function() {
1410 selectedStars = $(this).data("value");
1411 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
1414 $("#' . $htmlName .
'").val(selectedStars);
1415 container.find(".star").each(function() {
1416 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1434 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
1443 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
1444 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((string) $moreparam) .
'>';
1447 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
1448 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1449 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1452 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1453 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
1454 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1455 $options .=
" <div class=\"arrow\" ></div>";
1456 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1457 $options .=
" <div class=\"popover-content \" ></div>";
1458 $options .=
"</div>'}}";
1459 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
1460 $out .=
'</script>';
1476 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
1477 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
1483 if (!empty($value)) {
1484 $tmparray = $dolgeophp->parseGeoString($value);
1485 $geojson = $tmparray[
'geojson'];
1486 $centroidjson = $tmparray[
'centroidjson'];
1489 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
1502 $values = is_array($values) ? $values : array();
1504 foreach ($values as $value) {
1505 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
1507 if (!empty($toPrint)) {
1508 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
1524 for ($i = 1; $i <= $size; $i++) {
1525 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
1556 if (!empty($value)) {
1557 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
1559 if ($type ==
'point') {
1560 $out = $dolgeophp->getXYString($value);
1562 $out = $dolgeophp->getPointString($value);
1583 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
1586 $out =
$object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
1612 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
1614 $out = parent::showphoto($modulepart,
$object, $width, $height, $caneditfield, $cssclass, $imagesize, $addlinktofullsize, $cache, $forcecapture, $noexternsourceoverwrite, $usesharelinkifavailable);
1615 $out = self::convertAllLink($out);
1638 $required = !empty($params[
'required']) ?
' required' :
'';
1640 $cell_attributes = !empty($params[
'cell_attributes']) ?
' ' . trim($params[
'cell_attributes']) :
'';
1642 $label_attributes = !empty($params[
'label_attributes']) ?
' ' . trim($params[
'label_attributes']) :
'';
1644 $value_attributes = !empty($params[
'value_attributes']) ?
' ' . trim($params[
'value_attributes']) :
'';
1646 $out =
'<div class="grid field_' .
dolPrintHTMLForAttribute(strtolower($key)) . $cell_class .
'"' . $cell_attributes .
'>';
1647 $out .=
'<div class="' . $required . $label_class .
'"' . $label_attributes .
'>';
1650 $out .=
'<div class="' . $value_class .
'"' . $value_attributes .
'>';
1666 public static function convertAllLink($html, $additionalViewImageParams =
'', $additionalDocumentParams =
'')
1668 require_once DOL_DOCUMENT_ROOT .
'/webportal/class/context.class.php';
1671 $html = str_replace(DOL_URL_ROOT .
'/viewimage.php?',
$context->getControllerUrl(
'viewimage') . $additionalViewImageParams .
'&', $html);
1672 $html = str_replace(urlencode(
dol_escape_js(DOL_URL_ROOT .
'/viewimage.php?')), urlencode(
dol_escape_js(
$context->getControllerUrl(
'viewimage') . $additionalViewImageParams .
'&')), $html);
1673 $html = str_replace(DOL_URL_ROOT .
'/document.php?',
$context->getControllerUrl(
'document') . $additionalDocumentParams .
'&', $html);
1674 $html = str_replace(urlencode(
dol_escape_js(DOL_URL_ROOT .
'/document.php?')), urlencode(
dol_escape_js(
$context->getControllerUrl(
'document') . $additionalDocumentParams .
'&')), $html);
1688 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
1691 return '<span class="form-select-currency-container">'.parent::selectCurrency($selected, $htmlname, $mode, $useempty).
'</span>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage categories.
static getInstance()
Singleton method to create one instance of this object.
Class to manage a WYSIWYG editor.
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
Class to manage a Leaflet map width geometrics objects.
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.
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
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...
$context
@method int call_trigger(string $triggerName, ?User $user)