54 public $expand_display;
64 public $errors = array();
74 public static $type2label = array(
75 'varchar'=>
'String1Line',
76 'text'=>
'TextLongNLines',
81 'datetime'=>
'DateAndTime',
83 'price'=>
'ExtrafieldPrice',
84 'pricecy'=>
'ExtrafieldPriceWithCurrency',
85 'phone'=>
'ExtrafieldPhone',
86 'mail'=>
'ExtrafieldMail',
87 'url'=>
'ExtrafieldUrl',
89 'password' =>
'ExtrafieldPassword',
90 'select' =>
'ExtrafieldSelect',
91 'sellist' =>
'ExtrafieldSelectList',
92 'radio' =>
'ExtrafieldRadio',
93 'checkbox' =>
'ExtrafieldCheckBox',
94 'chkbxlst' =>
'ExtrafieldCheckBoxFromList',
95 'link' =>
'ExtrafieldLink',
96 'separate' =>
'ExtrafieldSeparator',
109 $this->errors = array();
110 $this->attributes = array();
139 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())
141 if (empty($attrname)) {
150 if ($type ==
'separate') {
154 if ($elementtype ==
'thirdparty') {
155 $elementtype =
'societe';
157 if ($elementtype ==
'contact') {
158 $elementtype =
'socpeople';
162 if ($type !=
'separate') {
163 $result = $this->
create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help, $moreparams);
165 $err1 = $this->errno;
166 if ($result > 0 || $err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type ==
'separate') {
168 $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);
169 $err2 = $this->errno;
170 if ($result2 > 0 || ($err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 ==
'DB_ERROR_RECORD_ALREADY_EXISTS')) {
201 private function create($attrname, $type =
'varchar', $length = 255, $elementtype =
'member', $unique = 0, $required = 0, $default_value =
'', $param =
'', $perms =
'', $list =
'0', $computed =
'', $help =
'', $moreparams = array())
203 if ($elementtype ==
'thirdparty') {
204 $elementtype =
'societe';
206 if ($elementtype ==
'contact') {
207 $elementtype =
'socpeople';
210 $table = $elementtype.
'_extrafields';
211 if ($elementtype ==
'categorie') {
212 $table =
'categories_extrafields';
215 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) {
216 if ($type ==
'boolean') {
219 } elseif ($type ==
'price') {
222 } elseif ($type ==
'pricecy') {
225 } elseif ($type ==
'phone') {
228 } elseif ($type ==
'mail' || $type ==
'ip') {
231 } elseif ($type ==
'url') {
234 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
237 } elseif ($type ==
'link') {
240 } elseif ($type ==
'html') {
243 } elseif ($type ==
'password') {
249 if ($type ==
'varchar' && empty($lengthdb)) {
256 'null'=>($required ?
'NOT NULL' :
'NULL'),
257 'default' => $default_value
260 $result = $this->
db->DDLAddField($this->
db->prefix().$table, $attrname, $field_desc);
263 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
264 $resql = $this->
db->query($sql, 1,
'dml');
268 $this->error = $this->
db->lasterror();
269 $this->errno = $this->
db->lasterrno();
305 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())
310 if ($elementtype ==
'thirdparty') {
311 $elementtype =
'societe';
313 if ($elementtype ==
'contact') {
314 $elementtype =
'socpeople';
324 if (empty($required)) {
327 if (empty($unique)) {
330 if (empty($printable)) {
333 if (empty($alwayseditable)) {
336 if (empty($totalizable)) {
341 if (!empty($moreparams) && !empty($moreparams[
'css'])) {
342 $css = $moreparams[
'css'];
345 if (!empty($moreparams) && !empty($moreparams[
'csslist'])) {
346 $csslist = $moreparams[
'csslist'];
349 if (!empty($moreparams) && !empty($moreparams[
'cssview'])) {
350 $cssview = $moreparams[
'cssview'];
353 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) {
354 if (is_array($param) && count($param) > 0) {
355 $params = serialize($param);
356 } elseif (strlen($param) > 0) {
357 $params = trim($param);
362 $sql =
"INSERT INTO ".$this->db->prefix().
"extrafields(";
369 $sql .=
" elementtype,";
370 $sql .=
" fieldunique,";
371 $sql .=
" fieldrequired,";
373 $sql .=
" alwayseditable,";
377 $sql .=
" printable,";
378 $sql .=
" fielddefault,";
379 $sql .=
" fieldcomputed,";
380 $sql .=
" fk_user_author,";
381 $sql .=
" fk_user_modif,";
385 $sql .=
" totalizable,";
390 $sql .=
" VALUES('".$this->db->escape($attrname).
"',";
391 $sql .=
" '".$this->db->escape($label).
"',";
392 $sql .=
" '".$this->db->escape($type).
"',";
393 $sql .=
" ".((int) $pos).
",";
394 $sql .=
" '".$this->db->escape($size).
"',";
395 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
396 $sql .=
" '".$this->db->escape($elementtype).
"',";
397 $sql .=
" ".((int) $unique).
",";
398 $sql .=
" ".((int) $required).
",";
399 $sql .=
" '".$this->db->escape($params).
"',";
400 $sql .=
" ".((int) $alwayseditable).
",";
401 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
402 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
403 $sql .=
" '".$this->db->escape($list).
"',";
404 $sql .=
" '".$this->db->escape($printable).
"',";
405 $sql .=
" ".($default ?
"'".$this->db->escape($default).
"'" :
"null").
",";
406 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
407 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
408 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
409 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
410 $sql .=
" ".($enabled ?
"'".$this->db->escape($enabled).
"'" :
"1").
",";
411 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
412 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE').
",";
413 $sql .=
" ".($css ?
"'".$this->db->escape($css).
"'" :
"null").
",";
414 $sql .=
" ".($csslist ?
"'".$this->db->escape($csslist).
"'" :
"null").
",";
415 $sql .=
" ".($cssview ?
"'".$this->db->escape($cssview).
"'" :
"null");
418 dol_syslog(get_class($this).
"::create_label", LOG_DEBUG);
419 if ($this->
db->query($sql)) {
422 $this->error = $this->
db->lasterror();
423 $this->errno = $this->
db->lasterrno();
436 public function delete($attrname, $elementtype =
'member')
438 if ($elementtype ==
'thirdparty') {
439 $elementtype =
'societe';
441 if ($elementtype ==
'contact') {
442 $elementtype =
'socpeople';
445 $table = $elementtype.
'_extrafields';
446 if ($elementtype ==
'categorie') {
447 $table =
'categories_extrafields';
452 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
455 $this->error = $this->
db->lasterror();
456 $this->errors[] = $this->
db->lasterror();
461 $sql =
"SELECT COUNT(rowid) as nb";
462 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
463 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
464 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
468 $obj = $this->
db->fetch_object(
$resql);
470 $result = $this->
db->DDLDropField($this->
db->prefix().$table, $attrname);
472 $this->error = $this->
db->lasterror();
473 $this->errors[] = $this->
db->lasterror();
499 if ($elementtype ==
'thirdparty') {
500 $elementtype =
'societe';
502 if ($elementtype ==
'contact') {
503 $elementtype =
'socpeople';
506 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
507 $sql =
"DELETE FROM ".$this->db->prefix().
"extrafields";
508 $sql .=
" WHERE name = '".$this->db->escape($attrname).
"'";
509 $sql .=
" AND entity IN (0,".$conf->entity.
')';
510 $sql .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
512 dol_syslog(get_class($this).
"::delete_label", LOG_DEBUG);
552 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())
556 if ($elementtype ==
'thirdparty') {
557 $elementtype =
'societe';
559 if ($elementtype ==
'contact') {
560 $elementtype =
'socpeople';
563 $table = $elementtype.
'_extrafields';
564 if ($elementtype ==
'categorie') {
565 $table =
'categories_extrafields';
568 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
569 if ($type ==
'boolean') {
572 } elseif ($type ==
'price') {
575 } elseif ($type ==
'pricecy') {
578 } elseif ($type ==
'phone') {
581 } elseif ($type ==
'mail' || $type ==
'ip') {
584 } elseif ($type ==
'url') {
587 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
590 } elseif ($type ==
'html') {
592 } elseif ($type ==
'link') {
595 } elseif ($type ==
'password') {
602 $field_desc = array(
'type'=>$typedb,
'value'=>$lengthdb,
'null'=>($required ?
'NOT NULL' :
'NULL'),
'default'=>$default);
604 if (is_object($hookmanager)) {
605 $hookmanager->initHooks(array(
'extrafieldsdao'));
606 $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);
607 $reshook = $hookmanager->executeHooks(
'updateExtrafields', $parameters, $this, $action);
610 $this->error = $this->
db->lasterror();
615 if ($type !=
'separate') {
616 $result = $this->
db->DDLUpdateField($this->
db->prefix().$table, $attrname, $field_desc);
618 if ($result > 0 || $type ==
'separate') {
620 $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);
625 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
627 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" DROP INDEX IF EXISTS uk_".$table.
"_".$attrname;
629 dol_syslog(get_class($this).
'::update', LOG_DEBUG);
630 $resql = $this->
db->query($sql, 1,
'dml');
637 $this->error = $this->
db->lasterror();
641 $this->error = $this->
db->lasterror();
677 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())
681 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);
684 if ($elementtype ==
'thirdparty') {
685 $elementtype =
'societe';
687 if ($elementtype ==
'contact') {
688 $elementtype =
'socpeople';
697 if (empty($totalizable)) {
700 if (empty($required)) {
703 if (empty($unique)) {
706 if (empty($alwayseditable)) {
711 if (!empty($moreparams) && !empty($moreparams[
'css'])) {
712 $css = $moreparams[
'css'];
715 if (!empty($moreparams) && !empty($moreparams[
'csslist'])) {
716 $csslist = $moreparams[
'csslist'];
719 if (!empty($moreparams) && !empty($moreparams[
'cssview'])) {
720 $cssview = $moreparams[
'cssview'];
723 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
726 if (is_array($param) && count($param) > 0) {
727 $params = serialize($param);
728 } elseif (strlen($param) > 0) {
729 $params = trim($param);
734 if ($entity ===
'' || $entity !=
'0') {
736 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
737 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
738 $sql_del .=
" AND entity IN (0, ".($entity ===
'' ? $conf->entity : $entity).
")";
739 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
742 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
743 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
744 $sql_del .=
" AND entity = 0";
745 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
747 $resql1 = $this->
db->query($sql_del);
749 $sql =
"INSERT INTO ".$this->db->prefix().
"extrafields(";
755 $sql .=
" elementtype,";
756 $sql .=
" fieldunique,";
757 $sql .=
" fieldrequired,";
761 $sql .=
" alwayseditable,";
764 $sql .=
" printable,";
765 $sql .=
" totalizable,";
766 $sql .=
" fielddefault,";
767 $sql .=
" fieldcomputed,";
768 $sql .=
" fk_user_author,";
769 $sql .=
" fk_user_modif,";
776 $sql .=
") VALUES (";
777 $sql .=
"'".$this->db->escape($attrname).
"',";
778 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
779 $sql .=
" '".$this->db->escape($label).
"',";
780 $sql .=
" '".$this->db->escape($type).
"',";
781 $sql .=
" '".$this->db->escape($size).
"',";
782 $sql .=
" '".$this->db->escape($elementtype).
"',";
783 $sql .=
" ".$unique.
",";
784 $sql .=
" ".$required.
",";
785 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
786 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
787 $sql .=
" ".$pos.
",";
788 $sql .=
" '".$this->db->escape($alwayseditable).
"',";
789 $sql .=
" '".$this->db->escape($params).
"',";
790 $sql .=
" '".$this->db->escape($list).
"', ";
791 $sql .=
" '".$this->db->escape($printable).
"', ";
792 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE').
",";
793 $sql .=
" ".(($default !=
'') ?
"'".$this->
db->escape($default).
"'" :
"null").
",";
794 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
795 $sql .=
" ".$user->id.
",";
796 $sql .=
" ".$user->id.
",";
797 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
798 $sql .=
"'".$this->db->escape($enabled).
"',";
799 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
800 $sql .=
" ".($css ?
"'".$this->db->escape($css).
"'" :
"null").
",";
801 $sql .=
" ".($csslist ?
"'".$this->db->escape($csslist).
"'" :
"null").
",";
802 $sql .=
" ".($cssview ?
"'".$this->db->escape($cssview).
"'" :
"null");
805 $resql2 = $this->
db->query($sql);
807 if ($resql1 && $resql2) {
811 $this->
db->rollback();
834 if (empty($elementtype)) {
838 if ($elementtype ==
'thirdparty') {
839 $elementtype =
'societe';
841 if ($elementtype ==
'contact') {
842 $elementtype =
'socpeople';
844 if ($elementtype ==
'order_supplier') {
845 $elementtype =
'commande_fournisseur';
848 $array_name_label = array();
851 $sql =
"SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help,";
852 $sql .=
" css, cssview, csslist";
853 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
856 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
858 $sql .=
" ORDER BY pos";
864 while ($tab = $this->
db->fetch_object(
$resql)) {
865 if ($tab->entity != 0 && $tab->entity != $conf->entity) {
867 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
868 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
874 if ($tab->type !=
'separate') {
875 $array_name_label[$tab->name] = $tab->label;
878 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
879 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
880 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
881 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
882 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
883 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
884 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
885 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
886 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
887 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
888 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
889 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = ((is_null($tab->perms) || strlen($tab->perms) == 0) ? 1 : $tab->perms);
890 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
891 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
892 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
893 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
894 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
895 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
896 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
897 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
898 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
899 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
901 $this->attributes[$tab->elementtype][
'loaded'] = 1;
906 $this->attributes[$elementtype][
'loaded'] = 1;
907 $this->attributes[$elementtype][
'count'] = $count;
910 $this->error = $this->
db->lasterror();
911 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
914 return $array_name_label;
933 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'', $objectid = 0, $extrafieldsobjectkey =
'', $mode = 0)
935 global $conf, $langs,
$form;
937 if (!is_object(
$form)) {
938 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
944 if (!preg_match(
'/options_$/', $keyprefix)) {
945 $keyprefix = $keyprefix.
'options_';
948 if (empty($extrafieldsobjectkey)) {
949 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
950 return 'BadValueForParamExtraFieldsObjectKey';
953 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
954 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
955 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
956 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
957 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
958 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
959 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
960 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
961 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
962 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
963 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
964 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
965 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
966 $hidden = (empty($list) ? 1 : 0);
969 if (!preg_match(
'/^search_/', $keyprefix)) {
970 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
978 if (empty($morecss)) {
980 if ($type ==
'date') {
981 $morecss =
'minwidth100imp';
982 } elseif ($type ==
'datetime' || $type ==
'link') {
983 $morecss =
'minwidth200imp';
984 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
985 $morecss =
'maxwidth75';
986 } elseif ($type ==
'password') {
987 $morecss =
'maxwidth100';
988 } elseif ($type ==
'url') {
989 $morecss =
'minwidth400';
990 } elseif ($type ==
'boolean') {
992 } elseif ($type ==
'radio') {
993 $morecss =
'width25';
995 if (empty($size) || round($size) < 12) {
996 $morecss =
'minwidth100';
997 } elseif (round($size) <= 48) {
998 $morecss =
'minwidth200';
1000 $morecss =
'minwidth400';
1004 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1005 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1009 if (in_array($type, array(
'date'))) {
1010 $tmp = explode(
',', $size);
1015 if (!$required && $value ==
'') {
1022 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1023 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1025 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1026 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1027 $out .=
'</div><div class="nowrap">';
1028 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1029 $out .=
'</div></div>';
1032 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1034 } elseif (in_array($type, array(
'datetime'))) {
1035 $tmp = explode(
',', $size);
1040 if (!$required && $value ==
'') {
1047 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1048 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1050 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1051 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1052 $out .=
'</div><div class="nowrap">';
1053 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1054 $out .=
'</div></div>';
1057 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1059 } elseif (in_array($type, array(
'int',
'integer'))) {
1060 $tmp = explode(
',', $size);
1062 $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 :
'').
'>';
1063 } elseif (preg_match(
'/varchar/', $type)) {
1064 $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 :
'').
'>';
1065 } elseif (in_array($type, array(
'mail',
'ip',
'phone',
'url'))) {
1066 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1067 } elseif ($type ==
'text') {
1068 if (!preg_match(
'/search_/', $keyprefix)) {
1069 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1070 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1071 $out = $doleditor->Create(1);
1073 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1075 } elseif ($type ==
'html') {
1076 if (!preg_match(
'/search_/', $keyprefix)) {
1077 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1078 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
1079 $out = $doleditor->Create(1);
1081 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1083 } elseif ($type ==
'boolean') {
1086 if (!empty($value)) {
1087 $checked =
' checked value="1" ';
1089 $checked =
' value="1" ';
1091 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1093 $out .=
$form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1);
1095 } elseif ($type ==
'price') {
1096 if (!empty($value)) {
1097 $value =
price($value);
1099 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
1100 } elseif ($type ==
'pricecy') {
1101 $currency = $conf->currency;
1102 if (!empty($value)) {
1104 $pricetmp = explode(
':', $value);
1105 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1106 $value =
price($pricetmp[0]);
1108 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1109 $out .=
$form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1110 } elseif ($type ==
'double') {
1111 if (!empty($value)) {
1112 $value =
price($value);
1114 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1115 } elseif ($type ==
'select') {
1119 foreach ($param[
'options'] as $okey => $val) {
1120 if ((
string) $okey ==
'') {
1124 $valarray = explode(
'|', $val);
1125 $val = $valarray[0];
1127 if ($langfile && $val) {
1128 $options[$okey] = $langs->trans($val);
1130 $options[$okey] = $val;
1133 $selected = array();
1134 if (!is_array($value)) {
1135 $selected = explode(
',', $value);
1138 $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));
1140 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1141 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1142 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1145 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1146 $out .=
'<option value="0"> </option>';
1147 foreach ($param[
'options'] as $key => $val) {
1148 if ((
string) $key ==
'') {
1151 $valarray = explode(
'|', $val);
1152 $val = $valarray[0];
1154 if (!empty($valarray[1])) {
1155 $parent = $valarray[1];
1157 $out .=
'<option value="'.$key.
'"';
1158 $out .= (((string) $value == (
string) $key) ?
' selected' :
'');
1159 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1161 if ($langfile && $val) {
1162 $out .= $langs->trans($val);
1166 $out .=
'</option>';
1168 $out .=
'</select>';
1170 } elseif ($type ==
'sellist') {
1172 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1173 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1174 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1177 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1178 if (is_array($param[
'options'])) {
1179 $param_list = array_keys($param[
'options']);
1180 $InfoFieldList = explode(
":", $param_list[0]);
1190 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1193 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1194 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1195 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1197 $keyList = $InfoFieldList[2].
' as rowid';
1200 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1201 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1202 $keyList .=
', '.$parentField;
1205 $filter_categorie =
false;
1206 if (count($InfoFieldList) > 5) {
1207 if ($InfoFieldList[0] ==
'categorie') {
1208 $filter_categorie =
true;
1212 if ($filter_categorie ===
false) {
1213 $fields_label = explode(
'|', $InfoFieldList[1]);
1214 if (is_array($fields_label)) {
1216 $keyList .= implode(
', ', $fields_label);
1220 $sql =
"SELECT ".$keyList;
1221 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1222 if (!empty($InfoFieldList[4])) {
1224 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1225 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1228 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1229 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1233 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1234 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1236 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1239 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1240 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1241 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1243 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1246 $sqlwhere .=
' WHERE 1=1';
1249 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1250 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1255 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1257 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1260 $out .=
'<option value="0"> </option>';
1261 $num = $this->
db->num_rows(
$resql);
1265 $obj = $this->
db->fetch_object(
$resql);
1269 $fields_label = explode(
'|', $InfoFieldList[1]);
1270 if (is_array($fields_label) && count($fields_label) > 1) {
1272 foreach ($fields_label as $field_toshow) {
1273 $labeltoshow .= $obj->$field_toshow.
' ';
1276 $labeltoshow = $obj->{$InfoFieldList[1]};
1278 $labeltoshow = $labeltoshow;
1280 if ($value == $obj->rowid) {
1282 foreach ($fields_label as $field_toshow) {
1283 $translabel = $langs->trans($obj->$field_toshow);
1284 $labeltoshow = $translabel.
' ';
1287 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1290 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1291 $labeltoshow = $translabel;
1293 if (empty($labeltoshow)) {
1294 $labeltoshow =
'(not defined)';
1297 if (!empty($InfoFieldList[3]) && $parentField) {
1298 $parent = $parentName.
':'.$obj->{$parentField};
1301 $out .=
'<option value="'.$obj->rowid.
'"';
1302 $out .= ($value == $obj->rowid ?
' selected' :
'');
1303 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1304 $out .=
'>'.$labeltoshow.
'</option>';
1311 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1314 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1315 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1316 $out .=
'<option value="0"> </option>';
1317 if (is_array($data)) {
1318 foreach ($data as $data_key => $data_value) {
1319 $out .=
'<option value="'.$data_key.
'"';
1320 $out .= ($value == $data_key ?
' selected' :
'');
1321 $out .=
'>'.$data_value.
'</option>';
1326 $out .=
'</select>';
1327 } elseif ($type ==
'checkbox') {
1328 $value_arr = $value;
1329 if (!is_array($value)) {
1330 $value_arr = explode(
',', $value);
1332 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1333 } elseif ($type ==
'radio') {
1335 foreach ($param[
'options'] as $keyopt => $val) {
1336 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1337 $out .=
' value="'.$keyopt.
'"';
1338 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1339 $out .= ($value == $keyopt ?
'checked' :
'');
1340 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1342 } elseif ($type ==
'chkbxlst') {
1343 if (is_array($value)) {
1344 $value_arr = $value;
1346 $value_arr = explode(
',', $value);
1349 if (is_array($param[
'options'])) {
1350 $param_list = array_keys($param[
'options']);
1351 $InfoFieldList = explode(
":", $param_list[0]);
1361 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1363 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1364 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1365 $keyList .=
', '.$parentField;
1367 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1368 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1369 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1371 $keyList = $InfoFieldList[2].
' as rowid';
1375 $filter_categorie =
false;
1376 if (count($InfoFieldList) > 5) {
1377 if ($InfoFieldList[0] ==
'categorie') {
1378 $filter_categorie =
true;
1382 if ($filter_categorie ===
false) {
1383 $fields_label = explode(
'|', $InfoFieldList[1]);
1384 if (is_array($fields_label)) {
1386 $keyList .= implode(
', ', $fields_label);
1390 $sql =
"SELECT ".$keyList;
1391 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1392 if (!empty($InfoFieldList[4])) {
1394 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1395 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1398 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1399 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1403 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1404 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1405 } elseif (preg_match(
"#^.*list.php$#", $_SERVER[
"PHP_SELF"])) {
1407 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1410 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1414 while ($nbPreg != 0) {
1416 $nbPregRepl = $nbPregSel = 0;
1418 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1420 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1422 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1424 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1427 $nbPreg = $nbPregRepl + $nbPregSel;
1431 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1432 while (!empty($matchCondition[0])) {
1434 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1436 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1438 if (!empty($matchCondition[1])) {
1439 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1440 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1441 } elseif (!empty($matchCondition[3])) {
1442 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1443 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1445 $InfoFieldList[4] =
" TRUE ";
1450 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1453 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1457 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1458 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1459 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1461 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1464 $sqlwhere .=
' WHERE 1=1';
1467 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1468 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1474 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1477 $num = $this->
db->num_rows(
$resql);
1484 $obj = $this->
db->fetch_object(
$resql);
1488 $fields_label = explode(
'|', $InfoFieldList[1]);
1489 if (is_array($fields_label)) {
1491 foreach ($fields_label as $field_toshow) {
1492 $labeltoshow .= $obj->$field_toshow.
' ';
1495 $labeltoshow = $obj->{$InfoFieldList[1]};
1497 $labeltoshow =
dol_trunc($labeltoshow, 45);
1499 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1501 foreach ($fields_label as $field_toshow) {
1502 $translabel = $langs->trans($obj->$field_toshow);
1503 if ($translabel != $obj->$field_toshow) {
1504 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1506 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1509 $data[$obj->rowid] = $labeltoshow;
1512 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1513 if ($translabel != $obj->{$InfoFieldList[1]}) {
1514 $labeltoshow =
dol_trunc($translabel, 18);
1516 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1519 if (empty($labeltoshow)) {
1520 $labeltoshow =
'(not defined)';
1523 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1524 $data[$obj->rowid] = $labeltoshow;
1527 if (!empty($InfoFieldList[3]) && $parentField) {
1528 $parent = $parentName.
':'.$obj->{$parentField};
1531 $data[$obj->rowid] = $labeltoshow;
1538 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1540 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1543 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1544 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1545 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1548 } elseif ($type ==
'link') {
1549 $param_list = array_keys($param[
'options']);
1550 $showempty = (($required && $default !=
'') ? 0 : 1);
1551 $out =
$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss);
1552 } elseif ($type ==
'password') {
1554 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1555 $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 :
'').
'>';
1557 if (!empty($hidden)) {
1558 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1580 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'')
1582 global $conf, $langs;
1584 if (empty($extrafieldsobjectkey)) {
1585 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
1586 return 'BadValueForParamExtraFieldsObjectKey';
1589 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1590 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1591 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1592 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1593 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1594 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1595 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1596 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1597 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1598 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1599 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1600 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1601 $hidden = (empty($list) ? 1 : 0);
1610 if ($type ==
'date') {
1612 if ($value !==
'') {
1615 } elseif ($type ==
'datetime') {
1617 if ($value !==
'') {
1620 } elseif ($type ==
'int') {
1622 } elseif ($type ==
'double') {
1623 if (!empty($value)) {
1625 $sizeparts = explode(
",", $size);
1626 $number_decimals = array_key_exists(1, $sizeparts) ? $sizeparts[1] : 0;
1627 $value =
price($value, 0, $langs, 0, 0, $number_decimals,
'');
1629 } elseif ($type ==
'boolean') {
1631 if (!empty($value)) {
1632 $checked =
' checked ';
1634 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1635 } elseif ($type ==
'mail') {
1637 } elseif ($type ==
'ip') {
1639 } elseif ($type ==
'url') {
1641 } elseif ($type ==
'phone') {
1643 } elseif ($type ==
'price') {
1645 if ($value || $value ==
'0') {
1646 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1).
' '.$langs->getCurrencySymbol($conf->currency);
1648 } elseif ($type ==
'pricecy') {
1649 $currency = $conf->currency;
1650 if (!empty($value)) {
1652 $pricetmp = explode(
':', $value);
1653 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1654 $value = $pricetmp[0];
1656 if ($value || $value ==
'0') {
1657 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1, $currency);
1659 } elseif ($type ==
'select') {
1660 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
1661 if (($pos = strpos($valstr,
"|")) !==
false) {
1662 $valstr = substr($valstr, 0, $pos);
1664 if ($langfile && $valstr) {
1665 $value = $langs->trans($valstr);
1669 } elseif ($type ==
'sellist') {
1670 $param_list = array_keys($param[
'options']);
1671 $InfoFieldList = explode(
":", $param_list[0]);
1673 $selectkey =
"rowid";
1676 if (count($InfoFieldList) >= 3) {
1677 $selectkey = $InfoFieldList[2];
1678 $keyList = $InfoFieldList[2].
' as rowid';
1681 $fields_label = explode(
'|', $InfoFieldList[1]);
1682 if (is_array($fields_label)) {
1684 $keyList .= implode(
', ', $fields_label);
1687 $filter_categorie =
false;
1688 if (count($InfoFieldList) > 5) {
1689 if ($InfoFieldList[0] ==
'categorie') {
1690 $filter_categorie =
true;
1694 $sql =
"SELECT ".$keyList;
1695 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1696 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1699 if ($selectkey ==
'rowid' && empty($value)) {
1700 $sql .=
" WHERE ".$selectkey.
" = 0";
1701 } elseif ($selectkey ==
'rowid') {
1702 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
1704 $sql .=
" WHERE ".$selectkey.
" = '".$this->
db->escape($value).
"'";
1709 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
1712 if ($filter_categorie ===
false) {
1715 $obj = $this->
db->fetch_object(
$resql);
1718 $fields_label = explode(
'|', $InfoFieldList[1]);
1720 if (is_array($fields_label) && count($fields_label) > 1) {
1721 foreach ($fields_label as $field_toshow) {
1723 if (!empty($obj->$field_toshow)) {
1724 $translabel = $langs->trans($obj->$field_toshow);
1726 if ($translabel != $obj->$field_toshow) {
1727 $value .=
dol_trunc($translabel, 24).
' ';
1729 $value .= $obj->$field_toshow.
' ';
1735 $tmppropname = $InfoFieldList[1];
1737 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1738 $translabel = $langs->trans($obj->$tmppropname);
1740 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1743 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
1748 $obj = $this->
db->fetch_object(
$resql);
1750 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1752 $result = $c->fetch($obj->rowid);
1754 $ways = $c->print_all_ways();
1755 foreach ($ways as $way) {
1756 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1760 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1763 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1765 } elseif ($type ==
'radio') {
1766 if (!isset($param[
'options'][$value])) {
1767 $langs->load(
'errors');
1768 $value = $langs->trans(
'ErrorNoValueForRadioType');
1770 $value = $langs->trans($param[
'options'][$value]);
1772 } elseif ($type ==
'checkbox') {
1773 $value_arr = explode(
',', $value);
1776 if (is_array($value_arr)) {
1777 foreach ($value_arr as $keyval => $valueval) {
1778 if (!empty($valueval)) {
1779 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
1783 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1784 } elseif ($type ==
'chkbxlst') {
1785 $value_arr = explode(
',', $value);
1787 $param_list = array_keys($param[
'options']);
1788 $InfoFieldList = explode(
":", $param_list[0]);
1790 $selectkey =
"rowid";
1793 if (count($InfoFieldList) >= 3) {
1794 $selectkey = $InfoFieldList[2];
1795 $keyList = $InfoFieldList[2].
' as rowid';
1798 $fields_label = explode(
'|', $InfoFieldList[1]);
1799 if (is_array($fields_label)) {
1801 $keyList .= implode(
', ', $fields_label);
1804 $filter_categorie =
false;
1805 if (count($InfoFieldList) > 5) {
1806 if ($InfoFieldList[0] ==
'categorie') {
1807 $filter_categorie =
true;
1811 $sql =
"SELECT ".$keyList;
1812 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
1813 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1819 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
1822 if ($filter_categorie ===
false) {
1825 while ($obj = $this->
db->fetch_object(
$resql)) {
1827 $fields_label = explode(
'|', $InfoFieldList[1]);
1828 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1829 if (is_array($fields_label) && count($fields_label) > 1) {
1830 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
1831 foreach ($fields_label as $field_toshow) {
1833 if (!empty($obj->$field_toshow)) {
1834 $translabel = $langs->trans($obj->$field_toshow);
1836 if ($translabel != $field_toshow) {
1837 $label .=
' '.dol_trunc($translabel, 18);
1839 $label .=
' '.$obj->$field_toshow;
1843 $toprint[] = $label;
1846 if (!empty($obj->{$InfoFieldList[1]})) {
1847 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1849 if ($translabel != $obj->{$InfoFieldList[1]}) {
1850 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1852 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
1858 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1861 while ($obj = $this->
db->fetch_object(
$resql)) {
1862 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1864 $c->fetch($obj->rowid);
1865 $ways = $c->print_all_ways();
1866 foreach ($ways as $way) {
1867 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1872 if (!empty($toprint)) $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1874 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1876 } elseif ($type ==
'link') {
1881 $param_list = array_keys($param[
'options']);
1883 $InfoFieldList = explode(
":", $param_list[0]);
1884 $classname = $InfoFieldList[0];
1885 $classpath = $InfoFieldList[1];
1886 if (!empty($classpath)) {
1888 if ($classname && class_exists($classname)) {
1889 $object =
new $classname($this->
db);
1890 $object->fetch($value);
1891 $value = $object->getNomUrl(3);
1894 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
1895 return 'Error bad setup of extrafield';
1898 } elseif ($type ==
'text') {
1900 } elseif ($type ==
'html') {
1902 } elseif ($type ==
'password') {
1903 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
1905 $showsize = round((
float) $size);
1906 if ($showsize > 48) {
1926 global $conf, $langs;
1929 if (!empty($extrafieldsobjectkey)) {
1930 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1935 if (in_array($type, array(
'date',
'datetime'))) {
1936 $cssstring =
"center";
1937 } elseif (in_array($type, array(
'int',
'price',
'double'))) {
1938 $cssstring =
"right";
1939 } elseif (in_array($type, array(
'boolean',
'radio',
'checkbox',
'ip'))) {
1940 $cssstring =
"center";
1943 if (!empty($this->attributes[$extrafieldsobjectkey][
'csslist'][$key])) {
1944 $cssstring .= ($cssstring ?
' ' :
'').$this->attributes[$extrafieldsobjectkey][
'csslist'][$key];
1946 if (in_array($type, array(
'ip'))) {
1947 $cssstring .= ($cssstring ?
' ' :
'').
'tdoverflowmax150';
1964 public function showSeparator($key, $object, $colspan = 2, $display_type =
'card', $mode =
'')
1966 global $conf, $langs;
1971 if ($display_type==
'line') {
1973 $tagtype_dyn=
'span';
1977 $extrafield_param = $this->attributes[$object->table_element][
'param'][$key];
1978 $extrafield_param_list = array();
1979 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1980 $extrafield_param_list = array_keys($extrafield_param[
'options']);
1984 $extrafield_collapse_display_value = -1;
1985 $expand_display =
false;
1986 if (is_array($extrafield_param_list) && count($extrafield_param_list) > 0) {
1987 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1988 $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));
1990 if ($mode ==
'create') {
1991 $extrafield_collapse_display_value = 0;
1994 $out =
'<'.$tagtype.
' id="trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'" class="trextrafieldseparator trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'">';
1995 $out .=
'<'.$tagtype_dyn.
' '.(!empty($colspan)?
'colspan="' . $colspan .
'"':
'').
'>';
1998 $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>';
2001 $out .= $langs->trans($this->attributes[$object->table_element][
'label'][$key]);
2002 $out .=
'</strong>';
2003 $out .=
'</'.$tagtype_dyn.
'>';
2004 $out .=
'</'.$tagtype.
'>';
2006 $collapse_group = $key.(!empty($object->id) ?
'_'.$object->id :
'');
2009 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
2011 $this->expand_display[$collapse_group] = $expand_display;
2013 if (!empty($conf->use_javascript_ajax) && $mode !=
'create') {
2014 $out .=
'<!-- Add js script to manage the collapse/uncollapse of extrafields separators '.$key.
' -->'.
"\n";
2015 $out .=
'<script type="text/javascript">'.
"\n";
2016 $out .=
'jQuery(document).ready(function(){'.
"\n";
2017 if ($expand_display ===
false) {
2018 $out .=
' console.log("Inject js for the collapsing of extrafield '.$key.
' - hide");'.
"\n";
2019 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").hide();'.
"\n";
2021 $out .=
' console.log("Inject js for collapsing of extrafield '.$key.
' - keep visible and set cookie");'.
"\n";
2022 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2024 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'").click(function(){'.
"\n";
2025 $out .=
' console.log("We click on collapse/uncollapse .trextrafields_collapse'.$collapse_group.
'");'.
"\n";
2026 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").toggle(100, function(){'.
"\n";
2027 $out .=
' if (jQuery(".trextrafields_collapse'.$collapse_group.
'").is(":hidden")) {'.
"\n";
2028 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-plus-square").removeClass("fa-minus-square");'.
"\n";
2029 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=0; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2030 $out .=
' } else {'.
"\n";
2031 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-minus-square").removeClass("fa-plus-square");'.
"\n";
2032 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2034 $out .=
' });'.
"\n";
2035 $out .=
' });'.
"\n";
2037 $out .=
'</script>'.
"\n";
2040 $this->expand_display[$collapse_group] = 1;
2059 global $_POST, $langs;
2061 $nofillrequired = 0;
2062 $error_field_required = array();
2064 if (isset($this->attributes[$object->table_element][
'label']) && is_array($this->attributes[$object->table_element][
'label'])) {
2065 $extralabels = $this->attributes[$object->table_element][
'label'];
2068 if (is_array($extralabels)) {
2070 foreach ($extralabels as $key => $value) {
2071 if (!empty($onlykey) && $onlykey !=
'@GETPOSTISSET' && $key != $onlykey) {
2075 if (!empty($onlykey) && $onlykey ==
'@GETPOSTISSET' && !
GETPOSTISSET(
'options_'.$key) && (! in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'checkbox',
'chkbxlst')))) {
2080 $key_type = $this->attributes[$object->table_element][
'type'][$key];
2081 if ($key_type ==
'separate') {
2086 if (isset($this->attributes[$object->table_element][
'enabled'][$key])) {
2087 $enabled =
dol_eval($this->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'2');
2091 if (isset($this->attributes[$object->table_element][
'list'][$key])) {
2092 $visibility = intval(
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1, 1,
'2'));
2096 if (isset($this->attributes[$object->table_element][
'perms'][$key])) {
2097 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1, 1,
'2');
2101 $onlykey ===
'@GETPOSTISSET'
2102 && in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'checkbox',
'chkbxlst'))
2103 && in_array(abs($enabled), array(2, 5))
2110 if (in_array($visibility, array(0, 2, 5))) {
2113 if (empty($perms)) {
2117 if ($this->attributes[$object->table_element][
'required'][$key]) {
2121 if ((!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] !=
'select' && $_POST[
"options_".$key] !=
'0')
2122 || (!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'select')
2123 || (!is_array($_POST[
"options_".$key]) && isset($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'sellist' && $_POST[
'options_'.$key] ==
'0')
2124 || (is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]))) {
2130 if (!empty($this->attributes[$object->table_element][
'langfile'][$key])) {
2131 $langs->load($this->attributes[$object->table_element][
'langfile'][$key]);
2133 $error_field_required[$key] = $langs->transnoentitiesnoconv($value);
2137 if (in_array($key_type, array(
'date'))) {
2139 $value_key =
dol_mktime(12, 0, 0,
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'));
2140 } elseif (in_array($key_type, array(
'datetime'))) {
2142 $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');
2143 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2144 $value_arr =
GETPOST(
"options_".$key,
'array');
2145 if (!empty($value_arr)) {
2146 $value_key = implode(
',', $value_arr);
2150 } elseif (in_array($key_type, array(
'price',
'double'))) {
2151 $value_arr =
GETPOST(
"options_".$key,
'alpha');
2153 } elseif (in_array($key_type, array(
'pricecy',
'double'))) {
2154 $value_key =
price2num(
GETPOST(
"options_".$key,
'alpha')).
':'.
GETPOST(
"options_".$key.
"currency_id",
'alpha');
2155 } elseif (in_array($key_type, array(
'html'))) {
2156 $value_key =
GETPOST(
"options_".$key,
'restricthtml');
2157 } elseif (in_array($key_type, array(
'text'))) {
2158 $value_key =
GETPOST(
"options_".$key,
'alphanohtml');
2160 $value_key =
GETPOST(
"options_".$key);
2161 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
2166 if (!empty($error_field_required[$key]) && $todefaultifmissing) {
2168 if (!empty($this->attributes[$object->table_element][
'default']) && !is_null($this->attributes[$object->table_element][
'default'][$key])) {
2169 $value_key = $this->attributes[$object->table_element][
'default'][$key];
2170 unset($error_field_required[$key]);
2175 $object->array_options[
"options_".$key] = $value_key;
2178 if ($nofillrequired) {
2179 $langs->load(
'errors');
2180 $this->error = $langs->trans(
'ErrorFieldsRequired').
' : '.implode(
', ', $error_field_required);
2203 if (is_string($extrafieldsobjectkey) && !empty($this->attributes[$extrafieldsobjectkey][
'label']) && is_array($this->attributes[$extrafieldsobjectkey][
'label'])) {
2204 $extralabels = $this->attributes[$extrafieldsobjectkey][
'label'];
2206 $extralabels = $extrafieldsobjectkey;
2209 if (is_array($extralabels)) {
2210 $array_options = array();
2213 foreach ($extralabels as $key => $value) {
2215 if (is_string($extrafieldsobjectkey)) {
2216 $key_type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2219 if (in_array($key_type, array(
'date'))) {
2220 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2221 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2225 'start' =>
dol_mktime(0, 0, 0,
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int')),
2226 'end' =>
dol_mktime(23, 59, 59,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'))
2228 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2230 $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'));
2234 } elseif (in_array($key_type, array(
'datetime'))) {
2235 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2236 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2239 $dateparamname_end_hour =
GETPOST($dateparamname_end .
'hour',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'hour',
'int') :
'23';
2240 $dateparamname_end_min =
GETPOST($dateparamname_end .
'min',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'min',
'int') :
'59';
2241 $dateparamname_end_sec =
GETPOST($dateparamname_end .
'sec',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'sec',
'int') :
'59';
2243 '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'),
2244 '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')
2246 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2248 $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');
2252 } elseif ($key_type ==
'select') {
2255 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix,
'array:aZ09');
2257 $value_arr = (array) $value_arr;
2258 $value_key = implode(
',', $value_arr);
2260 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2262 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2263 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2266 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2268 $value_arr = (array) $value_arr;
2269 $value_key = implode(
',', $value_arr);
2270 } elseif (in_array($key_type, array(
'price',
'double',
'int'))) {
2271 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2274 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2275 if ($keysuffix !=
'search_') {
2278 $value_key = $value_arr;
2280 } elseif (in_array($key_type, array(
'boolean'))) {
2281 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2284 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2285 $value_key = $value_arr;
2288 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2291 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2294 $array_options[$keysuffix.
"options_".$key] = $value_key;
2297 return $array_options;