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,
'1');
962 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
963 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'1');
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 if ($langfile && $val) {
1125 $options[$okey] = $langs->trans($val);
1127 $options[$okey] = $val;
1130 $selected = array();
1131 if (!is_array($value)) {
1132 $selected = explode(
',', $value);
1135 $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));
1137 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1138 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1139 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1142 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1143 $out .=
'<option value="0"> </option>';
1144 foreach ($param[
'options'] as $key2 => $val2) {
1145 if ((
string) $key2 ==
'') {
1148 $valarray = explode(
'|', $val2);
1149 $val2 = $valarray[0];
1151 if (!empty($valarray[1])) {
1152 $parent = $valarray[1];
1154 $out .=
'<option value="'.$key2.
'"';
1155 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1156 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1158 if ($langfile && $val2) {
1159 $out .= $langs->trans($val2);
1163 $out .=
'</option>';
1165 $out .=
'</select>';
1167 } elseif ($type ==
'sellist') {
1169 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
1170 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1171 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1174 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1175 if (is_array($param[
'options'])) {
1176 $param_list = array_keys($param[
'options']);
1177 $InfoFieldList = explode(
":", $param_list[0]);
1187 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1190 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1191 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1192 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1194 $keyList = $InfoFieldList[2].
' as rowid';
1197 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1198 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1199 $keyList .=
', '.$parentField;
1202 $filter_categorie =
false;
1203 if (count($InfoFieldList) > 5) {
1204 if ($InfoFieldList[0] ==
'categorie') {
1205 $filter_categorie =
true;
1209 if ($filter_categorie ===
false) {
1210 $fields_label = explode(
'|', $InfoFieldList[1]);
1211 if (is_array($fields_label)) {
1213 $keyList .= implode(
', ', $fields_label);
1217 $sql =
"SELECT ".$keyList;
1218 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1219 if (!empty($InfoFieldList[4])) {
1221 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1222 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1225 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1226 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1230 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1231 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1233 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1236 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1237 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1238 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1240 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1243 $sqlwhere .=
' WHERE 1=1';
1246 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1247 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1252 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1254 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1257 $out .=
'<option value="0"> </option>';
1258 $num = $this->
db->num_rows(
$resql);
1262 $obj = $this->
db->fetch_object(
$resql);
1266 $fields_label = explode(
'|', $InfoFieldList[1]);
1267 if (is_array($fields_label) && count($fields_label) > 1) {
1269 foreach ($fields_label as $field_toshow) {
1270 $labeltoshow .= $obj->$field_toshow.
' ';
1273 $labeltoshow = $obj->{$InfoFieldList[1]};
1275 $labeltoshow = $labeltoshow;
1277 if ($value == $obj->rowid) {
1279 foreach ($fields_label as $field_toshow) {
1280 $translabel = $langs->trans($obj->$field_toshow);
1281 $labeltoshow = $translabel.
' ';
1284 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1287 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1288 $labeltoshow = $translabel;
1290 if (empty($labeltoshow)) {
1291 $labeltoshow =
'(not defined)';
1294 if (!empty($InfoFieldList[3]) && $parentField) {
1295 $parent = $parentName.
':'.$obj->{$parentField};
1298 $out .=
'<option value="'.$obj->rowid.
'"';
1299 $out .= ($value == $obj->rowid ?
' selected' :
'');
1300 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1301 $out .=
'>'.$labeltoshow.
'</option>';
1308 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1311 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1312 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1313 $out .=
'<option value="0"> </option>';
1314 if (is_array($data)) {
1315 foreach ($data as $data_key => $data_value) {
1316 $out .=
'<option value="'.$data_key.
'"';
1317 $out .= ($value == $data_key ?
' selected' :
'');
1318 $out .=
'>'.$data_value.
'</option>';
1323 $out .=
'</select>';
1324 } elseif ($type ==
'checkbox') {
1325 $value_arr = $value;
1326 if (!is_array($value)) {
1327 $value_arr = explode(
',', $value);
1329 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1330 } elseif ($type ==
'radio') {
1332 foreach ($param[
'options'] as $keyopt => $val) {
1333 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1334 $out .=
' value="'.$keyopt.
'"';
1335 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1336 $out .= ($value == $keyopt ?
'checked' :
'');
1337 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1339 } elseif ($type ==
'chkbxlst') {
1340 if (is_array($value)) {
1341 $value_arr = $value;
1343 $value_arr = explode(
',', $value);
1346 if (is_array($param[
'options'])) {
1347 $param_list = array_keys($param[
'options']);
1348 $InfoFieldList = explode(
":", $param_list[0]);
1358 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1360 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1361 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1362 $keyList .=
', '.$parentField;
1364 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1365 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1366 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1368 $keyList = $InfoFieldList[2].
' as rowid';
1372 $filter_categorie =
false;
1373 if (count($InfoFieldList) > 5) {
1374 if ($InfoFieldList[0] ==
'categorie') {
1375 $filter_categorie =
true;
1379 if ($filter_categorie ===
false) {
1380 $fields_label = explode(
'|', $InfoFieldList[1]);
1381 if (is_array($fields_label)) {
1383 $keyList .= implode(
', ', $fields_label);
1387 $sql =
"SELECT ".$keyList;
1388 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1389 if (!empty($InfoFieldList[4])) {
1391 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1392 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1395 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1396 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1400 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1401 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1402 } elseif (preg_match(
"#^.*list.php$#", $_SERVER[
"PHP_SELF"])) {
1404 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1407 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1411 while ($nbPreg != 0) {
1413 $nbPregRepl = $nbPregSel = 0;
1415 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1417 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1419 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1421 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1424 $nbPreg = $nbPregRepl + $nbPregSel;
1428 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1429 while (!empty($matchCondition[0])) {
1431 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1433 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1435 if (!empty($matchCondition[1])) {
1436 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1437 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1438 } elseif (!empty($matchCondition[3])) {
1439 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1440 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1442 $InfoFieldList[4] =
" TRUE ";
1447 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1450 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1454 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1455 $sql .=
' as main, '.$this->db->prefix().$InfoFieldList[0].
'_extrafields as extra';
1456 $sqlwhere .=
" WHERE extra.fk_object=main.".$InfoFieldList[2].
" AND ".$InfoFieldList[4];
1458 $sqlwhere .=
" WHERE ".$InfoFieldList[4];
1461 $sqlwhere .=
' WHERE 1=1';
1464 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1465 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1471 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1474 $num = $this->
db->num_rows(
$resql);
1481 $obj = $this->
db->fetch_object(
$resql);
1485 $fields_label = explode(
'|', $InfoFieldList[1]);
1486 if (is_array($fields_label)) {
1488 foreach ($fields_label as $field_toshow) {
1489 $labeltoshow .= $obj->$field_toshow.
' ';
1492 $labeltoshow = $obj->{$InfoFieldList[1]};
1494 $labeltoshow =
dol_trunc($labeltoshow, 45);
1496 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1497 foreach ($fields_label as $field_toshow) {
1498 $translabel = $langs->trans($obj->$field_toshow);
1499 if ($translabel != $obj->$field_toshow) {
1500 $labeltoshow =
dol_trunc($translabel, 18).
' ';
1502 $labeltoshow =
dol_trunc($obj->$field_toshow, 18).
' ';
1506 $data[$obj->rowid] = $labeltoshow;
1509 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1510 if ($translabel != $obj->{$InfoFieldList[1]}) {
1511 $labeltoshow =
dol_trunc($translabel, 18);
1513 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1516 if (empty($labeltoshow)) {
1517 $labeltoshow =
'(not defined)';
1520 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1521 $data[$obj->rowid] = $labeltoshow;
1524 if (!empty($InfoFieldList[3]) && $parentField) {
1525 $parent = $parentName.
':'.$obj->{$parentField};
1528 $data[$obj->rowid] = $labeltoshow;
1535 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1537 print
'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1540 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1541 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1542 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1545 } elseif ($type ==
'link') {
1546 $param_list = array_keys($param[
'options']);
1547 $showempty = (($required && $default !=
'') ? 0 : 1);
1548 $out =
$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss);
1549 } elseif ($type ==
'password') {
1551 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1552 $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 :
'').
'>';
1554 if (!empty($hidden)) {
1555 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1577 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'')
1579 global $conf, $langs;
1581 if (empty($extrafieldsobjectkey)) {
1582 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
1583 return 'BadValueForParamExtraFieldsObjectKey';
1586 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1587 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1588 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1589 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1590 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1591 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1592 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1593 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1594 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'1');
1595 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1596 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'1');
1597 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1598 $hidden = (empty($list) ? 1 : 0);
1607 if ($type ==
'date') {
1609 if ($value !==
'') {
1612 } elseif ($type ==
'datetime') {
1614 if ($value !==
'') {
1617 } elseif ($type ==
'int') {
1619 } elseif ($type ==
'double') {
1620 if (!empty($value)) {
1622 $sizeparts = explode(
",", $size);
1623 $number_decimals = array_key_exists(1, $sizeparts) ? $sizeparts[1] : 0;
1624 $value =
price($value, 0, $langs, 0, 0, $number_decimals,
'');
1626 } elseif ($type ==
'boolean') {
1628 if (!empty($value)) {
1629 $checked =
' checked ';
1631 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1632 } elseif ($type ==
'mail') {
1634 } elseif ($type ==
'ip') {
1636 } elseif ($type ==
'url') {
1638 } elseif ($type ==
'phone') {
1640 } elseif ($type ==
'price') {
1642 if ($value || $value ==
'0') {
1643 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1).
' '.$langs->getCurrencySymbol($conf->currency);
1645 } elseif ($type ==
'pricecy') {
1646 $currency = $conf->currency;
1647 if (!empty($value)) {
1649 $pricetmp = explode(
':', $value);
1650 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1651 $value = $pricetmp[0];
1653 if ($value || $value ==
'0') {
1654 $value =
price($value, 0, $langs, 0, $conf->global->MAIN_MAX_DECIMALS_TOT, -1, $currency);
1656 } elseif ($type ==
'select') {
1657 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
1658 if (($pos = strpos($valstr,
"|")) !==
false) {
1659 $valstr = substr($valstr, 0, $pos);
1661 if ($langfile && $valstr) {
1662 $value = $langs->trans($valstr);
1666 } elseif ($type ==
'sellist') {
1667 $param_list = array_keys($param[
'options']);
1668 $InfoFieldList = explode(
":", $param_list[0]);
1670 $selectkey =
"rowid";
1673 if (count($InfoFieldList) >= 3) {
1674 $selectkey = $InfoFieldList[2];
1675 $keyList = $InfoFieldList[2].
' as rowid';
1678 $fields_label = explode(
'|', $InfoFieldList[1]);
1679 if (is_array($fields_label)) {
1681 $keyList .= implode(
', ', $fields_label);
1684 $filter_categorie =
false;
1685 if (count($InfoFieldList) > 5) {
1686 if ($InfoFieldList[0] ==
'categorie') {
1687 $filter_categorie =
true;
1691 $sql =
"SELECT ".$keyList;
1692 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1693 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra') !==
false) {
1696 if ($selectkey ==
'rowid' && empty($value)) {
1697 $sql .=
" WHERE ".$selectkey.
" = 0";
1698 } elseif ($selectkey ==
'rowid') {
1699 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
1701 $sql .=
" WHERE ".$selectkey.
" = '".$this->
db->escape($value).
"'";
1706 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
1709 if ($filter_categorie ===
false) {
1712 $obj = $this->
db->fetch_object(
$resql);
1715 $fields_label = explode(
'|', $InfoFieldList[1]);
1717 if (is_array($fields_label) && count($fields_label) > 1) {
1718 foreach ($fields_label as $field_toshow) {
1720 if (!empty($obj->$field_toshow)) {
1721 $translabel = $langs->trans($obj->$field_toshow);
1723 if ($translabel != $obj->$field_toshow) {
1724 $value .=
dol_trunc($translabel, 24).
' ';
1726 $value .= $obj->$field_toshow.
' ';
1731 $tmppropname = $InfoFieldList[1];
1733 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1734 $translabel = $langs->trans($obj->$tmppropname);
1736 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
1739 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
1744 $obj = $this->
db->fetch_object(
$resql);
1746 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1748 $result = $c->fetch($obj->rowid);
1750 $ways = $c->print_all_ways();
1751 foreach ($ways as $way) {
1752 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
1756 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1759 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1761 } elseif ($type ==
'radio') {
1762 if (!isset($param[
'options'][$value])) {
1763 $langs->load(
'errors');
1764 $value = $langs->trans(
'ErrorNoValueForRadioType');
1766 $value = $langs->trans($param[
'options'][$value]);
1768 } elseif ($type ==
'checkbox') {
1769 $value_arr = explode(
',', $value);
1772 if (is_array($value_arr)) {
1773 foreach ($value_arr as $keyval => $valueval) {
1774 if (!empty($valueval)) {
1775 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
1779 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1780 } elseif ($type ==
'chkbxlst') {
1781 $value_arr = explode(
',', $value);
1783 $param_list = array_keys($param[
'options']);
1784 $InfoFieldList = explode(
":", $param_list[0]);
1786 $selectkey =
"rowid";
1789 if (count($InfoFieldList) >= 3) {
1790 $selectkey = $InfoFieldList[2];
1791 $keyList = $InfoFieldList[2].
' as rowid';
1794 $fields_label = explode(
'|', $InfoFieldList[1]);
1795 if (is_array($fields_label)) {
1797 $keyList .= implode(
', ', $fields_label);
1800 $filter_categorie =
false;
1801 if (count($InfoFieldList) > 5) {
1802 if ($InfoFieldList[0] ==
'categorie') {
1803 $filter_categorie =
true;
1807 $sql =
"SELECT ".$keyList;
1808 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
1809 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1815 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
1818 if ($filter_categorie ===
false) {
1821 while ($obj = $this->
db->fetch_object(
$resql)) {
1823 $fields_label = explode(
'|', $InfoFieldList[1]);
1824 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1825 if (is_array($fields_label) && count($fields_label) > 1) {
1826 foreach ($fields_label as $field_toshow) {
1828 if (!empty($obj->$field_toshow)) {
1829 $translabel = $langs->trans($obj->$field_toshow);
1831 if ($translabel != $field_toshow) {
1832 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1834 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->$field_toshow.
'</li>';
1839 if (!empty($obj->{$InfoFieldList[1]})) {
1840 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1842 if ($translabel != $obj->{$InfoFieldList[1]}) {
1843 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1845 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
1851 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1854 while ($obj = $this->
db->fetch_object(
$resql)) {
1855 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1857 $c->fetch($obj->rowid);
1858 $ways = $c->print_all_ways();
1859 foreach ($ways as $way) {
1860 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1865 if (!empty($toprint)) $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1867 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1869 } elseif ($type ==
'link') {
1874 $param_list = array_keys($param[
'options']);
1876 $InfoFieldList = explode(
":", $param_list[0]);
1877 $classname = $InfoFieldList[0];
1878 $classpath = $InfoFieldList[1];
1879 if (!empty($classpath)) {
1881 if ($classname && class_exists($classname)) {
1882 $object =
new $classname($this->
db);
1883 $object->fetch($value);
1884 $value = $object->getNomUrl(3);
1887 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
1888 return 'Error bad setup of extrafield';
1891 } elseif ($type ==
'text') {
1893 } elseif ($type ==
'html') {
1895 } elseif ($type ==
'password') {
1896 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
1898 $showsize = round((
float) $size);
1899 if ($showsize > 48) {
1919 global $conf, $langs;
1922 if (!empty($extrafieldsobjectkey)) {
1923 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1928 if (in_array($type, array(
'date',
'datetime'))) {
1929 $cssstring =
"center";
1930 } elseif (in_array($type, array(
'int',
'price',
'double'))) {
1931 $cssstring =
"right";
1932 } elseif (in_array($type, array(
'boolean',
'radio',
'checkbox',
'ip'))) {
1933 $cssstring =
"center";
1936 if (!empty($this->attributes[$extrafieldsobjectkey][
'csslist'][$key])) {
1937 $cssstring .= ($cssstring ?
' ' :
'').$this->attributes[$extrafieldsobjectkey][
'csslist'][$key];
1939 if (in_array($type, array(
'ip'))) {
1940 $cssstring .= ($cssstring ?
' ' :
'').
'tdoverflowmax150';
1957 public function showSeparator($key, $object, $colspan = 2, $display_type =
'card', $mode =
'')
1959 global $conf, $langs;
1964 if ($display_type==
'line') {
1966 $tagtype_dyn=
'span';
1970 $extrafield_param = $this->attributes[$object->table_element][
'param'][$key];
1971 $extrafield_param_list = array();
1972 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1973 $extrafield_param_list = array_keys($extrafield_param[
'options']);
1975 $extrafield_collapse_display_value = -1;
1976 $expand_display =
false;
1977 if (is_array($extrafield_param_list) && count($extrafield_param_list) > 0) {
1978 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1979 $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));
1981 if ($mode ==
'create') {
1982 $extrafield_collapse_display_value = 0;
1985 $out =
'<'.$tagtype.
' id="trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'" class="trextrafieldseparator trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'">';
1986 $out .=
'<'.$tagtype_dyn.
' '.(!empty($colspan)?
'colspan="' . $colspan .
'"':
'').
'>';
1989 $out .=
'<span class="cursorpointer '.($extrafield_collapse_display_value == 0 ?
'fas fa-square opacitymedium' :
'far fa-'.(($expand_display ?
'minus' :
'plus').
'-square')).
'"></span>';
1992 $out .= $langs->trans($this->attributes[$object->table_element][
'label'][$key]);
1993 $out .=
'</strong>';
1994 $out .=
'</'.$tagtype_dyn.
'>';
1995 $out .=
'</'.$tagtype.
'>';
1997 $collapse_group = $key.(!empty($object->id) ?
'_'.$object->id :
'');
2000 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
2002 $this->expand_display[$collapse_group] = $expand_display;
2004 if (!empty($conf->use_javascript_ajax) && $mode !=
'create') {
2005 $out .=
'<!-- Add js script to manage the collapse/uncollapse of extrafields separators '.$key.
' -->'.
"\n";
2006 $out .=
'<script type="text/javascript">'.
"\n";
2007 $out .=
'jQuery(document).ready(function(){'.
"\n";
2008 if ($expand_display ===
false) {
2009 $out .=
' console.log("Inject js for the collapsing of extrafield '.$key.
' - hide");'.
"\n";
2010 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").hide();'.
"\n";
2012 $out .=
' console.log("Inject js for collapsing of extrafield '.$key.
' - keep visible and set cookie");'.
"\n";
2013 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2015 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
'").click(function(){'.
"\n";
2016 $out .=
' console.log("We click on collapse/uncollapse .trextrafields_collapse'.$collapse_group.
'");'.
"\n";
2017 $out .=
' jQuery(".trextrafields_collapse'.$collapse_group.
'").toggle(100, function(){'.
"\n";
2018 $out .=
' if (jQuery(".trextrafields_collapse'.$collapse_group.
'").is(":hidden")) {'.
"\n";
2019 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-plus-square").removeClass("fa-minus-square");'.
"\n";
2020 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=0; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2021 $out .=
' } else {'.
"\n";
2022 $out .=
' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?
'_'.$object->id:
'').
' '.$tagtype_dyn.
' span").addClass("fa-minus-square").removeClass("fa-plus-square");'.
"\n";
2023 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.$_SERVER[
"PHP_SELF"].
'"'.
"\n";
2025 $out .=
' });'.
"\n";
2026 $out .=
' });'.
"\n";
2028 $out .=
'</script>'.
"\n";
2031 $this->expand_display[$collapse_group] = 1;
2050 global $_POST, $langs;
2052 $nofillrequired = 0;
2053 $error_field_required = array();
2055 if (isset($this->attributes[$object->table_element][
'label']) && is_array($this->attributes[$object->table_element][
'label'])) {
2056 $extralabels = $this->attributes[$object->table_element][
'label'];
2059 if (is_array($extralabels)) {
2061 foreach ($extralabels as $key => $value) {
2062 if (!empty($onlykey) && $onlykey !=
'@GETPOSTISSET' && $key != $onlykey) {
2066 if (!empty($onlykey) && $onlykey ==
'@GETPOSTISSET' && !
GETPOSTISSET(
'options_'.$key) && (! in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'chkbxlst')))) {
2071 $key_type = $this->attributes[$object->table_element][
'type'][$key];
2072 if ($key_type ==
'separate') {
2077 if (isset($this->attributes[$object->table_element][
'enabled'][$key])) {
2078 $enabled =
dol_eval($this->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'1');
2082 if (isset($this->attributes[$object->table_element][
'list'][$key])) {
2083 $visibility = intval(
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1, 1,
'1'));
2087 if (isset($this->attributes[$object->table_element][
'perms'][$key])) {
2088 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1, 1,
'1');
2092 $onlykey ===
'@GETPOSTISSET'
2093 && in_array($this->attributes[$object->table_element][
'type'][$key], array(
'boolean',
'chkbxlst'))
2094 && in_array(abs($enabled), array(2, 5))
2100 if (empty($visibility)) {
2103 if (empty($perms)) {
2107 if ($this->attributes[$object->table_element][
'required'][$key]) {
2111 if ((!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] !=
'select' && $_POST[
"options_".$key] !=
'0')
2112 || (!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'select')
2113 || (!is_array($_POST[
"options_".$key]) && isset($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'sellist' && $_POST[
'options_'.$key] ==
'0')
2114 || (is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]))) {
2119 $error_field_required[$key] = $langs->transnoentitiesnoconv($value);
2123 if (in_array($key_type, array(
'date'))) {
2125 $value_key =
dol_mktime(12, 0, 0,
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'));
2126 } elseif (in_array($key_type, array(
'datetime'))) {
2128 $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');
2129 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2130 $value_arr =
GETPOST(
"options_".$key,
'array');
2131 if (!empty($value_arr)) {
2132 $value_key = implode(
',', $value_arr);
2136 } elseif (in_array($key_type, array(
'price',
'double'))) {
2137 $value_arr =
GETPOST(
"options_".$key,
'alpha');
2139 } elseif (in_array($key_type, array(
'pricecy',
'double'))) {
2140 $value_key =
price2num(
GETPOST(
"options_".$key,
'alpha')).
':'.
GETPOST(
"options_".$key.
"currency_id",
'alpha');
2141 } elseif (in_array($key_type, array(
'html'))) {
2142 $value_key =
GETPOST(
"options_".$key,
'restricthtml');
2143 } elseif (in_array($key_type, array(
'text'))) {
2144 $value_key =
GETPOST(
"options_".$key,
'alphanohtml');
2146 $value_key =
GETPOST(
"options_".$key);
2147 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
2152 if (!empty($error_field_required[$key]) && $todefaultifmissing) {
2154 if (!empty($this->attributes[$object->table_element][
'default']) && !is_null($this->attributes[$object->table_element][
'default'][$key])) {
2155 $value_key = $this->attributes[$object->table_element][
'default'][$key];
2156 unset($error_field_required[$key]);
2161 $object->array_options[
"options_".$key] = $value_key;
2164 if ($nofillrequired) {
2165 $langs->load(
'errors');
2166 $this->error = $langs->trans(
'ErrorFieldsRequired').
' : '.implode(
', ', $error_field_required);
2189 if (is_string($extrafieldsobjectkey) && !empty($this->attributes[$extrafieldsobjectkey][
'label']) && is_array($this->attributes[$extrafieldsobjectkey][
'label'])) {
2190 $extralabels = $this->attributes[$extrafieldsobjectkey][
'label'];
2192 $extralabels = $extrafieldsobjectkey;
2195 if (is_array($extralabels)) {
2196 $array_options = array();
2199 foreach ($extralabels as $key => $value) {
2201 if (is_string($extrafieldsobjectkey)) {
2202 $key_type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2205 if (in_array($key_type, array(
'date'))) {
2206 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2207 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2211 'start' =>
dol_mktime(0, 0, 0,
GETPOST($dateparamname_start .
'month',
'int'),
GETPOST($dateparamname_start .
'day',
'int'),
GETPOST($dateparamname_start .
'year',
'int')),
2212 'end' =>
dol_mktime(23, 59, 59,
GETPOST($dateparamname_end .
'month',
'int'),
GETPOST($dateparamname_end .
'day',
'int'),
GETPOST($dateparamname_end .
'year',
'int'))
2214 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2216 $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'));
2220 } elseif (in_array($key_type, array(
'datetime'))) {
2221 $dateparamname_start = $keysuffix .
'options_' . $key . $keyprefix .
'_start';
2222 $dateparamname_end = $keysuffix .
'options_' . $key . $keyprefix .
'_end';
2225 $dateparamname_end_hour =
GETPOST($dateparamname_end .
'hour',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'hour',
'int') :
'23';
2226 $dateparamname_end_min =
GETPOST($dateparamname_end .
'min',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'min',
'int') :
'59';
2227 $dateparamname_end_sec =
GETPOST($dateparamname_end .
'sec',
'int') !=
'-1' ?
GETPOST($dateparamname_end .
'sec',
'int') :
'59';
2229 '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'),
2230 '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')
2232 } elseif (
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year")) {
2234 $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');
2238 } elseif ($key_type ==
'select') {
2241 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix,
'array:aZ09');
2243 $value_arr = (array) $value_arr;
2244 $value_key = implode(
',', $value_arr);
2246 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2248 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2249 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2252 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2254 $value_arr = (array) $value_arr;
2255 $value_key = implode(
',', $value_arr);
2256 } elseif (in_array($key_type, array(
'price',
'double',
'int'))) {
2257 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2260 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2261 if ($keysuffix !=
'search_') {
2264 $value_key = $value_arr;
2266 } elseif (in_array($key_type, array(
'boolean'))) {
2267 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2270 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2271 $value_key = $value_arr;
2274 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix)) {
2277 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2280 $array_options[$keysuffix.
"options_".$key] = $value_key;
2283 return $array_options;
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to manage categories.
Class to manage a WYSIWYG editor.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0)
Show Url link.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
jsonOrUnserialize($stringtodecode)
Decode an encode string.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.