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();
86 public $errors = array();
100 $this->form =
new Form($this->db);
101 $this->formAttributes[
'action'] = $_SERVER[
"PHP_SELF"];
103 $this->formHiddenInputs[
'token'] = newToken();
104 $this->formHiddenInputs[
'action'] =
'update';
106 $this->entity = (is_null($this->entity) ? $conf->entity : $this->entity);
109 $this->langs = $outputLangs;
111 $this->langs = $langs;
124 if (is_array($attributes)) {
125 foreach ($attributes as $attribute => $value) {
126 if (is_array($value) || is_object($value)) {
133 return !empty($Aattr) ? implode(
' ', $Aattr) :
'';
145 global $hookmanager, $action, $langs;
146 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
149 'editMode' => $editMode
151 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutput', $parameters, $this, $action);
157 return $hookmanager->resPrint;
159 $out =
'<!-- Start generateOutput from FormSetup class -->';
160 $out.= $this->htmlBeforeOutputForm;
166 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
167 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
168 $out.=
'<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).
'" value="' .
dol_escape_htmltag($hiddenValue) .
'">';
177 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutputButton', $parameters, $this, $action);
183 return $hookmanager->resPrint;
184 } elseif ($editMode) {
186 $out .=
'<div class="form-setup-button-container center">';
187 $out.= $this->htmlOutputMoreButton;
188 $out .=
'<input class="button button-save" type="submit" value="' . $this->langs->trans(
"Save") .
'">';
189 $out .=
' ';
190 $out .=
'<a class="button button-cancel" type="submit" href="' . $this->formAttributes[
'action'] .
'">'.$langs->trans(
'Cancel').
'</a>';
198 $out.= $this->htmlAfterOutputForm;
212 global $hookmanager, $action;
213 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
216 'editMode' => $editMode
218 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateTableOutput', $parameters, $this, $action);
224 return $hookmanager->resPrint;
226 $out =
'<table class="noborder centpercent">';
228 $out .=
'<tr class="liste_titre">';
229 $out .=
' <td>' . $this->langs->trans(
"Parameter") .
'</td>';
230 $out .=
' <td>' . $this->langs->trans(
"Value") .
'</td>';
238 foreach ($this->items as $item) {
256 global $hookmanager, $conf;
258 $parameters = array();
259 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfFromPost', $parameters, $this);
261 $this->errors = $hookmanager->errors;
270 if (empty($this->items)) {
276 foreach ($this->items as $item) {
277 if ($item->getType() ==
'yesno' && !empty($conf->use_javascript_ajax)) {
281 $res = $item->setValueFromPost();
283 $item->saveConfValue();
284 } elseif ($res < 0) {
292 if (empty($noMessageInUpdate)) {
297 $this->db->rollback();
298 if (empty($noMessageInUpdate)) {
315 if ($item->enabled==1) {
316 $trClass =
'oddeven';
317 if ($item->getType() ==
'title') {
318 $trClass =
'liste_titre';
321 $this->setupNotEmpty++;
322 $out.=
'<tr class="'.$trClass.
'">';
324 $out.=
'<td class="col-setup-title">';
325 $out.=
'<span id="helplink'.$item->confKey.
'" class="spanforparamtooltip">';
326 $out.= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1,
'info',
'', 0, 3,
'tootips'.$item->confKey);
333 $out.= $item->generateInputField();
335 $out.= $item->generateOutputField();
338 if (!empty($item->errors)) {
359 if (!is_array($params) || empty($params)) {
362 foreach ($params as $confKey => $param) {
379 if (empty($confKey) || empty($params[
'type'])) {
397 $item->setTypeFromTypeString($params['type']);
399 if (!empty($params[
'enabled'])) {
400 $item->enabled = $params[
'enabled'];
403 if (!empty($params[
'css'])) {
404 $item->cssClass = $params[
'css'];
407 $this->items[$item->confKey] = $item;
420 $arrayofparameters = array();
421 foreach ($this->items as $item) {
422 $arrayofparameters[$item->confKey] = array(
423 'type' => $item->getType(),
424 'enabled' => $item->enabled
428 return $arrayofparameters;
439 if (!array($this->items)) {
442 foreach ($this->items as $item) {
443 $item->loadValueFromConf();
459 public function newItem($confKey, $targetItemKey =
'', $insertAfterTarget =
false)
463 $item->entity = $this->entity;
466 if (empty($item->rank)) {
472 if (!empty($targetItemKey)) {
473 if (isset($this->items[$targetItemKey])) {
474 $targetItem = $this->items[$targetItemKey];
475 $item->rank = $targetItem->rank;
476 if ($targetItem->rank >= 0 && $insertAfterTarget) {
482 foreach ($this->items as $fItem) {
483 if ($item->rank <= $fItem->rank) {
484 $fItem->rank = $fItem->rank + 1;
490 $this->items[$item->confKey] = $item;
491 return $this->items[$item->confKey];
502 return uasort($this->items, array($this,
'itemSort'));
513 if (empty($this->items)) {
517 if ($cache && $this->maxItemRank > 0) {
518 return $this->maxItemRank;
521 $this->maxItemRank = 0;
522 foreach ($this->items as $item) {
523 $this->maxItemRank = max($this->maxItemRank, $item->rank);
526 return $this->maxItemRank;
538 $this->maxItemRank = max($this->maxItemRank, $rank);
550 if (!isset($this->items[$itemKey]->rank)) {
553 return $this->items[$itemKey]->rank;
566 if (empty($a->rank)) {
569 if (empty($b->rank)) {
572 if ($a->rank == $b->rank) {
575 return ($a->rank < $b->rank) ? -1 : 1;
614 public $fieldAttr = array();
617 public $fieldOverride =
false;
620 public $fieldInputOverride =
false;
623 public $fieldOutputOverride =
false;
629 public $fieldOptions = array();
640 public $errors = array();
648 protected $type =
'string';
652 public $cssClass =
'';
661 global $langs, $db, $conf, $form;
664 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
667 $this->form =
new Form($this->db);
670 $this->langs = $langs;
671 $this->entity = (is_null($this->entity) ? $conf->entity : ((int) $this->entity));
673 $this->confKey = $confKey;
685 if (isset($conf->global->{$this->confKey})) {
689 $this->fieldValue =
null;
702 return $this->loadValueFromConf();
715 $parameters = array();
716 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
718 $this->setErrors($hookmanager->errors);
727 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
728 return call_user_func($this->saveCallBack, $this);
732 if ($this->
type !=
'title') {
733 $result =
dolibarr_set_const($this->db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
752 $this->saveCallBack = $callBack;
763 $this->setValueFromPostCallBack = $callBack;
773 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
774 return call_user_func($this->setValueFromPostCallBack);
778 if ($this->
type !=
'title') {
779 if (preg_match(
'/category:/', $this->
type)) {
780 if (
GETPOST($this->confKey,
'int') ==
'-1') {
783 $val_const =
GETPOST($this->confKey,
'int');
785 } elseif ($this->
type ==
'multiselect') {
786 $val =
GETPOST($this->confKey,
'array');
787 if ($val && is_array($val)) {
788 $val_const = implode(
',', $val);
792 } elseif ($this->
type ==
'html') {
793 $val_const =
GETPOST($this->confKey,
'restricthtml');
795 $val_const =
GETPOST($this->confKey,
'alpha');
799 $this->fieldValue = $val_const;
814 if (!empty($this->helpText)) {
815 return $this->helpText;
817 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
827 if (!empty($this->nameText)) {
828 return $this->nameText;
830 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
842 if (!empty($this->fieldOverride)) {
843 return $this->fieldOverride;
846 if (!empty($this->fieldInputOverride)) {
847 return $this->fieldInputOverride;
851 if (is_null($this->fieldValue)) {
852 $this->fieldValue = $this->defaultFieldValue;
856 $this->fieldAttr[
'name'] = $this->confKey;
857 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
858 $this->fieldAttr[
'value'] = $this->fieldValue;
862 if ($this->
type ==
'title') {
863 $out.= $this->generateOutputField();
864 } elseif ($this->
type ==
'multiselect') {
865 $out.= $this->generateInputFieldMultiSelect();
866 } elseif ($this->
type ==
'select') {
867 $out.= $this->generateInputFieldSelect();
868 } elseif ($this->
type ==
'selectUser') {
869 $out.= $this->generateInputFieldSelectUser();
870 } elseif ($this->
type ==
'textarea') {
871 $out.= $this->generateInputFieldTextarea();
872 } elseif ($this->
type==
'html') {
873 $out.= $this->generateInputFieldHtml();
874 } elseif ($this->
type==
'color') {
875 $out.= $this->generateInputFieldColor();
876 } elseif ($this->
type ==
'yesno') {
877 if (!empty($conf->use_javascript_ajax)) {
878 $out.= ajax_constantonoff($this->confKey);
880 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
882 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
883 $out.= $this->generateInputFieldEmailTemplate();
884 } elseif (preg_match(
'/category:/', $this->
type)) {
885 $out.=$this->generateInputFieldCategories();
886 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
887 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
889 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
890 } elseif ($this->
type ==
'securekey') {
891 $out.= $this->generateInputFieldSecureKey();
892 } elseif ($this->
type ==
'product') {
893 if (isModEnabled(
"product") || isModEnabled(
"service")) {
894 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
895 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
898 $out.= $this->generateInputFieldText();
911 if (empty($this->fieldAttr)) {
912 $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass);
914 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
924 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
926 $out.=
"</textarea>\n";
938 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
939 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, isModEnabled(
'fckeditor'), ROWS_5,
'90%');
940 return $doleditor->Create(1);
949 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
950 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
953 $tmp = explode(
':', $this->
type);
954 $out =
img_picto(
'',
'category',
'class="pictofixedwidth"');
955 $out .= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
969 if (preg_match(
'/emailtemplate:/', $this->
type)) {
970 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
971 $formmail =
new FormMail($this->db);
973 $tmp = explode(
':', $this->
type);
974 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
975 $arrayOfMessageName = array();
976 if (is_array($formmail->lines_model)) {
977 foreach ($formmail->lines_model as $modelMail) {
979 if (!empty($arrayOfMessageName[$modelMail->label])) {
980 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
983 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
986 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
1001 $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">';
1002 if (!empty($conf->use_javascript_ajax)) {
1003 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
1007 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1021 $TSelected = array();
1022 if ($this->fieldValue) {
1023 $TSelected = explode(
',', $this->fieldValue);
1026 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
1037 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1045 return $this->form->select_dolusers($this->fieldValue, $this->confKey);
1071 $this->
type = $type;
1084 if (is_array($errors)) {
1085 if (!empty($errors)) {
1086 foreach ($errors as $error) {
1087 $this->setErrors($error);
1090 } elseif (!empty($errors)) {
1091 $this->errors[] = $errors;
1102 global $conf, $user, $langs;
1104 if (!empty($this->fieldOverride)) {
1105 return $this->fieldOverride;
1108 if (!empty($this->fieldOutputOverride)) {
1109 return $this->fieldOutputOverride;
1114 if ($this->
type ==
'title') {
1116 } elseif ($this->
type ==
'textarea') {
1118 } elseif ($this->
type ==
'multiselect') {
1119 $out.= $this->generateOutputFieldMultiSelect();
1120 } elseif ($this->
type ==
'select') {
1121 $out.= $this->generateOutputFieldSelect();
1122 } elseif ($this->
type ==
'selectUser') {
1123 $out.= $this->generateOutputFieldSelectUser();
1124 } elseif ($this->
type ==
'html') {
1125 $out.= $this->fieldValue;
1126 } elseif ($this->
type ==
'color') {
1127 $out.= $this->generateOutputFieldColor();
1128 } elseif ($this->
type ==
'yesno') {
1129 if (!empty($conf->use_javascript_ajax)) {
1130 $out.= ajax_constantonoff($this->confKey, array(), $this->entity);
1132 if ($this->fieldValue == 1) {
1133 $out.= $langs->trans(
'yes');
1135 $out.= $langs->trans(
'no');
1138 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1139 if ($this->fieldValue > 0) {
1140 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1141 $formmail =
new FormMail($this->db);
1143 $tmp = explode(
':', $this->
type);
1145 $template = $formmail->getEMailTemplate($this->db, $tmp[1], $user, $this->langs, $this->fieldValue);
1146 if (is_numeric($template) && $template < 0) {
1147 $this->setErrors($formmail->errors);
1149 $out.= $this->langs->trans($template->label);
1151 } elseif (preg_match(
'/category:/', $this->
type)) {
1152 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1154 $result = $c->fetch($this->fieldValue);
1156 $this->setErrors($c->errors);
1158 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1160 foreach ($ways as $way) {
1161 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1163 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1164 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1165 if ($this->fieldValue==2) {
1166 $out.= $this->langs->trans(
"Prospect");
1167 } elseif ($this->fieldValue==3) {
1168 $out.= $this->langs->trans(
"ProspectCustomer");
1169 } elseif ($this->fieldValue==1) {
1170 $out.= $this->langs->trans(
"Customer");
1171 } elseif ($this->fieldValue==0) {
1172 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1174 } elseif ($this->
type ==
'product') {
1175 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1177 $product =
new Product($this->db);
1178 $resprod = $product->fetch($this->fieldValue);
1180 $out.= $product->ref;
1181 } elseif ($resprod < 0) {
1182 $this->setErrors($product->errors);
1185 $out.= $this->fieldValue;
1200 $TSelected = array();
1201 if (!empty($this->fieldValue)) {
1202 $TSelected = explode(
',', $this->fieldValue);
1205 if (!empty($TSelected)) {
1206 foreach ($TSelected as $selected) {
1207 if (!empty($this->fieldOptions[$selected])) {
1208 $outPut.= dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1222 $this->fieldAttr[
'disabled']=
null;
1223 return $this->generateInputField();
1232 $this->fieldAttr[
'type']=
'color';
1233 return $this->generateInputFieldText();
1244 if (!empty($this->fieldOptions[$this->fieldValue])) {
1245 $outPut = $this->fieldOptions[$this->fieldValue];
1259 $user =
new User($this->db);
1260 $user->fetch($this->fieldValue);
1261 $outPut = $user->firstname .
" " . $user->lastname;
1276 $this->
type =
'string';
1287 $this->
type =
'color';
1298 $this->
type =
'textarea';
1309 $this->
type =
'html';
1321 $this->
type =
'emailtemplate:'.$templateType;
1332 $this->
type =
'thirdparty_type';
1343 $this->
type =
'yesno';
1354 $this->
type =
'securekey';
1365 $this->
type =
'product';
1378 $this->
type =
'category:'.$catType;
1389 $this->
type =
'title';
1402 if (is_array($fieldOptions)) {
1403 $this->fieldOptions = $fieldOptions;
1406 $this->
type =
'multiselect';
1418 if (is_array($fieldOptions)) {
1419 $this->fieldOptions = $fieldOptions;
1422 $this->
type =
'select';
1433 $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.