dolibarr 25.0.0-alpha
fieldsmanager.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
7 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro>
9 * Copyright (C) 2015 Charles-Fr BENKE <charles.fr@benke.fr>
10 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
11 * Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com>
12 * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
13 * Copyright (C) 2022 Antonin MARCHAL <antonin@letempledujeu.fr>
14 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36require_once DOL_DOCUMENT_ROOT . '/core/class/fieldinfos.class.php';
37require_once DOL_DOCUMENT_ROOT . '/core/class/fields/commonfield.class.php';
38
39
44{
48 public $db;
49
53 public $error = '';
54
58 public $errors = array();
59
63 public $validateFieldsErrors = array();
64
68 public $fieldsPath = '/core/class/fields/';
69
73 public static $fieldClasses = array();
74
78 public static $fieldInfos = array();
79
83 public $expand_display = array();
84
86 // * @var array<string,string> Array of type to label
87 // */
88 //public static $type2label = array(
89 // 'varchar' => 'String1Line',
90 // 'text' => 'TextLongNLines',
91 // 'html' => 'HtmlText',
92 // 'int' => 'Int',
93 // 'double' => 'Float',
94 // 'date' => 'Date',
95 // 'datetime' => 'DateAndTime',
96 // 'duration' => 'Duration',
97 // //'datetimegmt'=>'DateAndTimeUTC',
98 // 'boolean' => 'Boolean',
99 // 'price' => 'ExtrafieldPrice',
100 // 'pricecy' => 'ExtrafieldPriceWithCurrency',
101 // 'phone' => 'ExtrafieldPhone',
102 // 'email' => 'ExtrafieldMail',
103 // 'url' => 'ExtrafieldUrl',
104 // 'ip' => 'ExtrafieldIP',
105 // 'icon' => 'Icon',
106 // 'password' => 'ExtrafieldPassword',
107 // 'radio' => 'ExtrafieldRadio',
108 // 'select' => 'ExtrafieldSelect',
109 // 'sellist' => 'ExtrafieldSelectList',
110 // 'checkbox' => 'ExtrafieldCheckBox',
111 // 'chkbxlst' => 'ExtrafieldCheckBoxFromList',
112 // 'link' => 'ExtrafieldLink',
113 // 'point' => 'ExtrafieldPointGeo',
114 // 'multipts' => 'ExtrafieldMultiPointGeo',
115 // 'linestrg' => 'ExtrafieldLinestringGeo',
116 // 'polygon' => 'ExtrafieldPolygonGeo',
117 // 'separate' => 'ExtrafieldSeparator',
118 // 'stars' => 'ExtrafieldStars',
119 // //'real' => 'ExtrafieldReal',
120 //);
121
122
129 public function __construct($db, $form = null)
130 {
131 $this->db = $db;
132 $this->error = '';
133 $this->errors = array();
134
135 if (isset($form)) {
137 }
138 }
139
146 public function getFieldClass($type)
147 {
148 global $hookmanager, $langs;
149
150 $type = trim($type);
151
152 if (!isset(self::$fieldClasses[$type])) {
153 $field = null;
154 $parameters = array(
155 'type' => $type,
156 // @phan-suppress-next-line PhanPluginConstantVariableNull
157 'field' => &$field,
158 );
159
160 $hookmanager->executeHooks('getFieldClass', $parameters, $this); // Note that $object may have been modified by hook
161 // @phpstan-ignore-next-line @phan-suppress-next-line PhanPluginConstantVariableNull
162 if (isset($field) && is_object($field)) {
163 self::$fieldClasses[$type] = $field;
164 } else {
165 $filename = strtolower($type) . 'field.class.php';
166 $classname = ucfirst($type) . 'Field';
167
168 // Load class file
169 dol_include_once(rtrim($this->fieldsPath, '/') . '/' . $filename);
170 if (!class_exists($classname)) {
171 @include_once DOL_DOCUMENT_ROOT . '/core/class/fields/' . $filename;
172 }
173
174 if (class_exists($classname)) {
175 self::$fieldClasses[$type] = new $classname($this->db);
176 } else {
177 $langs->load("errors");
178 $this->errors[] = $langs->trans('ErrorFieldClassNotFoundForClassName', $classname, $type);
179 return null;
180 }
181 }
182 }
183
184 $field = self::$fieldClasses[$type];
185 $field->clearErrors();
186
187 return $field;
188 }
189
195 public function getAllFields()
196 {
197 // Todo to make
198 return self::$fieldClasses;
199 }
200
206 public function clearErrors()
207 {
208 $this->error = '';
209 $this->errors = array();
210 }
211
218 public function errorsToString($separator = ', ')
219 {
220 return $this->error . (is_array($this->errors) ? (!empty($this->error) ? $separator : '') . implode($separator, $this->errors) : '');
221 }
222
229 public function clearFieldError($fieldKey)
230 {
231 $this->error = '';
232 unset($this->validateFieldsErrors[$fieldKey]);
233 }
234
242 public function setFieldError($fieldKey, $msg = '')
243 {
244 global $langs;
245 if (empty($msg)) {
246 $msg = $langs->trans("UnknownError");
247 }
248
249 $this->error = $this->validateFieldsErrors[$fieldKey] = $msg;
250 }
251
258 public function getFieldError($fieldKey)
259 {
260 if (!empty($this->validateFieldsErrors[$fieldKey])) {
261 return $this->validateFieldsErrors[$fieldKey];
262 }
263 return '';
264 }
265
272 public function getFieldErrorIcon($fieldValidationErrorMsg)
273 {
274 $out = '';
275
276 if (!empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) {
277 $out .= ' ' . getFieldErrorIcon($fieldValidationErrorMsg);
278 }
279
280 return $out;
281 }
282
294 public function getAllFieldsInfos(&$object, &$extrafields = null, $mode = 'view', $nbColumn = 2, $breakKeys = array(), $params = array())
295 {
296 global $hookmanager, $langs;
297
298 // Get object fields
299 $fields = $this->getAllObjectFieldsInfos($object, $mode, $params);
300
301 // Old sort
302 if (!getDolGlobalInt('MAIN_FIELDS_SORT_WITH_EXTRA_FIELDS')) {
303 $fields = dol_sort_array($fields, 'position');
304 }
305
306 // Get extra fields
307 $fields2 = $this->getAllExtraFieldsInfos($object, $extrafields, $mode, $params);
308 $fields = array_merge($fields, $fields2);
309
310 // New sort
311 if (getDolGlobalInt('MAIN_FIELDS_SORT_WITH_EXTRA_FIELDS')) {
312 $fields = dol_sort_array($fields, 'position');
313 }
314
315 // Split in columns
316 $idxColumn = 1;
317 $columns = array();
318 $hiddenFields = array();
319 $columns[$idxColumn] = array();
320 $nbVisibleFields = 0;
321 foreach ($fields as $field) {
322 if ($field->visible) {
323 $nbVisibleFields++;
324 }
325 }
326 $nbFieldsByColumn = ceil($nbVisibleFields / $nbColumn);
327 $breakKey = $breakKeys[$idxColumn] ?? '';
328 $idxField = 0;
329 foreach ($fields as $key => $field) {
330 if ($idxColumn < $nbColumn && ((!empty($breakKey) && $key == $breakKey) || (empty($breakKey) && $idxField == $nbFieldsByColumn))) {
331 $idxColumn++;
332 $idxField = 0;
333 $columns[$idxColumn] = array();
334 }
335
336 if ($field->visible) {
337 if ($field->type != 'separate') {
338 $idxField++;
339 }
340
341 // Add field into column
342 $columns[$idxColumn][$key] = $field;
343 } else {
344 $hiddenFields[$key] = $field;
345 }
346 }
347
348 // Add column not created
349 for ($idxColumn = 1; $idxColumn <= $nbColumn; $idxColumn++) {
350 if (!isset($columns[$idxColumn])) {
351 $columns[$idxColumn] = array();
352 }
353 }
354
355 $parameters = array(
356 'object' => &$object,
357 'extrafields' => &$extrafields,
358 'mode' => $mode,
359 'nbColumn' => $nbColumn,
360 'breakKeys' => $breakKeys,
361 'params' => $params,
362 'columns' => &$columns,
363 'hiddenFields' => &$hiddenFields,
364 );
365
366 $hookmanager->executeHooks('getFieldInfosFromObjectField', $parameters, $this); // Note that $object may have been modified by hook
367
368 return array(
369 'columns' => $columns,
370 'hiddenFields' => $hiddenFields,
371 );
372 }
373
382 public function getAllObjectFieldsInfos(&$object, $mode = 'view', $params = array())
383 {
384 global $hookmanager;
385
386 // Get object fields
387 $fields = array();
388 // @phpstan-ignore-next-line
389 if (isset($object->fields) && is_array($object->fields)) {
390 $keyPrefix = getDolGlobalInt('MAIN_FIELDS_NEW_OBJECT_KEY_PREFIX') ? 'object_' : '';
391 foreach ($object->fields as $key => $field) {
392 $fieldInfos = $this->getFieldInfosFromObjectField($object, $key, $mode, $params);
393 $fields[$keyPrefix . $key] = $fieldInfos;
394 }
395 }
396
397 $parameters = array(
398 'object' => &$object,
399 'mode' => $mode,
400 'params' => $params,
401 'fields' => &$fields,
402 );
403
404 $hookmanager->executeHooks('getAllObjectFieldsInfos', $parameters, $this); // Note that $object may have been modified by hook
405
406 return $fields;
407 }
408
418 public function getAllExtraFieldsInfos(&$object, &$extrafields = null, $mode = 'view', $params = array())
419 {
420 global $hookmanager;
421
422 // Get extra fields
423 $fields = array();
424 if (isset($extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element])) {
425 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
426 $keyPrefix = 'options_';
427 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
428 $fieldInfos = $this->getFieldInfosFromExtraField($object, $extrafields, $key, $mode, $params);
429 $fields[$keyPrefix . $key] = $fieldInfos;
430 }
431 }
432 }
433
434 $parameters = array(
435 'object' => &$object,
436 'extrafields' => &$extrafields,
437 'mode' => $mode,
438 'params' => $params,
439 'fields' => &$fields,
440 );
441
442 $hookmanager->executeHooks('getAllExtraFieldsInfos', $parameters, $this); // Note that $object may have been modified by hook
443
444 return $fields;
445 }
446
457 public function getFieldsInfos($key, &$object, &$extrafields = null, $mode = 'view', $params = array())
458 {
459 $fieldInfos = null;
460
461 $patternObjectPrefix = getDolGlobalInt('MAIN_FIELDS_NEW_OBJECT_KEY_PREFIX') ? 'object_' : '';
462 $matches = array();
463 if (preg_match('/^options_(.*)/i', $key, $matches)) {
464 $fieldKey = $matches[1];
465 $fieldInfos = $this->getFieldInfosFromExtraField($object, $extrafields, $fieldKey, $mode, $params);
466 } elseif (preg_match('/^' . $patternObjectPrefix . '(.*)/i', $key, $matches)) {
467 $fieldKey = $matches[2];
468 $fieldInfos = $this->getFieldInfosFromObjectField($object, $fieldKey, $mode, $params);
469 }
470
471 return $fieldInfos;
472 }
473
483 public function getFieldInfosFromObjectField(&$object, $key, $mode = 'view', $params = array())
484 {
485 global $hookmanager;
486
487 if (!isset($object->fields[$key])) {
488 return null;
489 }
490
491 if (isset(self::$fieldInfos[$object->element][$mode]['object'][$key])) {
492 return self::$fieldInfos[$object->element][$mode]['object'][$key];
493 }
494
495 $attributes = $object->fields[$key];
496
497 $fieldInfos = new FieldInfos();
498 $fieldInfos->fieldType = FieldInfos::FIELD_TYPE_OBJECT;
499 $fieldInfos->originType = $attributes['type'] ?? '';
500 $fieldInfos->size = $attributes['length'] ?? '';
501 $fieldInfos->label = $attributes['label'] ?? '';
502 $fieldInfos->langFile = $attributes['langfile'] ?? '';
503 $fieldInfos->sqlAlias = $attributes['alias'] ?? null; // @phan-suppress-current-line SqlInjection
504 $fieldInfos->picto = $attributes['picto'] ?? '';
505 $fieldInfos->position = $attributes['position'] ?? 0;
506 $fieldInfos->required = ($attributes['notnull'] ?? 0) > 0;
507 $fieldInfos->alwaysEditable = !empty($attributes['alwayseditable']);
508 $fieldInfos->defaultValue = $attributes['default'] ?? '';
509 $fieldInfos->css = $attributes['css'] ?? '';
510 $fieldInfos->viewCss = $attributes['cssview'] ?? '';
511 $fieldInfos->listCss = $attributes['csslist'] ?? '';
512 $fieldInfos->inputPlaceholder = $attributes['placeholder'] ?? '';
513 $fieldInfos->help = $attributes['help'] ?? '';
514 $fieldInfos->listHelp = $attributes['helplist'] ?? '';
515 $fieldInfos->showOnComboBox = !empty($attributes['showoncombobox']);
516 $fieldInfos->inputDisabled = !empty($attributes['disabled']);
517 $fieldInfos->inputAutofocus = !empty($attributes['autofocusoncreate']) && $mode == 'create';
518 $fieldInfos->comment = $attributes['comment'] ?? '';
519 $fieldInfos->listTotalizable = !empty($attributes['isameasure']) && $attributes['isameasure'] == 1;
520 $fieldInfos->validateField = !empty($attributes['validate']);
521 $fieldInfos->copyToClipboard = $attributes['copytoclipboard'] ?? 0;
522 $fieldInfos->tdCss = $attributes['tdcss'] ?? '';
523 $fieldInfos->multiInput = !empty($attributes['multiinput']);
524 $fieldInfos->nameInClass = $attributes['nameinclass'] ?? $key;
525 $fieldInfos->nameInTable = $attributes['nameintable'] ?? $key;
526 $fieldInfos->getNameUrlParams = $attributes['get_name_url_params'] ?? null;
527 $fieldInfos->showOnHeader = !empty($attributes['showonheader']);
528
529 // TODO set nameinclass = "id" in fields "rowid"
530 if ($fieldInfos->nameInClass == 'rowid') {
531 $fieldInfos->nameInClass = 'id';
532 }
533
534 $enabled = $attributes['enabled'] ?? '1';
535 $visibility = $attributes['visible'] ?? '1';
536 $perms = empty($attributes['noteditable']) ? '1' : '0';
537
538 $this->setCommonFieldInfos($fieldInfos, $object, $extrafields, $key, $mode, $enabled, $visibility, $perms, $params);
539
540 // Special case that force options and type ($type can be integer, varchar, ...)
541 if (!empty($attributes['arrayofkeyval']) && is_array($attributes['arrayofkeyval'])) {
542 $fieldInfos->options = $attributes['arrayofkeyval'];
543 // Special case that prevent to force $type to have multiple input @phan-suppress-next-line PhanTypeMismatchProperty
544 if (!$fieldInfos->multiInput) {
545 $fieldInfos->type = (($fieldInfos->type == 'checkbox') ? $fieldInfos->type : 'select');
546 }
547 }
548
549 $parameters = array(
550 'object' => &$object,
551 'key' => $key,
552 'mode' => $mode,
553 'fieldInfos' => &$fieldInfos,
554 );
555
556 $hookmanager->executeHooks('getFieldInfosFromObjectField', $parameters, $this); // Note that $object may have been modified by hook
557
558 self::$fieldInfos[$object->element][$mode]['object'][$key] = $fieldInfos;
559 return $fieldInfos;
560 }
561
572 public function getFieldInfosFromExtraField(&$object, &$extrafields, $key, $mode = 'view', $params = array())
573 {
574 global $hookmanager;
575
576 if (!isset($extrafields->attributes[$object->table_element]['label'][$key])) {
577 return null;
578 }
579
580 if (isset(self::$fieldInfos[$object->element][$mode]['extraField'][$key])) {
581 return self::$fieldInfos[$object->element][$mode]['extraField'][$key];
582 }
583
584 $attributes = $extrafields->attributes[$object->table_element];
585
586 $fieldInfos = new FieldInfos();
587 $fieldInfos->fieldType = FieldInfos::FIELD_TYPE_EXTRA_FIELD;
588 $fieldInfos->originType = $attributes['type'][$key] ?? '';
589 $fieldInfos->label = $attributes['label'][$key] ?? '';
590 $fieldInfos->position = $attributes['pos'][$key] ?? 0;
591 $fieldInfos->required = !empty($attributes['required'][$key]);
592 $fieldInfos->defaultValue = $attributes['default'][$key] ?? '';
593 $fieldInfos->css = $attributes['css'][$key] ?? '';
594 $fieldInfos->help = $attributes['help'][$key] ?? '';
595 $fieldInfos->size = $attributes['size'][$key] ?? '';
596 $fieldInfos->computed = $attributes['computed'][$key] ?? '';
597 $fieldInfos->unique = !empty($attributes['unique'][$key]);
598 $fieldInfos->alwaysEditable = !empty($attributes['alwayseditable'][$key]);
599 $fieldInfos->emptyOnClone = !empty($attributes['emptyonclone'][$key]);
600 $fieldInfos->langFile = $attributes['langfile'][$key] ?? '';
601 $fieldInfos->printable = !empty($attributes['printable'][$key]);
602 $fieldInfos->showintooltip = !empty($attributes['showintooltip'][$key]);
603 $fieldInfos->aiPrompt = $attributes['aiprompt'][$key] ?? '';
604 $fieldInfos->viewCss = $attributes['cssview'][$key] ?? '';
605 $fieldInfos->listCss = $attributes['csslist'][$key] ?? '';
606 $fieldInfos->listTotalizable = !empty($attributes['totalizable'][$key]);
607 $fieldInfos->options = array_diff_assoc($attributes['param'][$key]['options'] ?? array(), array('' => null)); // For remove case when not defined
608 $fieldInfos->nameInClass = $key;
609 $fieldInfos->nameInTable = $key;
610
611 $enabled = $attributes['enabled'][$key] ?? '1';
612 $visibility = $attributes['list'][$key] ?? '1';
613 $perms = $attributes['perms'][$key] ?? null;
614
615 $this->setCommonFieldInfos($fieldInfos, $object, $extrafields, $key, $mode, $enabled, $visibility, $perms, $params);
616
617 $parameters = array(
618 'object' => &$object,
619 'extraFields' => &$extrafields,
620 'key' => $key,
621 'mode' => $mode,
622 'fieldInfos' => &$fieldInfos,
623 );
624
625 $hookmanager->executeHooks('getFieldInfosFromExtraField', $parameters, $this); // Note that $object may have been modified by hook
626
627 self::$fieldInfos[$object->element][$mode]['extraField'][$key] = $fieldInfos;
628 return $fieldInfos;
629 }
630
645 public function setCommonFieldInfos(&$fieldInfos, &$object, &$extrafields, $key, $mode = 'view', $enabled = '1', $visibility = '', $perms = null, $params = array())
646 {
647 global $user;
648
649 $fieldInfos->object = &$object;
650 $fieldInfos->mode = preg_replace('/[^a-z0-9_]/i', '', $mode);
651 $fieldInfos->type = $fieldInfos->originType;
652 $fieldInfos->key = $key;
653 $fieldInfos->otherParams = $params;
654
655 if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
656 $fieldInfos->options = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
657 $fieldInfos->type = 'link';
658 } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
659 $fieldInfos->options = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
660 $fieldInfos->type = 'link';
661 } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
662 $fieldInfos->options = array($reg[2] . ':' . $reg[3] . ($reg[1] == 'User' ? ':#getnomurlparam1=-1' : '') => 'N');
663 $fieldInfos->type = 'link';
664 } elseif (preg_match('/^(sellist):(.*):(.*):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
665 $fieldInfos->options = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
666 $fieldInfos->type = 'sellist';
667 } elseif (preg_match('/^(sellist):(.*):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
668 $fieldInfos->options = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
669 $fieldInfos->type = 'sellist';
670 } elseif (preg_match('/^(sellist):(.*):(.*)/i', $fieldInfos->originType, $reg)) {
671 $fieldInfos->options = array($reg[2] . ':' . $reg[3] => 'N');
672 $fieldInfos->type = 'sellist';
673 } elseif (preg_match('/^chkbxlst:(.*)/i', $fieldInfos->originType, $reg)) {
674 $fieldInfos->options = array($reg[1] => 'N');
675 $fieldInfos->type = 'chkbxlst';
676 } elseif (preg_match('/varchar\‍((\d+)\‍)/', $fieldInfos->originType, $reg)) {
677 $fieldInfos->options = array();
678 $fieldInfos->type = 'varchar';
679 $fieldInfos->size = $reg[1];
680 $fieldInfos->maxLength = (int) $reg[1];
681 } elseif (preg_match('/varchar/', $fieldInfos->originType)) {
682 $fieldInfos->options = array();
683 $fieldInfos->type = 'varchar';
684 } elseif (preg_match('/stars\‍((\d+)\‍)/', $fieldInfos->originType, $reg)) {
685 $fieldInfos->options = array();
686 $fieldInfos->type = 'stars';
687 $fieldInfos->size = $reg[1];
688 } elseif (preg_match('/integer/', $fieldInfos->originType)) {
689 $fieldInfos->type = 'int';
690 } elseif ($fieldInfos->originType == 'mail') {
691 $fieldInfos->type = 'email';
692 } elseif (preg_match('/^(text):(.*)/i', $fieldInfos->originType, $reg)) {
693 $fieldInfos->type = 'text';
694 $fieldInfos->getPostCheck = $reg[2];
695 } elseif (preg_match('/^(html):(.*)/i', $fieldInfos->originType, $reg)) {
696 $fieldInfos->type = 'html';
697 $fieldInfos->getPostCheck = $reg[2];
698 } elseif (preg_match('/^double\‍(([0-9]+,[0-9]+)\‍)/', $fieldInfos->originType, $reg)) {
699 $fieldInfos->type = 'double';
700 $fieldInfos->size = $reg[1];
701 }
702
703 // Set visibility
704 $visibility = (int) dol_eval((string) $visibility, 1, 1, '2');
705 $absVisibility = abs($visibility);
706 $enabled = (int) dol_eval((string) $enabled, 1, 1, '2');
707 $fieldInfos->visible = true;
708 if (empty($visibility) ||
709 empty($enabled) ||
710 ($mode == 'create' && !in_array($absVisibility, array(1, 3, 6))) ||
711 ($mode == 'edit' && !in_array($absVisibility, array(1, 3, 4))) ||
712 ($mode == 'view' && (!in_array($absVisibility, array(1, 3, 4, 5)) || $fieldInfos->showOnHeader)) ||
713 ($mode == 'list' && $absVisibility == 3)
714 ) {
715 $fieldInfos->visible = false;
716 }
717
718 // Set edit perms
719 if (isset($perms)) {
720 $perms = (int) dol_eval((string) $perms, 1, 1, '2');
721 } else {
722 //TODO Improve element and rights detection
723 $mappingKeyForPerm = array(
724 'fichinter' => 'ficheinter',
725 'product' => 'produit',
726 'project' => 'projet',
727 'order_supplier' => 'supplier_order',
728 'invoice_supplier' => 'supplier_invoice',
729 'shipping' => 'expedition',
730 'productlot' => 'stock',
731 'facturerec' => 'facture',
732 'mo' => 'mrp',
733 'salary' => 'salaries',
734 'member' => 'adherent',
735 );
736 $keyForPerm = $mappingKeyForPerm[$object->element] ?? $object->element;
737
738 $perms = false;
739 if (isset($user->rights->$keyForPerm)) {
740 $perms = $user->hasRight($keyForPerm, 'creer') || $user->hasRight($keyForPerm, 'create') || $user->hasRight($keyForPerm, 'write');
741 }
742 if ($object->element == 'order_supplier' && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
743 $perms = $user->hasRight('fournisseur', 'commande', 'creer');
744 } elseif ($object->element == 'invoice_supplier' && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
745 $perms = $user->hasRight('fournisseur', 'facture', 'creer');
746 } elseif ($object->element == 'delivery') {
747 $perms = $user->hasRight('expedition', 'delivery', 'creer');
748 } elseif ($object->element == 'contact') {
749 $perms = $user->hasRight('societe', 'contact', 'creer');
750 }
751 }
752 // Manage always editable of extra field
753 $isDraft = ((isset($object->statut) && $object->statut == 0) || (isset($object->status) && $object->status == 0));
754 if ($mode == 'view' && !$isDraft && !$fieldInfos->alwaysEditable) {
755 $perms = false;
756 }
757 // Case visible only in view so not editable
758 if ($mode == 'view' && $absVisibility == 5) {
759 $perms = false;
760 }
761 // Case field computed
762 if (!empty($fieldInfos->computed)) {
763 $perms = false;
764 }
765 $fieldInfos->editable = !empty($perms);
766
767 // Set list info 'checked'
768 $fieldInfos->listChecked = $mode == 'list' && $visibility > 0;
769 }
770
782 public function setFieldValuesFromPost(&$object, &$extrafields, $keyPrefix = '', $keySuffix = '', $mode = 'view', $params = array())
783 {
784 $result = $this->setObjectFieldValuesFromPost($object, $keyPrefix, $keySuffix, $mode, $params);
785 $result2 = $this->setExtraFieldValuesFromPost($object, $extrafields, $keyPrefix, $keySuffix, $mode, $params);
786
787 return $result > 0 && $result2 > 0 ? 1 : -1;
788 }
789
800 public function setObjectFieldValuesFromPost(&$object, $keyPrefix = '', $keySuffix = '', $mode = 'view', $params = array())
801 {
802 $fields = $this->getAllObjectFieldsInfos($object, $mode, $params);
803
804 $error = 0;
805 foreach ($fields as $fieldKey => $fieldInfos) {
806 $check = true;
807 $key = $fieldInfos->nameInClass ?? $fieldInfos->key;
808 if ($fieldInfos->visible) {
809 $check = $this->verifyPostFieldValue($fieldInfos, $fieldKey, $keyPrefix, $keySuffix);
810 }
811 if ($check) {
812 $object->$key = $this->getPostFieldValue($fieldInfos, $fieldKey, $object->$key, $keyPrefix, $keySuffix);
813 }
814 if (!$fieldInfos->visible) {
815 $check = $this->verifyFieldValue($fieldInfos, $fieldKey, $object->$key);
816 }
817 if (!$check) {
818 $error++;
819 }
820 }
821
822 return $error ? -1 : 1;
823 }
824
836 public function setExtraFieldValuesFromPost(&$object, &$extrafields, $keyPrefix = '', $keySuffix = '', $mode = 'view', $params = array())
837 {
838 $fields = $this->getAllExtraFieldsInfos($object, $extrafields, $mode, $params);
839
840 $error = 0;
841 foreach ($fields as $fieldKey => $fieldInfos) {
842 $check = true;
843 $key = 'options_' . ($fieldInfos->nameInClass ?? $fieldInfos->key);
844 if ($fieldInfos->visible) {
845 $check = $this->verifyPostFieldValue($fieldInfos, $fieldKey, $keyPrefix, $keySuffix);
846 }
847 if ($check) {
848 $object->array_options[$key] = $this->getPostFieldValue($fieldInfos, $fieldKey, $object->array_options[$key], $keyPrefix, $keySuffix);
849 }
850 if (!$fieldInfos->visible) {
851 $check = $this->verifyFieldValue($fieldInfos, $fieldKey, $object->array_options[$key]);
852 }
853 if (!$check) {
854 $error++;
855 }
856 }
857
858 return $error ? -1 : 1;
859 }
860
870 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
871 {
872 global $hookmanager;
873
874 $result = true;
875 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
876 $parameters = array(
877 'fieldInfos' => &$fieldInfos,
878 'key' => $key,
879 'keyPrefix' => $keyPrefix,
880 'keySuffix' => $keySuffix,
881 );
882
883 $reshook = $hookmanager->executeHooks('verifyPostFieldValue', $parameters, $this); // Note that $object may have been modified by hook
884 if ($reshook > 0) {
885 return (bool) $hookmanager->resPrint;
886 }
887
888 $this->clearErrors();
889 $field = $this->getFieldClass($fieldInfos->type);
890 if (isset($field)) {
891 $this->clearFieldError($key);
892 $result = $field->verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
893 if (!$result) {
894 $this->setFieldError($key, CommonField::$validator->error);
895 }
896 }
897 }
898
899 return $result;
900 }
901
910 public function verifyFieldValue($fieldInfos, $key, $value)
911 {
912 global $hookmanager;
913
914 $result = true;
915 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
916 $parameters = array(
917 'fieldInfos' => &$fieldInfos,
918 'key' => $key,
919 'value' => $value,
920 );
921
922 $reshook = $hookmanager->executeHooks('verifyFieldValue', $parameters, $this); // Note that $object may have been modified by hook
923 if ($reshook > 0) {
924 return (bool) $hookmanager->resPrint;
925 }
926
927 $this->clearErrors();
928 $field = $this->getFieldClass($fieldInfos->type);
929 if (isset($field)) {
930 $this->clearFieldError($key);
931 $result = $field->verifyFieldValue($fieldInfos, $key, $value);
932 if (!$result) {
933 $this->setFieldError($key, CommonField::$validator->error);
934 }
935 }
936 }
937
938 return $result;
939 }
940
951 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
952 {
953 global $hookmanager;
954
955 $value = '';
956 $parameters = array(
957 'fieldInfos' => &$fieldInfos,
958 'key' => $key,
959 'value' => &$value,
960 'keyPrefix' => $keyPrefix,
961 'keySuffix' => $keySuffix,
962 );
963
964 $reshook = $hookmanager->executeHooks('getPostFieldValue', $parameters, $this); // Note that $object may have been modified by hook
965 if ($reshook > 0) {
966 return $value;
967 }
968
969 $this->clearErrors();
970 $field = $this->getFieldClass($fieldInfos->type);
971 if (isset($field)) {
972 $value = $field->getPostFieldValue($fieldInfos, $key, $defaultValue, $keyPrefix, $keySuffix);
973 } else {
974 $value = $defaultValue;
975 }
976
977 return $value;
978 }
979
990 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
991 {
992 global $hookmanager;
993
994 $value = '';
995 $parameters = array(
996 'fieldInfos' => &$fieldInfos,
997 'key' => $key,
998 'value' => &$value,
999 'keyPrefix' => $keyPrefix,
1000 'keySuffix' => $keySuffix,
1001 );
1002
1003 $reshook = $hookmanager->executeHooks('getPostSearchFieldValue', $parameters, $this); // Note that $object may have been modified by hook
1004 if ($reshook > 0) {
1005 return $value;
1006 }
1007
1008 $this->clearErrors();
1009 $field = $this->getFieldClass($fieldInfos->type);
1010 if (isset($field)) {
1011 $value = $field->getPostSearchFieldValue($fieldInfos, $key, $defaultValue, $keyPrefix, $keySuffix);
1012 } else {
1013 $value = $defaultValue;
1014 }
1015
1016 return $value;
1017 }
1018
1032 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '', $noNewButton = 0)
1033 {
1034 global $hookmanager;
1035
1036 $overwrite_before = '';
1037 $overwrite_content = '';
1038 $overwrite_after = '';
1039
1040 $parameters = array(
1041 'fieldInfos' => &$fieldInfos,
1042 'key' => $key,
1043 'value' => &$value,
1044 'keyPrefix' => $keyPrefix,
1045 'keySuffix' => $keySuffix,
1046 'moreCss' => $moreCss,
1047 'moreAttrib' => $moreAttrib,
1048 'noNewButton' => $noNewButton,
1049 'overwrite_before' => &$overwrite_before,
1050 'overwrite_content' => &$overwrite_content,
1051 'overwrite_after' => &$overwrite_after,
1052 );
1053
1054 $hookmanager->executeHooks('printInputSearchField', $parameters, $this); // Note that $this may have been modified by hook
1055
1056 if (!empty($fieldInfos->computed)) {
1057 return '';
1058 }
1059
1060 $out = $overwrite_before;
1061 if (empty($overwrite_content)) {
1062 $this->clearErrors();
1063 $field = $this->getFieldClass($fieldInfos->type);
1064 if (isset($field)) {
1065 $moreCss = $field->getInputCss($fieldInfos, $moreCss);
1066
1067 $out .= $field->printInputSearchField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
1068 } else {
1069 $out .= $this->errorsToString();
1070 }
1071 } else {
1072 $out .= $overwrite_content;
1073 }
1074 $out .= $overwrite_after;
1075
1076 return $out;
1077 }
1078
1092 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '', $noNewButton = 0)
1093 {
1094 global $hookmanager, $langs;
1095
1096 $overwrite_before = '';
1097 $overwrite_content = '';
1098 $overwrite_after = '';
1099
1100 $parameters = array(
1101 'fieldInfos' => &$fieldInfos,
1102 'key' => $key,
1103 'value' => &$value,
1104 'keyPrefix' => $keyPrefix,
1105 'keySuffix' => $keySuffix,
1106 'moreCss' => $moreCss,
1107 'moreAttrib' => $moreAttrib,
1108 'noNewButton' => $noNewButton,
1109 'overwrite_before' => &$overwrite_before,
1110 'overwrite_content' => &$overwrite_content,
1111 'overwrite_after' => &$overwrite_after,
1112 );
1113
1114 $hookmanager->executeHooks('printInputField', $parameters, $this); // Note that $this may have been modified by hook
1115
1116 if (!empty($fieldInfos->computed)) {
1117 return '<span class="opacitymedium">' . $langs->trans("AutomaticallyCalculated") . '</span>';
1118 }
1119
1120 if (!$fieldInfos->editable) {
1121 return $this->printOutputField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
1122 }
1123
1124 // Get validation error
1125 $fieldValidationErrorMsg = $this->getFieldError($key);
1126
1127 $out = $overwrite_before;
1128 if (empty($overwrite_content)) {
1129 $this->clearErrors();
1130 $field = $this->getFieldClass($fieldInfos->type);
1131 if (isset($field)) {
1132 $moreCss = $field->getInputCss($fieldInfos, $moreCss);
1133
1134 // Add validation state class
1135 if (!empty($fieldValidationErrorMsg)) {
1136 $moreCss .= ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error
1137 } else {
1138 $moreCss .= ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success
1139 }
1140
1141 $out .= $field->printInputField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
1142 } else {
1143 $out .= $this->errorsToString();
1144 }
1145 } else {
1146 $out .= $overwrite_content;
1147 }
1148 if (empty($overwrite_after)) {
1149 // Display error message for field
1150 $out .= $this->getFieldErrorIcon($fieldValidationErrorMsg);
1151 } else {
1152 $out .= $overwrite_after;
1153 }
1154
1155 return $out;
1156 }
1157
1170 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
1171 {
1172 global $hookmanager;
1173
1174 $overwrite_before = '';
1175 $overwrite_content = '';
1176 $overwrite_after = '';
1177
1178 $parameters = array(
1179 'fieldInfos' => &$fieldInfos,
1180 'key' => $key,
1181 'value' => &$value,
1182 'keyPrefix' => $keyPrefix,
1183 'keySuffix' => $keySuffix,
1184 'moreCss' => $moreCss,
1185 'moreAttrib' => $moreAttrib,
1186 'overwrite_before' => &$overwrite_before,
1187 'overwrite_content' => &$overwrite_content,
1188 'overwrite_after' => &$overwrite_after,
1189 );
1190
1191 $hookmanager->executeHooks('printOutputField', $parameters, $this); // Note that $object may have been modified by hook
1192
1193 $out = $overwrite_before;
1194 if (empty($overwrite_content)) {
1195 $this->clearErrors();
1196 $field = $this->getFieldClass($fieldInfos->type);
1197 if (isset($field)) {
1198 $moreCss = $field->getInputCss($fieldInfos, $moreCss);
1199
1200 $out .= $field->printOutputField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
1201 } else {
1202 $out .= $this->errorsToString();
1203 }
1204 } else {
1205 $out .= $overwrite_content;
1206 }
1207 $out .= $overwrite_after;
1208
1209 return $out;
1210 }
1211
1222 public function printSeparator($key, &$object, $colspan = 2, $display_type = 'card', $mode = 'view')
1223 {
1224 global $conf, $langs;
1225
1226 // TODO to adapt for field and not extra fields only
1227 $out = '';
1228
1229 /*$tagtype = 'tr';
1230 $tagtype_dyn = 'td';
1231
1232 if ($display_type == 'line') {
1233 $tagtype = 'div';
1234 $tagtype_dyn = 'span';
1235 $colspan = 0;
1236 }
1237
1238 $extrafield_param = $this->attributes[$object->table_element]['param'][$key];
1239 $extrafield_param_list = array();
1240 if (!empty($extrafield_param) && is_array($extrafield_param)) {
1241 $extrafield_param_list = array_keys($extrafield_param['options']);
1242 }
1243
1244 // Set $extrafield_collapse_display_value (do we have to collapse/expand the group after the separator)
1245 $extrafield_collapse_display_value = -1;
1246 $expand_display = false;
1247 if (is_array($extrafield_param_list) && count($extrafield_param_list) > 0) {
1248 $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
1249 $expand_display = ((isset($_COOKIE['DOLUSER_COLLAPSE_' . $object->table_element . '_extrafields_' . $key]) || GETPOSTINT('ignorecollapsesetup')) ? (!empty($_COOKIE['DOLUSER_COLLAPSE_' . $object->table_element . '_extrafields_' . $key])) : !($extrafield_collapse_display_value == 2));
1250 }
1251 $disabledcookiewrite = 0;
1252 if ($mode == 'create') {
1253 // On create mode, force separator group to not be collapsible
1254 $extrafield_collapse_display_value = 1;
1255 $expand_display = true; // We force group to be shown expanded
1256 $disabledcookiewrite = 1; // We keep status of group unchanged into the cookie
1257 }
1258
1259 $out = '<' . $tagtype . ' id="trextrafieldseparator' . $key . (!empty($object->id) ? '_' . $object->id : '') . '" class="trextrafieldseparator trextrafieldseparator' . $key . (!empty($object->id) ? '_' . $object->id : '') . '">';
1260 $out .= '<' . $tagtype_dyn . ' ' . (!empty($colspan) ? 'colspan="' . $colspan . '"' : '') . '>';
1261 // Some js code will be injected here to manage the collapsing of fields
1262 // Output the picto
1263 $out .= '<span class="' . ($extrafield_collapse_display_value ? 'cursorpointer ' : '') . ($extrafield_collapse_display_value == 0 ? 'fas fa-square opacitymedium' : 'far fa-' . (($expand_display ? 'minus' : 'plus') . '-square')) . '"></span>';
1264 $out .= '&nbsp;';
1265 $out .= '<strong>';
1266 $out .= $langs->trans($this->attributes[$object->table_element]['label'][$key]);
1267 $out .= '</strong>';
1268 $out .= '</' . $tagtype_dyn . '>';
1269 $out .= '</' . $tagtype . '>';
1270
1271 $collapse_group = $key . (!empty($object->id) ? '_' . $object->id : '');
1272 //$extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key].(!empty($object->id)?'_'.$object->id:'');
1273
1274 if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
1275 // Set the collapse_display status to cookie in priority or if ignorecollapsesetup is 1, if cookie and ignorecollapsesetup not defined, use the setup.
1276 $this->expand_display[$collapse_group] = $expand_display;
1277
1278 if (!empty($conf->use_javascript_ajax)) {
1279 $out .= '<!-- Add js script to manage the collapse/uncollapse of extrafields separators ' . $key . ' -->' . "\n";
1280 $out .= '<script nonce="' . getNonce() . '" type="text/javascript">' . "\n";
1281 $out .= 'jQuery(document).ready(function(){' . "\n";
1282 if (empty($disabledcookiewrite)) {
1283 if (!$expand_display) {
1284 $out .= ' console.log("Inject js for the collapsing of extrafield ' . $key . ' - hide");' . "\n";
1285 $out .= ' jQuery(".trextrafields_collapse' . $collapse_group . '").hide();' . "\n";
1286 } else {
1287 $out .= ' console.log("Inject js for collapsing of extrafield ' . $key . ' - keep visible and set cookie");' . "\n";
1288 $out .= ' document.cookie = "DOLUSER_COLLAPSE_' . $object->table_element . '_extrafields_' . $key . '=1; path=' . $_SERVER["PHP_SELF"] . '"' . "\n";
1289 }
1290 }
1291 $out .= ' jQuery("#trextrafieldseparator' . $key . (!empty($object->id) ? '_' . $object->id : '') . '").click(function(){' . "\n";
1292 $out .= ' console.log("We click on collapse/uncollapse to hide/show .trextrafields_collapse' . $collapse_group . '");' . "\n";
1293 $out .= ' jQuery(".trextrafields_collapse' . $collapse_group . '").toggle(100, function(){' . "\n";
1294 $out .= ' if (jQuery(".trextrafields_collapse' . $collapse_group . '").is(":hidden")) {' . "\n";
1295 $out .= ' jQuery("#trextrafieldseparator' . $key . (!empty($object->id) ? '_' . $object->id : '') . ' ' . $tagtype_dyn . ' span").addClass("fa-plus-square").removeClass("fa-minus-square");' . "\n";
1296 $out .= ' document.cookie = "DOLUSER_COLLAPSE_' . $object->table_element . '_extrafields_' . $key . '=0; path=' . $_SERVER["PHP_SELF"] . '"' . "\n";
1297 $out .= ' } else {' . "\n";
1298 $out .= ' jQuery("#trextrafieldseparator' . $key . (!empty($object->id) ? '_' . $object->id : '') . ' ' . $tagtype_dyn . ' span").addClass("fa-minus-square").removeClass("fa-plus-square");' . "\n";
1299 $out .= ' document.cookie = "DOLUSER_COLLAPSE_' . $object->table_element . '_extrafields_' . $key . '=1; path=' . $_SERVER["PHP_SELF"] . '"' . "\n";
1300 $out .= ' }' . "\n";
1301 $out .= ' });' . "\n";
1302 $out .= ' });' . "\n";
1303 $out .= '});' . "\n";
1304 $out .= '</script>' . "\n";
1305 }
1306 } else {
1307 $this->expand_display[$collapse_group] = 1;
1308 }*/
1309
1310 return $out;
1311 }
1312}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
static setForm(&$form)
Set form used for print the field.
Class to stock field infos.
Class to manage fields.
getAllFields()
Get all fields handler available.
getFieldsInfos($key, &$object, &$extrafields=null, $mode='view', $params=array())
Get list of fields infos for the provided mode into X columns.
setObjectFieldValuesFromPost(&$object, $keyPrefix='', $keySuffix='', $mode='view', $params=array())
Set all object values of the object from POST.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value is valid.
getAllExtraFieldsInfos(&$object, &$extrafields=null, $mode='view', $params=array())
Get list of extra fields infos.
getAllFieldsInfos(&$object, &$extrafields=null, $mode='view', $nbColumn=2, $breakKeys=array(), $params=array())
Get list of fields infos for the provided mode into X columns.
getFieldInfosFromObjectField(&$object, $key, $mode='view', $params=array())
Get field infos from object field infos.
errorsToString($separator=', ')
Method to output saved errors.
getFieldClass($type)
Get field handler for the provided type.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
setExtraFieldValuesFromPost(&$object, &$extrafields, $keyPrefix='', $keySuffix='', $mode='view', $params=array())
Set all extra field values of the object from POST.
getAllObjectFieldsInfos(&$object, $mode='view', $params=array())
Get list of object fields infos.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getFieldInfosFromExtraField(&$object, &$extrafields, $key, $mode='view', $params=array())
Get field infos from extra field infos.
setFieldError($fieldKey, $msg='')
set validation error message a field
setCommonFieldInfos(&$fieldInfos, &$object, &$extrafields, $key, $mode='view', $enabled='1', $visibility='', $perms=null, $params=array())
Set common field infos.
setFieldValuesFromPost(&$object, &$extrafields, $keyPrefix='', $keySuffix='', $mode='view', $params=array())
Set all values of the object (with extra field) from POST.
clearErrors()
clear errors
printSeparator($key, &$object, $colspan=2, $display_type='card', $mode='view')
Return HTML string to print separator field.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getFieldErrorIcon($fieldValidationErrorMsg)
get field error icon
__construct($db, $form=null)
Constructor.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='', $noNewButton=0)
Return HTML string to put an input field into a page.
clearFieldError($fieldKey)
clear validation message result for a field
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='', $noNewButton=0)
Return HTML string to put an input search field into a page.
getFieldError($fieldKey)
get field error message
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.