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();
437 public function delete($attrname, $elementtype =
'member')
439 if ($elementtype ==
'thirdparty') {
440 $elementtype =
'societe';
442 if ($elementtype ==
'contact') {
443 $elementtype =
'socpeople';
446 $table = $elementtype.
'_extrafields';
447 if ($elementtype ==
'categorie') {
448 $table =
'categories_extrafields';
453 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
456 $this->error = $this->
db->lasterror();
457 $this->errors[] = $this->
db->lasterror();
462 $sql =
"SELECT COUNT(rowid) as nb";
463 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
464 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
465 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
467 $resql = $this->
db->query(
$sql);
469 $obj = $this->
db->fetch_object($resql);
471 $result = $this->
db->DDLDropField($this->
db->prefix().$table, $attrname);
473 $this->error = $this->
db->lasterror();
474 $this->errors[] = $this->
db->lasterror();
500 if ($elementtype ==
'thirdparty') {
501 $elementtype =
'societe';
503 if ($elementtype ==
'contact') {
504 $elementtype =
'socpeople';
507 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
508 $sql =
"DELETE FROM ".$this->db->prefix().
"extrafields";
509 $sql .=
" WHERE name = '".$this->db->escape($attrname).
"'";
510 $sql .=
" AND entity IN (0,".$conf->entity.
')';
511 $sql .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
513 dol_syslog(get_class($this).
"::delete_label", LOG_DEBUG);
514 $resql = $this->
db->query(
$sql);
553 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())
557 if ($elementtype ==
'thirdparty') {
558 $elementtype =
'societe';
560 if ($elementtype ==
'contact') {
561 $elementtype =
'socpeople';
564 $table = $elementtype.
'_extrafields';
565 if ($elementtype ==
'categorie') {
566 $table =
'categories_extrafields';
569 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
570 if ($type ==
'boolean') {
573 } elseif ($type ==
'price') {
576 } elseif ($type ==
'pricecy') {
579 } elseif ($type ==
'phone') {
582 } elseif ($type ==
'mail' || $type ==
'ip') {
585 } elseif ($type ==
'url') {
588 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
591 } elseif ($type ==
'html') {
593 } elseif ($type ==
'link') {
596 } elseif ($type ==
'password') {
603 $field_desc = array(
'type'=>$typedb,
'value'=>$lengthdb,
'null'=>($required ?
'NOT NULL' :
'NULL'),
'default'=>$default);
605 if (is_object($hookmanager)) {
606 $hookmanager->initHooks(array(
'extrafieldsdao'));
607 $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);
608 $reshook = $hookmanager->executeHooks(
'updateExtrafields', $parameters, $this, $action);
611 $this->error = $this->
db->lasterror();
616 if ($type !=
'separate') {
617 $result = $this->
db->DDLUpdateField($this->
db->prefix().$table, $attrname, $field_desc);
619 if ($result > 0 || $type ==
'separate') {
621 $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);
626 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
628 $sql =
"ALTER TABLE ".$this->db->prefix().$table.
" DROP INDEX IF EXISTS uk_".$table.
"_".$attrname;
630 dol_syslog(get_class($this).
'::update', LOG_DEBUG);
631 $resql = $this->
db->query(
$sql, 1,
'dml');
638 $this->error = $this->
db->lasterror();
642 $this->error = $this->
db->lasterror();
678 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())
682 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);
685 if ($elementtype ==
'thirdparty') {
686 $elementtype =
'societe';
688 if ($elementtype ==
'contact') {
689 $elementtype =
'socpeople';
698 if (empty($totalizable)) {
701 if (empty($required)) {
704 if (empty($unique)) {
707 if (empty($alwayseditable)) {
712 if (!empty($moreparams) && !empty($moreparams[
'css'])) {
713 $css = $moreparams[
'css'];
716 if (!empty($moreparams) && !empty($moreparams[
'csslist'])) {
717 $csslist = $moreparams[
'csslist'];
720 if (!empty($moreparams) && !empty($moreparams[
'cssview'])) {
721 $cssview = $moreparams[
'cssview'];
724 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
727 if (is_array($param) && count($param) > 0) {
728 $params = serialize($param);
729 } elseif (strlen($param) > 0) {
730 $params = trim($param);
735 if ($entity ===
'' || $entity !=
'0') {
737 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
738 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
739 $sql_del .=
" AND entity IN (0, ".($entity ===
'' ? $conf->entity : $entity).
")";
740 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
743 $sql_del =
"DELETE FROM ".$this->db->prefix().
"extrafields";
744 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
745 $sql_del .=
" AND entity = 0";
746 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
748 $resql1 = $this->
db->query($sql_del);
750 $sql =
"INSERT INTO ".$this->db->prefix().
"extrafields(";
756 $sql .=
" elementtype,";
757 $sql .=
" fieldunique,";
758 $sql .=
" fieldrequired,";
762 $sql .=
" alwayseditable,";
765 $sql .=
" printable,";
766 $sql .=
" totalizable,";
767 $sql .=
" fielddefault,";
768 $sql .=
" fieldcomputed,";
769 $sql .=
" fk_user_author,";
770 $sql .=
" fk_user_modif,";
777 $sql .=
") VALUES (";
778 $sql .=
"'".$this->db->escape($attrname).
"',";
779 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
780 $sql .=
" '".$this->db->escape($label).
"',";
781 $sql .=
" '".$this->db->escape($type).
"',";
782 $sql .=
" '".$this->db->escape($size).
"',";
783 $sql .=
" '".$this->db->escape($elementtype).
"',";
784 $sql .=
" ".$unique.
",";
785 $sql .=
" ".$required.
",";
786 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
787 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
788 $sql .=
" ".$pos.
",";
789 $sql .=
" '".$this->db->escape($alwayseditable).
"',";
790 $sql .=
" '".$this->db->escape($params).
"',";
791 $sql .=
" '".$this->db->escape($list).
"', ";
792 $sql .=
" '".$this->db->escape($printable).
"', ";
793 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE').
",";
794 $sql .=
" ".(($default !=
'') ?
"'".$this->
db->escape($default).
"'" :
"null").
",";
795 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
796 $sql .=
" ".$user->id.
",";
797 $sql .=
" ".$user->id.
",";
799 $sql .=
"'".$this->db->escape($enabled).
"',";
800 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
801 $sql .=
" ".($css ?
"'".$this->db->escape($css).
"'" :
"null").
",";
802 $sql .=
" ".($csslist ?
"'".$this->db->escape($csslist).
"'" :
"null").
",";
803 $sql .=
" ".($cssview ?
"'".$this->db->escape($cssview).
"'" :
"null");
806 $resql2 = $this->
db->query(
$sql);
808 if ($resql1 && $resql2) {
812 $this->
db->rollback();
835 if (empty($elementtype)) {
839 if ($elementtype ==
'thirdparty') {
840 $elementtype =
'societe';
842 if ($elementtype ==
'contact') {
843 $elementtype =
'socpeople';
845 if ($elementtype ==
'order_supplier') {
846 $elementtype =
'commande_fournisseur';
849 $array_name_label = array();
852 $sql =
"SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help,";
853 $sql .=
" css, cssview, csslist";
854 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
857 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
859 $sql .=
" ORDER BY pos";
861 $resql = $this->
db->query(
$sql);
864 if ($this->
db->num_rows($resql)) {
865 while ($tab = $this->
db->fetch_object($resql)) {
866 if ($tab->entity != 0 && $tab->entity != $conf->entity) {
868 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
869 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
875 if ($tab->type !=
'separate') {
876 $array_name_label[$tab->name] = $tab->label;
879 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
880 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
881 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
882 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
883 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
884 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
885 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
886 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
887 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
888 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
889 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
890 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = ((is_null($tab->perms) || strlen($tab->perms) == 0) ? 1 : $tab->perms);
891 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
892 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
893 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
894 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
895 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
896 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
897 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
898 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
899 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
900 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
902 $this->attributes[$tab->elementtype][
'loaded'] = 1;
907 $this->attributes[$elementtype][
'loaded'] = 1;
908 $this->attributes[$elementtype][
'count'] = $count;
911 $this->error = $this->
db->lasterror();
912 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
915 return $array_name_label;
934 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'', $objectid = 0, $extrafieldsobjectkey =
'', $mode = 0)
936 global $conf, $langs,
$form;
938 if (!is_object(
$form)) {
939 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
945 if (!preg_match(
'/options_$/', $keyprefix)) {
946 $keyprefix = $keyprefix.
'options_';
949 if (empty($extrafieldsobjectkey)) {
950 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
951 return 'BadValueForParamExtraFieldsObjectKey';
954 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
955 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
956 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
957 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
958 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
959 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
960 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
961 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
962 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'1');
963 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
964 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'1');
965 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
966 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
967 $hidden = (empty($list) ? 1 : 0);
970 if (!preg_match(
'/^search_/', $keyprefix)) {
971 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
979 if (empty($morecss)) {
981 if ($type ==
'date') {
982 $morecss =
'minwidth100imp';
983 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
984 $morecss =
'minwidth200imp';
985 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
986 $morecss =
'maxwidth75';
987 } elseif ($type ==
'password') {
988 $morecss =
'maxwidth100';
989 } elseif ($type ==
'url') {
990 $morecss =
'minwidth400';
991 } elseif ($type ==
'boolean') {
993 } elseif ($type ==
'radio') {
994 $morecss =
'width25';
996 if (empty($size) || round($size) < 12) {
997 $morecss =
'minwidth100';
998 } elseif (round($size) <= 48) {
999 $morecss =
'minwidth200';
1001 $morecss =
'minwidth400';
1005 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1006 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1010 if (in_array($type, array(
'date'))) {
1011 $tmp = explode(
',', $size);
1016 if (!$required && $value ==
'') {
1023 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1024 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1026 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1027 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1028 $out .=
'</div><div class="nowrap">';
1029 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1030 $out .=
'</div></div>';
1033 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1035 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1036 $tmp = explode(
',', $size);
1041 if (!$required && $value ==
'') {
1048 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1049 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1051 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1052 $out .=
$form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1053 $out .=
'</div><div class="nowrap">';
1054 $out .=
$form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1055 $out .=
'</div></div>';
1058 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1060 } elseif (in_array($type, array(
'int',
'integer'))) {
1061 $tmp = explode(
',', $size);
1063 $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 :
'').
'>';
1064 } elseif (preg_match(
'/varchar/', $type)) {
1065 $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 :
'').
'>';
1066 } elseif (in_array($type, array(
'mail',
'ip',
'phone',
'url'))) {
1067 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1068 } elseif ($type ==
'text') {
1069 if (!preg_match(
'/search_/', $keyprefix)) {
1070 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1071 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1072 $out = $doleditor->Create(1);
1074 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1076 } elseif ($type ==
'html') {
1077 if (!preg_match(
'/search_/', $keyprefix)) {
1078 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1079 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
1080 $out = $doleditor->Create(1);
1082 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1084 } elseif ($type ==
'boolean') {
1087 if (!empty($value)) {
1088 $checked =
' checked value="1" ';
1090 $checked =
' value="1" ';
1092 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1094 $out .=
$form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1);
1096 } elseif ($type ==
'price') {
1097 if (!empty($value)) {
1098 $value =
price($value);
1100 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
1101 } elseif ($type ==
'pricecy') {
1102 $currency = $conf->currency;
1103 if (!empty($value)) {
1105 $pricetmp = explode(
':', $value);
1106 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1107 $value =
price($pricetmp[0]);
1109 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1110 $out .=
$form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1111 } elseif ($type ==
'double') {
1112 if (!empty($value)) {
1113 $value =
price($value);
1115 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1116 } elseif ($type ==
'select') {
1120 foreach ($param[
'options'] as $okey => $val) {
1121 if ((
string) $okey ==
'') {
1125 if ($langfile && $val) {
1126 $options[$okey] = $langs->trans($val);
1128 $options[$okey] = $val;
1131 $selected = array();
1132 if (!is_array($value)) {
1133 $selected = explode(
',', $value);
1136 $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));
1138 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1139 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1140 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1143 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1144 $out .=
'<option value="0"> </option>';
1145 foreach ($param[
'options'] as $key2 => $val2) {
1146 if ((
string) $key2 ==
'') {
1149 $valarray = explode(
'|', $val2);
1150 $val2 = $valarray[0];
1152 if (!empty($valarray[1])) {
1153 $parent = $valarray[1];
1155 $out .=
'<option value="'.$key2.
'"';
1156 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1157 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1159 if ($langfile && $val2) {
1160 $out .= $langs->trans($val2);
1164 $out .=
'</option>';
1166 $out .=
'</select>';
1168 } elseif ($type ==
'sellist') {
1170 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1171 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1172 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1175 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1176 if (is_array($param[
'options'])) {
1177 $param_list = array_keys($param[
'options']);
1178 $InfoFieldList = explode(
":", $param_list[0]);
1188 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1191 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1192 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1193 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1195 $keyList = $InfoFieldList[2].
' as rowid';
1198 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1199 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1200 $keyList .=
', '.$parentField;
1203 $filter_categorie =
false;
1204 if (count($InfoFieldList) > 5) {
1205 if ($InfoFieldList[0] ==
'categorie') {
1206 $filter_categorie =
true;
1210 if ($filter_categorie ===
false) {
1211 $fields_label = explode(
'|', $InfoFieldList[1]);
1212 if (is_array($fields_label)) {
1214 $keyList .= implode(
', ', $fields_label);
1218 $sql =
"SELECT ".$keyList;
1219 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1220 if (!empty($InfoFieldList[4])) {
1222 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1223 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1226 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1227 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1231 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1232 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1234 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1237 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1238 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1239 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1241 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1244 $sqlwhere .=
' WHERE 1=1';
1247 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1248 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1253 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1255 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1256 $resql = $this->
db->query(
$sql);
1258 $out .=
'<option value="0"> </option>';
1259 $num = $this->
db->num_rows($resql);
1263 $obj = $this->
db->fetch_object($resql);
1267 $fields_label = explode(
'|', $InfoFieldList[1]);
1268 if (is_array($fields_label) && count($fields_label) > 1) {
1270 foreach ($fields_label as $field_toshow) {
1271 $labeltoshow .= $obj->$field_toshow.
' ';
1274 $labeltoshow = $obj->{$InfoFieldList[1]};
1276 $labeltoshow = $labeltoshow;
1278 if ($value == $obj->rowid) {
1280 foreach ($fields_label as $field_toshow) {
1281 $translabel = $langs->trans($obj->$field_toshow);
1282 $labeltoshow = $translabel.
' ';
1285 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1288 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1289 $labeltoshow = $translabel;
1291 if (empty($labeltoshow)) {
1292 $labeltoshow =
'(not defined)';
1295 if (!empty($InfoFieldList[3]) && $parentField) {
1296 $parent = $parentName.
':'.$obj->{$parentField};
1299 $out .=
'<option value="'.$obj->rowid.
'"';
1300 $out .= ($value == $obj->rowid ?
' selected' :
'');
1301 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1302 $out .=
'>'.$labeltoshow.
'</option>';
1307 $this->
db->free($resql);
1309 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1312 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1313 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1314 $out .=
'<option value="0"> </option>';
1315 if (is_array($data)) {
1316 foreach ($data as $data_key => $data_value) {
1317 $out .=
'<option value="'.$data_key.
'"';
1318 $out .= ($value == $data_key ?
' selected' :
'');
1319 $out .=
'>'.$data_value.
'</option>';
1324 $out .=
'</select>';
1325 } elseif ($type ==
'checkbox') {
1326 $value_arr = $value;
1327 if (!is_array($value)) {
1328 $value_arr = explode(
',', $value);
1330 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1331 } elseif ($type ==
'radio') {
1333 foreach ($param[
'options'] as $keyopt => $val) {
1334 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1335 $out .=
' value="'.$keyopt.
'"';
1336 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1337 $out .= ($value == $keyopt ?
'checked' :
'');
1338 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1340 } elseif ($type ==
'chkbxlst') {
1341 if (is_array($value)) {
1342 $value_arr = $value;
1344 $value_arr = explode(
',', $value);
1347 if (is_array($param[
'options'])) {
1348 $param_list = array_keys($param[
'options']);
1349 $InfoFieldList = explode(
":", $param_list[0]);
1359 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1361 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1362 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1363 $keyList .=
', '.$parentField;
1365 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1366 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1367 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1369 $keyList = $InfoFieldList[2].
' as rowid';
1373 $filter_categorie =
false;
1374 if (count($InfoFieldList) > 5) {
1375 if ($InfoFieldList[0] ==
'categorie') {
1376 $filter_categorie =
true;
1380 if ($filter_categorie ===
false) {
1381 $fields_label = explode(
'|', $InfoFieldList[1]);
1382 if (is_array($fields_label)) {
1384 $keyList .= implode(
', ', $fields_label);
1388 $sql =
"SELECT ".$keyList;
1389 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1390 if (!empty($InfoFieldList[4])) {
1392 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1393 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1396 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1397 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1401 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1402 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1403 } elseif (preg_match(
"#^.*list.php$#", $_SERVER[
"PHP_SELF"])) {
1405 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1408 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1412 while ($nbPreg != 0) {
1414 $nbPregRepl = $nbPregSel = 0;
1416 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1418 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1420 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1422 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1425 $nbPreg = $nbPregRepl + $nbPregSel;
1429 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1430 while (!empty($matchCondition[0])) {
1432 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1434 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1436 if (!empty($matchCondition[1])) {
1437 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1438 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1439 } elseif (!empty($matchCondition[3])) {
1440 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1441 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1443 $InfoFieldList[4] =
" TRUE ";
1448 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1451 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1455 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1456 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1457 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1459 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1462 $sqlwhere .=
' WHERE 1=1';
1465 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1466 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1472 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1473 $resql = $this->
db->query(
$sql);
1475 $num = $this->
db->num_rows($resql);
1482 $obj = $this->
db->fetch_object($resql);
1486 $fields_label = explode(
'|', $InfoFieldList[1]);
1487 if (is_array($fields_label)) {
1489 foreach ($fields_label as $field_toshow) {
1490 $labeltoshow .= $obj->$field_toshow.
' ';
1493 $labeltoshow = $obj->{$InfoFieldList[1]};
1495 $labeltoshow =
dol_trunc($labeltoshow, 45);
1497 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1499 foreach ($fields_label as $field_toshow) {
1500 $translabel = $langs->trans($obj->$field_toshow);
1501 if ($translabel != $obj->$field_toshow) {
1502 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1504 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1507 $data[$obj->rowid] = $labeltoshow;
1510 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1511 if ($translabel != $obj->{$InfoFieldList[1]}) {
1512 $labeltoshow =
dol_trunc($translabel, 18);
1514 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1517 if (empty($labeltoshow)) {
1518 $labeltoshow =
'(not defined)';
1521 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1522 $data[$obj->rowid] = $labeltoshow;
1525 if (!empty($InfoFieldList[3]) && $parentField) {
1526 $parent = $parentName.
':'.$obj->{$parentField};
1529 $data[$obj->rowid] = $labeltoshow;
1534 $this->
db->free($resql);
1536 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1538 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1541 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1542 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1543 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1546 } elseif ($type ==
'link') {
1547 $param_list = array_keys($param[
'options']);
1548 $showempty = (($required && $default !=
'') ? 0 : 1);
1549 $out =
$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss);
1550 } elseif ($type ==
'password') {
1552 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1553 $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 :
'').
'>';
1555 if (!empty($hidden)) {
1556 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1578 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'')
1580 global $conf, $langs;
1582 if (empty($extrafieldsobjectkey)) {
1583 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
1584 return 'BadValueForParamExtraFieldsObjectKey';
1587 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1588 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1589 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1590 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1591 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1592 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1593 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1594 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1595 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'1');
1596 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1597 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'1');
1598 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1599 $hidden = (empty($list) ? 1 : 0);
1608 if ($type ==
'date') {
1610 if ($value !==
'') {
1613 } elseif ($type ==
'datetime') {
1615 if ($value !==
'') {
1618 } elseif ($type ==
'datetimegmt') {
1620 if ($value !==
'') {
1623 } elseif ($type ==
'int') {
1625 } elseif ($type ==
'double') {
1626 if (!empty($value)) {
1628 $sizeparts = explode(
",", $size);
1629 $number_decimals = array_key_exists(1, $sizeparts) ? $sizeparts[1] : 0;
1630 $value =
price($value, 0, $langs, 0, 0, $number_decimals,
'');
1632 } elseif ($type ==
'boolean') {
1634 if (!empty($value)) {
1635 $checked =
' checked ';
1637 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1638 } elseif ($type ==
'mail') {
1640 } elseif ($type ==
'ip') {
1642 } elseif ($type ==
'url') {
1644 } elseif ($type ==
'phone') {
1646 } elseif ($type ==
'price') {
1648 if ($value || $value ==
'0') {
1649 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1).
' '.$langs->getCurrencySymbol($conf->currency);
1651 } elseif ($type ==
'pricecy') {
1652 $currency = $conf->currency;
1653 if (!empty($value)) {
1655 $pricetmp = explode(
':', $value);
1656 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1657 $value = $pricetmp[0];
1659 if ($value || $value ==
'0') {
1660 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1, $currency);
1662 } elseif ($type ==
'select') {
1663 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
1664 if (($pos = strpos($valstr,
"|")) !==
false) {
1665 $valstr = substr($valstr, 0, $pos);
1667 if ($langfile && $valstr) {
1668 $value = $langs->trans($valstr);
1672 } elseif ($type ==
'sellist') {
1673 $param_list = array_keys($param[
'options']);
1674 $InfoFieldList = explode(
":", $param_list[0]);
1676 $selectkey =
"rowid";
1679 if (count($InfoFieldList) >= 3) {
1680 $selectkey = $InfoFieldList[2];
1681 $keyList = $InfoFieldList[2].
' as rowid';
1684 $fields_label = explode(
'|', $InfoFieldList[1]);
1685 if (is_array($fields_label)) {
1687 $keyList .= implode(
', ', $fields_label);
1690 $filter_categorie =
false;
1691 if (count($InfoFieldList) > 5) {
1692 if ($InfoFieldList[0] ==
'categorie') {
1693 $filter_categorie =
true;
1697 $sql =
"SELECT ".$keyList;
1698 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1699 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1702 if ($selectkey ==
'rowid' && empty($value)) {
1703 $sql .=
" WHERE ".$selectkey.
" = 0";
1704 } elseif ($selectkey ==
'rowid') {
1705 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
1707 $sql .=
" WHERE ".$selectkey.
" = '".$this->
db->escape($value).
"'";
1712 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
1713 $resql = $this->
db->query(
$sql);
1715 if ($filter_categorie ===
false) {
1718 $obj = $this->
db->fetch_object($resql);
1721 $fields_label = explode(
'|', $InfoFieldList[1]);
1723 if (is_array($fields_label) && count($fields_label) > 1) {
1724 foreach ($fields_label as $field_toshow) {
1726 if (!empty($obj->$field_toshow)) {
1727 $translabel = $langs->trans($obj->$field_toshow);
1729 if ($translabel != $obj->$field_toshow) {
1730 $value .=
dol_trunc($translabel, 24).
' ';
1732 $value .= $obj->$field_toshow.
' ';
1737 $tmppropname = $InfoFieldList[1];
1739 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1740 $translabel = $langs->trans($obj->$tmppropname);
1742 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1745 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
1750 $obj = $this->
db->fetch_object($resql);
1752 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1754 $result = $c->fetch($obj->rowid);
1756 $ways = $c->print_all_ways();
1757 foreach ($ways as $way) {
1758 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1762 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1765 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1767 } elseif ($type ==
'radio') {
1768 if (!isset($param[
'options'][$value])) {
1769 $langs->load(
'errors');
1770 $value = $langs->trans(
'ErrorNoValueForRadioType');
1772 $value = $langs->trans($param[
'options'][$value]);
1774 } elseif ($type ==
'checkbox') {
1775 $value_arr = explode(
',', $value);
1778 if (is_array($value_arr)) {
1779 foreach ($value_arr as $keyval => $valueval) {
1780 if (!empty($valueval)) {
1781 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
1785 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1786 } elseif ($type ==
'chkbxlst') {
1787 $value_arr = explode(
',', $value);
1789 $param_list = array_keys($param[
'options']);
1790 $InfoFieldList = explode(
":", $param_list[0]);
1792 $selectkey =
"rowid";
1795 if (count($InfoFieldList) >= 3) {
1796 $selectkey = $InfoFieldList[2];
1797 $keyList = $InfoFieldList[2].
' as rowid';
1800 $fields_label = explode(
'|', $InfoFieldList[1]);
1801 if (is_array($fields_label)) {
1803 $keyList .= implode(
', ', $fields_label);
1806 $filter_categorie =
false;
1807 if (count($InfoFieldList) > 5) {
1808 if ($InfoFieldList[0] ==
'categorie') {
1809 $filter_categorie =
true;
1813 $sql =
"SELECT ".$keyList;
1814 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
1815 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1821 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
1822 $resql = $this->
db->query(
$sql);
1824 if ($filter_categorie ===
false) {
1827 while ($obj = $this->
db->fetch_object($resql)) {
1829 $fields_label = explode(
'|', $InfoFieldList[1]);
1830 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1831 if (is_array($fields_label) && count($fields_label) > 1) {
1832 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
1833 foreach ($fields_label as $field_toshow) {
1835 if (!empty($obj->$field_toshow)) {
1836 $translabel = $langs->trans($obj->$field_toshow);
1838 if ($translabel != $field_toshow) {
1839 $label .=
' '.dol_trunc($translabel, 18);
1841 $label .=
' '.$obj->$field_toshow;
1845 $toprint[] = $label;
1848 if (!empty($obj->{$InfoFieldList[1]})) {
1849 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1851 if ($translabel != $obj->{$InfoFieldList[1]}) {
1852 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1854 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
1860 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1863 while ($obj = $this->
db->fetch_object($resql)) {
1864 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1866 $c->fetch($obj->rowid);
1867 $ways = $c->print_all_ways();
1868 foreach ($ways as $way) {
1869 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1874 if (!empty($toprint)) $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1876 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1878 } elseif ($type ==
'link') {
1883 $param_list = array_keys($param[
'options']);
1885 $InfoFieldList = explode(
":", $param_list[0]);
1886 $classname = $InfoFieldList[0];
1887 $classpath = $InfoFieldList[1];
1888 if (!empty($classpath)) {
1890 if ($classname && class_exists($classname)) {
1891 $object =
new $classname($this->
db);
1892 $object->fetch($value);
1893 $value = $object->getNomUrl(3);
1896 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
1897 return 'Error bad setup of extrafield';
1900 } elseif ($type ==
'text') {
1902 } elseif ($type ==
'html') {
1904 } elseif ($type ==
'password') {
1905 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
1907 $showsize = round((
float) $size);
1908 if ($showsize > 48) {
1928 global $conf, $langs;
1931 if (!empty($extrafieldsobjectkey)) {
1932 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1937 if (in_array($type, array(
'date',
'datetime',
'datetimegmt'))) {
1938 $cssstring =
"center";
1939 } elseif (in_array($type, array(
'int',
'price',
'double'))) {
1940 $cssstring =
"right";
1941 } elseif (in_array($type, array(
'boolean',
'radio',
'checkbox',
'ip'))) {
1942 $cssstring =
"center";
1945 if (!empty($this->attributes[$extrafieldsobjectkey][
'csslist'][$key])) {
1946 $cssstring .= ($cssstring ?
' ' :
'').$this->attributes[$extrafieldsobjectkey][
'csslist'][$key];
1948 if (in_array($type, array(
'ip'))) {
1949 $cssstring .= ($cssstring ?
' ' :
'').
'tdoverflowmax150';
1966 public function showSeparator($key, $object, $colspan = 2, $display_type =
'card', $mode =
'')
1968 global $conf, $langs;
1973 if ($display_type==
'line') {
1975 $tagtype_dyn=
'span';
1979 $extrafield_param = $this->attributes[$object->table_element][
'param'][$key];
1980 $extrafield_param_list = array();
1981 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1982 $extrafield_param_list = array_keys($extrafield_param[
'options']);
1986 $extrafield_collapse_display_value = -1;
1987 $expand_display =
false;
1988 if (is_array($extrafield_param_list) && count($extrafield_param_list) > 0) {
1989 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1990 $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));
1992 $disabledcookiewrite = 0;
1993 if ($mode ==
'create') {
1995 $extrafield_collapse_display_value = 1;
1996 $expand_display =
true;
1997 $disabledcookiewrite = 1;
2000 $out =
'<'.$tagtype.
' id="trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'" class="trextrafieldseparator trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'">';
2001 $out .=
'<'.$tagtype_dyn.
' '.(!empty($colspan)?
'colspan="' . $colspan .
'"':
'').
'>';
2004 $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>';
2007 $out .= $langs->trans($this->attributes[$object->table_element][
'label'][$key]);
2008 $out .=
'</strong>';
2009 $out .=
'</'.$tagtype_dyn.
'>';
2010 $out .=
'</'.$tagtype.
'>';
2012 $collapse_group = $key.(!empty($object->id) ?
'_'.$object->id :
'');
2015 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
2017 $this->expand_display[$collapse_group] = $expand_display;
2019 if (!empty($conf->use_javascript_ajax)) {
2020 $out .=
'<!-- Add js script to manage the collapse/uncollapse of extrafields separators '.$key.
' -->'.
"\n";
2021 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
2022 $out .=
'jQuery(document).ready(function(){'.
"\n";
2023 if (empty($disabledcookiewrite)) {
2024 if ($expand_display ===
false) {
2025 $out .=
' console.log("Inject js for the collapsing of extrafield '.$key.
' - hide");'.
"\n";
2026 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").hide();'.
"\n";
2028 $out .=
' console.log("Inject js for collapsing of extrafield '.$key.
' - keep visible and set cookie");'.
"\n";
2029 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2032 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'").click(function(){'.
"\n";
2033 $out .=
' console.log("We click on collapse/uncollapse to hide/show .trextrafields_collapse'.$collapse_group.
'");'.
"\n";
2034 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").toggle(100, function(){'.
"\n";
2035 $out .=
' if (jQuery(".trextrafields_collapse'.$collapse_group.
'").is(":hidden")) {'.
"\n";
2036 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-plus-square").removeClass("fa-minus-square");'.
"\n";
2037 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=0; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2038 $out .=
' } else {'.
"\n";
2039 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-minus-square").removeClass("fa-plus-square");'.
"\n";
2040 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2042 $out .=
' });'.
"\n";
2043 $out .=
' });'.
"\n";
2045 $out .=
'</script>'.
"\n";
2048 $this->expand_display[$collapse_group] = 1;
2067 global $_POST, $langs;
2069 $nofillrequired = 0;
2070 $error_field_required = array();
2072 if (isset($this->attributes[$object->table_element][
'label']) && is_array($this->attributes[$object->table_element][
'label'])) {
2073 $extralabels = $this->attributes[$object->table_element][
'label'];
2076 if (is_array($extralabels)) {
2078 foreach ($extralabels as $key => $value) {
2079 if (!empty($onlykey) && $onlykey !=
'@GETPOSTISSET' && $key != $onlykey) {
2083 if (!empty($onlykey) && $onlykey ==
'@GETPOSTISSET' && !
GETPOSTISSET(
'options_'.$key) && (! in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'chkbxlst')))) {
2088 $key_type = $this->attributes[$object->table_element][
'type'][$key];
2089 if ($key_type ==
'separate') {
2094 if (isset($this->attributes[$object->table_element][
'enabled'][$key])) {
2095 $enabled =
dol_eval($this->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'1');
2099 if (isset($this->attributes[$object->table_element][
'list'][$key])) {
2100 $visibility = intval(
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1, 1,
'1'));
2104 if (isset($this->attributes[$object->table_element][
'perms'][$key])) {
2105 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1, 1,
'1');
2109 $onlykey ===
'@GETPOSTISSET'
2110 && in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'chkbxlst'))
2111 && in_array(abs($enabled), array(2, 5))
2117 if (empty($visibility) || $visibility == 5) {
2120 if (empty($perms)) {
2124 if ($this->attributes[$object->table_element][
'required'][$key]) {
2128 if ((!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] !=
'select' && $_POST[
"options_".$key] !=
'0')
2129 || (!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'select')
2130 || (!is_array($_POST[
"options_".$key]) && isset($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'sellist' && $_POST[
'options_'.$key] ==
'0')
2131 || (is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]))) {
2136 $error_field_required[$key] = $langs->transnoentitiesnoconv($value);
2140 if (in_array($key_type, array(
'date'))) {
2142 $value_key =
dol_mktime(12, 0, 0,
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'));
2143 } elseif (in_array($key_type, array(
'datetime'))) {
2145 $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');
2146 } elseif (in_array($key_type, array(
'datetimegmt'))) {
2148 $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');
2149 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2150 $value_arr =
GETPOST(
"options_".$key,
'array');
2151 if (!empty($value_arr)) {
2152 $value_key = implode(
',', $value_arr);
2156 } elseif (in_array($key_type, array(
'price',
'double'))) {
2157 $value_arr =
GETPOST(
"options_".$key,
'alpha');
2159 } elseif (in_array($key_type, array(
'pricecy',
'double'))) {
2160 $value_key =
price2num(
GETPOST(
"options_".$key,
'alpha')).
':'.
GETPOST(
"options_".$key.
"currency_id",
'alpha');
2161 } elseif (in_array($key_type, array(
'html'))) {
2162 $value_key =
GETPOST(
"options_".$key,
'restricthtml');
2163 } elseif (in_array($key_type, array(
'text'))) {
2164 $value_key =
GETPOST(
"options_".$key,
'alphanohtml');
2166 $value_key =
GETPOST(
"options_".$key);
2167 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
2172 if (!empty($error_field_required[$key]) && $todefaultifmissing) {
2174 if (!empty($this->attributes[$object->table_element][
'default']) && !is_null($this->attributes[$object->table_element][
'default'][$key])) {
2175 $value_key = $this->attributes[$object->table_element][
'default'][$key];
2176 unset($error_field_required[$key]);
2181 $object->array_options[
"options_".$key] = $value_key;
2184 if ($nofillrequired) {
2185 $langs->load(
'errors');
2186 $this->error = $langs->trans(
'ErrorFieldsRequired').
' : '.implode(
', ', $error_field_required);
2209 if (is_string($extrafieldsobjectkey) && !empty($this->attributes[$extrafieldsobjectkey][
'label']) && is_array($this->attributes[$extrafieldsobjectkey][
'label'])) {
2210 $extralabels = $this->attributes[$extrafieldsobjectkey][
'label'];
2212 $extralabels = $extrafieldsobjectkey;
2215 if (is_array($extralabels)) {
2216 $array_options = array();
2219 foreach ($extralabels as $key => $value) {
2221 if (is_string($extrafieldsobjectkey)) {
2222 $key_type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2225 if (in_array($key_type, array(
'date'))) {
2226 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2227 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2231 'start' =>
dol_mktime(0, 0, 0,
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int')),
2232 'end' =>
dol_mktime(23, 59, 59,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'))
2234 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2236 $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'));
2240 } elseif (in_array($key_type, array(
'datetime',
'datetimegmt'))) {
2241 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2242 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2245 $dateparamname_end_hour =
GETPOST($dateparamname_end .
'hour',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'hour',
'int') :
'23';
2246 $dateparamname_end_min =
GETPOST($dateparamname_end .
'min',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'min',
'int') :
'59';
2247 $dateparamname_end_sec =
GETPOST($dateparamname_end .
'sec',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'sec',
'int') :
'59';
2248 if ($key_type ==
'datetimegmt') {
2250 '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'),
2251 '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')
2255 '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'),
2256 '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')
2259 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2261 if ($key_type ==
'datetimegmt') {
2262 $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');
2264 $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');
2269 } elseif ($key_type ==
'select') {
2272 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix,
'array:aZ09');
2274 $value_arr = (array) $value_arr;
2275 $value_key = implode(
',', $value_arr);
2277 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2279 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2280 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2283 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2285 $value_arr = (array) $value_arr;
2286 $value_key = implode(
',', $value_arr);
2287 } elseif (in_array($key_type, array(
'price',
'double',
'int'))) {
2288 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2291 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2292 if ($keysuffix !=
'search_') {
2295 $value_key = $value_arr;
2297 } elseif (in_array($key_type, array(
'boolean'))) {
2298 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2301 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2302 $value_key = $value_arr;
2305 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2308 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2311 $array_options[$keysuffix.
"options_".$key] = $value_key;
2314 return $array_options;