30 public $items = array();
35 public $setupNotEmpty = 0;
44 protected $maxItemRank;
50 public $htmlBeforeOutputForm =
'';
56 public $htmlAfterOutputForm =
'';
62 public $htmlOutputMoreButton =
'';
69 public $formAttributes = array(
78 public $formHiddenInputs = array();
91 $this->form =
new Form($this->db);
92 $this->formAttributes[
'action'] = $_SERVER[
"PHP_SELF"];
94 $this->formHiddenInputs[
'token'] =
newToken();
95 $this->formHiddenInputs[
'action'] =
'update';
99 $this->langs = $outputLangs;
101 $this->langs = $langs;
114 if (is_array($attributes)) {
115 foreach ($attributes as $attribute => $value) {
116 if (is_array($value) || is_object($value)) {
123 return !empty($Aattr)?implode(
' ', $Aattr):
'';
135 global $hookmanager, $action, $langs;
136 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
139 'editMode' => $editMode
141 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutput', $parameters, $this, $action);
147 return $hookmanager->resPrint;
149 $out =
'<!-- Start generateOutput from FormSetup class -->';
150 $out.= $this->htmlBeforeOutputForm;
156 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
157 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
158 $out.=
'<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).
'" value="' .
dol_escape_htmltag($hiddenValue) .
'">';
167 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutputButton', $parameters, $this, $action);
173 return $hookmanager->resPrint;
174 } elseif ($editMode) {
176 $out .=
'<div class="form-setup-button-container center">';
177 $out.= $this->htmlOutputMoreButton;
178 $out .=
'<input class="button button-save" type="submit" value="' . $this->langs->trans(
"Save") .
'">';
179 $out .=
' ';
180 $out .=
'<a class="button button-cancel" type="submit" href="' . $this->formAttributes[
'action'] .
'">'.$langs->trans(
'Cancel').
'</a>';
188 $out.= $this->htmlAfterOutputForm;
202 global $hookmanager, $action;
203 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
206 'editMode' => $editMode
208 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateTableOutput', $parameters, $this, $action);
214 return $hookmanager->resPrint;
216 $out =
'<table class="noborder centpercent">';
218 $out .=
'<tr class="liste_titre">';
219 $out .=
' <td>' . $this->langs->trans(
"Parameter") .
'</td>';
220 $out .=
' <td>' . $this->langs->trans(
"Value") .
'</td>';
228 foreach ($this->items as $item) {
246 global $hookmanager, $conf;
248 $parameters = array();
249 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfFromPost', $parameters, $this);
251 $this->setErrors($hookmanager->errors);
260 if (empty($this->items)) {
266 foreach ($this->items as $item) {
267 if ($item->getType() ==
'yesno' && !empty($conf->use_javascript_ajax)) {
271 $res = $item->setValueFromPost();
273 $item->saveConfValue();
274 } elseif ($res < 0) {
282 if (empty($noMessageInUpdate)) {
287 $this->db->rollback();
288 if (empty($noMessageInUpdate)) {
306 if ($item->enabled==1) {
307 $trClass =
'oddeven';
308 if ($item->getType() ==
'title') {
309 $trClass =
'liste_titre';
312 $this->setupNotEmpty++;
313 $out.=
'<tr class="'.$trClass.
'">';
315 $out.=
'<td class="col-setup-title">';
316 $out.=
'<span id="helplink'.$item->confKey.
'" class="spanforparamtooltip">';
317 $out.= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1,
'info',
'', 0, 3,
'tootips'.$item->confKey);
324 $out.= $item->generateInputField();
326 $out.= $item->generateOutputField();
329 if (!empty($item->errors)) {
350 if (!is_array($params) || empty($params)) {
return false; }
351 foreach ($params as $confKey => $param) {
368 if (empty($confKey) || empty($params[
'type'])) {
return false; }
386 if (!empty($params[
'enabled'])) {
387 $item->enabled = $params[
'enabled'];
390 if (!empty($params[
'css'])) {
391 $item->cssClass = $params[
'css'];
394 $this->items[$item->confKey] = $item;
407 $arrayofparameters = array();
408 foreach ($this->items as $item) {
409 $arrayofparameters[$item->confKey] = array(
410 'type' => $item->getType(),
411 'enabled' => $item->enabled
415 return $arrayofparameters;
427 if (!array($this->items)) {
return false; }
428 foreach ($this->items as $item) {
429 $item->loadValueFromConf();
445 public function newItem($confKey, $targetItemKey =
false, $insertAfterTarget =
false)
450 if (empty($item->rank)) {
456 if (!empty($targetItemKey)) {
457 if (isset($this->items[$targetItemKey])) {
458 $targetItem = $this->items[$targetItemKey];
459 $item->rank = $targetItem->rank;
460 if ($targetItem->rank >= 0 && $insertAfterTarget) {
466 foreach ($this->items as $fItem) {
467 if ($item->rank <= $fItem->rank) {
468 $fItem->rank = $fItem->rank + 1;
474 $this->items[$item->confKey] = $item;
475 return $this->items[$item->confKey];
486 return uasort($this->items, array($this,
'itemSort'));
497 if (empty($this->items)) {
501 if ($cache && $this->maxItemRank > 0) {
502 return $this->maxItemRank;
505 $this->maxItemRank = 0;
506 foreach ($this->items as $item) {
507 $this->maxItemRank = max($this->maxItemRank, $item->rank);
510 return $this->maxItemRank;
522 $this->maxItemRank = max($this->maxItemRank, $rank);
534 if (!isset($this->items[$itemKey]->rank)) {
537 return $this->items[$itemKey]->rank;
550 if (empty($a->rank)) {
553 if (empty($b->rank)) {
556 if ($a->rank == $b->rank) {
559 return ($a->rank < $b->rank) ? -1 : 1;
598 public $fieldAttr = array();
601 public $fieldOverride =
false;
604 public $fieldInputOverride =
false;
607 public $fieldOutputOverride =
false;
613 public $fieldOptions = array();
624 public $errors = array();
632 protected $type =
'string';
636 public $cssClass =
'';
645 global $langs, $db, $conf, $form;
648 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
651 $this->form =
new Form($this->db);
654 $this->langs = $langs;
655 $this->entity = $conf->entity;
657 $this->confKey = $confKey;
668 if (isset($conf->global->{$this->confKey})) {
672 $this->fieldValue =
null;
684 return $this->loadValueFromConf();
697 $parameters = array();
698 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
700 $this->setErrors($hookmanager->errors);
709 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
710 return call_user_func($this->saveCallBack, $this);
714 if ($this->
type !=
'title') {
715 $result =
dolibarr_set_const($this->db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
734 $this->saveCallBack = $callBack;
744 $this->setValueFromPostCallBack = $callBack;
753 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
754 return call_user_func($this->setValueFromPostCallBack);
758 if ($this->
type !=
'title') {
759 if (preg_match(
'/category:/', $this->
type)) {
760 if (
GETPOST($this->confKey,
'int') ==
'-1') {
763 $val_const =
GETPOST($this->confKey,
'int');
765 } elseif ($this->
type ==
'multiselect') {
766 $val =
GETPOST($this->confKey,
'array');
767 if ($val && is_array($val)) {
768 $val_const = implode(
',', $val);
772 } elseif ($this->
type ==
'html') {
773 $val_const =
GETPOST($this->confKey,
'restricthtml');
775 $val_const =
GETPOST($this->confKey,
'alpha');
779 $this->fieldValue = $val_const;
793 if (!empty($this->helpText)) {
return $this->helpText; }
794 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
803 if (!empty($this->nameText)) {
return $this->nameText; }
804 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
815 if (!empty($this->fieldOverride)) {
816 return $this->fieldOverride;
819 if (!empty($this->fieldInputOverride)) {
820 return $this->fieldInputOverride;
824 if (is_null($this->fieldValue)) {
825 $this->fieldValue = $this->defaultFieldValue;
829 $this->fieldAttr[
'name'] = $this->confKey;
830 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
831 $this->fieldAttr[
'value'] = $this->fieldValue;
835 if ($this->
type ==
'title') {
836 $out.= $this->generateOutputField();
837 } elseif ($this->
type ==
'multiselect') {
838 $out.= $this->generateInputFieldMultiSelect();
839 } elseif ($this->
type ==
'select') {
840 $out.= $this->generateInputFieldSelect();
841 } elseif ($this->
type ==
'selectUser') {
842 $out.= $this->generateInputFieldSelectUser();
843 } elseif ($this->
type ==
'textarea') {
844 $out.= $this->generateInputFieldTextarea();
845 } elseif ($this->
type==
'html') {
846 $out.= $this->generateInputFieldHtml();
847 } elseif ($this->
type==
'color') {
848 $out.= $this->generateInputFieldColor();
849 } elseif ($this->
type ==
'yesno') {
850 if (!empty($conf->use_javascript_ajax)) {
853 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
855 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
856 $out.= $this->generateInputFieldEmailTemplate();
857 } elseif (preg_match(
'/category:/', $this->
type)) {
858 $out.=$this->generateInputFieldCategories();
859 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
860 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
862 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
863 } elseif ($this->
type ==
'securekey') {
864 $out.= $this->generateInputFieldSecureKey();
865 } elseif ($this->
type ==
'product') {
867 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
868 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
871 $out.= $this->generateInputFieldText();
883 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
884 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
893 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
895 $out.=
"</textarea>\n";
906 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
907 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false,
isModEnabled(
'fckeditor'), ROWS_5,
'90%');
908 return $doleditor->Create(1);
918 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
919 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
922 $tmp = explode(
':', $this->
type);
923 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
924 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
936 if (preg_match(
'/emailtemplate:/', $this->
type)) {
937 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
938 $formmail =
new FormMail($this->db);
940 $tmp = explode(
':', $this->
type);
941 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
942 $arrayOfMessageName = array();
943 if (is_array($formmail->lines_model)) {
944 foreach ($formmail->lines_model as $modelMail) {
946 if (!empty($arrayOfMessageName[$modelMail->label])) {
947 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
950 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
953 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
967 $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">';
968 if (!empty($conf->use_javascript_ajax)) {
969 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
973 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
985 $TSelected = array();
986 if ($this->fieldValue) {
987 $TSelected = explode(
',', $this->fieldValue);
990 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
999 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1007 return $this->form->select_dolusers($this->fieldValue, $this->confKey);
1033 $this->
type = $type;
1046 if (is_array($errors)) {
1047 if (!empty($errors)) {
1048 foreach ($errors as $error) {
1049 $this->setErrors($error);
1052 } elseif (!empty($errors)) {
1053 $this->errors[] = $errors;
1064 global $conf, $user, $langs;
1066 if (!empty($this->fieldOverride)) {
1067 return $this->fieldOverride;
1070 if (!empty($this->fieldOutputOverride)) {
1071 return $this->fieldOutputOverride;
1076 if ($this->
type ==
'title') {
1078 } elseif ($this->
type ==
'textarea') {
1080 } elseif ($this->
type ==
'multiselect') {
1081 $out.= $this->generateOutputFieldMultiSelect();
1082 } elseif ($this->
type ==
'select') {
1083 $out.= $this->generateOutputFieldSelect();
1084 } elseif ($this->
type ==
'selectUser') {
1085 $out.= $this->generateOutputFieldSelectUser();
1086 } elseif ($this->
type==
'html') {
1087 $out.= $this->fieldValue;
1088 } elseif ($this->
type==
'color') {
1089 $out.= $this->generateOutputFieldColor();
1090 } elseif ($this->
type ==
'yesno') {
1091 if (!empty($conf->use_javascript_ajax)) {
1094 if ($this->fieldValue == 1) {
1095 $out.= $langs->trans(
'yes');
1097 $out.= $langs->trans(
'no');
1100 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1101 if ($this->fieldValue > 0) {
1102 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1103 $formmail =
new FormMail($this->db);
1105 $tmp = explode(
':', $this->
type);
1107 $template = $formmail->getEMailTemplate($this->db, $tmp[1], $user, $this->langs, $this->fieldValue);
1108 if (is_numeric($template) && $template < 0) {
1109 $this->setErrors($formmail->errors);
1111 $out.= $this->langs->trans($template->label);
1113 } elseif (preg_match(
'/category:/', $this->
type)) {
1114 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1116 $result = $c->fetch($this->fieldValue);
1118 $this->setErrors($c->errors);
1120 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1122 foreach ($ways as $way) {
1123 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1125 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1126 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1127 if ($this->fieldValue==2) {
1128 $out.= $this->langs->trans(
"Prospect");
1129 } elseif ($this->fieldValue==3) {
1130 $out.= $this->langs->trans(
"ProspectCustomer");
1131 } elseif ($this->fieldValue==1) {
1132 $out.= $this->langs->trans(
"Customer");
1133 } elseif ($this->fieldValue==0) {
1134 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1136 } elseif ($this->
type ==
'product') {
1137 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1139 $product =
new Product($this->db);
1140 $resprod = $product->fetch($this->fieldValue);
1142 $out.= $product->ref;
1143 } elseif ($resprod < 0) {
1144 $this->setErrors($product->errors);
1147 $out.= $this->fieldValue;
1162 $TSelected = array();
1163 if (!empty($this->fieldValue)) {
1164 $TSelected = explode(
',', $this->fieldValue);
1167 if (!empty($TSelected)) {
1168 foreach ($TSelected as $selected) {
1169 if (!empty($this->fieldOptions[$selected])) {
1170 $outPut.=
dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1184 $this->fieldAttr[
'disabled']=
null;
1185 return $this->generateInputField();
1194 $this->fieldAttr[
'type']=
'color';
1195 return $this->generateInputFieldText();
1206 if (!empty($this->fieldOptions[$this->fieldValue])) {
1207 $outPut = $this->fieldOptions[$this->fieldValue];
1221 $user =
new User($this->db);
1222 $user->fetch($this->fieldValue);
1223 $outPut = $user->firstname .
" " . $user->lastname;
1238 $this->
type =
'string';
1249 $this->
type =
'color';
1260 $this->
type =
'textarea';
1271 $this->
type =
'html';
1283 $this->
type =
'emailtemplate:'.$templateType;
1294 $this->
type =
'thirdparty_type';
1305 $this->
type =
'yesno';
1316 $this->
type =
'securekey';
1327 $this->
type =
'product';
1340 $this->
type =
'category:'.$catType;
1351 $this->
type =
'title';
1364 if (is_array($fieldOptions)) {
1365 $this->fieldOptions = $fieldOptions;
1368 $this->
type =
'multiselect';
1380 if (is_array($fieldOptions)) {
1381 $this->fieldOptions = $fieldOptions;
1384 $this->
type =
'select';
1395 $this->
type =
'selectUser';