dolibarr 25.0.0-alpha
html.formsetup.class.php
1<?php
2/* Copyright (C) 2021 John BOTELLA <john.botella@atm-consulting.fr>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28{
32 public $db;
33
35 public $entity;
36
38 public $items = array();
39
43 public $setupNotEmpty = 0;
44
46 public $langs;
47
49 public $form;
50
52 protected $maxItemRank;
53
58 public $htmlBeforeOutputForm = '';
59
64 public $htmlAfterOutputForm = '';
65
70 public $htmlOutputMoreButton = '';
71
76 public $htmlButtonLabel = 'Save';
77
81 public $formAttributes = array(
82 'action' => '', // set in __construct
83 'method' => 'POST'
84 );
85
90 public $formHiddenInputs = array();
91
95 public $errors = array();
96
97
104 public function __construct($db, $outputLangs = null)
105 {
106 global $conf, $langs;
107
108 $this->db = $db;
109
110 $this->form = new Form($this->db);
111 $this->formAttributes['action'] = $_SERVER["PHP_SELF"];
112
113 $this->formHiddenInputs['token'] = newToken();
114 $this->formHiddenInputs['action'] = 'update';
115
116 $this->entity = (is_null($this->entity) ? $conf->entity : $this->entity);
117
118 if ($outputLangs) {
119 $this->langs = $outputLangs;
120 } else {
121 $this->langs = $langs;
122 }
123 }
124
131 public static function generateAttributesStringFromArray($attributes)
132 {
133 $Aattr = array();
134 if (is_array($attributes)) {
135 foreach ($attributes as $attribute => $value) {
136 if (is_array($value) || is_object($value)) {
137 continue;
138 }
139 $Aattr[] = $attribute.'="'.dol_escape_htmltag($value).'"';
140 }
141 }
142
143 return !empty($Aattr) ? implode(' ', $Aattr) : '';
144 }
145
146
156 public function generateOutput($editMode = false, $hideTitle = false, $title = '', $cssfirstcolumn = '')
157 {
158 global $hookmanager, $action;
159
160 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
161
162 $parameters = array(
163 'editMode' => $editMode
164 );
165 $reshook = $hookmanager->executeHooks('formSetupBeforeGenerateOutput', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
166 if ($reshook < 0) {
167 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168 }
169
170 if ($reshook > 0) {
171 return $hookmanager->resPrint;
172 } else {
173 $out = '<!-- Start generateOutput from FormSetup class -->';
174 $out .= $this->htmlBeforeOutputForm;
175
176 if ($editMode) {
177 $out .= '<form ' . self::generateAttributesStringFromArray($this->formAttributes) . ' autocomplete="off">';
178 $out .= '<input type="hidden" name="page_y" value="">';
179
180 // generate hidden values from $this->formHiddenInputs
181 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
182 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
183 $out .= '<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).'" value="' . dol_escape_htmltag($hiddenValue) . '">';
184 }
185 }
186 }
187
188 // generate output table
189 $out .= $this->generateTableOutput((bool) $editMode, $hideTitle, $title, $cssfirstcolumn);
190
191
192 $reshook = $hookmanager->executeHooks('formSetupBeforeGenerateOutputButton', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
193 if ($reshook < 0) {
194 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
195 }
196
197 if ($reshook > 0) {
198 return $hookmanager->resPrint;
199 } elseif ($editMode) {
200 $out .= '<div class="form-setup-button-container center">'; // Todo : remove .center by adding style to form-setup-button-container css class in all themes
201 $out .= $this->htmlOutputMoreButton;
202 if ($editMode !== 3) {
203 $out .= '<input class="button button-save reposition" type="submit" value="' . $this->langs->trans($this->htmlButtonLabel ?: "Save") . '" name="save">'; // Todo fix dolibarr style for <button and use <button instead of input
204 }
205 if ($editMode === 2) {
206 // Add also a cancel button
207 $out .= ' &nbsp;&nbsp; ';
208 $out .= '<input class="button button-cancel" type="submit" value="' . $this->langs->trans('Cancel') . '" name="cancel">';
209 }
210 $out .= '</div>';
211 }
212
213 if ($editMode) {
214 $out .= '</form>';
215 }
216
217 $out .= $this->htmlAfterOutputForm;
218
219 return $out;
220 }
221 }
222
232 public function generateTableOutput($editMode = false, $hideTitle = false, $title = '', $cssfirstcolumn = '')
233 {
234 global $hookmanager, $action;
235 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
236
237 $parameters = array(
238 'editMode' => $editMode
239 );
240 $reshook = $hookmanager->executeHooks('formSetupBeforeGenerateTableOutput', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
241 if ($reshook < 0) {
242 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
243 }
244
245 if ($reshook > 0) {
246 return $hookmanager->resPrint;
247 } else {
248 $out = '<div class="div-table-responsive-no-min">';
249 $out .= '<table class="noborder centpercent">';
250 if (empty($hideTitle)) {
251 if (empty($title)) {
252 $title = $this->langs->transnoentitiesnoconv("Parameter");
253 }
254 $out .= '<thead>';
255 $out .= '<tr class="liste_titre">';
256 $out .= ' <td'.($cssfirstcolumn ? ' class="'.$cssfirstcolumn.'"' : '').'>' . dolPrintHTML($title) . '</td>';
257 $out .= ' <td></td>';
258 $out .= '</tr>';
259 $out .= '</thead>';
260 }
261
262 // Sort items before render
263 $this->sortingItems();
264
265 $out .= '<tbody>';
266 foreach ($this->items as $item) {
267 $out .= $this->generateLineOutput($item, $editMode);
268 }
269 $out .= '</tbody>';
270
271 $out .= '</table>';
272 $out .= '</div>';
273 return $out;
274 }
275 }
276
283 public function saveConfFromPost($noMessageInUpdate = false)
284 {
285 global $hookmanager, $conf;
286
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks('formSetupBeforeSaveConfFromPost', $parameters, $this); // Note that $action and $object may have been modified by some hooks
289 if ($reshook < 0) {
290 $this->errors = $hookmanager->errors;
291 return -1;
292 }
293 if ($reshook > 0) {
294 return $reshook;
295 }
296
297 if (empty($this->items)) {
298 return null;
299 }
300
301 $this->db->begin();
302 $error = 0;
303 foreach ($this->items as $item) {
304 if ($item->getType() == 'yesno' && !empty($conf->use_javascript_ajax)) {
305 continue;
306 }
307
308 $res = $item->setValueFromPost();
309 if ($res > 0) {
310 $item->saveConfValue();
311 } elseif ($res < 0) {
312 $error++;
313 break;
314 }
315 }
316
317 if (!$error) {
318 $this->db->commit();
319 if (empty($noMessageInUpdate)) {
320 setEventMessages($this->langs->trans("SetupSaved"), null);
321 }
322 return 1;
323 } else {
324 $this->db->rollback();
325 if (empty($noMessageInUpdate)) {
326 setEventMessages($this->langs->trans("SetupNotSaved"), null, 'errors');
327 }
328 return -1;
329 }
330 }
331
339 public function generateLineOutput($item, $editMode = false)
340 {
341 $out = '';
342 if ($item->enabled == 1) {
343 $trClass = 'oddeven';
344 $tdOutputFieldClass = '';
345 if ($item->getType() == 'title') {
346 $trClass = 'liste_titre';
347 }
348 if (!empty($item->fieldParams['trClass'])) {
349 $trClass .= ' '.$item->fieldParams['trClass'];
350 }
351 if (!empty($item->fieldParams['tdOutputFieldClass'])) {
352 $tdOutputFieldClass .= ' class="'.$item->fieldParams['tdOutputFieldClass'].'"';
353 }
354
355 $this->setupNotEmpty++;
356
357 $tableLineAttr = [
358 'id' => 'setup-line-item_'. preg_replace('/[^a-zA-Z_]/', '', $item->confKey),
359 'class' => $trClass
360 ];
361
362 if ($item->getType() !== 'title') {
363 $tableLineAttr['data-conf-key'] = $item->confKey;
364 }
365
366 $tableLineAttrCompiled = commonHtmlAttributeBuilder($tableLineAttr);
367 $out .= '<tr '. implode(' ', $tableLineAttrCompiled).' >';
368
369 $out .= '<td class="col-setup-title'.(!empty($item->fieldParams['isMandatory']) ? ' fieldrequired' : '').'">';
370 $out .= '<span id="helplink'.$item->confKey.'" class="spanforparamtooltip">';
371 $out .= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1, 'info', '', 0, 3, empty($item->fieldParams['helpText']) ? 'tootips'.$item->confKey : ($item->fieldParams['helpText'] != 'noclick' ? $item->fieldParams['helpText'] : ''));
372 $out .= '</span>';
373 $out .= '</td>';
374
375 $out .= '<td'.$tdOutputFieldClass.'>';
376
377 if ($editMode) {
378 $out .= $item->generateInputField();
379 } else {
380 $out .= $item->generateOutputField();
381 }
382
383 if (!empty($item->errors)) {
384 // TODO : move set event message in a method to be called by cards not by this class
385 setEventMessages(null, $item->errors, 'errors');
386 }
387
388 $out .= '</td>';
389 $out .= '</tr>';
390 }
391
392 return $out;
393 }
394
395
402 public function addItemsFromParamsArray($params)
403 {
404 if (!is_array($params) || empty($params)) {
405 return false;
406 }
407 foreach ($params as $confKey => $param) {
408 $this->addItemFromParams($confKey, $param); // todo manage error
409 }
410 return true;
411 }
412
413
422 public function addItemFromParams($confKey, $params)
423 {
424 if (empty($confKey) || empty($params['type'])) {
425 return false;
426 }
427
428 /*
429 * Example from old module builder setup page
430 * // 'MYMODULE_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>1),
431 // 'MYMODULE_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
432 //'MYMODULE_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
433 //'MYMODULE_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
434 //'MYMODULE_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
435 //'MYMODULE_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
436 //'MYMODULE_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
437 //'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
438 */
439
440 $item = new FormSetupItem($confKey);
441 // setTypeFromTypeString was created as deprecated to incite developer to use object oriented usage
443 $item->setTypeFromTypeString((string) $params['type']);
444
445 if (!empty($params['enabled']) && is_numeric($params['enabled'])) {
446 $item->enabled = (int) $params['enabled'];
447 }
448
449 if (!empty($params['css'])) {
450 $item->cssClass = (string) $params['css'];
451 }
452
453 $this->items[$item->confKey] = $item;
454
455 return true;
456 }
457
464 public function exportItemsAsParamsArray()
465 {
466 $arrayofparameters = array();
467 foreach ($this->items as $item) {
468 $arrayofparameters[$item->confKey] = array(
469 'type' => $item->getType(),
470 'enabled' => $item->enabled
471 );
472 }
473
474 return $arrayofparameters;
475 }
476
483 public function reloadConfs()
484 {
485 if (!array($this->items)) {
486 return false;
487 }
488 foreach ($this->items as $item) {
489 $item->loadValueFromConf();
490 }
491
492 return true;
493 }
494
495
505 public function newItem($confKey, $targetItemKey = '', $insertAfterTarget = false)
506 {
507 $item = new FormSetupItem($confKey);
508
509 $item->entity = $this->entity;
510
511 // set item rank if not defined as last item
512 if (empty($item->rank)) {
513 $item->rank = $this->getCurentItemMaxRank() + 1;
514 $this->setItemMaxRank($item->rank); // set new max rank if needed
515 }
516
517 // try to get rank from target column, this will override item->rank
518 if (!empty($targetItemKey)) {
519 if (isset($this->items[$targetItemKey])) {
520 $targetItem = $this->items[$targetItemKey];
521 $item->rank = $targetItem->rank; // $targetItem->rank will be increase after
522 if ($targetItem->rank >= 0 && $insertAfterTarget) {
523 $item->rank++;
524 }
525 }
526
527 // calc new rank for each item to make place for new item
528 foreach ($this->items as $fItem) {
529 if ($item->rank <= $fItem->rank) {
530 $fItem->rank += 1;
531 $this->setItemMaxRank($fItem->rank); // set new max rank if needed
532 }
533 }
534 }
535
536 $this->items[$item->confKey] = $item;
537 return $this->items[$item->confKey];
538 }
539
545 public function sortingItems()
546 {
547 // Sorting
548 return uasort($this->items, array($this, 'itemSort'));
549 }
550
557 public function getCurentItemMaxRank($cache = true)
558 {
559 if (empty($this->items)) {
560 return 0;
561 }
562
563 if ($cache && $this->maxItemRank > 0) {
564 return $this->maxItemRank;
565 }
566
567 $this->maxItemRank = 0;
568 foreach ($this->items as $item) {
569 $this->maxItemRank = max($this->maxItemRank, $item->rank);
570 }
571
572 return $this->maxItemRank;
573 }
574
575
582 public function setItemMaxRank($rank)
583 {
584 $this->maxItemRank = max($this->maxItemRank, $rank);
585 }
586
587
594 public function getLineRank($itemKey)
595 {
596 if (!isset($this->items[$itemKey]->rank)) {
597 return -1;
598 }
599 return $this->items[$itemKey]->rank;
600 }
601
602
610 public function itemSort(FormSetupItem $a, FormSetupItem $b)
611 {
612 if (empty($a->rank)) {
613 $a->rank = 0;
614 }
615 if (empty($b->rank)) {
616 $b->rank = 0;
617 }
618 if ($a->rank == $b->rank) {
619 return 0;
620 }
621 return ($a->rank < $b->rank) ? -1 : 1;
622 }
623}
624
625
630{
634 public $db;
635
637 public $langs;
638
640 public $entity;
641
643 public $form;
644
645
647 public $confKey;
648
650 public $nameText = false;
651
653 public $helpText = '';
654
656 public $picto = '';
657
659 public $fieldValue;
660
662 public $defaultFieldValue = null;
663
665 public $fieldAttr = array();
666
668 public $fieldOverride = false;
669
671 public $fieldInputOverride = false;
672
674 public $fieldInputCallBack;
675
677 public $fieldOutputOverride = false;
678
680 public $fieldOutputCallBack;
681
683 public $rank = 0;
684
686 public $fieldOptions = array();
687
689 public $fieldParams = array();
690
692 public $saveCallBack;
693
695 public $setValueFromPostCallBack;
696
700 public $errors = array();
701
708 protected $type = 'string';
709
710
712 public $enabled = 1;
713
717 public $cssClass = '';
718
719
725 public function __construct($confKey)
726 {
727 global $langs, $db, $conf, $form;
728 $this->db = $db;
729
730 if (!empty($form) && is_object($form) && get_class($form) == 'Form') { // the form class has a cache inside so I am using it to optimize
731 $this->form = $form;
732 } else {
733 $this->form = new Form($this->db);
734 }
735
736 $this->langs = $langs;
737 $this->entity = (is_null($this->entity) ? $conf->entity : ((int) $this->entity));
738
739 $this->confKey = $confKey;
740 $this->loadValueFromConf();
741 }
742
748 public function loadValueFromConf()
749 {
750 global $conf;
751 if (isset($conf->global->{$this->confKey})) {
752 $this->fieldValue = getDolGlobalString($this->confKey);
753 return true;
754 } else {
755 $this->fieldValue = null;
756 return false;
757 }
758 }
759
766 public function reloadValueFromConf()
767 {
768 return $this->loadValueFromConf();
769 }
770
771
777 public function saveConfValue()
778 {
779 global $hookmanager;
780
781 $parameters = array();
782 $reshook = $hookmanager->executeHooks('formSetupBeforeSaveConfValue', $parameters, $this); // Note that $action and $object may have been modified by some hooks
783 if ($reshook < 0) {
784 $this->setErrors($hookmanager->errors);
785 return -1;
786 }
787
788 if ($reshook > 0) {
789 return $reshook;
790 }
791
792 if ($this->saveCallBack !== null && is_callable($this->saveCallBack)) {
793 return call_user_func($this->saveCallBack, $this);
794 }
795
796 // Modify constant only if key was posted (avoid resetting key to the null value)
797 if ($this->type != 'title') {
798 $result = dolibarr_set_const($this->db, $this->confKey, $this->fieldValue, 'chaine', 0, '', $this->entity);
799 if ($result < 0) {
800 return -1;
801 } else {
802 return 1;
803 }
804 }
805
806 return 0;
807 }
808
815 public function setSaveCallBack(callable $callBack)
816 {
817 $this->saveCallBack = $callBack;
818 }
819
826 public function setValueFromPostCallBack(callable $callBack)
827 {
828 $this->setValueFromPostCallBack = $callBack;
829 }
830
836 public function setValueFromPost()
837 {
838 if ($this->setValueFromPostCallBack !== null && is_callable($this->setValueFromPostCallBack)) {
839 return call_user_func($this->setValueFromPostCallBack);
840 }
841
842 // Modify constant only if key was posted (avoid resetting key to the null value).
843 // A multiselect with no option selected posts nothing, so its input adds a hidden marker field.
844 $posted = GETPOSTISSET($this->confKey) || ($this->type == 'multiselect' && GETPOSTISSET($this->confKey.'_multiselect'));
845 if (!$posted) {
846 return 0;
847 }
848 if ($this->type != 'title') {
849 if (preg_match('/category:/', $this->type)) {
850 if (GETPOSTINT($this->confKey) == '-1') {
851 $val_const = '';
852 } else {
853 $val_const = GETPOSTINT($this->confKey);
854 }
855 } elseif ($this->type == 'multiselect') {
856 $val = GETPOST($this->confKey, 'array');
857 if ($val && is_array($val)) {
858 $val_const = implode(',', $val);
859 } else {
860 $val_const = '';
861 }
862 } elseif ($this->type == 'html') {
863 $val_const = GETPOST($this->confKey, 'restricthtml');
864 } elseif ($this->type == 'email') {
865 $val_const = GETPOST($this->confKey, 'alphawithlgt');
866 } elseif ($this->type == 'number') {
867 $val_const = GETPOSTINT($this->confKey);
868 } elseif ($this->type == 'password' || $this->type == 'genericpassword') {
869 $val_const = GETPOST($this->confKey, 'password');
870 } else {
871 $val_const = GETPOST($this->confKey, 'alphanohtml');
872 }
873
874 // TODO add value check with class validate
875 $this->fieldValue = $val_const;
876
877 return 1;
878 }
879
880 return 0;
881 }
882
888 public function getHelpText()
889 {
890 if (!empty($this->helpText)) {
891 return $this->helpText;
892 }
893 return (($this->langs->trans($this->confKey . 'Tooltip') != $this->confKey . 'Tooltip') ? $this->langs->trans($this->confKey . 'Tooltip') : '');
894 }
895
901 public function getNameText()
902 {
903 if (!empty($this->nameText)) {
904 return $this->nameText;
905 }
906 $out = (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans('MissingTranslationForConfKey', $this->confKey));
907
908 // if conf defined on entity 0, prepend a picto to indicate it will apply across all entities
909 if (isModEnabled('multicompany') && $this->entity == 0) {
910 $out = img_picto($this->langs->trans('AllEntities'), 'fa-globe-americas em088 opacityhigh') . '&nbsp;' . $out;
911 }
912
913 return $out;
914 }
915
921 public function generateInputField()
922 {
923 global $conf;
924
925 if ($this->fieldInputCallBack !== null && is_callable($this->fieldInputCallBack)) {
926 // can be used to populate fieldInputOverride, fieldOverride or change stuff
927 $resCallback = call_user_func($this->fieldInputCallBack, $this);
928 if (!empty($resCallback)) {
929 return $resCallback;
930 }
931 }
932
933 if (!empty($this->fieldOverride)) {
934 return $this->fieldOverride;
935 }
936
937 if (!empty($this->fieldInputOverride)) {
938 return $this->fieldInputOverride;
939 }
940
941 // Set default value
942 if (is_null($this->fieldValue)) {
943 $this->fieldValue = $this->defaultFieldValue;
944 }
945
946
947 $this->fieldAttr['name'] = $this->confKey;
948 $this->fieldAttr['id'] = 'setup-'.$this->confKey;
949 $this->fieldAttr['value'] = $this->fieldValue;
950
951 $out = '';
952
953 if ($this->type == 'title') {
954 $out .= $this->generateOutputField(); // title have no input
955 } elseif ($this->type == 'multiselect') {
956 $out .= $this->generateInputFieldMultiSelect();
957 } elseif ($this->type == 'select') {
958 $out .= $this->generateInputFieldSelect();
959 } elseif ($this->type == 'radio') {
960 $out .= $this->generateInputFieldRadio();
961 } elseif ($this->type == 'selectUser') {
962 $out .= $this->generateInputFieldSelectUser();
963 } elseif ($this->type == 'textarea') {
964 $out .= $this->generateInputFieldTextarea();
965 } elseif ($this->type == 'html') {
966 $out .= $this->generateInputFieldHtml();
967 } elseif ($this->type == 'color') {
968 $out .= $this->generateInputFieldColor();
969 } elseif ($this->type == 'yesno') {
970 if (!empty($conf->use_javascript_ajax)) {
971 $input = $this->fieldParams['input'] ?? array();
972 $revertonoff = empty($this->fieldParams['revertonoff']) ? 0 : 1;
973 $forcereload = empty($this->fieldParams['forcereload']) ? 0 : 1;
974 $suffixarray = array(
975 'ifoff' => '',
976 'ifon' => '',
977 );
978 if (!empty($this->fieldParams['alertifoff'])) {
979 $suffixarray['ifoff'] = '_red';
980 } elseif (!empty($this->fieldParams['warningifoff'])) {
981 $suffixarray['ifoff'] = '_warning';
982 }
983 if (!empty($this->fieldParams['alertifon'])) {
984 $suffixarray['ifon'] = '_red';
985 } elseif (!empty($this->fieldParams['warningifon'])) {
986 $suffixarray['ifon'] = '_warning';
987 }
988
989 $out .= ajax_constantonoff($this->confKey, $input, $this->entity, $revertonoff, 0, $forcereload, 2, 0, 0, $suffixarray, '', $this->cssClass);
990 } else {
991 $out .= $this->form->selectyesno($this->confKey, $this->fieldValue, 1, false, 0, 0, $this->cssClass);
992 }
993 } elseif (preg_match('/emailtemplate:/', $this->type)) {
994 $out .= $this->generateInputFieldEmailTemplate();
995 } elseif (preg_match('/category:/', $this->type)) {
996 $out .= $this->generateInputFieldCategories();
997 } elseif (preg_match('/thirdparty_type/', $this->type)) {
998 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
999 $formcompany = new FormCompany($this->db);
1000 $out .= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
1001 } elseif ($this->type == 'securekey') {
1002 $out .= $this->generateInputFieldSecureKey();
1003 } elseif ($this->type == 'product') {
1004 if (isModEnabled("product") || isModEnabled("service")) {
1005 $selected = (empty($this->fieldValue) ? '' : $this->fieldValue);
1006 $out .= img_picto('', 'product', 'class="pictofixedwidth"');
1007 $out .= $this->form->select_produits((int) $selected, $this->confKey, '', 0, 0, 1, 2, '', 0, array(), 0, '1', 0, $this->cssClass, 0, '', null, 1);
1008 }
1009 } elseif ($this->type == 'selectBankAccount') {
1010 if (isModEnabled("bank")) {
1011 $selected = (empty($this->fieldValue) ? '' : $this->fieldValue);
1012 $out .= img_picto('', 'bank', 'class="pictofixedwidth"').$this->form->select_comptes($selected, $this->confKey, 0, '', 0, '', 0, '', 1);
1013 }
1014 } elseif ($this->type == 'password') {
1015 $out .= $this->generateInputFieldPassword('dolibarr');
1016 } elseif ($this->type == 'genericpassword') {
1017 $out .= $this->generateInputFieldPassword('generic', 0, 0);
1018 } elseif ($this->type == 'price') {
1019 $out .= $this->generateInputFieldPrice();
1020 } elseif ($this->type == 'email') {
1021 $out .= $this->generateInputFieldEmail();
1022 } elseif ($this->type == 'url') {
1023 $out .= $this->generateInputFieldUrl();
1024 } else {
1025 $out .= $this->generateInputFieldText();
1026 }
1027
1028 return $out;
1029 }
1030
1036 public function generateInputFieldText()
1037 {
1038 if (empty($this->fieldAttr) || empty($this->fieldAttr['class'])) {
1039 $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth200' : $this->cssClass);
1040 }
1041 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' spellcheck="false">';
1042 }
1043
1049 public function generateInputFieldPrice()
1050 {
1051 global $langs, $mysoc;
1052
1053 if (empty($this->fieldAttr) || empty($this->fieldAttr['class'])) {
1054 $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth40 maxwidth75' : $this->cssClass);
1055 }
1056 //return img_picto('', 'currency', 'class="pictofixedwidth"').'<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' /> '.$langs->getCurrencySymbol($mysoc->currency_code);
1057 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' spellcheck="false"> '.$langs->getCurrencySymbol($mysoc->currency_code);
1058 }
1059
1065 public function generateInputFieldEmail()
1066 {
1067 if (empty($this->fieldAttr) || empty($this->fieldAttr['class'])) {
1068 $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth100 maxwidth500' : $this->cssClass);
1069 }
1070 return img_picto('', 'email', 'class="pictofixedwidth"').'<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' spellcheck="false">';
1071 }
1072
1078 public function generateInputFieldUrl()
1079 {
1080 if (empty($this->fieldAttr) || empty($this->fieldAttr['class'])) {
1081 $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth100 maxwidth500' : $this->cssClass);
1082 }
1083 return img_picto('', 'url', 'class="pictofixedwidth"').'<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' spellcheck="false">';
1084 }
1085
1092 {
1093 $out = '<textarea class="flat" name="'.$this->confKey.'" id="'.$this->confKey.'" cols="50" rows="5" wrap="soft" spellcheck="false">' . "\n";
1094 $out .= dol_htmlentities($this->fieldValue);
1095 $out .= "</textarea>\n";
1096 return $out;
1097 }
1098
1104 public function generateInputFieldHtml()
1105 {
1106 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
1107 $doleditor = new DolEditor($this->confKey, $this->fieldValue, '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
1108 return $doleditor->Create(1);
1109 }
1110
1117 {
1118 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1119 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
1120 $formother = new FormOther($this->db);
1121
1122 $tmp = explode(':', $this->type);
1123 $out = img_picto('', 'category', 'class="pictofixedwidth"');
1124
1125 $label = 'Categories';
1126 if ($this->type == 'customer') {
1127 $label = 'CustomersProspectsCategoriesShort';
1128 }
1129 $out .= $formother->select_categories($tmp[1], (int) $this->fieldValue, $this->confKey, 0, $this->langs->trans($label));
1130
1131 return $out;
1132 }
1133
1139 {
1140 global $user;
1141
1142 $out = '';
1143 if (preg_match('/emailtemplate:/', $this->type)) {
1144 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
1145 $formmail = new FormMail($this->db);
1146
1147 $tmp = explode(':', $this->type);
1148 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
1149 $arrayOfMessageName = array();
1150 if (is_array($formmail->lines_model)) {
1151 foreach ($formmail->lines_model as $modelMail) {
1152 $moreonlabel = '';
1153 if (!empty($arrayOfMessageName[$modelMail->label])) {
1154 $moreonlabel = ' <span class="opacitymedium">(' . $this->langs->trans("SeveralLangugeVariatFound") . ')</span>';
1155 }
1156 // The 'label' is the key that is unique if we exclude the language
1157 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace('/\‍(|\‍)/', '', $modelMail->label)) . $moreonlabel;
1158 }
1159 }
1160 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue, 'None', 0, 0, '', 0, 0, 0, '', '', 1);
1161 }
1162
1163 return $out;
1164 }
1165
1166
1173 {
1174 global $conf;
1175 $out = '<input type="text" class="flat minwidth150'.($this->cssClass ? ' '.$this->cssClass : '').'" id="'.$this->confKey.'" name="'.$this->confKey.'" value="'.(GETPOST($this->confKey, 'alpha') ? GETPOST($this->confKey, 'alpha') : $this->fieldValue).'">';
1176
1177 if (!empty($conf->use_javascript_ajax) && empty($this->fieldParams['hideGenerateButton'])) {
1178 $out .= '&nbsp;'.img_picto($this->langs->trans('Generate'), 'refresh', 'id="generate_token'.$this->confKey.'" class="linkobject"');
1179
1180 // Add button to autosuggest a key
1181 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1182 $out .= dolJSToSetRandomPassword($this->confKey, 'generate_token'.$this->confKey);
1183 }
1184
1185 // Add button to show/hide a key masked with the css class 'text-security'
1186 if (!empty($conf->use_javascript_ajax) && !empty($this->fieldParams['showEyeButton'])) {
1187 $out .= '<span class="fa fa-eye paddingleft paddingright cursorpointer pictofixedwidth" title="'.dolPrintHTMLForAttribute($this->langs->trans('Show')).'" onclick="jQuery(\'#'.trim($this->confKey).'\').toggleClass(\'text-security\'); jQuery(this).toggleClass(\'fa-eye fa-eye-slash\');"></span>';
1188 }
1189
1190 return $out;
1191 }
1192
1193
1202 public function generateInputFieldPassword($type = 'generic', $defaultmin = 6, $defaultmax = 50)
1203 {
1204 global $conf, $langs, $user;
1205
1206 $min = $defaultmin;
1207 $max = $defaultmax;
1208 if ($type == 'dolibarr') {
1209 $gen = getDolGlobalString('USER_PASSWORD_GENERATED', 'standard');
1210 if ($gen == 'none') {
1211 $gen = 'standard';
1212 }
1213 require_once DOL_DOCUMENT_ROOT."/core/modules/security/generate/modules_genpassword.php";
1214 $genhandler = ModeleGenPassword::loadAndInstantiate($gen, $this->db, $conf, $langs, $user);
1215 if ($genhandler) {
1216 $min = $genhandler->length;
1217 $max = $genhandler->length2;
1218 }
1219 }
1220 $out = '<input required="required" type="password" class="flat minwidth150'.($this->cssClass ? ' '.$this->cssClass : '').'" id="'.$this->confKey.'" name="'.$this->confKey.'" value="'.(GETPOST($this->confKey, 'alpha') ? GETPOST($this->confKey, 'alpha') : $this->fieldValue).'"';
1221 if ($min) {
1222 $out .= ' minlength="' . $min . '"';
1223 }
1224 if ($max) {
1225 $out .= ' maxlength="' . $max . '"';
1226 }
1227 $out .= '>';
1228
1229 $out .= '<span class="fa fa-eye paddingleft paddingright" onclick="javascript: console.log(\'click on show-hide pass\'); newtype = (jQuery(\'#'.trim($this->confKey).'\').attr(\'type\') == \'text\' ? \'password\' : \'text\'); jQuery(\'#'.trim($this->confKey).'\').attr(\'type\', newtype);"></span>';
1230
1231 return $out;
1232 }
1233
1234
1235
1242 {
1243 $TSelected = array();
1244 if ($this->fieldValue) {
1245 $TSelected = explode(',', $this->fieldValue);
1246 }
1247
1248 $out = $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0, '', 0, 0, 'style="min-width:100px"');
1249 // Marker so that setValueFromPost() also saves an empty selection
1250 $out .= '<input type="hidden" name="'.dol_escape_htmltag($this->confKey).'_multiselect" value="1">';
1251
1252 return $out;
1253 }
1254
1261 {
1262 $s = '';
1263 if ($this->picto) {
1264 $s .= img_picto('', $this->picto, 'class="pictofixedwidth"');
1265 }
1266
1267 $s .= $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue, 0, 0, 0, '', 0, 0, 0, '', $this->cssClass);
1268
1269 return $s;
1270 }
1271
1277 public function generateInputFieldRadio()
1278 {
1279 $s = '';
1280 if ($this->picto) {
1281 $s .= img_picto('', $this->picto, 'class="pictofixedwidth"');
1282 }
1283
1284 $s .= $this->form->radio($this->confKey, $this->fieldOptions, $this->fieldValue, ['attrLabel' => ['class' => $this->cssClass]]);
1285
1286 return $s;
1287 }
1288
1293 {
1294 return $this->form->select_dolusers($this->fieldValue, $this->confKey);
1295 }
1296
1304 public function getType()
1305 {
1306 return $this->type;
1307 }
1308
1318 public function setTypeFromTypeString($type)
1319 {
1320 $this->type = $type;
1321
1322 return true;
1323 }
1324
1331 public function setErrors($errors)
1332 {
1333 if (is_array($errors)) {
1334 if (!empty($errors)) {
1335 foreach ($errors as $error) {
1336 $this->setErrors($error);
1337 }
1338 }
1339 } elseif (!empty($errors)) {
1340 $this->errors[] = $errors;
1341 }
1342 return null;
1343 }
1344
1350 public function generateOutputField()
1351 {
1352 global $conf, $user, $langs;
1353
1354 if ($this->fieldOutputCallBack !== null && is_callable($this->fieldOutputCallBack)) {
1355 // can be used to populate fieldOutputOverride, fieldOverride or change stuff
1356 $resCallback = call_user_func($this->fieldOutputCallBack, $this);
1357 if (!empty($resCallback)) {
1358 return $resCallback;
1359 }
1360 }
1361
1362 if (!empty($this->fieldOverride)) {
1363 return $this->fieldOverride;
1364 }
1365
1366 if (!empty($this->fieldOutputOverride)) {
1367 return $this->fieldOutputOverride;
1368 }
1369
1370 $out = '';
1371
1372 if ($this->type == 'title') {
1373 // nothing to do
1374 } elseif ($this->type == 'textarea') {
1375 $out .= dol_nl2br($this->fieldValue);
1376 } elseif ($this->type == 'multiselect') {
1377 $out .= $this->generateOutputFieldMultiSelect();
1378 } elseif ($this->type == 'select') {
1379 $out .= $this->generateOutputFieldSelect();
1380 } elseif ($this->type == 'selectUser') {
1381 $out .= $this->generateOutputFieldSelectUser();
1382 } elseif ($this->type == 'html') {
1383 $out .= $this->fieldValue;
1384 } elseif ($this->type == 'color') {
1385 $out .= $this->generateOutputFieldColor();
1386 } elseif ($this->type == 'yesno') {
1387 if (!empty($conf->use_javascript_ajax)) {
1388 $revertonoff = empty($this->fieldParams['revertonoff']) ? 0 : 1;
1389 $forcereload = empty($this->fieldParams['forcereload']) ? 0 : 1;
1390
1391 $out .= ajax_constantonoff($this->confKey, array(), $this->entity, $revertonoff, 0, $forcereload, 2, 0, 0, '', '', $this->cssClass); // TODO possibility to add $input parameter
1392 } else {
1393 if ($this->fieldValue == 1) {
1394 $out .= $langs->trans('yes');
1395 } else {
1396 $out .= $langs->trans('no');
1397 }
1398 }
1399 } elseif (preg_match('/emailtemplate:/', $this->type)) {
1400 if ($this->fieldValue > 0) {
1401 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
1402 $formmail = new FormMail($this->db);
1403
1404 $tmp = explode(':', $this->type);
1405
1406 $template = $formmail->getEMailTemplate($this->db, $tmp[1], $user, $this->langs, (int) $this->fieldValue);
1407 if (is_numeric($template) && $template < 0) {
1408 $this->setErrors($formmail->errors);
1409 }
1410 $out .= $this->langs->trans($template->label);
1411 }
1412 } elseif (preg_match('/category:/', $this->type)) {
1413 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1414 $c = new Categorie($this->db);
1415 $result = $c->fetch((int) $this->fieldValue);
1416 if ($result < 0) {
1417 $this->setErrors($c->errors);
1418 }
1419 $ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1420 $toprint = array();
1421 foreach ($ways as $way) {
1422 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
1423 }
1424 $out .= '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
1425 } elseif (preg_match('/thirdparty_type/', $this->type)) {
1426 if ($this->fieldValue == 2) {
1427 $out .= $this->langs->trans("Prospect");
1428 } elseif ($this->fieldValue == 3) {
1429 $out .= $this->langs->trans("ProspectCustomer");
1430 } elseif ($this->fieldValue == 1) {
1431 $out .= $this->langs->trans("Customer");
1432 } elseif ($this->fieldValue == 0) {
1433 $out .= $this->langs->trans("NorProspectNorCustomer");
1434 }
1435 } elseif ($this->type == 'product') {
1436 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1437
1438 $product = new Product($this->db);
1439 $resprod = $product->fetch((int) $this->fieldValue);
1440 if ($resprod > 0) {
1441 $out .= $product->getNomUrl(1, '', 0, -1, 0, '', 1);
1442 } elseif ($resprod < 0) {
1443 $this->setErrors($product->errors);
1444 }
1445 } elseif ($this->type == 'selectBankAccount') {
1446 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1447
1448 $bankaccount = new Account($this->db);
1449 $resbank = $bankaccount->fetch((int) $this->fieldValue);
1450 if ($resbank > 0) {
1451 $out .= $bankaccount->label;
1452 } elseif ($resbank < 0) {
1453 $this->setErrors($bankaccount->errors);
1454 }
1455 } elseif ($this->type == 'password' || $this->type == 'genericpassword') {
1456 $out .= str_repeat('*', strlen($this->fieldValue));
1457 } else {
1458 $out .= dolPrintHTML($this->fieldValue);
1459 }
1460
1461 return $out;
1462 }
1463
1464
1471 {
1472 $outPut = '';
1473 $TSelected = array();
1474 if (!empty($this->fieldValue)) {
1475 $TSelected = explode(',', $this->fieldValue);
1476 }
1477
1478 if (!empty($TSelected)) {
1479 foreach ($TSelected as $selected) {
1480 if (!empty($this->fieldOptions[$selected])) {
1481 $outPut .= dolGetBadge('', $this->fieldOptions[$selected], 'info').' ';
1482 }
1483 }
1484 }
1485 return $outPut;
1486 }
1487
1494 {
1495 global $langs;
1496 $out = '';
1497 $this->fieldAttr['disabled'] = null;
1498 $color = colorArrayToHex(colorStringToArray($this->fieldValue, array()), '');
1499 $useDefaultColor = false;
1500 if (!$color && !empty($this->defaultFieldValue)) {
1501 $color = $this->defaultFieldValue;
1502 $useDefaultColor = true;
1503 }
1504 if ($color) {
1505 $out .= '<input type="color" class="colorthumb" disabled="disabled" style="padding: 1px; margin-top: 0; margin-bottom: 0; " value="#'.$color.'">';
1506 }
1507
1508 if ($useDefaultColor) {
1509 $out .= ' '.$langs->trans("Default");
1510 } else {
1511 $out .= ' #'.$color;
1512 }
1513
1514 return $out;
1515 }
1521 public function generateInputFieldColor()
1522 {
1523 $this->fieldAttr['type'] = 'color';
1524 $default = $this->defaultFieldValue;
1525 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
1526 $formother = new FormOther($this->db);
1527 return $formother->selectColor(colorArrayToHex(colorStringToArray((string) $this->fieldAttr['value'], array()), ''), $this->fieldAttr['name'], '', 1, array(), '', '', (string) $default).' ';
1528 }
1529
1536 {
1537 $outPut = '';
1538 if (!empty($this->fieldOptions[$this->fieldValue])) {
1539 $outPut = $this->fieldOptions[$this->fieldValue];
1540 }
1541
1542 return $outPut;
1543 }
1544
1551 {
1552 $outPut = '';
1553 $user = new User($this->db);
1554 $user->fetch((int) $this->fieldValue);
1555 $outPut = $user->firstname . " " . $user->lastname;
1556 return $outPut;
1557 }
1558
1559 /*
1560 * METHODS FOR SETTING DISPLAY TYPE
1561 */
1562
1568 public function setAsString()
1569 {
1570 $this->type = 'string';
1571 return $this;
1572 }
1573
1582 public function setAsNumber($min = null, $max = null, $step = null)
1583 {
1584 $this->type = 'number'; //for GETPOSTINT
1585 $this->fieldAttr['type'] = 'number'; //generic thanks to generateAttributesStringFromArray
1586 if (!is_null($min)) {
1587 $this->fieldAttr['min'] = $min;
1588 }
1589 if (!is_null($max)) {
1590 $this->fieldAttr['max'] = $max;
1591 }
1592 if (!is_null($step)) {
1593 $this->fieldAttr['step'] = $step;
1594 }
1595 return $this;
1596 }
1597
1598
1604 public function setAsEmail()
1605 {
1606 $this->type = 'email';
1607 return $this;
1608 }
1609
1615 public function setAsUrl()
1616 {
1617 $this->type = 'url';
1618 return $this;
1619 }
1620
1626 public function setAsColor()
1627 {
1628 $this->type = 'color';
1629 return $this;
1630 }
1631
1637 public function setAsTextarea()
1638 {
1639 $this->type = 'textarea';
1640 return $this;
1641 }
1642
1648 public function setAsHtml()
1649 {
1650 $this->type = 'html';
1651 return $this;
1652 }
1653
1660 public function setAsEmailTemplate($templateType)
1661 {
1662 $this->type = 'emailtemplate:'.$templateType;
1663 return $this;
1664 }
1665
1671 public function setAsThirdpartyType()
1672 {
1673 $this->type = 'thirdparty_type';
1674 return $this;
1675 }
1676
1682 public function setAsYesNo()
1683 {
1684 $this->type = 'yesno';
1685 return $this;
1686 }
1687
1693 public function setAsSecureKey()
1694 {
1695 $this->type = 'securekey';
1696 return $this;
1697 }
1698
1704 public function setAsProduct()
1705 {
1706 $this->type = 'product';
1707 return $this;
1708 }
1709
1715 public function setAsPrice()
1716 {
1717 $this->type = 'price';
1718 return $this;
1719 }
1720
1728 public function setAsCategory($catType)
1729 {
1730 $this->type = 'category:'.$catType;
1731 return $this;
1732 }
1733
1739 public function setAsTitle()
1740 {
1741 $this->type = 'title';
1742 return $this;
1743 }
1744
1745
1752 public function setAsMultiSelect($fieldOptions)
1753 {
1754 if (is_array($fieldOptions)) {
1755 $this->fieldOptions = $fieldOptions;
1756 }
1757
1758 $this->type = 'multiselect';
1759 return $this;
1760 }
1761
1768 public function setAsSelect($fieldOptions)
1769 {
1770 if (is_array($fieldOptions)) {
1771 $this->fieldOptions = $fieldOptions;
1772 }
1773
1774 $this->type = 'select';
1775 return $this;
1776 }
1777
1778
1785 public function setAsRadio($fieldOptions)
1786 {
1787 if (is_array($fieldOptions)) {
1788 $this->fieldOptions = $fieldOptions;
1789 }
1790
1791 $this->type = 'radio';
1792 return $this;
1793 }
1794
1800 public function setAsSelectUser()
1801 {
1802 $this->type = 'selectUser';
1803 return $this;
1804 }
1805
1811 public function setAsSelectBankAccount()
1812 {
1813 $this->type = 'selectBankAccount';
1814 return $this;
1815 }
1816
1824 public function setAsPassword()
1825 {
1826 $this->type = 'password';
1827 return $this;
1828 }
1829
1837 public function setAsGenericPassword()
1838 {
1839 $this->type = 'genericpassword';
1840 return $this;
1841 }
1842}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
$c
Definition line.php:353
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to help generate other html components Only common components are here.
This class help you create setup render.
sortingItems()
Sort items according to rank.
saveConfFromPost($noMessageInUpdate=false)
saveConfFromPost
generateOutput($editMode=false, $hideTitle=false, $title='', $cssfirstcolumn='')
Generate the form (in read or edit mode depending on $editMode)
itemSort(FormSetupItem $a, FormSetupItem $b)
uasort callback function to Sort params items
newItem($confKey, $targetItemKey='', $insertAfterTarget=false)
Create a new item The target is useful with hooks : that allow externals modules to add setup items o...
__construct($db, $outputLangs=null)
Constructor.
setItemMaxRank($rank)
set new max rank if needed
exportItemsAsParamsArray()
Used to export param array for /core/actions_setmoduleoptions.inc.php template Method exists only for...
getLineRank($itemKey)
get item position rank from item key
addItemsFromParamsArray($params)
Method used to test module builder conversion to this form usage.
addItemFromParams($confKey, $params)
From old Method was used to test module builder conversion to this form usage.
static generateAttributesStringFromArray($attributes)
Generate an attributes string form an input array.
generateTableOutput($editMode=false, $hideTitle=false, $title='', $cssfirstcolumn='')
generateTableOutput
reloadConfs()
Reload for each item default conf note: this will override custom configuration.
generateLineOutput($item, $editMode=false)
generateLineOutput
getCurentItemMaxRank($cache=true)
getCurentItemMaxRank
This class help to create item for class formSetup.
reloadValueFromConf()
Reload conf value from databases is an alias of loadValueFromConf.
setSaveCallBack(callable $callBack)
Set an override function for saving data.
generateInputFieldTextarea()
generate input field for textarea
setAsString()
Set type of input as string.
setValueFromPostCallBack(callable $callBack)
Set an override function for get data from post.
setAsSecureKey()
Set type of input as secure key.
generateInputFieldMultiSelect()
generateInputFieldMultiSelect
generateOutputFieldColor()
generateOutputFieldColor
generateOutputField()
generateOutputField
saveConfValue()
Save const value based on htdocs/core/actions_setmoduleoptions.inc.php.
loadValueFromConf()
load conf value from databases
setAsHtml()
Set type of input as html editor.
generateInputField()
generate input field
generateOutputFieldMultiSelect()
generateOutputFieldMultiSelect
setAsColor()
Set type of input as color.
generateInputFieldRadio()
generateInputFieldSelect
generateInputFieldEmail()
Generate default input field.
generateOutputFieldSelectUser()
generateOutputFieldSelectUser
generateOutputFieldSelect()
generateOutputFieldSelect
setAsPrice()
Set type of input as product.
setErrors($errors)
Add error.
getType()
get the type : used for old module builder setup conf style conversion and tests because this two cla...
setAsTitle()
Set type of input as a simple title.
generateInputFieldText()
Generate default input field.
setAsCategory($catType)
Set type of input as a category selector TODO add default value.
setAsSelect($fieldOptions)
Set type of input as a select list.
setAsRadio($fieldOptions)
Set type of input as a radio button.
generateInputFieldUrl()
Generate default input field.
setAsSelectUser()
Set type of input as a selection of a user from dolibarr users list.
setAsSelectBankAccount()
Set type of input as a bank account selection from dolibarr bank accounts list.
generateInputFieldPrice()
Generate default input field.
setValueFromPost()
Save const value based on htdocs/core/actions_setmoduleoptions.inc.php.
setAsMultiSelect($fieldOptions)
Set type of input as a multiselect list.
generateInputFieldCategories()
generate input field for categories
setAsProduct()
Set type of input as product.
setAsThirdpartyType()
Set type of input as thirdparty_type selector.
setAsPassword()
Set type of input as a password with dolibarr password rules apply.
generateInputFieldEmailTemplate()
generate input field for email template selector
setTypeFromTypeString($type)
set the type from string : used for old module builder setup conf style conversion and tests because ...
generateInputFieldColor()
generateInputFieldColor
generateInputFieldHtml()
generate input field for html
setAsEmail()
Set type of input as string.
__construct($confKey)
Constructor.
setAsNumber($min=null, $max=null, $step=null)
Set type of input as number.
setAsGenericPassword()
Set type of input as a generic password without dolibarr password rules (for external passwords for e...
setAsUrl()
Set type of input as string.
getNameText()
Get field name text or generate it.
generateInputFieldPassword($type='generic', $defaultmin=6, $defaultmax=50)
generate input field for a password
setAsYesNo()
Set type of input as Yes.
generateInputFieldSecureKey()
generate input field for secure key
generateInputFieldSelect()
generateInputFieldSelect
setAsEmailTemplate($templateType)
Set type of input as emailtemplate selector.
getHelpText()
Get help text or generate it.
setAsTextarea()
Set type of input as textarea.
static loadAndInstantiate($id, $db, $conf, $langs, $user)
Locate, load and instantiate a password generator/validator model by its id (the value stored in USER...
Class to manage products or services.
Class to manage Dolibarr users.
global $mysoc
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
$item fieldInputCallBack
Callback used to generate the custom HTML input field.
Definition setup.php:82
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.