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