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) {
367 if (empty($confKey) || empty($params[
'type'])) {
return false; }
385 if (!empty($params[
'enabled'])) {
386 $item->enabled = $params[
'enabled'];
389 if (!empty($params[
'css'])) {
390 $item->cssClass = $params[
'css'];
393 $this->items[$item->confKey] = $item;
406 $arrayofparameters = array();
407 foreach ($this->items as $item) {
408 $arrayofparameters[$item->confKey] = array(
409 'type' => $item->getType(),
410 'enabled' => $item->enabled
414 return $arrayofparameters;
426 if (!array($this->items)) {
return false; }
427 foreach ($this->items as $item) {
428 $item->loadValueFromConf();
444 public function newItem($confKey, $targetItemKey =
false, $insertAfterTarget =
false)
449 if (empty($item->rank)) {
455 if (!empty($targetItemKey)) {
456 if (isset($this->items[$targetItemKey])) {
457 $targetItem = $this->items[$targetItemKey];
458 $item->rank = $targetItem->rank;
459 if ($targetItem->rank >= 0 && $insertAfterTarget) {
465 foreach ($this->items as $fItem) {
466 if ($item->rank <= $fItem->rank) {
467 $fItem->rank = $fItem->rank + 1;
473 $this->items[$item->confKey] = $item;
474 return $this->items[$item->confKey];
485 return uasort($this->items, array($this,
'itemSort'));
496 if (empty($this->items)) {
500 if ($cache && $this->maxItemRank > 0) {
501 return $this->maxItemRank;
504 $this->maxItemRank = 0;
505 foreach ($this->items as $item) {
506 $this->maxItemRank = max($this->maxItemRank, $item->rank);
509 return $this->maxItemRank;
521 $this->maxItemRank = max($this->maxItemRank, $rank);
533 if (!isset($this->items[$itemKey]->rank)) {
536 return $this->items[$itemKey]->rank;
549 if (empty($a->rank)) {
552 if (empty($b->rank)) {
555 if ($a->rank == $b->rank) {
558 return ($a->rank < $b->rank) ? -1 : 1;
597 public $fieldAttr = array();
600 public $fieldOverride =
false;
603 public $fieldInputOverride =
false;
606 public $fieldOutputOverride =
false;
612 public $fieldOptions = array();
623 public $errors = array();
631 protected $type =
'string';
635 public $cssClass =
'';
644 global $langs, $db, $conf, $form;
647 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
650 $this->form =
new Form($this->
db);
653 $this->langs = $langs;
654 $this->entity = $conf->entity;
656 $this->confKey = $confKey;
667 if (isset($conf->global->{$this->confKey})) {
668 $this->fieldValue = $conf->global->{$this->confKey};
671 $this->fieldValue =
null;
683 return $this->loadValueFromConf();
695 $parameters = array();
696 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
698 $this->setErrors($hookmanager->errors);
707 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
708 return call_user_func($this->saveCallBack, $this);
712 if ($this->
type !=
'title') {
713 $result =
dolibarr_set_const($this->
db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
729 $this->saveCallBack = $callBack;
739 $this->setValueFromPostCallBack = $callBack;
748 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
749 return call_user_func($this->setValueFromPostCallBack);
753 if ($this->
type !=
'title') {
754 if (preg_match(
'/category:/', $this->
type)) {
755 if (
GETPOST($this->confKey,
'int') ==
'-1') {
758 $val_const =
GETPOST($this->confKey,
'int');
760 } elseif ($this->
type ==
'multiselect') {
761 $val =
GETPOST($this->confKey,
'array');
762 if ($val && is_array($val)) {
763 $val_const = implode(
',', $val);
767 } elseif ($this->
type ==
'html') {
768 $val_const =
GETPOST($this->confKey,
'restricthtml');
770 $val_const =
GETPOST($this->confKey,
'alpha');
774 $this->fieldValue = $val_const;
788 if (!empty($this->helpText)) {
return $this->helpText; }
789 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
798 if (!empty($this->nameText)) {
return $this->nameText; }
799 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
810 if (!empty($this->fieldOverride)) {
811 return $this->fieldOverride;
814 if (!empty($this->fieldInputOverride)) {
815 return $this->fieldInputOverride;
819 if (is_null($this->fieldValue)) {
820 $this->fieldValue = $this->defaultFieldValue;
824 $this->fieldAttr[
'name'] = $this->confKey;
825 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
826 $this->fieldAttr[
'value'] = $this->fieldValue;
830 if ($this->
type ==
'title') {
831 $out.= $this->generateOutputField();
832 } elseif ($this->
type ==
'multiselect') {
833 $out.= $this->generateInputFieldMultiSelect();
834 } elseif ($this->
type ==
'select') {
835 $out.= $this->generateInputFieldSelect();
836 } elseif ($this->
type ==
'textarea') {
837 $out.= $this->generateInputFieldTextarea();
838 } elseif ($this->
type==
'html') {
839 $out.= $this->generateInputFieldHtml();
840 } elseif ($this->
type==
'color') {
841 $out.= $this->generateInputFieldColor();
842 } elseif ($this->
type ==
'yesno') {
843 if (!empty($conf->use_javascript_ajax)) {
846 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
848 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
849 $out.= $this->generateInputFieldEmailTemplate();
850 } elseif (preg_match(
'/category:/', $this->
type)) {
851 $out.=$this->generateInputFieldCategories();
852 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
853 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
855 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
856 } elseif ($this->
type ==
'securekey') {
857 $out.= $this->generateInputFieldSecureKey();
858 } elseif ($this->
type ==
'product') {
860 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
861 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
864 $out.= $this->generateInputFieldText();
876 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
877 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
886 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
888 $out.=
"</textarea>\n";
899 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
900 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, $conf->fckeditor->enabled, ROWS_5,
'90%');
901 return $doleditor->Create(1);
911 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
912 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
915 $tmp = explode(
':', $this->
type);
916 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
917 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
929 if (preg_match(
'/emailtemplate:/', $this->
type)) {
930 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
933 $tmp = explode(
':', $this->
type);
934 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
935 $arrayOfMessageName = array();
936 if (is_array($formmail->lines_model)) {
937 foreach ($formmail->lines_model as $modelMail) {
939 if (!empty($arrayOfMessageName[$modelMail->label])) {
940 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
943 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
946 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
960 $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">';
961 if (!empty($conf->use_javascript_ajax)) {
962 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
966 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
978 $TSelected = array();
979 if ($this->fieldValue) {
980 $TSelected = explode(
',', $this->fieldValue);
983 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
992 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1017 $this->
type = $type;
1028 if (is_array($errors)) {
1029 if (!empty($errors)) {
1030 foreach ($errors as $error) {
1031 $this->setErrors($error);
1034 } elseif (!empty($errors)) {
1035 $this->errors[] = $errors;
1044 global $conf, $user, $langs;
1046 if (!empty($this->fieldOverride)) {
1047 return $this->fieldOverride;
1050 if (!empty($this->fieldOutputOverride)) {
1051 return $this->fieldOutputOverride;
1056 if ($this->
type ==
'title') {
1058 } elseif ($this->
type ==
'textarea') {
1060 } elseif ($this->
type ==
'multiselect') {
1061 $out.= $this->generateOutputFieldMultiSelect();
1062 } elseif ($this->
type ==
'select') {
1063 $out.= $this->generateOutputFieldSelect();
1064 } elseif ($this->
type==
'html') {
1065 $out.= $this->fieldValue;
1066 } elseif ($this->
type==
'color') {
1067 $out.= $this->generateOutputFieldColor();
1068 } elseif ($this->
type ==
'yesno') {
1069 if (!empty($conf->use_javascript_ajax)) {
1072 if ($this->fieldValue == 1) {
1073 $out.= $langs->trans(
'yes');
1075 $out.= $langs->trans(
'no');
1078 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1079 if ($this->fieldValue > 0) {
1080 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1083 $tmp = explode(
':', $this->
type);
1085 $template = $formmail->getEMailTemplate($this->
db, $tmp[1], $user, $this->langs, $this->fieldValue);
1086 if (is_numeric($template) && $template < 0) {
1087 $this->setErrors($formmail->errors);
1089 $out.= $this->langs->trans($template->label);
1091 } elseif (preg_match(
'/category:/', $this->
type)) {
1092 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1094 $result = $c->fetch($this->fieldValue);
1096 $this->setErrors($c->errors);
1098 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1100 foreach ($ways as $way) {
1101 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1103 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1104 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1105 if ($this->fieldValue==2) {
1106 $out.= $this->langs->trans(
"Prospect");
1107 } elseif ($this->fieldValue==3) {
1108 $out.= $this->langs->trans(
"ProspectCustomer");
1109 } elseif ($this->fieldValue==1) {
1110 $out.= $this->langs->trans(
"Customer");
1111 } elseif ($this->fieldValue==0) {
1112 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1114 } elseif ($this->
type ==
'product') {
1115 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1118 $resprod = $product->fetch($this->fieldValue);
1120 $out.= $product->ref;
1121 } elseif ($resprod < 0) {
1122 $this->setErrors($product->errors);
1125 $out.= $this->fieldValue;
1138 $TSelected = array();
1139 if (!empty($this->fieldValue)) {
1140 $TSelected = explode(
',', $this->fieldValue);
1143 if (!empty($TSelected)) {
1144 foreach ($TSelected as $selected) {
1145 if (!empty($this->fieldOptions[$selected])) {
1146 $outPut.=
dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1158 $this->fieldAttr[
'disabled']=
null;
1159 return $this->generateInputField();
1166 $this->fieldAttr[
'type']=
'color';
1167 return $this->generateInputFieldText();
1176 if (!empty($this->fieldOptions[$this->fieldValue])) {
1177 $outPut = $this->fieldOptions[$this->fieldValue];
1193 $this->
type =
'string';
1203 $this->
type =
'color';
1213 $this->
type =
'textarea';
1223 $this->
type =
'html';
1234 $this->
type =
'emailtemplate:'.$templateType;
1244 $this->
type =
'thirdparty_type';
1254 $this->
type =
'yesno';
1264 $this->
type =
'securekey';
1274 $this->
type =
'product';
1286 $this->
type =
'category:'.$catType;
1297 $this->
type =
'title';
1310 if (is_array($fieldOptions)) {
1311 $this->fieldOptions = $fieldOptions;
1314 $this->
type =
'multiselect';
1326 if (is_array($fieldOptions)) {
1327 $this->fieldOptions = $fieldOptions;
1330 $this->
type =
'select';