49 public $attribute_elementtype;
55 public $attribute_type;
61 public $attribute_label;
67 public $attribute_size;
73 public $attribute_choice;
79 public $attribute_computed;
85 public $attribute_default;
91 public $attribute_unique;
97 public $attribute_required;
103 public $attribute_param;
109 public $attribute_pos;
115 public $attribute_alwayseditable;
121 public $attribute_perms;
127 public $attribute_langfile;
133 public $attribute_list;
139 public $attribute_totalizable;
145 public $attribute_entityid;
161 public $errors = array();
169 public static $type2label = array(
170 'varchar'=>
'String1Line',
171 'text'=>
'TextLongNLines',
176 'datetime'=>
'DateAndTime',
177 'boolean'=>
'Boolean',
178 'price'=>
'ExtrafieldPrice',
179 'phone'=>
'ExtrafieldPhone',
180 'mail'=>
'ExtrafieldMail',
181 'url'=>
'ExtrafieldUrl',
182 'password' =>
'ExtrafieldPassword',
183 'select' =>
'ExtrafieldSelect',
184 'sellist' =>
'ExtrafieldSelectList',
185 'radio' =>
'ExtrafieldRadio',
186 'checkbox' =>
'ExtrafieldCheckBox',
187 'chkbxlst' =>
'ExtrafieldCheckBoxFromList',
188 'link' =>
'ExtrafieldLink',
189 'separate' =>
'ExtrafieldSeparator',
202 $this->errors = array();
203 $this->attributes = array();
206 $this->attribute_elementtype = array();
207 $this->attribute_type = array();
208 $this->attribute_label = array();
209 $this->attribute_size = array();
210 $this->attribute_computed = array();
211 $this->attribute_default = array();
212 $this->attribute_unique = array();
213 $this->attribute_required = array();
214 $this->attribute_perms = array();
215 $this->attribute_langfile = array();
216 $this->attribute_list = array();
244 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)
246 if (empty($attrname))
return -1;
247 if (empty($label))
return -1;
249 if ($type ==
'separate') { $unique = 0; $required = 0; }
250 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
251 if ($elementtype ==
'contact') $elementtype =
'socpeople';
254 if ($type !=
'separate')
256 $result = $this->
create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help);
258 $err1 = $this->errno;
259 if ($result > 0 || $err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type ==
'separate')
262 $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);
263 $err2 = $this->errno;
264 if ($result2 > 0 || ($err1 ==
'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 ==
'DB_ERROR_RECORD_ALREADY_EXISTS'))
293 private function create($attrname, $type =
'varchar', $length = 255, $elementtype =
'member', $unique = 0, $required = 0, $default_value =
'', $param =
'', $perms =
'', $list =
'0', $computed =
'', $help =
'')
295 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
296 if ($elementtype ==
'contact') $elementtype =
'socpeople';
298 $table = $elementtype.
'_extrafields';
299 if ($elementtype ==
'categorie') $table =
'categories_extrafields';
301 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname))
303 if ($type ==
'boolean') {
306 } elseif ($type ==
'price') {
309 } elseif ($type ==
'phone') {
312 } elseif ($type ==
'mail') {
315 } elseif ($type ==
'url') {
318 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
321 } elseif ($type ==
'link') {
324 } elseif ($type ==
'html') {
327 } elseif ($type ==
'password') {
333 if ($type ==
'varchar' && empty($lengthdb)) $lengthdb =
'255';
338 'null'=>($required ?
'NOT NULL' :
'NULL'),
339 'default' => $default_value
342 $result = $this->
db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
347 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
348 $resql = $this->
db->query($sql, 1,
'dml');
352 $this->error = $this->
db->lasterror();
353 $this->errno = $this->
db->lasterrno();
388 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)
393 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
394 if ($elementtype ==
'contact') $elementtype =
'socpeople';
397 if (empty($pos)) $pos = 0;
398 if (empty($list)) $list =
'0';
399 if (empty($required)) $required = 0;
400 if (empty($unique)) $unique = 0;
401 if (empty($printable)) $printable = 0;
402 if (empty($alwayseditable)) $alwayseditable = 0;
403 if (empty($totalizable)) $totalizable = 0;
405 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname))
407 if (is_array($param) && count($param) > 0)
409 $params = serialize($param);
410 } elseif (strlen($param) > 0)
412 $params = trim($param);
417 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"extrafields(";
424 $sql .=
" elementtype,";
425 $sql .=
" fieldunique,";
426 $sql .=
" fieldrequired,";
428 $sql .=
" alwayseditable,";
432 $sql .=
" printable,";
433 $sql .=
" fielddefault,";
434 $sql .=
" fieldcomputed,";
435 $sql .=
" fk_user_author,";
436 $sql .=
" fk_user_modif,";
440 $sql .=
" totalizable";
442 $sql .=
" VALUES('".$this->db->escape($attrname).
"',";
443 $sql .=
" '".$this->db->escape($label).
"',";
444 $sql .=
" '".$this->db->escape($type).
"',";
445 $sql .=
" ".$pos.
",";
446 $sql .=
" '".$this->db->escape($size).
"',";
447 $sql .=
" ".($entity ===
'' ? $conf->entity : $entity).
",";
448 $sql .=
" '".$this->db->escape($elementtype).
"',";
449 $sql .=
" ".$unique.
",";
450 $sql .=
" ".$required.
",";
451 $sql .=
" '".$this->db->escape($params).
"',";
452 $sql .=
" ".$alwayseditable.
",";
453 $sql .=
" ".($perms ?
"'".$this->db->escape($perms).
"'" :
"null").
",";
454 $sql .=
" ".($langfile ?
"'".$this->db->escape($langfile).
"'" :
"null").
",";
455 $sql .=
" '".$this->db->escape($list).
"',";
456 $sql .=
" '".$this->db->escape($printable).
"',";
457 $sql .=
" ".($default ?
"'".$this->db->escape($default).
"'" :
"null").
",";
458 $sql .=
" ".($computed ?
"'".$this->db->escape($computed).
"'" :
"null").
",";
459 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
460 $sql .=
" ".(is_object($user) ? $user->id : 0).
",";
461 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
462 $sql .=
" ".($enabled ?
"'".$this->db->escape($enabled).
"'" :
"1").
",";
463 $sql .=
" ".($help ?
"'".$this->db->escape($help).
"'" :
"null").
",";
464 $sql .=
" ".($totalizable ?
'TRUE' :
'FALSE');
467 dol_syslog(get_class($this).
"::create_label", LOG_DEBUG);
468 if ($this->
db->query($sql))
472 $this->error = $this->
db->lasterror();
473 $this->errno = $this->
db->lasterrno();
486 public function delete($attrname, $elementtype =
'member')
488 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
489 if ($elementtype ==
'contact') $elementtype =
'socpeople';
491 $table = $elementtype.
'_extrafields';
492 if ($elementtype ==
'categorie') $table =
'categories_extrafields';
496 if (!empty($attrname) && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname))
501 $this->error = $this->
db->lasterror();
502 $this->errors[] = $this->
db->lasterror();
508 $sql =
"SELECT COUNT(rowid) as nb";
509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields";
510 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
511 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
516 $obj = $this->
db->fetch_object(
$resql);
519 $result = $this->
db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname);
522 $this->error = $this->
db->lasterror();
523 $this->errors[] = $this->
db->lasterror();
549 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
550 if ($elementtype ==
'contact') $elementtype =
'socpeople';
552 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname))
554 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"extrafields";
555 $sql .=
" WHERE name = '".$this->db->escape($attrname).
"'";
556 $sql .=
" AND entity IN (0,".$conf->entity.
')';
557 $sql .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
559 dol_syslog(get_class($this).
"::delete_label", LOG_DEBUG);
599 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)
601 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
602 if ($elementtype ==
'contact') $elementtype =
'socpeople';
604 $table = $elementtype.
'_extrafields';
605 if ($elementtype ==
'categorie') $table =
'categories_extrafields';
607 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname))
609 if ($type ==
'boolean') {
612 } elseif ($type ==
'price') {
615 } elseif ($type ==
'phone') {
618 } elseif ($type ==
'mail') {
621 } elseif ($type ==
'url') {
624 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
627 } elseif ($type ==
'html') {
629 } elseif ($type ==
'link') {
632 } elseif ($type ==
'password') {
639 $field_desc = array(
'type'=>$typedb,
'value'=>$lengthdb,
'null'=>($required ?
'NOT NULL' :
'NULL'),
'default'=>$default);
641 if ($type !=
'separate')
643 $result = $this->
db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
645 if ($result > 0 || $type ==
'separate')
649 $result = $this->
update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $printable);
656 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.$table.
" ADD UNIQUE INDEX uk_".$table.
"_".$attrname.
" (".$attrname.
")";
658 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.$table.
" DROP INDEX uk_".$table.
"_".$attrname;
660 dol_syslog(get_class($this).
'::update', LOG_DEBUG);
661 $resql = $this->
db->query($sql, 1,
'dml');
664 $this->error = $this->
db->lasterror();
668 $this->error = $this->
db->lasterror();
703 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)
707 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);
710 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
711 if ($elementtype ==
'contact') $elementtype =
'socpeople';
713 if (empty($pos)) $pos = 0;
714 if (empty($list)) $list =
'0';
715 if (empty($totalizable)) {
718 if (empty($required)) $required = 0;
719 if (empty($unique)) $unique = 0;
720 if (empty($alwayseditable)) $alwayseditable = 0;
722 if (isset($attrname) && $attrname !=
'' && preg_match(
"/^\w[a-zA-Z0-9-_]*$/", $attrname))
726 if (is_array($param) && count($param) > 0)
728 $params = serialize($param);
729 } elseif (strlen($param) > 0)
731 $params = trim($param);
736 if ($entity ===
'' || $entity !=
'0')
739 $sql_del =
"DELETE FROM ".MAIN_DB_PREFIX.
"extrafields";
740 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
741 $sql_del .=
" AND entity IN (0, ".($entity ===
'' ? $conf->entity : $entity).
")";
742 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
745 $sql_del =
"DELETE FROM ".MAIN_DB_PREFIX.
"extrafields";
746 $sql_del .=
" WHERE name = '".$this->db->escape($attrname).
"'";
747 $sql_del .=
" AND entity = 0";
748 $sql_del .=
" AND elementtype = '".$this->db->escape($elementtype).
"'";
750 $resql1 = $this->
db->query($sql_del);
752 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"extrafields(";
758 $sql .=
" elementtype,";
759 $sql .=
" fieldunique,";
760 $sql .=
" fieldrequired,";
764 $sql .=
" alwayseditable,";
767 $sql .=
" printable,";
768 $sql .=
" totalizable,";
769 $sql .=
" fielddefault,";
770 $sql .=
" fieldcomputed,";
771 $sql .=
" fk_user_author,";
772 $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");
802 $resql2 = $this->
db->query($sql);
804 if ($resql1 && $resql2)
809 $this->
db->rollback();
832 if (empty($elementtype))
return array();
834 if ($elementtype ==
'thirdparty') $elementtype =
'societe';
835 if ($elementtype ==
'contact') $elementtype =
'socpeople';
836 if ($elementtype ==
'order_supplier') $elementtype =
'commande_fournisseur';
837 if ($elementtype ==
'stock_mouvement') $elementtype =
'movement';
839 $array_name_label = array();
842 $sql =
"SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help";
843 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields";
845 if ($elementtype) $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
846 $sql .=
" ORDER BY pos";
853 while ($tab = $this->
db->fetch_object(
$resql))
855 if ($tab->entity != 0 && $tab->entity != $conf->entity)
858 if ($tab->fieldrequired && is_null($tab->fielddefault))
860 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
866 if ($tab->type !=
'separate')
868 $array_name_label[$tab->name] = $tab->label;
872 $this->attribute_type[$tab->name] = $tab->type;
873 $this->attribute_label[$tab->name] = $tab->label;
874 $this->attribute_size[$tab->name] = $tab->size;
875 $this->attribute_elementtype[$tab->name] = $tab->elementtype;
876 $this->attribute_default[$tab->name] = $tab->fielddefault;
877 $this->attribute_computed[$tab->name] = $tab->fieldcomputed;
878 $this->attribute_unique[$tab->name] = $tab->fieldunique;
879 $this->attribute_required[$tab->name] = $tab->fieldrequired;
880 $this->attribute_param[$tab->name] = ($tab->param ? unserialize($tab->param) :
'');
881 $this->attribute_pos[$tab->name] = $tab->pos;
882 $this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable;
883 $this->attribute_perms[$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms);
884 $this->attribute_langfile[$tab->name] = $tab->langs;
885 $this->attribute_list[$tab->name] = $tab->list;
886 $this->attribute_totalizable[$tab->name] = $tab->totalizable;
887 $this->attribute_entityid[$tab->name] = $tab->entity;
890 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
891 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
892 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
893 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
894 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
895 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
896 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
897 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
898 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ? unserialize($tab->param) :
'');
899 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
900 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
901 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms);
902 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
903 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
904 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
905 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
906 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
907 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
908 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
910 $this->attributes[$tab->elementtype][
'loaded'] = 1;
913 if ($elementtype) $this->attributes[$elementtype][
'loaded'] = 1;
915 $this->error = $this->
db->lasterror();
916 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
919 return $array_name_label;
938 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'', $objectid = 0, $extrafieldsobjectkey =
'', $mode = 0)
940 global $conf, $langs, $form;
942 if (!is_object($form))
944 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
945 $form =
new Form($this->
db);
950 if (!preg_match(
'/options_$/', $keyprefix))
952 $keyprefix = $keyprefix.
'options_';
955 if (!empty($extrafieldsobjectkey))
957 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
958 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
959 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
960 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
961 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
962 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
963 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
964 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
965 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1);
966 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
967 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1);
968 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
969 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
970 $hidden = (empty($list) ? 1 : 0);
973 $label = $this->attribute_label[$key];
974 $type = $this->attribute_type[$key];
975 $size = $this->attribute_size[$key];
976 $elementtype = $this->attribute_elementtype[$key];
977 $default = $this->attribute_default[$key];
978 $computed = $this->attribute_computed[$key];
979 $unique = $this->attribute_unique[$key];
980 $required = $this->attribute_required[$key];
981 $param = $this->attribute_param[$key];
982 $langfile = $this->attribute_langfile[$key];
983 $list = $this->attribute_list[$key];
984 $totalizable = $this->attribute_totalizable[$key];
985 $hidden = (empty($list) ? 1 : 0);
990 if (!preg_match(
'/^search_/', $keyprefix))
return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
994 if (empty($morecss)) {
995 if ($type ==
'date') {
996 $morecss =
'minwidth100imp';
997 } elseif ($type ==
'datetime' || $type ==
'link') {
998 $morecss =
'minwidth200imp';
999 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1000 $morecss =
'maxwidth75';
1001 } elseif ($type ==
'password') {
1002 $morecss =
'maxwidth100';
1003 } elseif ($type ==
'url') {
1004 $morecss =
'minwidth400';
1005 } elseif ($type ==
'boolean') {
1008 if (empty($size) || round($size) < 12) {
1009 $morecss =
'minwidth100';
1010 } elseif (round($size) <= 48) {
1011 $morecss =
'minwidth200';
1013 $morecss =
'minwidth400';
1018 if (in_array($type, array(
'date'))) {
1019 $tmp = explode(
',', $size);
1024 if (!$required && $value ==
'') $value =
'-1';
1027 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1028 } elseif (in_array($type, array(
'datetime'))) {
1029 $tmp = explode(
',', $size);
1034 if (!$required && $value ==
'') $value =
'-1';
1037 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1038 } elseif (in_array($type, array(
'int',
'integer')))
1040 $tmp = explode(
',', $size);
1042 $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 :
'').
'>';
1043 } elseif (preg_match(
'/varchar/', $type))
1045 $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 :
'').
'>';
1046 } elseif (in_array($type, array(
'mail',
'phone',
'url')))
1048 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1049 } elseif ($type ==
'text')
1051 if (!preg_match(
'/search_/', $keyprefix))
1053 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1054 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1055 $out = $doleditor->Create(1);
1057 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1059 } elseif ($type ==
'html')
1061 if (!preg_match(
'/search_/', $keyprefix))
1063 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1064 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
1065 $out = $doleditor->Create(1);
1067 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1069 } elseif ($type ==
'boolean')
1074 if (!empty($value)) {
1075 $checked =
' checked value="1" ';
1077 $checked =
' value="1" ';
1079 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1081 $out .= $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1);
1083 } elseif ($type ==
'price')
1085 if (!empty($value)) {
1086 $value =
price($value);
1088 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
1089 } elseif ($type ==
'double')
1091 if (!empty($value)) {
1092 $value =
price($value);
1094 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1095 } elseif ($type ==
'select')
1098 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
1100 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1101 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1104 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1105 $out .=
'<option value="0"> </option>';
1106 foreach ($param[
'options'] as $key => $val)
1108 if ((
string) $key ==
'')
continue;
1109 list($val, $parent) = explode(
'|', $val);
1110 $out .=
'<option value="'.$key.
'"';
1111 $out .= (((string) $value == (
string) $key) ?
' selected' :
'');
1112 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1114 if ($langfile && $val) $out .= $langs->trans($val);
1116 $out .=
'</option>';
1118 $out .=
'</select>';
1119 } elseif ($type ==
'sellist')
1122 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
1124 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1125 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1128 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1129 if (is_array($param[
'options']))
1131 $param_list = array_keys($param[
'options']);
1132 $InfoFieldList = explode(
":", $param_list[0]);
1142 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1145 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4]))
1147 if (strpos($InfoFieldList[4],
'extra.') !==
false)
1149 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1151 $keyList = $InfoFieldList[2].
' as rowid';
1154 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3]))
1156 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1157 $keyList .=
', '.$parentField;
1160 $filter_categorie =
false;
1161 if (count($InfoFieldList) > 5) {
1162 if ($InfoFieldList[0] ==
'categorie') {
1163 $filter_categorie =
true;
1167 if ($filter_categorie ===
false) {
1168 $fields_label = explode(
'|', $InfoFieldList[1]);
1169 if (is_array($fields_label)) {
1171 $keyList .= implode(
', ', $fields_label);
1175 $sql =
'SELECT '.$keyList;
1176 $sql .=
' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
1177 if (!empty($InfoFieldList[4])) {
1179 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1180 $InfoFieldList[4] = str_replace(
'$ENTITY$', $conf->entity, $InfoFieldList[4]);
1183 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1184 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1188 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1189 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1191 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1194 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1195 $sql .=
' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].
'_extrafields as extra';
1196 $sqlwhere .=
' WHERE extra.fk_object=main.'.$InfoFieldList[2].
' AND '.$InfoFieldList[4];
1198 $sqlwhere .=
' WHERE '.$InfoFieldList[4];
1201 $sqlwhere .=
' WHERE 1=1';
1204 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1205 $sqlwhere .=
' AND entity = '.$conf->entity;
1210 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1212 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1215 $out .=
'<option value="0"> </option>';
1216 $num = $this->
db->num_rows(
$resql);
1220 $obj = $this->
db->fetch_object(
$resql);
1224 $fields_label = explode(
'|', $InfoFieldList[1]);
1225 if (is_array($fields_label) && count($fields_label) > 1) {
1227 foreach ($fields_label as $field_toshow) {
1228 $labeltoshow .= $obj->$field_toshow.
' ';
1231 $labeltoshow = $obj->{$InfoFieldList[1]};
1233 $labeltoshow = $labeltoshow;
1235 if ($value == $obj->rowid) {
1237 foreach ($fields_label as $field_toshow) {
1238 $translabel = $langs->trans($obj->$field_toshow);
1239 $labeltoshow = $translabel.
' ';
1242 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1245 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1246 $labeltoshow = $translabel;
1248 if (empty($labeltoshow)) $labeltoshow =
'(not defined)';
1250 if (!empty($InfoFieldList[3]) && $parentField) {
1251 $parent = $parentName.
':'.$obj->{$parentField};
1254 $out .=
'<option value="'.$obj->rowid.
'"';
1255 $out .= ($value == $obj->rowid ?
' selected' :
'');
1256 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1257 $out .=
'>'.$labeltoshow.
'</option>';
1264 print 'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1267 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1268 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1269 $out .=
'<option value="0"> </option>';
1270 foreach ($data as $data_key => $data_value) {
1271 $out .=
'<option value="'.$data_key.
'"';
1272 $out .= ($value == $data_key ?
' selected' :
'');
1273 $out .=
'>'.$data_value.
'</option>';
1277 $out .=
'</select>';
1278 } elseif ($type ==
'checkbox')
1280 $value_arr = explode(
',', $value);
1281 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?null:$param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1282 } elseif ($type ==
'radio')
1285 foreach ($param[
'options'] as $keyopt => $val)
1287 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1288 $out .=
' value="'.$keyopt.
'"';
1289 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1290 $out .= ($value == $keyopt ?
'checked' :
'');
1291 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$val.
'</label><br>';
1293 } elseif ($type ==
'chkbxlst')
1295 if (is_array($value)) {
1296 $value_arr = $value;
1298 $value_arr = explode(
',', $value);
1301 if (is_array($param[
'options'])) {
1302 $param_list = array_keys($param[
'options']);
1303 $InfoFieldList = explode(
":", $param_list[0]);
1313 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1315 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1316 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1317 $keyList .=
', '.$parentField;
1319 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1320 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1321 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1323 $keyList = $InfoFieldList[2].
' as rowid';
1327 $filter_categorie =
false;
1328 if (count($InfoFieldList) > 5) {
1329 if ($InfoFieldList[0] ==
'categorie') {
1330 $filter_categorie =
true;
1334 if ($filter_categorie ===
false) {
1335 $fields_label = explode(
'|', $InfoFieldList[1]);
1336 if (is_array($fields_label)) {
1338 $keyList .= implode(
', ', $fields_label);
1342 $sql =
'SELECT '.$keyList;
1343 $sql .=
' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
1344 if (!empty($InfoFieldList[4])) {
1346 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1347 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1351 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1352 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
1353 } elseif (preg_match(
"#^.*list.php$#",
$_SERVER[
"PHP_SELF"])) {
1355 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1358 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1362 while ($nbPreg != 0) {
1364 $nbPregRepl = $nbPregSel = 0;
1366 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1368 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1370 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1372 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1375 $nbPreg = $nbPregRepl + $nbPregSel;
1379 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1380 while (!empty($matchCondition[0])) {
1382 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1384 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1386 if (!empty($matchCondition[1])) {
1387 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1388 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1389 } elseif (!empty($matchCondition[3])) {
1390 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1391 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1393 $InfoFieldList[4] =
" TRUE ";
1398 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1401 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1405 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1406 $sql .=
' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].
'_extrafields as extra';
1407 $sqlwhere .=
' WHERE extra.fk_object=main.'.$InfoFieldList[2].
' AND '.$InfoFieldList[4];
1409 $sqlwhere .=
' WHERE '.$InfoFieldList[4];
1412 $sqlwhere .=
' WHERE 1=1';
1415 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1416 $sqlwhere .=
' AND entity = '.$conf->entity;
1422 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1425 $num = $this->
db->num_rows(
$resql);
1432 $obj = $this->
db->fetch_object(
$resql);
1436 $fields_label = explode(
'|', $InfoFieldList[1]);
1437 if (is_array($fields_label)) {
1439 foreach ($fields_label as $field_toshow) {
1440 $labeltoshow .= $obj->$field_toshow.
' ';
1443 $labeltoshow = $obj->{$InfoFieldList[1]};
1445 $labeltoshow =
dol_trunc($labeltoshow, 45);
1447 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1448 foreach ($fields_label as $field_toshow) {
1449 $translabel = $langs->trans($obj->$field_toshow);
1450 if ($translabel != $obj->$field_toshow) {
1451 $labeltoshow =
dol_trunc($translabel, 18).
' ';
1453 $labeltoshow =
dol_trunc($obj->$field_toshow, 18).
' ';
1457 $data[$obj->rowid] = $labeltoshow;
1460 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1461 if ($translabel != $obj->{$InfoFieldList[1]}) {
1462 $labeltoshow =
dol_trunc($translabel, 18);
1464 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1467 if (empty($labeltoshow))
1468 $labeltoshow =
'(not defined)';
1470 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1471 $data[$obj->rowid] = $labeltoshow;
1474 if (!empty($InfoFieldList[3]) && $parentField) {
1475 $parent = $parentName.
':'.$obj->{$parentField};
1478 $data[$obj->rowid] = $labeltoshow;
1485 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1487 print 'Error in request '.$sql.
' '.$this->
db->lasterror().
'. Check setup of extra parameters.<br>';
1490 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1491 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1492 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1495 } elseif ($type ==
'link')
1497 $param_list = array_keys($param[
'options']);
1498 $showempty = (($required && $default !=
'') ? 0 : 1);
1499 $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss);
1500 } elseif ($type ==
'password')
1503 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1504 $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 :
'').
'>';
1506 if (!empty($hidden)) {
1507 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1529 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'')
1531 global $conf, $langs;
1533 if (!empty($extrafieldsobjectkey))
1535 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1536 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1537 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1538 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1539 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1540 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1541 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1542 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1543 $perms =
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1);
1544 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1545 $list =
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1);
1546 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1547 $hidden = (empty($list) ? 1 : 0);
1551 $label = $this->attribute_label[$key];
1552 $type = $this->attribute_type[$key];
1553 $size = $this->attribute_size[$key];
1554 $default = $this->attribute_default[$key];
1555 $computed = $this->attribute_computed[$key];
1556 $unique = $this->attribute_unique[$key];
1557 $required = $this->attribute_required[$key];
1558 $param = $this->attribute_param[$key];
1559 $perms =
dol_eval($this->attribute_perms[$key], 1);
1560 $langfile = $this->attribute_langfile[$key];
1561 $list =
dol_eval($this->attribute_list[$key], 1);
1563 $hidden = (empty($list) ? 1 : 0);
1566 if ($hidden)
return '';
1571 if ($type ==
'date')
1575 } elseif ($type ==
'datetime')
1579 } elseif ($type ==
'int')
1582 } elseif ($type ==
'double')
1584 if (!empty($value)) {
1586 $sizeparts = explode(
",", $size);
1587 $number_decimals = $sizeparts[1];
1588 $value =
price($value, 0, $langs, 0, 0, $number_decimals,
'');
1590 } elseif ($type ==
'boolean')
1593 if (!empty($value)) {
1594 $checked =
' checked ';
1596 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1597 } elseif ($type ==
'mail')
1600 } elseif ($type ==
'url')
1603 } elseif ($type ==
'phone')
1606 } elseif ($type ==
'price')
1609 if ($value || $value ==
'0') $value =
price($value, 0, $langs, 0, 0, -1);
1610 } elseif ($type ==
'select') {
1611 $valstr = $param[
'options'][$value];
1612 if (($pos = strpos($valstr,
"|")) !==
false)
1614 $valstr = substr($valstr, 0, $pos);
1616 if ($langfile && $valstr) $value = $langs->trans($valstr);
1617 else $value = $valstr;
1618 } elseif ($type ==
'sellist') {
1619 $param_list = array_keys($param[
'options']);
1620 $InfoFieldList = explode(
":", $param_list[0]);
1622 $selectkey =
"rowid";
1625 if (count($InfoFieldList) >= 3)
1627 $selectkey = $InfoFieldList[2];
1628 $keyList = $InfoFieldList[2].
' as rowid';
1631 $fields_label = explode(
'|', $InfoFieldList[1]);
1632 if (is_array($fields_label)) {
1634 $keyList .= implode(
', ', $fields_label);
1637 $filter_categorie =
false;
1638 if (count($InfoFieldList) > 5) {
1639 if ($InfoFieldList[0] ==
'categorie') {
1640 $filter_categorie =
true;
1644 $sql =
'SELECT '.$keyList;
1645 $sql .=
' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
1646 if (strpos($InfoFieldList[4],
'extra') !==
false)
1650 if ($selectkey ==
'rowid' && empty($value)) {
1651 $sql .=
" WHERE ".$selectkey.
"=0";
1652 } elseif ($selectkey ==
'rowid') {
1653 $sql .=
" WHERE ".$selectkey.
"=".$this->
db->escape($value);
1655 $sql .=
" WHERE ".$selectkey.
"='".$this->
db->escape($value).
"'";
1660 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
1664 if ($filter_categorie ===
false) {
1667 $obj = $this->
db->fetch_object(
$resql);
1670 $fields_label = explode(
'|', $InfoFieldList[1]);
1672 if (is_array($fields_label) && count($fields_label) > 1) {
1673 foreach ($fields_label as $field_toshow) {
1675 if (!empty($obj->$field_toshow)) {
1676 $translabel = $langs->trans($obj->$field_toshow);
1678 if ($translabel != $field_toshow) {
1679 $value .=
dol_trunc($translabel, 18).
' ';
1681 $value .= $obj->$field_toshow.
' ';
1686 if (!empty($obj->{$InfoFieldList[1]})) {
1687 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1689 if ($translabel != $obj->{$InfoFieldList[1]}) {
1692 $value = $obj->{$InfoFieldList[1]};
1696 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1699 $obj = $this->
db->fetch_object(
$resql);
1701 $c->fetch($obj->rowid);
1702 $ways = $c->print_all_ways();
1703 foreach ($ways as $way) {
1704 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1706 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1708 }
else dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1709 } elseif ($type ==
'radio')
1711 $value = $param[
'options'][$value];
1712 } elseif ($type ==
'checkbox')
1714 $value_arr = explode(
',', $value);
1717 if (is_array($value_arr))
1719 foreach ($value_arr as $keyval=>$valueval) {
1720 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
1723 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1724 } elseif ($type ==
'chkbxlst')
1726 $value_arr = explode(
',', $value);
1728 $param_list = array_keys($param[
'options']);
1729 $InfoFieldList = explode(
":", $param_list[0]);
1731 $selectkey =
"rowid";
1734 if (count($InfoFieldList) >= 3) {
1735 $selectkey = $InfoFieldList[2];
1736 $keyList = $InfoFieldList[2].
' as rowid';
1739 $fields_label = explode(
'|', $InfoFieldList[1]);
1740 if (is_array($fields_label)) {
1742 $keyList .= implode(
', ', $fields_label);
1745 $filter_categorie =
false;
1746 if (count($InfoFieldList) > 5) {
1747 if ($InfoFieldList[0] ==
'categorie') {
1748 $filter_categorie =
true;
1752 $sql =
'SELECT '.$keyList;
1753 $sql .=
' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
1754 if (strpos($InfoFieldList[4],
'extra') !==
false) {
1760 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
1763 if ($filter_categorie ===
false) {
1766 while ($obj = $this->
db->fetch_object(
$resql)) {
1768 $fields_label = explode(
'|', $InfoFieldList[1]);
1769 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1770 if (is_array($fields_label) && count($fields_label) > 1) {
1771 foreach ($fields_label as $field_toshow) {
1773 if (!empty($obj->$field_toshow)) {
1774 $translabel = $langs->trans($obj->$field_toshow);
1776 if ($translabel != $field_toshow) {
1777 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1779 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->$field_toshow.
'</li>';
1784 if (!empty($obj->{$InfoFieldList[1]})) {
1785 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1787 if ($translabel != $obj->{$InfoFieldList[1]}) {
1788 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
1790 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
1796 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1799 while ($obj = $this->
db->fetch_object(
$resql)) {
1800 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1802 $c->fetch($obj->rowid);
1803 $ways = $c->print_all_ways();
1804 foreach ($ways as $way) {
1805 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
1810 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
1812 dol_syslog(get_class($this).
'::showOutputField error '.$this->
db->lasterror(), LOG_WARNING);
1814 } elseif ($type ==
'link')
1821 $param_list = array_keys($param[
'options']);
1823 $InfoFieldList = explode(
":", $param_list[0]);
1824 $classname = $InfoFieldList[0];
1825 $classpath = $InfoFieldList[1];
1826 if (!empty($classpath))
1829 if ($classname && class_exists($classname))
1831 $object =
new $classname($this->
db);
1832 $object->fetch($value);
1833 $value = $object->getNomUrl(3);
1836 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
1837 return 'Error bad setup of extrafield';
1840 } elseif ($type ==
'text')
1843 } elseif ($type ==
'html')
1846 } elseif ($type ==
'password')
1848 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
1850 $showsize = round($size);
1851 if ($showsize > 48) $showsize = 48;
1869 global $conf, $langs;
1871 if (!empty($extrafieldsobjectkey)) $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1872 else $type = $this->attribute_type[$key];
1876 if ($type ==
'date')
1879 } elseif ($type ==
'datetime')
1882 } elseif ($type ==
'int')
1885 } elseif ($type ==
'price')
1888 } elseif ($type ==
'double')
1891 } elseif ($type ==
'boolean')
1894 } elseif ($type ==
'radio')
1897 } elseif ($type ==
'checkbox')
1900 } elseif ($type ==
'price')
1920 $out =
'<tr id="trextrafieldseparator'.$key.
'" class="trextrafieldseparator trextrafieldseparator'.$key.
'"><td colspan="'.$colspan.
'"><strong>';
1921 $out .= $langs->trans($this->attributes[$object->table_element][
'label'][$key]);
1922 $out .=
'</strong></td></tr>';
1924 $extrafield_param = $this->attributes[$object->table_element][
'param'][$key];
1925 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1926 $extrafield_param_list = array_keys($extrafield_param[
'options']);
1928 if (count($extrafield_param_list) > 0) {
1929 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1930 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
1932 $collapse_display = ((isset($_COOKIE[
'DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key]) ||
GETPOST(
'ignorecollapsesetup',
'int')) ? ($_COOKIE[
'DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key] ?
true :
false) : ($extrafield_collapse_display_value == 2 ?
false :
true));
1933 $extrafields_collapse_num = $this->attributes[$object->table_element][
'pos'][$key];
1935 $out .=
'<!-- Add js script to manage the collpase/uncollapse of extrafields separators '.$key.
' -->';
1936 $out .=
'<script type="text/javascript">';
1937 $out .=
'jQuery(document).ready(function(){';
1938 if ($collapse_display ===
false) {
1939 $out .=
' jQuery("#trextrafieldseparator'.$key.
' td").prepend("<span class=\"cursorpointer far fa-plus-square\"></span> ");'.
"\n";
1940 $out .=
' jQuery(".trextrafields_collapse'.$extrafields_collapse_num.
'").hide();'.
"\n";
1942 $out .=
' jQuery("#trextrafieldseparator'.$key.
' td").prepend("<span class=\"cursorpointer far fa-minus-square\"></span> ");'.
"\n";
1943 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.
$_SERVER[
"PHP_SELF"].
'"'.
"\n";
1945 $out .=
' jQuery("#trextrafieldseparator'.$key.
'").click(function(){'.
"\n";
1946 $out .=
' jQuery(".trextrafields_collapse'.$extrafields_collapse_num.
'").toggle(300, function(){'.
"\n";
1947 $out .=
' if (jQuery(".trextrafields_collapse'.$extrafields_collapse_num.
'").is(":hidden")) {'.
"\n";
1948 $out .=
' jQuery("#trextrafieldseparator'.$key.
' td span").addClass("fa-plus-square").removeClass("fa-minus-square");'.
"\n";
1949 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=0; path='.
$_SERVER[
"PHP_SELF"].
'"'.
"\n";
1950 $out .=
' } else {'.
"\n";
1951 $out .=
' jQuery("#trextrafieldseparator'.$key.
' td span").addClass("fa-minus-square").removeClass("fa-plus-square");'.
"\n";
1952 $out .=
' document.cookie = "DOLCOLLAPSE_'.$object->table_element.
'_extrafields_'.$key.
'=1; path='.
$_SERVER[
"PHP_SELF"].
'"'.
"\n";
1957 $out .=
'</script>';
1977 global $_POST, $langs;
1979 $nofillrequired = 0;
1980 $error_field_required = array();
1982 if (is_array($this->attributes[$object->table_element][
'label'])) $extralabels = $this->attributes[$object->table_element][
'label'];
1984 if (is_array($extralabels))
1987 foreach ($extralabels as $key => $value)
1989 if (!empty($onlykey) && $onlykey !=
'@GETPOSTISSET' && $key != $onlykey)
continue;
1990 if (!empty($onlykey) && $onlykey ==
'@GETPOSTISSET' && !
GETPOSTISSET(
'options_'.$key))
continue;
1992 $key_type = $this->attributes[$object->table_element][
'type'][$key];
1993 if ($key_type ==
'separate')
continue;
1996 if (isset($this->attributes[$object->table_element][
'list'][$key]))
1998 $enabled =
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1);
2001 if (isset($this->attributes[$object->table_element][
'perms'][$key]))
2003 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1);
2005 if (empty($enabled))
continue;
2006 if (empty($perms))
continue;
2008 if ($this->attributes[$object->table_element][
'required'][$key])
2013 if ((!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] !=
'select' && $_POST[
"options_".$key] !=
'0')
2014 || (!is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'select')
2015 || (!is_array($_POST[
"options_".$key]) && isset($_POST[
"options_".$key]) && $this->attributes[$object->table_element][
'type'][$key] ==
'sellist' && $_POST[
'options_'.$key] ==
'0')
2016 || (is_array($_POST[
"options_".$key]) && empty($_POST[
"options_".$key])))
2020 $error_field_required[] = $langs->transnoentitiesnoconv($value);
2024 if (in_array($key_type, array(
'date'))) {
2026 $value_key =
dol_mktime(12, 0, 0,
GETPOST(
"options_".$key.
"month",
'int'),
GETPOST(
"options_".$key.
"day",
'int'),
GETPOST(
"options_".$key.
"year",
'int'));
2027 } elseif (in_array($key_type, array(
'datetime'))) {
2029 $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');
2030 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2031 $value_arr =
GETPOST(
"options_".$key,
'array');
2032 if (!empty($value_arr)) {
2033 $value_key = implode($value_arr,
',');
2037 } elseif (in_array($key_type, array(
'price',
'double'))) {
2038 $value_arr =
GETPOST(
"options_".$key,
'alpha');
2040 } elseif (in_array($key_type, array(
'html'))) {
2041 $value_key =
GETPOST(
"options_".$key,
'restricthtml');
2042 } elseif (in_array($key_type, array(
'text'))) {
2043 $value_key =
GETPOST(
"options_".$key,
'alphanohtml');
2045 $value_key =
GETPOST(
"options_".$key);
2046 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') $value_key =
'';
2049 $object->array_options[
"options_".$key] = $value_key;
2052 if ($nofillrequired) {
2053 $langs->load(
'errors');
2054 setEventMessages($langs->trans(
'ErrorFieldsRequired').
' : '.implode(
', ', $error_field_required), null,
'errors');
2076 if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey][
'label']))
2078 $extralabels = $this->attributes[$extrafieldsobjectkey][
'label'];
2080 $extralabels = $extrafieldsobjectkey;
2083 if (is_array($extralabels))
2085 $array_options = array();
2088 foreach ($extralabels as $key => $value)
2091 if (is_string($extrafieldsobjectkey))
2093 $key_type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2096 if (in_array($key_type, array(
'date'))) {
2097 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year"))
continue;
2099 $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'));
2100 } elseif (in_array($key_type, array(
'datetime'))) {
2101 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix.
"year"))
continue;
2103 $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');
2104 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
2105 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix))
continue;
2106 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2108 $value_arr = (array) $value_arr;
2109 $value_key = implode(
',', $value_arr);
2110 } elseif (in_array($key_type, array(
'price',
'double',
'int')))
2112 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix))
continue;
2113 $value_arr =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2116 if (!
GETPOSTISSET($keysuffix.
"options_".$key.$keyprefix))
continue;
2117 $value_key =
GETPOST($keysuffix.
"options_".$key.$keyprefix);
2120 $array_options[$keysuffix.
"options_".$key] = $value_key;
2123 return $array_options;
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
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_url($url, $target= '_blank', $max=32, $withpicto=0)
Show Url link.
dol_now($mode= 'auto')
Return date for now.
dol_print_phone($phone, $countrycode= '', $cid=0, $socid=0, $addlink= '', $separ=" ", $withpicto= '', $titlealt= '', $adddivfloat=0)
Format phone numbers according to country.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
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...
$conf db
API class for accounts.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage categories.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
Class to manage a WYSIWYG editor.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...