33 public $items = array();
38 public $setupNotEmpty = 0;
47 protected $maxItemRank;
53 public $htmlBeforeOutputForm =
'';
59 public $htmlAfterOutputForm =
'';
65 public $htmlOutputMoreButton =
'';
72 public $formAttributes = array(
81 public $formHiddenInputs = array();
95 $this->form =
new Form($this->db);
96 $this->formAttributes[
'action'] = $_SERVER[
"PHP_SELF"];
98 $this->formHiddenInputs[
'token'] = newToken();
99 $this->formHiddenInputs[
'action'] =
'update';
101 $this->entity = (is_null($this->entity) ? $conf->entity : $this->entity);
104 $this->langs = $outputLangs;
106 $this->langs = $langs;
119 if (is_array($attributes)) {
120 foreach ($attributes as $attribute => $value) {
121 if (is_array($value) || is_object($value)) {
128 return !empty($Aattr)?implode(
' ', $Aattr):
'';
140 global $hookmanager, $action, $langs;
141 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
144 'editMode' => $editMode
146 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutput', $parameters, $this, $action);
152 return $hookmanager->resPrint;
154 $out =
'<!-- Start generateOutput from FormSetup class -->';
155 $out.= $this->htmlBeforeOutputForm;
161 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
162 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
163 $out.=
'<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).
'" value="' .
dol_escape_htmltag($hiddenValue) .
'">';
172 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutputButton', $parameters, $this, $action);
178 return $hookmanager->resPrint;
179 } elseif ($editMode) {
181 $out .=
'<div class="form-setup-button-container center">';
182 $out.= $this->htmlOutputMoreButton;
183 $out .=
'<input class="button button-save" type="submit" value="' . $this->langs->trans(
"Save") .
'">';
184 $out .=
' ';
185 $out .=
'<a class="button button-cancel" type="submit" href="' . $this->formAttributes[
'action'] .
'">'.$langs->trans(
'Cancel').
'</a>';
193 $out.= $this->htmlAfterOutputForm;
207 global $hookmanager, $action;
208 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
211 'editMode' => $editMode
213 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateTableOutput', $parameters, $this, $action);
219 return $hookmanager->resPrint;
221 $out =
'<table class="noborder centpercent">';
223 $out .=
'<tr class="liste_titre">';
224 $out .=
' <td>' . $this->langs->trans(
"Parameter") .
'</td>';
225 $out .=
' <td>' . $this->langs->trans(
"Value") .
'</td>';
233 foreach ($this->items as $item) {
251 global $hookmanager, $conf;
253 $parameters = array();
254 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfFromPost', $parameters, $this);
256 $this->setErrors($hookmanager->errors);
265 if (empty($this->items)) {
271 foreach ($this->items as $item) {
272 if ($item->getType() ==
'yesno' && !empty($conf->use_javascript_ajax)) {
276 $res = $item->setValueFromPost();
278 $item->saveConfValue();
279 } elseif ($res < 0) {
287 if (empty($noMessageInUpdate)) {
292 $this->db->rollback();
293 if (empty($noMessageInUpdate)) {
311 if ($item->enabled==1) {
312 $trClass =
'oddeven';
313 if ($item->getType() ==
'title') {
314 $trClass =
'liste_titre';
317 $this->setupNotEmpty++;
318 $out.=
'<tr class="'.$trClass.
'">';
320 $out.=
'<td class="col-setup-title">';
321 $out.=
'<span id="helplink'.$item->confKey.
'" class="spanforparamtooltip">';
322 $out.= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1,
'info',
'', 0, 3,
'tootips'.$item->confKey);
329 $out.= $item->generateInputField();
331 $out.= $item->generateOutputField();
334 if (!empty($item->errors)) {
355 if (!is_array($params) || empty($params)) {
return false; }
356 foreach ($params as $confKey => $param) {
373 if (empty($confKey) || empty($params[
'type'])) {
return false; }
389 $item->setTypeFromTypeString($params['type']);
391 if (!empty($params[
'enabled'])) {
392 $item->enabled = $params[
'enabled'];
395 if (!empty($params[
'css'])) {
396 $item->cssClass = $params[
'css'];
399 $this->items[$item->confKey] = $item;
412 $arrayofparameters = array();
413 foreach ($this->items as $item) {
414 $arrayofparameters[$item->confKey] = array(
415 'type' => $item->getType(),
416 'enabled' => $item->enabled
420 return $arrayofparameters;
432 if (!array($this->items)) {
return false; }
433 foreach ($this->items as $item) {
434 $item->loadValueFromConf();
450 public function newItem($confKey, $targetItemKey =
false, $insertAfterTarget =
false)
454 $item->entity = $this->entity;
457 if (empty($item->rank)) {
463 if (!empty($targetItemKey)) {
464 if (isset($this->items[$targetItemKey])) {
465 $targetItem = $this->items[$targetItemKey];
466 $item->rank = $targetItem->rank;
467 if ($targetItem->rank >= 0 && $insertAfterTarget) {
473 foreach ($this->items as $fItem) {
474 if ($item->rank <= $fItem->rank) {
475 $fItem->rank = $fItem->rank + 1;
481 $this->items[$item->confKey] = $item;
482 return $this->items[$item->confKey];
493 return uasort($this->items, array($this,
'itemSort'));
504 if (empty($this->items)) {
508 if ($cache && $this->maxItemRank > 0) {
509 return $this->maxItemRank;
512 $this->maxItemRank = 0;
513 foreach ($this->items as $item) {
514 $this->maxItemRank = max($this->maxItemRank, $item->rank);
517 return $this->maxItemRank;
529 $this->maxItemRank = max($this->maxItemRank, $rank);
541 if (!isset($this->items[$itemKey]->rank)) {
544 return $this->items[$itemKey]->rank;
557 if (empty($a->rank)) {
560 if (empty($b->rank)) {
563 if ($a->rank == $b->rank) {
566 return ($a->rank < $b->rank) ? -1 : 1;
605 public $fieldAttr = array();
608 public $fieldOverride =
false;
611 public $fieldInputOverride =
false;
614 public $fieldOutputOverride =
false;
620 public $fieldOptions = array();
631 public $errors = array();
639 protected $type =
'string';
643 public $cssClass =
'';
652 global $langs, $db, $conf, $form;
655 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
658 $this->form =
new Form($this->db);
661 $this->langs = $langs;
662 $this->entity = (is_null($this->entity) ? $conf->entity : ((int) $this->entity));
664 $this->confKey = $confKey;
675 if (isset($conf->global->{$this->confKey})) {
679 $this->fieldValue =
null;
691 return $this->loadValueFromConf();
704 $parameters = array();
705 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
707 $this->setErrors($hookmanager->errors);
716 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
717 return call_user_func($this->saveCallBack, $this);
721 if ($this->
type !=
'title') {
722 $result =
dolibarr_set_const($this->db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
741 $this->saveCallBack = $callBack;
751 $this->setValueFromPostCallBack = $callBack;
760 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
761 return call_user_func($this->setValueFromPostCallBack);
765 if ($this->
type !=
'title') {
766 if (preg_match(
'/category:/', $this->
type)) {
767 if (
GETPOST($this->confKey,
'int') ==
'-1') {
770 $val_const =
GETPOST($this->confKey,
'int');
772 } elseif ($this->
type ==
'multiselect') {
773 $val =
GETPOST($this->confKey,
'array');
774 if ($val && is_array($val)) {
775 $val_const = implode(
',', $val);
779 } elseif ($this->
type ==
'html') {
780 $val_const =
GETPOST($this->confKey,
'restricthtml');
782 $val_const =
GETPOST($this->confKey,
'alpha');
786 $this->fieldValue = $val_const;
800 if (!empty($this->helpText)) {
return $this->helpText; }
801 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
810 if (!empty($this->nameText)) {
return $this->nameText; }
811 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
822 if (!empty($this->fieldOverride)) {
823 return $this->fieldOverride;
826 if (!empty($this->fieldInputOverride)) {
827 return $this->fieldInputOverride;
831 if (is_null($this->fieldValue)) {
832 $this->fieldValue = $this->defaultFieldValue;
836 $this->fieldAttr[
'name'] = $this->confKey;
837 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
838 $this->fieldAttr[
'value'] = $this->fieldValue;
842 if ($this->
type ==
'title') {
843 $out.= $this->generateOutputField();
844 } elseif ($this->
type ==
'multiselect') {
845 $out.= $this->generateInputFieldMultiSelect();
846 } elseif ($this->
type ==
'select') {
847 $out.= $this->generateInputFieldSelect();
848 } elseif ($this->
type ==
'selectUser') {
849 $out.= $this->generateInputFieldSelectUser();
850 } elseif ($this->
type ==
'textarea') {
851 $out.= $this->generateInputFieldTextarea();
852 } elseif ($this->
type==
'html') {
853 $out.= $this->generateInputFieldHtml();
854 } elseif ($this->
type==
'color') {
855 $out.= $this->generateInputFieldColor();
856 } elseif ($this->
type ==
'yesno') {
857 if (!empty($conf->use_javascript_ajax)) {
858 $out.= ajax_constantonoff($this->confKey);
860 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
862 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
863 $out.= $this->generateInputFieldEmailTemplate();
864 } elseif (preg_match(
'/category:/', $this->
type)) {
865 $out.=$this->generateInputFieldCategories();
866 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
867 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
869 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
870 } elseif ($this->
type ==
'securekey') {
871 $out.= $this->generateInputFieldSecureKey();
872 } elseif ($this->
type ==
'product') {
873 if (isModEnabled(
"product") || isModEnabled(
"service")) {
874 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
875 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
878 $out.= $this->generateInputFieldText();
890 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
891 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
900 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
902 $out.=
"</textarea>\n";
913 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
914 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, isModEnabled(
'fckeditor'), ROWS_5,
'90%');
915 return $doleditor->Create(1);
925 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
926 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
929 $tmp = explode(
':', $this->
type);
930 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
931 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
943 if (preg_match(
'/emailtemplate:/', $this->
type)) {
944 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
945 $formmail =
new FormMail($this->db);
947 $tmp = explode(
':', $this->
type);
948 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
949 $arrayOfMessageName = array();
950 if (is_array($formmail->lines_model)) {
951 foreach ($formmail->lines_model as $modelMail) {
953 if (!empty($arrayOfMessageName[$modelMail->label])) {
954 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
957 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
960 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
974 $out =
'<input required="required" type="text" class="flat" id="'.$this->confKey.
'" name="'.$this->confKey.
'" value="'.(
GETPOST($this->confKey,
'alpha') ?
GETPOST($this->confKey,
'alpha') : $this->fieldValue).
'" size="40">';
975 if (!empty($conf->use_javascript_ajax)) {
976 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
980 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
992 $TSelected = array();
993 if ($this->fieldValue) {
994 $TSelected = explode(
',', $this->fieldValue);
997 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
1006 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1014 return $this->form->select_dolusers($this->fieldValue, $this->confKey);
1040 $this->
type = $type;
1053 if (is_array($errors)) {
1054 if (!empty($errors)) {
1055 foreach ($errors as $error) {
1056 $this->setErrors($error);
1059 } elseif (!empty($errors)) {
1060 $this->errors[] = $errors;
1071 global $conf, $user, $langs;
1073 if (!empty($this->fieldOverride)) {
1074 return $this->fieldOverride;
1077 if (!empty($this->fieldOutputOverride)) {
1078 return $this->fieldOutputOverride;
1083 if ($this->
type ==
'title') {
1085 } elseif ($this->
type ==
'textarea') {
1087 } elseif ($this->
type ==
'multiselect') {
1088 $out.= $this->generateOutputFieldMultiSelect();
1089 } elseif ($this->
type ==
'select') {
1090 $out.= $this->generateOutputFieldSelect();
1091 } elseif ($this->
type ==
'selectUser') {
1092 $out.= $this->generateOutputFieldSelectUser();
1093 } elseif ($this->
type==
'html') {
1094 $out.= $this->fieldValue;
1095 } elseif ($this->
type==
'color') {
1096 $out.= $this->generateOutputFieldColor();
1097 } elseif ($this->
type ==
'yesno') {
1098 if (!empty($conf->use_javascript_ajax)) {
1099 $out.= ajax_constantonoff($this->confKey, array(), $this->entity);
1101 if ($this->fieldValue == 1) {
1102 $out.= $langs->trans(
'yes');
1104 $out.= $langs->trans(
'no');
1107 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1108 if ($this->fieldValue > 0) {
1109 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1110 $formmail =
new FormMail($this->db);
1112 $tmp = explode(
':', $this->
type);
1114 $template = $formmail->getEMailTemplate($this->db, $tmp[1], $user, $this->langs, $this->fieldValue);
1115 if (is_numeric($template) && $template < 0) {
1116 $this->setErrors($formmail->errors);
1118 $out.= $this->langs->trans($template->label);
1120 } elseif (preg_match(
'/category:/', $this->
type)) {
1121 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1123 $result = $c->fetch($this->fieldValue);
1125 $this->setErrors($c->errors);
1127 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1129 foreach ($ways as $way) {
1130 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1132 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1133 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1134 if ($this->fieldValue==2) {
1135 $out.= $this->langs->trans(
"Prospect");
1136 } elseif ($this->fieldValue==3) {
1137 $out.= $this->langs->trans(
"ProspectCustomer");
1138 } elseif ($this->fieldValue==1) {
1139 $out.= $this->langs->trans(
"Customer");
1140 } elseif ($this->fieldValue==0) {
1141 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1143 } elseif ($this->
type ==
'product') {
1144 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1146 $product =
new Product($this->db);
1147 $resprod = $product->fetch($this->fieldValue);
1149 $out.= $product->ref;
1150 } elseif ($resprod < 0) {
1151 $this->setErrors($product->errors);
1154 $out.= $this->fieldValue;
1169 $TSelected = array();
1170 if (!empty($this->fieldValue)) {
1171 $TSelected = explode(
',', $this->fieldValue);
1174 if (!empty($TSelected)) {
1175 foreach ($TSelected as $selected) {
1176 if (!empty($this->fieldOptions[$selected])) {
1177 $outPut.= dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1191 $this->fieldAttr[
'disabled']=
null;
1192 return $this->generateInputField();
1201 $this->fieldAttr[
'type']=
'color';
1202 return $this->generateInputFieldText();
1213 if (!empty($this->fieldOptions[$this->fieldValue])) {
1214 $outPut = $this->fieldOptions[$this->fieldValue];
1228 $user =
new User($this->db);
1229 $user->fetch($this->fieldValue);
1230 $outPut = $user->firstname .
" " . $user->lastname;
1245 $this->
type =
'string';
1256 $this->
type =
'color';
1267 $this->
type =
'textarea';
1278 $this->
type =
'html';
1290 $this->
type =
'emailtemplate:'.$templateType;
1301 $this->
type =
'thirdparty_type';
1312 $this->
type =
'yesno';
1323 $this->
type =
'securekey';
1334 $this->
type =
'product';
1347 $this->
type =
'category:'.$catType;
1358 $this->
type =
'title';
1371 if (is_array($fieldOptions)) {
1372 $this->fieldOptions = $fieldOptions;
1375 $this->
type =
'multiselect';
1387 if (is_array($fieldOptions)) {
1388 $this->fieldOptions = $fieldOptions;
1391 $this->
type =
'select';
1402 $this->
type =
'selectUser';
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).
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage products or services.
Class to manage Dolibarr users.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript to autoset a generated password using default module into a HTML element.