31 public $items = array();
36 public $setupNotEmpty = 0;
45 protected $maxItemRank;
51 public $htmlBeforeOutputForm =
'';
57 public $htmlAfterOutputForm =
'';
63 public $htmlOutputMoreButton =
'';
70 public $formAttributes = array(
79 public $formHiddenInputs = array();
92 $this->form =
new Form($this->
db);
93 $this->formAttributes[
'action'] = $_SERVER[
"PHP_SELF"];
95 $this->formHiddenInputs[
'token'] =
newToken();
96 $this->formHiddenInputs[
'action'] =
'update';
100 $this->langs = $outputLangs;
102 $this->langs = $langs;
115 if (is_array($attributes)) {
116 foreach ($attributes as $attribute => $value) {
117 if (is_array($value) || is_object($value)) {
124 return !empty($Aattr)?implode(
' ', $Aattr):
'';
136 global $hookmanager, $action, $langs;
137 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
140 'editMode' => $editMode
142 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutput', $parameters, $this, $action);
148 return $hookmanager->resPrint;
150 $out =
'<!-- Start generateOutput from FormSetup class -->';
151 $out.= $this->htmlBeforeOutputForm;
157 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
158 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
159 $out.=
'<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).
'" value="' .
dol_escape_htmltag($hiddenValue) .
'">';
168 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutputButton', $parameters, $this, $action);
174 return $hookmanager->resPrint;
175 } elseif ($editMode) {
177 $out .=
'<div class="form-setup-button-container center">';
178 $out.= $this->htmlOutputMoreButton;
179 $out .=
'<input class="button button-save" type="submit" value="' . $this->langs->trans(
"Save") .
'">';
180 $out .=
' ';
181 $out .=
'<a class="button button-cancel" type="submit" href="' . $this->formAttributes[
'action'] .
'">'.$langs->trans(
'Cancel').
'</a>';
189 $out.= $this->htmlAfterOutputForm;
203 global $hookmanager, $action;
204 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
207 'editMode' => $editMode
209 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateTableOutput', $parameters, $this, $action);
215 return $hookmanager->resPrint;
217 $out =
'<table class="noborder centpercent">';
219 $out .=
'<tr class="liste_titre">';
220 $out .=
' <td>' . $this->langs->trans(
"Parameter") .
'</td>';
221 $out .=
' <td>' . $this->langs->trans(
"Value") .
'</td>';
229 foreach ($this->items as $item) {
249 $parameters = array();
250 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfFromPost', $parameters, $this);
252 $this->setErrors($hookmanager->errors);
261 if (empty($this->items)) {
267 foreach ($this->items as $item) {
268 $res = $item->setValueFromPost();
270 $item->saveConfValue();
271 } elseif ($res < 0) {
279 if (empty($noMessageInUpdate)) {
284 $this->
db->rollback();
285 if (empty($noMessageInUpdate)) {
303 if ($item->enabled==1) {
304 $trClass =
'oddeven';
305 if ($item->getType() ==
'title') {
306 $trClass =
'liste_titre';
309 $this->setupNotEmpty++;
310 $out.=
'<tr class="'.$trClass.
'">';
312 $out.=
'<td class="col-setup-title">';
313 $out.=
'<span id="helplink'.$item->confKey.
'" class="spanforparamtooltip">';
314 $out.= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1,
'info',
'', 0, 3,
'tootips'.$item->confKey);
321 $out.= $item->generateInputField();
323 $out.= $item->generateOutputField();
326 if (!empty($item->errors)) {
347 if (!is_array($params) || empty($params)) {
return false; }
348 foreach ($params as $confKey => $param) {
364 if (empty($confKey) || empty($params[
'type'])) {
return false; }
382 if (!empty($params[
'enabled'])) {
383 $item->enabled = $params[
'enabled'];
386 if (!empty($params[
'css'])) {
387 $item->cssClass = $params[
'css'];
390 $this->items[$item->confKey] = $item;
403 $arrayofparameters = array();
404 foreach ($this->items as $item) {
405 $arrayofparameters[$item->confKey] = array(
406 'type' => $item->getType(),
407 'enabled' => $item->enabled
411 return $arrayofparameters;
423 if (!array($this->items)) {
return false; }
424 foreach ($this->items as $item) {
425 $item->loadValueFromConf();
441 public function newItem($confKey, $targetItemKey =
false, $insertAfterTarget =
false)
446 if (empty($item->rank)) {
452 if (!empty($targetItemKey)) {
453 if (isset($this->items[$targetItemKey])) {
454 $targetItem = $this->items[$targetItemKey];
455 $item->rank = $targetItem->rank;
456 if ($targetItem->rank >= 0 && $insertAfterTarget) {
462 foreach ($this->items as $fItem) {
463 if ($item->rank <= $fItem->rank) {
464 $fItem->rank = $fItem->rank + 1;
470 $this->items[$item->confKey] = $item;
471 return $this->items[$item->confKey];
482 return uasort($this->items, array($this,
'itemSort'));
493 if (empty($this->items)) {
497 if ($cache && $this->maxItemRank > 0) {
498 return $this->maxItemRank;
501 $this->maxItemRank = 0;
502 foreach ($this->items as $item) {
503 $this->maxItemRank = max($this->maxItemRank, $item->rank);
506 return $this->maxItemRank;
518 $this->maxItemRank = max($this->maxItemRank, $rank);
530 if (!isset($this->items[$itemKey]->rank)) {
533 return $this->items[$itemKey]->rank;
546 if (empty($a->rank)) {
549 if (empty($b->rank)) {
552 if ($a->rank == $b->rank) {
555 return ($a->rank < $b->rank) ? -1 : 1;
594 public $fieldAttr = array();
597 public $fieldOverride =
false;
600 public $fieldInputOverride =
false;
603 public $fieldOutputOverride =
false;
609 public $fieldOptions = array();
620 public $errors = array();
628 protected $type =
'string';
632 public $cssClass =
'';
641 global $langs, $db, $conf, $form;
644 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
647 $this->form =
new Form($this->
db);
650 $this->langs = $langs;
651 $this->entity = $conf->entity;
653 $this->confKey = $confKey;
664 if (isset($conf->global->{$this->confKey})) {
665 $this->fieldValue = $conf->global->{$this->confKey};
668 $this->fieldValue =
null;
680 return $this->loadValueFromConf();
692 $parameters = array();
693 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
695 $this->setErrors($hookmanager->errors);
704 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
705 return call_user_func($this->saveCallBack, $this);
709 if ($this->
type !=
'title') {
710 $result =
dolibarr_set_const($this->
db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
726 $this->saveCallBack = $callBack;
736 $this->setValueFromPostCallBack = $callBack;
745 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
746 return call_user_func($this->setValueFromPostCallBack);
750 if ($this->
type !=
'title') {
751 if (preg_match(
'/category:/', $this->
type)) {
752 if (
GETPOST($this->confKey,
'int') ==
'-1') {
755 $val_const =
GETPOST($this->confKey,
'int');
757 } elseif ($this->
type ==
'multiselect') {
758 $val =
GETPOST($this->confKey,
'array');
759 if ($val && is_array($val)) {
760 $val_const = implode(
',', $val);
762 } elseif ($this->
type ==
'html') {
763 $val_const =
GETPOST($this->confKey,
'restricthtml');
765 $val_const =
GETPOST($this->confKey,
'alpha');
769 $this->fieldValue = $val_const;
783 if (!empty($this->helpText)) {
return $this->helpText; }
784 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
793 if (!empty($this->nameText)) {
return $this->nameText; }
794 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
805 if (!empty($this->fieldOverride)) {
806 return $this->fieldOverride;
809 if (!empty($this->fieldInputOverride)) {
810 return $this->fieldInputOverride;
814 if (is_null($this->fieldValue)) {
815 $this->fieldValue = $this->defaultFieldValue;
819 $this->fieldAttr[
'name'] = $this->confKey;
820 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
821 $this->fieldAttr[
'value'] = $this->fieldValue;
825 if ($this->
type ==
'title') {
826 $out.= $this->generateOutputField();
827 } elseif ($this->
type ==
'multiselect') {
828 $out.= $this->generateInputFieldMultiSelect();
829 } elseif ($this->
type ==
'select') {
830 $out.= $this->generateInputFieldSelect();
831 } elseif ($this->
type ==
'textarea') {
832 $out.= $this->generateInputFieldTextarea();
833 } elseif ($this->
type==
'html') {
834 $out.= $this->generateInputFieldHtml();
835 } elseif ($this->
type==
'color') {
836 $out.= $this->generateInputFieldColor();
837 } elseif ($this->
type ==
'yesno') {
838 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
839 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
840 $out.= $this->generateInputFieldEmailTemplate();
841 } elseif (preg_match(
'/category:/', $this->
type)) {
842 $out.=$this->generateInputFieldCategories();
843 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
844 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
846 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
847 } elseif ($this->
type ==
'securekey') {
848 $out.= $this->generateInputFieldSecureKey();
849 } elseif ($this->
type ==
'product') {
850 if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
851 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
852 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
855 $out.= $this->generateInputFieldText();
867 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
868 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
877 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
879 $out.=
"</textarea>\n";
890 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
891 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, $conf->fckeditor->enabled, ROWS_5,
'90%');
892 return $doleditor->Create(1);
902 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
903 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
906 $tmp = explode(
':', $this->
type);
907 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
908 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
920 if (preg_match(
'/emailtemplate:/', $this->
type)) {
921 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
924 $tmp = explode(
':', $this->
type);
925 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
926 $arrayOfMessageName = array();
927 if (is_array($formmail->lines_model)) {
928 foreach ($formmail->lines_model as $modelMail) {
930 if (!empty($arrayOfMessageName[$modelMail->label])) {
931 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
934 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
937 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
951 $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">';
952 if (!empty($conf->use_javascript_ajax)) {
953 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
955 if (!empty($conf->use_javascript_ajax)) {
956 $out .=
"\n" .
'<script type="text/javascript">';
957 $out .=
'$(document).ready(function () {
958 $("#generate_token' . $this->confKey .
'").click(function() {
959 $.get( "' . DOL_URL_ROOT .
'/core/ajax/security.php", {
960 action: \'getrandompassword\',
964 $("#' . $this->confKey .
'").val(token);
979 $TSelected = array();
980 if ($this->fieldValue) {
981 $TSelected = explode(
',', $this->fieldValue);
984 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
993 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1018 $this->
type = $type;
1029 if (is_array($errors)) {
1030 if (!empty($errors)) {
1031 foreach ($errors as $error) {
1032 $this->setErrors($error);
1035 } elseif (!empty($errors)) {
1036 $this->errors[] = $errors;
1045 global $conf, $user;
1047 if (!empty($this->fieldOverride)) {
1048 return $this->fieldOverride;
1051 if (!empty($this->fieldOutputOverride)) {
1052 return $this->fieldOutputOverride;
1057 if ($this->
type ==
'title') {
1059 } elseif ($this->
type ==
'textarea') {
1061 } elseif ($this->
type ==
'multiselect') {
1062 $out.= $this->generateOutputFieldMultiSelect();
1063 } elseif ($this->
type ==
'select') {
1064 $out.= $this->generateOutputFieldSelect();
1065 } elseif ($this->
type==
'html') {
1066 $out.= $this->fieldValue;
1067 } elseif ($this->
type==
'color') {
1068 $out.= $this->generateOutputFieldColor();
1069 } elseif ($this->
type ==
'yesno') {
1071 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1072 if ($this->fieldValue > 0) {
1073 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1076 $tmp = explode(
':', $this->
type);
1078 $template = $formmail->getEMailTemplate($this->
db, $tmp[1], $user, $this->langs, $this->fieldValue);
1080 $this->setErrors($formmail->errors);
1082 $out.= $this->langs->trans($template->label);
1084 } elseif (preg_match(
'/category:/', $this->
type)) {
1085 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1087 $result = $c->fetch($this->fieldValue);
1089 $this->setErrors($c->errors);
1091 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1093 foreach ($ways as $way) {
1094 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1096 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1097 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1098 if ($this->fieldValue==2) {
1099 $out.= $this->langs->trans(
"Prospect");
1100 } elseif ($this->fieldValue==3) {
1101 $out.= $this->langs->trans(
"ProspectCustomer");
1102 } elseif ($this->fieldValue==1) {
1103 $out.= $this->langs->trans(
"Customer");
1104 } elseif ($this->fieldValue==0) {
1105 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1107 } elseif ($this->
type ==
'product') {
1108 if (!class_exists(
"Product")) {
1109 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1112 $resprod = $product->fetch($this->fieldValue);
1114 $out.= $product->ref;
1115 } elseif ($resprod < 0) {
1116 $this->setErrors($product->errors);
1119 $out.= $this->fieldValue;
1132 $TSelected = array();
1133 if (!empty($this->fieldValue)) {
1134 $TSelected = explode(
',', $this->fieldValue);
1137 if (!empty($TSelected)) {
1138 foreach ($TSelected as $selected) {
1139 if (!empty($this->fieldOptions[$selected])) {
1140 $outPut.=
dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1152 $this->fieldAttr[
'disabled']=
null;
1153 return $this->generateInputField();
1160 $this->fieldAttr[
'type']=
'color';
1161 return $this->generateInputFieldText();
1170 if (!empty($this->fieldOptions[$this->fieldValue])) {
1171 $outPut = $this->fieldOptions[$this->fieldValue];
1187 $this->
type =
'string';
1197 $this->
type =
'color';
1207 $this->
type =
'textarea';
1217 $this->
type =
'html';
1228 $this->
type =
'emailtemplate:'.$templateType;
1238 $this->
type =
'thirdparty_type';
1248 $this->
type =
'yesno';
1258 $this->
type =
'securekey';
1268 $this->
type =
'product';
1280 $this->
type =
'category:'.$catType;
1291 $this->
type =
'title';
1304 if (is_array($fieldOptions)) {
1305 $this->fieldOptions = $fieldOptions;
1308 $this->
type =
'multiselect';
1320 if (is_array($fieldOptions)) {
1321 $this->fieldOptions = $fieldOptions;
1324 $this->
type =
'select';