54 public $expand_display;
64 public $errors = array();
74 public static $type2label = array(
75 'varchar'=>
'String1Line',
76 'text'=>
'TextLongNLines',
81 'datetime'=>
'DateAndTime',
84 'price'=>
'ExtrafieldPrice',
85 'pricecy'=>
'ExtrafieldPriceWithCurrency',
86 'phone'=>
'ExtrafieldPhone',
87 'mail'=>
'ExtrafieldMail',
88 'url'=>
'ExtrafieldUrl',
90 'password' =>
'ExtrafieldPassword',
91 'select' =>
'ExtrafieldSelect',
92 'sellist' =>
'ExtrafieldSelectList',
93 'radio' =>
'ExtrafieldRadio',
94 'checkbox' =>
'ExtrafieldCheckBox',
95 'chkbxlst' =>
'ExtrafieldCheckBoxFromList',
96 'link' =>
'ExtrafieldLink',
97 'separate' =>
'ExtrafieldSeparator',
110 $this->errors = array();
111 $this->attributes = array();
140 public function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value =
'', $param =
'', $alwayseditable = 0, $perms =
'', $list =
'-1', $help =
'', $computed =
'', $entity =
'', $langfile =
'', $enabled =
'1', $totalizable = 0, $printable = 0, $moreparams = array())
142 if (empty($attrname)) {
151 if ($type ==
'separate') {
155 if ($elementtype ==
'thirdparty') {
156 $elementtype =
'societe';
158 if ($elementtype ==
'contact') {
159 $elementtype =
'socpeople';
163 if ($type !=
'separate') {
164 $result = $this->
create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help, $moreparams);
166 $err1 = $this->errno;
167 if ($result > 0 || $err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type ==
'separate') {
169 $result2 = $this->
create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams);
170 $err2 = $this->errno;
171 if ($result2 > 0 || ($err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 ==
'DB_ERROR_RECORD_ALREADY_EXISTS')) {
202 private function create($attrname, $type =
'varchar', $length = 255, $elementtype =
'member', $unique = 0, $required = 0, $default_value =
'', $param =
'', $perms =
'', $list =
'0', $computed =
'', $help =
'', $moreparams = array())
204 if ($elementtype ==
'thirdparty') {
205 $elementtype =
'societe';
207 if ($elementtype ==
'contact') {
208 $elementtype =
'socpeople';
211 $table = $elementtype.
'_extrafields';
212 if ($elementtype ==
'categorie') {
213 $table =
'categories_extrafields';
216 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) {
217 if ($type ==
'boolean') {
220 } elseif ($type ==
'price') {
223 } elseif ($type ==
'pricecy') {
226 } elseif ($type ==
'phone') {
229 } elseif ($type ==
'mail' || $type ==
'ip') {
232 } elseif ($type ==
'url') {
235 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
238 } elseif ($type ==
'link') {
241 } elseif ($type ==
'html') {
244 } elseif ($type ==
'password') {
250 if ($type ==
'varchar' && empty($lengthdb)) {
257 'null'=>($required ?
'NOT NULL' :
'NULL'),
258 'default' => $default_value
261 $result = $this->db->DDLAddField($this->db->prefix().$table, $attrname, $field_desc);
264 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
265 $resql = $this->db->query(
$sql, 1,
'dml');
269 $this->error = $this->db->lasterror();
270 $this->errno = $this->db->lasterrno();
306 private function create_label($attrname, $label =
'', $type =
'', $pos = 0, $size = 0, $elementtype =
'member', $unique = 0, $required = 0, $param =
'', $alwayseditable = 0, $perms =
'', $list =
'-1', $help =
'', $default =
'', $computed =
'', $entity =
'', $langfile =
'', $enabled =
'1', $totalizable = 0, $printable = 0, $moreparams = array())
311 if ($elementtype ==
'thirdparty') {
312 $elementtype =
'societe';
314 if ($elementtype ==
'contact') {
315 $elementtype =
'socpeople';
325 if (empty($required)) {
328 if (empty($unique)) {
331 if (empty($printable)) {
334 if (empty($alwayseditable)) {
337 if (empty($totalizable)) {
342 if (!empty($moreparams) && !empty($moreparams[
'css'])) {
343 $css = $moreparams[
'css'];
346 if (!empty($moreparams) && !empty($moreparams[
'csslist'])) {
347 $csslist = $moreparams[
'csslist'];
350 if (!empty($moreparams) && !empty($moreparams[
'cssview'])) {
351 $cssview = $moreparams[
'cssview'];
354 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) {
355 if (is_array($param) && count($param) > 0) {
356 $params = serialize($param);
357 } elseif (strlen($param) > 0) {
358 $params = trim($param);
363 $sql =
"INSERT INTO ".$this->db->prefix().
"extrafields(";
370 $sql .=
" elementtype,";
371 $sql .=
" fieldunique,";
372 $sql .=
" fieldrequired,";
374 $sql .=
" alwayseditable,";
378 $sql .=
" printable,";
379 $sql .=
" fielddefault,";
380 $sql .=
" fieldcomputed,";
381 $sql .=
" fk_user_author,";
382 $sql .=
" fk_user_modif,";
386 $sql .=
" totalizable,";
391 $sql .=
" VALUES('".$this->db->escape($attrname).
"',";
392 $sql .=
" '".$this->db->escape($label).
"',";
393 $sql .=
" '".$this->db->escape($type).
"',";
394 $sql .=
" ".((int) $pos).
",";
395 $sql .=
" '".$this->db->escape($size).
"',";
396 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
397 $sql .=
" '".$this->db->escape($elementtype).
"',";
398 $sql .=
" ".((int) $unique).
",";
399 $sql .=
" ".((int) $required).
",";
400 $sql .=
" '".$this->db->escape($params).
"',";
401 $sql .=
" ".((int) $alwayseditable).
",";
402 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
403 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
404 $sql .=
" '".$this->db->escape($list).
"',";
405 $sql .=
" '".$this->db->escape($printable).
"',";
406 $sql .=
" ".($default ?
"'".$this->db->escape($default).
"'" :
"null").
",";
407 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
408 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
409 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
411 $sql .=
" ".($enabled ?
"'".$this->db->escape($enabled).
"'" :
"1").
",";
412 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
413 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE').
",";
414 $sql .=
" ".($css ?
"'".$this->db->escape($css).
"'" :
"null").
",";
415 $sql .=
" ".($csslist ?
"'".$this->db->escape($csslist).
"'" :
"null").
",";
416 $sql .=
" ".($cssview ?
"'".$this->db->escape($cssview).
"'" :
"null");
419 dol_syslog(get_class($this).
"::create_label", LOG_DEBUG);
420 if ($this->db->query(
$sql)) {
423 $this->error = $this->db->lasterror();
424 $this->errno = $this->db->lasterrno();
438 public function delete($attrname, $elementtype =
'member')
440 if ($elementtype ==
'thirdparty') {
441 $elementtype =
'societe';
443 if ($elementtype ==
'contact') {
444 $elementtype =
'socpeople';
447 $table = $elementtype.
'_extrafields';
448 if ($elementtype ==
'categorie') {
449 $table =
'categories_extrafields';
454 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
457 $this->error = $this->db->lasterror();
458 $this->errors[] = $this->db->lasterror();
463 $sql =
"SELECT COUNT(rowid) as nb";
464 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
465 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
466 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
468 $resql = $this->db->query(
$sql);
470 $obj = $this->db->fetch_object($resql);
472 $result = $this->db->DDLDropField($this->db->prefix().$table, $attrname);
474 $this->error = $this->db->lasterror();
475 $this->errors[] = $this->db->lasterror();
501 if ($elementtype ==
'thirdparty') {
502 $elementtype =
'societe';
504 if ($elementtype ==
'contact') {
505 $elementtype =
'socpeople';
508 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
509 $sql =
"DELETE FROM ".$this->db->prefix().
"extrafields";
510 $sql .=
" WHERE name = '".$this->db->escape($attrname).
"'";
511 $sql .=
" AND entity IN (0,".$conf->entity.
')';
512 $sql .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
514 dol_syslog(get_class($this).
"::delete_label", LOG_DEBUG);
515 $resql = $this->db->query(
$sql);
554 public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param =
'', $alwayseditable = 0, $perms =
'', $list =
'', $help =
'', $default =
'', $computed =
'', $entity =
'', $langfile =
'', $enabled =
'1', $totalizable = 0, $printable = 0, $moreparams = array())
558 if ($elementtype ==
'thirdparty') {
559 $elementtype =
'societe';
561 if ($elementtype ==
'contact') {
562 $elementtype =
'socpeople';
565 $table = $elementtype.
'_extrafields';
566 if ($elementtype ==
'categorie') {
567 $table =
'categories_extrafields';
570 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
571 if ($type ==
'boolean') {
574 } elseif ($type ==
'price') {
577 } elseif ($type ==
'pricecy') {
580 } elseif ($type ==
'phone') {
583 } elseif ($type ==
'mail' || $type ==
'ip') {
586 } elseif ($type ==
'url') {
589 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
592 } elseif ($type ==
'html') {
594 } elseif ($type ==
'link') {
597 } elseif ($type ==
'password') {
604 $field_desc = array(
'type'=>$typedb,
'value'=>$lengthdb,
'null'=>($required ?
'NOT NULL' :
'NULL'),
'default'=>$default);
606 if (is_object($hookmanager)) {
607 $hookmanager->initHooks(array(
'extrafieldsdao'));
608 $parameters = array(
'field_desc'=>&$field_desc,
'table'=>$table,
'attr_name'=>$attrname,
'label'=>$label,
'type'=>$type,
'length'=>$length,
'unique'=>$unique,
'required'=>$required,
'pos'=>$pos,
'param'=>$param,
'alwayseditable'=>$alwayseditable,
'perms'=>$perms,
'list'=>$list,
'help'=>$help,
'default'=>$default,
'computed'=>$computed,
'entity'=>$entity,
'langfile'=>$langfile,
'enabled'=>$enabled,
'totalizable'=>$totalizable,
'printable'=>$printable);
609 $reshook = $hookmanager->executeHooks(
'updateExtrafields', $parameters, $this, $action);
612 $this->error = $this->db->lasterror();
617 if ($type !=
'separate') {
618 $result = $this->db->DDLUpdateField($this->db->prefix().$table, $attrname, $field_desc);
620 if ($result > 0 || $type ==
'separate') {
622 $result = $this->
update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams);
627 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
629 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" DROP INDEX IF EXISTS uk_".$table.
"_".$attrname;
631 dol_syslog(get_class($this).
'::update', LOG_DEBUG);
632 $resql = $this->db->query(
$sql, 1,
'dml');
639 $this->error = $this->db->lasterror();
643 $this->error = $this->db->lasterror();
679 private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param =
'', $alwayseditable = 0, $perms =
'', $list =
'0', $help =
'', $default =
'', $computed =
'', $entity =
'', $langfile =
'', $enabled =
'1', $totalizable = 0, $printable = 0, $moreparams = array())
683 dol_syslog(get_class($this).
"::update_label ".$attrname.
", ".$label.
", ".$type.
", ".$size.
", ".$elementtype.
", ".$unique.
", ".$required.
", ".$pos.
", ".$alwayseditable.
", ".$perms.
", ".$list.
", ".$default.
", ".$computed.
", ".$entity.
", ".$langfile.
", ".$enabled.
", ".$totalizable.
", ".$printable);
686 if ($elementtype ==
'thirdparty') {
687 $elementtype =
'societe';
689 if ($elementtype ==
'contact') {
690 $elementtype =
'socpeople';
699 if (empty($totalizable)) {
702 if (empty($required)) {
705 if (empty($unique)) {
708 if (empty($alwayseditable)) {
713 if (!empty($moreparams) && !empty($moreparams[
'css'])) {
714 $css = $moreparams[
'css'];
717 if (!empty($moreparams) && !empty($moreparams[
'csslist'])) {
718 $csslist = $moreparams[
'csslist'];
721 if (!empty($moreparams) && !empty($moreparams[
'cssview'])) {
722 $cssview = $moreparams[
'cssview'];
725 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
728 if (is_array($param) && count($param) > 0) {
729 $params = serialize($param);
730 } elseif (is_array($param)) {
732 } elseif (strlen($param) > 0) {
733 $params = trim($param);
738 if ($entity ===
'' || $entity !=
'0') {
740 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
741 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
742 $sql_del .=
" AND entity IN (0, ".($entity ===
'' ? $conf->entity : $entity).
")";
743 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
746 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
747 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
748 $sql_del .=
" AND entity = 0";
749 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
751 $resql1 = $this->db->query($sql_del);
753 $sql =
"INSERT INTO ".$this->db->prefix().
"extrafields(";
759 $sql .=
" elementtype,";
760 $sql .=
" fieldunique,";
761 $sql .=
" fieldrequired,";
765 $sql .=
" alwayseditable,";
768 $sql .=
" printable,";
769 $sql .=
" totalizable,";
770 $sql .=
" fielddefault,";
771 $sql .=
" fieldcomputed,";
772 $sql .=
" fk_user_author,";
773 $sql .=
" fk_user_modif,";
780 $sql .=
") VALUES (";
781 $sql .=
"'".$this->db->escape($attrname).
"',";
782 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
783 $sql .=
" '".$this->db->escape($label).
"',";
784 $sql .=
" '".$this->db->escape($type).
"',";
785 $sql .=
" '".$this->db->escape($size).
"',";
786 $sql .=
" '".$this->db->escape($elementtype).
"',";
787 $sql .=
" ".$unique.
",";
788 $sql .=
" ".$required.
",";
789 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
790 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
791 $sql .=
" ".$pos.
",";
792 $sql .=
" '".$this->db->escape($alwayseditable).
"',";
793 $sql .=
" '".$this->db->escape($params).
"',";
794 $sql .=
" '".$this->db->escape($list).
"', ";
795 $sql .=
" '".$this->db->escape($printable).
"', ";
796 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE').
",";
797 $sql .=
" ".(($default !=
'') ?
"'".$this->db->escape($default).
"'" :
"null").
",";
798 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
799 $sql .=
" ".$user->id.
",";
800 $sql .=
" ".$user->id.
",";
802 $sql .=
"'".$this->db->escape($enabled).
"',";
803 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
804 $sql .=
" ".($css ?
"'".$this->db->escape($css).
"'" :
"null").
",";
805 $sql .=
" ".($csslist ?
"'".$this->db->escape($csslist).
"'" :
"null").
",";
806 $sql .=
" ".($cssview ?
"'".$this->db->escape($cssview).
"'" :
"null");
809 $resql2 = $this->db->query(
$sql);
811 if ($resql1 && $resql2) {
815 $this->db->rollback();
838 if (empty($elementtype)) {
842 if ($elementtype ==
'thirdparty') {
843 $elementtype =
'societe';
845 if ($elementtype ==
'contact') {
846 $elementtype =
'socpeople';
848 if ($elementtype ==
'order_supplier') {
849 $elementtype =
'commande_fournisseur';
855 $array_name_label = array();
858 $sql =
"SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help,";
859 $sql .=
" css, cssview, csslist";
860 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
862 if ($elementtype && $elementtype !=
'all') {
863 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
865 $sql .=
" ORDER BY pos";
867 $resql = $this->db->query(
$sql);
870 if ($this->db->num_rows($resql)) {
871 while ($tab = $this->db->fetch_object($resql)) {
872 if ($tab->entity != 0 && $tab->entity != $conf->entity) {
874 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
875 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
881 if ($tab->type !=
'separate') {
882 $array_name_label[$tab->name] = $tab->label;
885 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
886 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
887 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
888 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
889 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
890 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
891 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
892 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
893 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
894 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
895 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
896 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = ((is_null($tab->perms) || strlen($tab->perms) == 0) ? 1 : $tab->perms);
897 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
898 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
899 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
900 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
901 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
902 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
903 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
904 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
905 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
906 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
908 $this->attributes[$tab->elementtype][
'loaded'] = 1;
913 $this->attributes[$elementtype][
'loaded'] = 1;
914 $this->attributes[$elementtype][
'count'] = $count;
917 $this->error = $this->db->lasterror();
918 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
921 return $array_name_label;
940 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'', $objectid = 0, $extrafieldsobjectkey =
'', $mode = 0)
942 global $conf, $langs,
$form;
944 if (!is_object(
$form)) {
945 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
951 if (!preg_match(
'/options_$/', $keyprefix)) {
952 $keyprefix = $keyprefix.
'options_';
955 if (empty($extrafieldsobjectkey)) {
956 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
957 return 'BadValueForParamExtraFieldsObjectKey';
960 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
961 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
962 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
963 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
964 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
965 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
966 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
967 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
968 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
969 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
970 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
971 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
972 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
973 $hidden = (empty($list) ? 1 : 0);
976 if (!preg_match(
'/^search_/', $keyprefix)) {
977 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
985 if (empty($morecss)) {
987 if ($type ==
'date') {
988 $morecss =
'minwidth100imp';
989 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
990 $morecss =
'minwidth200imp';
991 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
992 $morecss =
'maxwidth75';
993 } elseif ($type ==
'password') {
994 $morecss =
'maxwidth100';
995 } elseif ($type ==
'url') {
996 $morecss =
'minwidth400';
997 } elseif ($type ==
'boolean') {
999 } elseif ($type ==
'radio') {
1000 $morecss =
'width25';
1002 if (empty($size) || round($size) < 12) {
1003 $morecss =
'minwidth100';
1004 } elseif (round($size) <= 48) {
1005 $morecss =
'minwidth200';
1007 $morecss =
'minwidth400';
1011 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1012 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1016 if (in_array($type, array(
'date'))) {
1017 $tmp = explode(
',', $size);
1022 if (!$required && $value ==
'') {
1029 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1030 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1032 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1033 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1034 $out .=
'</div><div class="nowrap">';
1035 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1036 $out .=
'</div></div>';
1039 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1041 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1042 $tmp = explode(
',', $size);
1047 if (!$required && $value ==
'') {
1054 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1055 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1057 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1058 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1059 $out .=
'</div><div class="nowrap">';
1060 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1061 $out .=
'</div></div>';
1064 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1066 } elseif (in_array($type, array(
'int',
'integer'))) {
1067 $tmp = explode(
',', $size);
1069 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" maxlength="'.$newsize.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
1070 } elseif (preg_match(
'/varchar/', $type)) {
1071 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" maxlength="'.$size.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
1072 } elseif (in_array($type, array(
'mail',
'ip',
'phone',
'url'))) {
1073 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1074 } elseif ($type ==
'text') {
1075 if (!preg_match(
'/search_/', $keyprefix)) {
1076 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1077 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1078 $out = $doleditor->Create(1);
1080 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1082 } elseif ($type ==
'html') {
1083 if (!preg_match(
'/search_/', $keyprefix)) {
1084 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1085 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
1086 $out = $doleditor->Create(1);
1088 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1090 } elseif ($type ==
'boolean') {
1093 if (!empty($value)) {
1094 $checked =
' checked value="1" ';
1096 $checked =
' value="1" ';
1098 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1100 $out .=
$form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1);
1102 } elseif ($type ==
'price') {
1103 if (!empty($value)) {
1104 $value =
price($value);
1106 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
1107 } elseif ($type ==
'pricecy') {
1108 $currency = $conf->currency;
1109 if (!empty($value)) {
1111 $pricetmp = explode(
':', $value);
1112 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1113 $value =
price($pricetmp[0]);
1115 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1116 $out .=
$form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1117 } elseif ($type ==
'double') {
1118 if (!empty($value)) {
1119 $value =
price($value);
1121 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1122 } elseif ($type ==
'select') {
1126 foreach ($param[
'options'] as $okey => $val) {
1127 if ((
string) $okey ==
'') {
1131 $valarray = explode(
'|', $val);
1132 $val = $valarray[0];
1134 if ($langfile && $val) {
1135 $options[$okey] = $langs->trans($val);
1137 $options[$okey] = $val;
1140 $selected = array();
1141 if (!is_array($value)) {
1142 $selected = explode(
',', $value);
1145 $out .=
$form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', !empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2));
1147 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1148 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1149 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1152 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1153 $out .=
'<option value="0"> </option>';
1154 foreach ($param[
'options'] as $key2 => $val2) {
1155 if ((
string) $key2 ==
'') {
1158 $valarray = explode(
'|', $val2);
1159 $val2 = $valarray[0];
1161 if (!empty($valarray[1])) {
1162 $parent = $valarray[1];
1164 $out .=
'<option value="'.$key2.
'"';
1165 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1166 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1168 if ($langfile && $val2) {
1169 $out .= $langs->trans($val2);
1173 $out .=
'</option>';
1175 $out .=
'</select>';
1177 } elseif ($type ==
'sellist') {
1179 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1180 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1181 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1184 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1185 if (is_array($param[
'options'])) {
1186 $param_list = array_keys($param[
'options']);
1187 $InfoFieldList = explode(
":", $param_list[0]);
1197 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1200 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1201 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1202 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1204 $keyList = $InfoFieldList[2].
' as rowid';
1207 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1208 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1209 $keyList .=
', '.$parentField;
1212 $filter_categorie =
false;
1213 if (count($InfoFieldList) > 5) {
1214 if ($InfoFieldList[0] ==
'categorie') {
1215 $filter_categorie =
true;
1219 if ($filter_categorie ===
false) {
1220 $fields_label = explode(
'|', $InfoFieldList[1]);
1221 if (is_array($fields_label)) {
1223 $keyList .= implode(
', ', $fields_label);
1227 $sql =
"SELECT ".$keyList;
1228 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1229 if (!empty($InfoFieldList[4])) {
1231 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1232 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1235 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1236 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1240 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1241 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1243 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1246 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1247 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1248 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1250 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1253 $sqlwhere .=
' WHERE 1=1';
1256 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1257 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1262 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1264 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1265 $resql = $this->db->query(
$sql);
1267 $out .=
'<option value="0"> </option>';
1268 $num = $this->db->num_rows($resql);
1272 $obj = $this->db->fetch_object($resql);
1276 $fields_label = explode(
'|', $InfoFieldList[1]);
1277 if (is_array($fields_label) && count($fields_label) > 1) {
1279 foreach ($fields_label as $field_toshow) {
1280 $labeltoshow .= $obj->$field_toshow.
' ';
1283 $labeltoshow = $obj->{$InfoFieldList[1]};
1285 $labeltoshow = $labeltoshow;
1287 if ($value == $obj->rowid) {
1289 foreach ($fields_label as $field_toshow) {
1290 $translabel = $langs->trans($obj->$field_toshow);
1291 $labeltoshow = $translabel.
' ';
1294 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1297 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1298 $labeltoshow = $translabel;
1300 if (empty($labeltoshow)) {
1301 $labeltoshow =
'(not defined)';
1304 if (!empty($InfoFieldList[3]) && $parentField) {
1305 $parent = $parentName.
':'.$obj->{$parentField};
1308 $out .=
'<option value="'.$obj->rowid.
'"';
1309 $out .= ($value == $obj->rowid ?
' selected' :
'');
1310 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1311 $out .=
'>'.$labeltoshow.
'</option>';
1316 $this->db->free($resql);
1318 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1321 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1322 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1323 $out .=
'<option value="0"> </option>';
1324 if (is_array($data)) {
1325 foreach ($data as $data_key => $data_value) {
1326 $out .=
'<option value="'.$data_key.
'"';
1327 $out .= ($value == $data_key ?
' selected' :
'');
1328 $out .=
'>'.$data_value.
'</option>';
1333 $out .=
'</select>';
1334 } elseif ($type ==
'checkbox') {
1335 $value_arr = $value;
1336 if (!is_array($value)) {
1337 $value_arr = explode(
',', $value);
1339 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1340 } elseif ($type ==
'radio') {
1342 foreach ($param[
'options'] as $keyopt => $val) {
1343 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1344 $out .=
' value="'.$keyopt.
'"';
1345 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1346 $out .= ($value == $keyopt ?
'checked' :
'');
1347 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1349 } elseif ($type ==
'chkbxlst') {
1350 if (is_array($value)) {
1351 $value_arr = $value;
1353 $value_arr = explode(
',', $value);
1356 if (is_array($param[
'options'])) {
1357 $param_list = array_keys($param[
'options']);
1358 $InfoFieldList = explode(
":", $param_list[0]);
1368 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1370 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1371 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1372 $keyList .=
', '.$parentField;
1374 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1375 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1376 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1378 $keyList = $InfoFieldList[2].
' as rowid';
1382 $filter_categorie =
false;
1383 if (count($InfoFieldList) > 5) {
1384 if ($InfoFieldList[0] ==
'categorie') {
1385 $filter_categorie =
true;
1389 if ($filter_categorie ===
false) {
1390 $fields_label = explode(
'|', $InfoFieldList[1]);
1391 if (is_array($fields_label)) {
1393 $keyList .= implode(
', ', $fields_label);
1397 $sql =
"SELECT ".$keyList;
1398 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1399 if (!empty($InfoFieldList[4])) {
1401 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1402 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1405 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1406 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1410 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1411 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1412 } elseif (preg_match(
"#^.*list.php$#", $_SERVER[
"PHP_SELF"])) {
1414 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1417 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1421 while ($nbPreg != 0) {
1423 $nbPregRepl = $nbPregSel = 0;
1425 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1427 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1429 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1431 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1434 $nbPreg = $nbPregRepl + $nbPregSel;
1438 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1439 while (!empty($matchCondition[0])) {
1441 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1443 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1445 if (!empty($matchCondition[1])) {
1446 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1447 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1448 } elseif (!empty($matchCondition[3])) {
1449 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1450 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1452 $InfoFieldList[4] =
" TRUE ";
1457 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1460 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1464 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1465 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1466 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1468 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1471 $sqlwhere .=
' WHERE 1=1';
1474 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1475 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1481 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1482 $resql = $this->db->query(
$sql);
1484 $num = $this->db->num_rows($resql);
1491 $obj = $this->db->fetch_object($resql);
1495 $fields_label = explode(
'|', $InfoFieldList[1]);
1496 if (is_array($fields_label)) {
1498 foreach ($fields_label as $field_toshow) {
1499 $labeltoshow .= $obj->$field_toshow.
' ';
1502 $labeltoshow = $obj->{$InfoFieldList[1]};
1504 $labeltoshow =
dol_trunc($labeltoshow, 45);
1506 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1508 foreach ($fields_label as $field_toshow) {
1509 $translabel = $langs->trans($obj->$field_toshow);
1510 if ($translabel != $obj->$field_toshow) {
1511 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1513 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1516 $data[$obj->rowid] = $labeltoshow;
1519 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1520 if ($translabel != $obj->{$InfoFieldList[1]}) {
1521 $labeltoshow =
dol_trunc($translabel, 18);
1523 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1526 if (empty($labeltoshow)) {
1527 $labeltoshow =
'(not defined)';
1530 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1531 $data[$obj->rowid] = $labeltoshow;
1534 if (!empty($InfoFieldList[3]) && $parentField) {
1535 $parent = $parentName.
':'.$obj->{$parentField};
1538 $data[$obj->rowid] = $labeltoshow;
1543 $this->db->free($resql);
1545 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1547 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1550 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1551 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1552 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1555 } elseif ($type ==
'link') {
1556 $param_list = array_keys($param[
'options']);
1557 $showempty = (($required && $default !=
'') ? 0 : 1);
1558 $out =
$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss);
1559 } elseif ($type ==
'password') {
1561 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1562 $out .=
'<input autocomplete="new-password" type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
1564 if (!empty($hidden)) {
1565 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1587 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'')
1589 global $conf, $langs;
1591 if (empty($extrafieldsobjectkey)) {
1592 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
1593 return 'BadValueForParamExtraFieldsObjectKey';
1596 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1597 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1598 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1599 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1600 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1601 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1602 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1603 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1604 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1605 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1606 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1607 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1608 $hidden = (empty($list) ? 1 : 0);
1617 if ($type ==
'date') {
1619 if ($value !==
'') {
1622 } elseif ($type ==
'datetime') {
1624 if ($value !==
'') {
1627 } elseif ($type ==
'datetimegmt') {
1629 if ($value !==
'') {
1632 } elseif ($type ==
'int') {
1634 } elseif ($type ==
'double') {
1635 if (!empty($value)) {
1637 $sizeparts = explode(
",", $size);
1638 $number_decimals = array_key_exists(1, $sizeparts) ? $sizeparts[1] : 0;
1639 $value =
price($value, 0, $langs, 0, 0, $number_decimals,
'');
1641 } elseif ($type ==
'boolean') {
1643 if (!empty($value)) {
1644 $checked =
' checked ';
1646 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1647 } elseif ($type ==
'mail') {
1649 } elseif ($type ==
'ip') {
1651 } elseif ($type ==
'url') {
1653 } elseif ($type ==
'phone') {
1655 } elseif ($type ==
'price') {
1657 if ($value || $value ==
'0') {
1658 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1).
' '.$langs->getCurrencySymbol($conf->currency);
1660 } elseif ($type ==
'pricecy') {
1661 $currency = $conf->currency;
1662 if (!empty($value)) {
1664 $pricetmp = explode(
':', $value);
1665 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1666 $value = $pricetmp[0];
1668 if ($value || $value ==
'0') {
1669 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1, $currency);
1671 } elseif ($type ==
'select') {
1672 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
1673 if (($pos = strpos($valstr,
"|")) !==
false) {
1674 $valstr = substr($valstr, 0, $pos);
1676 if ($langfile && $valstr) {
1677 $value = $langs->trans($valstr);
1681 } elseif ($type ==
'sellist') {
1682 $param_list = array_keys($param[
'options']);
1683 $InfoFieldList = explode(
":", $param_list[0]);
1685 $selectkey =
"rowid";
1688 if (count($InfoFieldList) >= 3) {
1689 $selectkey = $InfoFieldList[2];
1690 $keyList = $InfoFieldList[2].
' as rowid';
1693 $fields_label = explode(
'|', $InfoFieldList[1]);
1694 if (is_array($fields_label)) {
1696 $keyList .= implode(
', ', $fields_label);
1699 $filter_categorie =
false;
1700 if (count($InfoFieldList) > 5) {
1701 if ($InfoFieldList[0] ==
'categorie') {
1702 $filter_categorie =
true;
1706 $sql =
"SELECT ".$keyList;
1707 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1708 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1711 if ($selectkey ==
'rowid' && empty($value)) {
1712 $sql .=
" WHERE ".$selectkey.
" = 0";
1713 } elseif ($selectkey ==
'rowid') {
1714 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
1716 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
1721 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
1722 $resql = $this->db->query(
$sql);
1724 if ($filter_categorie ===
false) {
1727 $obj = $this->db->fetch_object($resql);
1730 $fields_label = explode(
'|', $InfoFieldList[1]);
1732 if (is_array($fields_label) && count($fields_label) > 1) {
1733 foreach ($fields_label as $field_toshow) {
1735 if (!empty($obj->$field_toshow)) {
1736 $translabel = $langs->trans($obj->$field_toshow);
1738 if ($translabel != $obj->$field_toshow) {
1739 $value .=
dol_trunc($translabel, 24).
' ';
1741 $value .= $obj->$field_toshow.
' ';
1746 $tmppropname = $InfoFieldList[1];
1748 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1749 $translabel = $langs->trans($obj->$tmppropname);
1751 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1754 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
1759 $obj = $this->db->fetch_object($resql);
1761 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1763 $result = $c->fetch($obj->rowid);
1765 $ways = $c->print_all_ways();
1766 foreach ($ways as $way) {
1767 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1771 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1774 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
1776 } elseif ($type ==
'radio') {
1777 if (!isset($param[
'options'][$value])) {
1778 $langs->load(
'errors');
1779 $value = $langs->trans(
'ErrorNoValueForRadioType');
1781 $value = $langs->trans($param[
'options'][$value]);
1783 } elseif ($type ==
'checkbox') {
1784 $value_arr = explode(
',', $value);
1787 if (is_array($value_arr)) {
1788 foreach ($value_arr as $keyval => $valueval) {
1789 if (!empty($valueval)) {
1790 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
1794 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1795 } elseif ($type ==
'chkbxlst') {
1796 $value_arr = explode(
',', $value);
1798 $param_list = array_keys($param[
'options']);
1799 $InfoFieldList = explode(
":", $param_list[0]);
1801 $selectkey =
"rowid";
1804 if (count($InfoFieldList) >= 3) {
1805 $selectkey = $InfoFieldList[2];
1806 $keyList = $InfoFieldList[2].
' as rowid';
1809 $fields_label = explode(
'|', $InfoFieldList[1]);
1810 if (is_array($fields_label)) {
1812 $keyList .= implode(
', ', $fields_label);
1815 $filter_categorie =
false;
1816 if (count($InfoFieldList) > 5) {
1817 if ($InfoFieldList[0] ==
'categorie') {
1818 $filter_categorie =
true;
1822 $sql =
"SELECT ".$keyList;
1823 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
1824 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1830 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
1831 $resql = $this->db->query(
$sql);
1833 if ($filter_categorie ===
false) {
1836 while ($obj = $this->db->fetch_object($resql)) {
1838 $fields_label = explode(
'|', $InfoFieldList[1]);
1839 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1840 if (is_array($fields_label) && count($fields_label) > 1) {
1841 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
1842 foreach ($fields_label as $field_toshow) {
1844 if (!empty($obj->$field_toshow)) {
1845 $translabel = $langs->trans($obj->$field_toshow);
1847 if ($translabel != $field_toshow) {
1848 $label .=
' '.dol_trunc($translabel, 18);
1850 $label .=
' '.$obj->$field_toshow;
1854 $toprint[] = $label;
1857 if (!empty($obj->{$InfoFieldList[1]})) {
1858 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1860 if ($translabel != $obj->{$InfoFieldList[1]}) {
1861 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1863 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
1869 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1872 while ($obj = $this->db->fetch_object($resql)) {
1873 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1875 $c->fetch($obj->rowid);
1876 $ways = $c->print_all_ways();
1877 foreach ($ways as $way) {
1878 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1883 if (!empty($toprint)) $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1885 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
1887 } elseif ($type ==
'link') {
1892 $param_list = array_keys($param[
'options']);
1894 $InfoFieldList = explode(
":", $param_list[0]);
1895 $classname = $InfoFieldList[0];
1896 $classpath = $InfoFieldList[1];
1897 if (!empty($classpath)) {
1899 if ($classname && class_exists($classname)) {
1900 $object =
new $classname($this->db);
1901 $object->fetch($value);
1902 $value = $object->getNomUrl(3);
1905 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
1906 return 'Error bad setup of extrafield';
1909 } elseif ($type ==
'text') {
1911 } elseif ($type ==
'html') {
1913 } elseif ($type ==
'password') {
1914 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
1916 $showsize = round((
float) $size);
1917 if ($showsize > 48) {
1937 global $conf, $langs;
1940 if (!empty($extrafieldsobjectkey)) {
1941 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1946 if (in_array($type, array(
'date',
'datetime',
'datetimegmt'))) {
1947 $cssstring =
"center";
1948 } elseif (in_array($type, array(
'int',
'price',
'double'))) {
1949 $cssstring =
"right";
1950 } elseif (in_array($type, array(
'boolean',
'radio',
'checkbox',
'ip'))) {
1951 $cssstring =
"center";
1954 if (!empty($this->attributes[$extrafieldsobjectkey][
'csslist'][$key])) {
1955 $cssstring .= ($cssstring ?
' ' :
'').$this->attributes[$extrafieldsobjectkey][
'csslist'][$key];
1957 if (in_array($type, array(
'ip'))) {
1958 $cssstring .= ($cssstring ?
' ' :
'').
'tdoverflowmax150';
1975 public function showSeparator($key, $object, $colspan = 2, $display_type =
'card', $mode =
'')
1977 global $conf, $langs;
1982 if ($display_type==
'line') {
1984 $tagtype_dyn=
'span';
1988 $extrafield_param = $this->attributes[$object->table_element][
'param'][$key];
1989 $extrafield_param_list = array();
1990 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1991 $extrafield_param_list = array_keys($extrafield_param[
'options']);
1995 $extrafield_collapse_display_value = -1;
1996 $expand_display =
false;
1997 if (is_array($extrafield_param_list) && count($extrafield_param_list) > 0) {
1998 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1999 $expand_display = ((isset($_COOKIE[
'DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key]) ||
GETPOST(
'ignorecollapsesetup',
'int')) ? (empty($_COOKIE[
'DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key]) ? false :
true) : ($extrafield_collapse_display_value == 2 ?
false :
true));
2001 $disabledcookiewrite = 0;
2002 if ($mode ==
'create') {
2004 $extrafield_collapse_display_value = 1;
2005 $expand_display =
true;
2006 $disabledcookiewrite = 1;
2009 $out =
'<'.$tagtype.
' id="trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'" class="trextrafieldseparator trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'">';
2010 $out .=
'<'.$tagtype_dyn.
' '.(!empty($colspan)?
'colspan="' . $colspan .
'"':
'').
'>';
2013 $out .=
'<span class="'.($extrafield_collapse_display_value ?
'cursorpointer ' :
'').($extrafield_collapse_display_value == 0 ?
'fas fa-square opacitymedium' :
'far fa-'.(($expand_display ?
'minus' :
'plus').
'-square')).
'"></span>';
2016 $out .= $langs->trans($this->attributes[$object->table_element][
'label'][$key]);
2017 $out .=
'</strong>';
2018 $out .=
'</'.$tagtype_dyn.
'>';
2019 $out .=
'</'.$tagtype.
'>';
2021 $collapse_group = $key.(!empty($object->id) ?
'_'.$object->id :
'');
2024 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
2026 $this->expand_display[$collapse_group] = $expand_display;
2028 if (!empty($conf->use_javascript_ajax)) {
2029 $out .=
'<!-- Add js script to manage the collapse/uncollapse of extrafields separators '.$key.
' -->'.
"\n";
2030 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
2031 $out .=
'jQuery(document).ready(function(){'.
"\n";
2032 if (empty($disabledcookiewrite)) {
2033 if ($expand_display ===
false) {
2034 $out .=
' console.log("Inject js for the collapsing of extrafield '.$key.
' - hide");'.
"\n";
2035 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").hide();'.
"\n";
2037 $out .=
' console.log("Inject js for collapsing of extrafield '.$key.
' - keep visible and set cookie");'.
"\n";
2038 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2041 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'").click(function(){'.
"\n";
2042 $out .=
' console.log("We click on collapse/uncollapse to hide/show .trextrafields_collapse'.$collapse_group.
'");'.
"\n";
2043 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").toggle(100, function(){'.
"\n";
2044 $out .=
' if (jQuery(".trextrafields_collapse'.$collapse_group.
'").is(":hidden")) {'.
"\n";
2045 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-plus-square").removeClass("fa-minus-square");'.
"\n";
2046 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=0; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2047 $out .=
' } else {'.
"\n";
2048 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-minus-square").removeClass("fa-plus-square");'.
"\n";
2049 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2051 $out .=
' });'.
"\n";
2052 $out .=
' });'.
"\n";
2054 $out .=
'</script>'.
"\n";
2057 $this->expand_display[$collapse_group] = 1;
2076 global $_POST, $langs;
2078 $nofillrequired = 0;
2079 $error_field_required = array();
2081 if (isset($this->attributes[$object->table_element][
'label']) && is_array($this->attributes[$object->table_element][
'label'])) {
2082 $extralabels = $this->attributes[$object->table_element][
'label'];
2085 if (is_array($extralabels)) {
2087 foreach ($extralabels as $key => $value) {
2088 if (!empty($onlykey) && $onlykey !=
'@GETPOSTISSET' && $key != $onlykey) {
2092 if (!empty($onlykey) && $onlykey ==
'@GETPOSTISSET' && !
GETPOSTISSET(
'options_'.$key) && (! in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'checkbox',
'chkbxlst')))) {
2097 $key_type = $this->attributes[$object->table_element][
'type'][$key];
2098 if ($key_type ==
'separate') {
2103 if (isset($this->attributes[$object->table_element][
'enabled'][$key])) {
2104 $enabled =
dol_eval($this->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'2');
2108 if (isset($this->attributes[$object->table_element][
'list'][$key])) {
2109 $visibility = intval(
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1, 1,
'2'));
2113 if (isset($this->attributes[$object->table_element][
'perms'][$key])) {
2114 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1, 1,
'2');
2118 $onlykey ===
'@GETPOSTISSET'
2119 && in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'checkbox',
'chkbxlst'))
2120 && in_array(abs($enabled), array(2, 5))
2126 $visibility_abs = abs($visibility);
2128 if (empty($visibility_abs) || $visibility_abs == 2 || $visibility_abs == 5) {
2131 if (empty($perms)) {
2135 if ($this->attributes[$object->table_element][
'required'][$key]) {
2139 if ((!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] !=
'select' && $_POST[
"options_".$key] !=
'0')
2140 || (!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'select')
2141 || (!is_array($_POST[
"options_".$key]) && isset($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'sellist' && $_POST[
'options_'.$key] ==
'0')
2142 || (is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]))) {
2148 if (!empty($this->attributes[$object->table_element][
'langfile'][$key])) {
2149 $langs->load($this->attributes[$object->table_element][
'langfile'][$key]);
2151 $error_field_required[$key] = $langs->transnoentitiesnoconv($value);
2155 if (in_array($key_type, array(
'date'))) {
2157 $value_key =
dol_mktime(12, 0, 0,
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'));
2158 } elseif (in_array($key_type, array(
'datetime'))) {
2160 $value_key =
dol_mktime(
GETPOST(
"options_".$key.
"hour",
'int'),
GETPOST(
"options_".$key.
"min",
'int'),
GETPOST(
"options_".$key.
"sec",
'int'),
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'),
'tzuserrel');
2161 } elseif (in_array($key_type, array(
'datetimegmt'))) {
2163 $value_key =
dol_mktime(
GETPOST(
"options_".$key.
"hour",
'int'),
GETPOST(
"options_".$key.
"min",
'int'),
GETPOST(
"options_".$key.
"sec",
'int'),
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'),
'gmt');
2164 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2165 $value_arr =
GETPOST(
"options_".$key,
'array');
2166 if (!empty($value_arr)) {
2167 $value_key = implode(
',', $value_arr);
2171 } elseif (in_array($key_type, array(
'price',
'double'))) {
2172 $value_arr =
GETPOST(
"options_".$key,
'alpha');
2174 } elseif (in_array($key_type, array(
'pricecy',
'double'))) {
2175 $value_key =
price2num(
GETPOST(
"options_".$key,
'alpha')).
':'.
GETPOST(
"options_".$key.
"currency_id",
'alpha');
2176 } elseif (in_array($key_type, array(
'html'))) {
2177 $value_key =
GETPOST(
"options_".$key,
'restricthtml');
2178 } elseif (in_array($key_type, array(
'text'))) {
2179 $label_security_check =
'alphanohtml';
2181 if (!empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_REF_LABELS)) {
2182 $label_security_check =
'nohtml';
2184 $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML) ?
'alphanohtml' :
'restricthtml';
2186 $value_key =
GETPOST(
"options_".$key, $label_security_check);
2188 $value_key =
GETPOST(
"options_".$key);
2189 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
2194 if (!empty($error_field_required[$key]) && $todefaultifmissing) {
2196 if (!empty($this->attributes[$object->table_element][
'default']) && !is_null($this->attributes[$object->table_element][
'default'][$key])) {
2197 $value_key = $this->attributes[$object->table_element][
'default'][$key];
2198 unset($error_field_required[$key]);
2203 $object->array_options[
"options_".$key] = $value_key;
2206 if ($nofillrequired) {
2207 $langs->load(
'errors');
2208 $this->error = $langs->trans(
'ErrorFieldsRequired').
' : '.implode(
', ', $error_field_required);
2231 if (is_string($extrafieldsobjectkey) && !empty($this->attributes[$extrafieldsobjectkey][
'label']) && is_array($this->attributes[$extrafieldsobjectkey][
'label'])) {
2232 $extralabels = $this->attributes[$extrafieldsobjectkey][
'label'];
2234 $extralabels = $extrafieldsobjectkey;
2237 if (is_array($extralabels)) {
2238 $array_options = array();
2241 foreach ($extralabels as $key => $value) {
2243 if (is_string($extrafieldsobjectkey)) {
2244 $key_type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2247 if (in_array($key_type, array(
'date'))) {
2248 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2249 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2253 'start' =>
dol_mktime(0, 0, 0,
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int')),
2254 'end' =>
dol_mktime(23, 59, 59,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'))
2256 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2258 $value_key =
dol_mktime(12, 0, 0,
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"month",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"day",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"year",
'int'));
2262 } elseif (in_array($key_type, array(
'datetime',
'datetimegmt'))) {
2263 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2264 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2267 $dateparamname_end_hour =
GETPOST($dateparamname_end .
'hour',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'hour',
'int') :
'23';
2268 $dateparamname_end_min =
GETPOST($dateparamname_end .
'min',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'min',
'int') :
'59';
2269 $dateparamname_end_sec =
GETPOST($dateparamname_end .
'sec',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'sec',
'int') :
'59';
2270 if ($key_type ==
'datetimegmt') {
2272 'start' =>
dol_mktime(
GETPOST($dateparamname_start .
'hour',
'int'),
GETPOST($dateparamname_start .
'min',
'int'),
GETPOST($dateparamname_start .
'sec',
'int'),
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int'),
'gmt'),
2273 'end' =>
dol_mktime($dateparamname_end_hour, $dateparamname_end_min, $dateparamname_end_sec,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'),
'gmt')
2277 'start' =>
dol_mktime(
GETPOST($dateparamname_start .
'hour',
'int'),
GETPOST($dateparamname_start .
'min',
'int'),
GETPOST($dateparamname_start .
'sec',
'int'),
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int'),
'tzuserrel'),
2278 'end' =>
dol_mktime($dateparamname_end_hour, $dateparamname_end_min, $dateparamname_end_sec,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'),
'tzuserrel')
2281 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2283 if ($key_type ==
'datetimegmt') {
2284 $value_key =
dol_mktime(
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"hour",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"min",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"sec",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"month",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"day",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"year",
'int'),
'gmt');
2286 $value_key =
dol_mktime(
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"hour",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"min",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"sec",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"month",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"day",
'int'),
GETPOST($keysuffix.
"options_".$key.$keyprefix.
"year",
'int'),
'tzuserrel');
2291 } elseif ($key_type ==
'select') {
2294 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix,
'array:aZ09');
2296 $value_arr = (array) $value_arr;
2297 $value_key = implode(
',', $value_arr);
2299 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2301 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2302 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2305 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2307 $value_arr = (array) $value_arr;
2308 $value_key = implode(
',', $value_arr);
2309 } elseif (in_array($key_type, array(
'price',
'double',
'int'))) {
2310 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2313 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2314 if ($keysuffix !=
'search_') {
2317 $value_key = $value_arr;
2319 } elseif (in_array($key_type, array(
'boolean'))) {
2320 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2323 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2324 $value_key = $value_arr;
2326 } elseif (in_array($key_type, array(
'html'))) {
2327 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2332 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2335 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2338 $array_options[$keysuffix.
"options_".$key] = $value_key;
2341 return $array_options;