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();
99 $this->form =
new Form($this->db);
100 $this->formAttributes[
'action'] = $_SERVER[
"PHP_SELF"];
102 $this->formHiddenInputs[
'token'] = newToken();
103 $this->formHiddenInputs[
'action'] =
'update';
105 $this->entity = (is_null($this->entity) ? $conf->entity : $this->entity);
108 $this->langs = $outputLangs;
110 $this->langs = $langs;
123 if (is_array($attributes)) {
124 foreach ($attributes as $attribute => $value) {
125 if (is_array($value) || is_object($value)) {
132 return !empty($Aattr)?implode(
' ', $Aattr):
'';
144 global $hookmanager, $action, $langs;
145 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
148 'editMode' => $editMode
150 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutput', $parameters, $this, $action);
156 return $hookmanager->resPrint;
158 $out =
'<!-- Start generateOutput from FormSetup class -->';
159 $out.= $this->htmlBeforeOutputForm;
165 if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
166 foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
167 $out.=
'<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).
'" value="' .
dol_escape_htmltag($hiddenValue) .
'">';
176 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateOutputButton', $parameters, $this, $action);
182 return $hookmanager->resPrint;
183 } elseif ($editMode) {
185 $out .=
'<div class="form-setup-button-container center">';
186 $out.= $this->htmlOutputMoreButton;
187 $out .=
'<input class="button button-save" type="submit" value="' . $this->langs->trans(
"Save") .
'">';
188 $out .=
' ';
189 $out .=
'<a class="button button-cancel" type="submit" href="' . $this->formAttributes[
'action'] .
'">'.$langs->trans(
'Cancel').
'</a>';
197 $out.= $this->htmlAfterOutputForm;
211 global $hookmanager, $action;
212 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
215 'editMode' => $editMode
217 $reshook = $hookmanager->executeHooks(
'formSetupBeforeGenerateTableOutput', $parameters, $this, $action);
223 return $hookmanager->resPrint;
225 $out =
'<table class="noborder centpercent">';
227 $out .=
'<tr class="liste_titre">';
228 $out .=
' <td>' . $this->langs->trans(
"Parameter") .
'</td>';
229 $out .=
' <td>' . $this->langs->trans(
"Value") .
'</td>';
237 foreach ($this->items as $item) {
255 global $hookmanager, $conf;
257 $parameters = array();
258 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfFromPost', $parameters, $this);
260 $this->errors = $hookmanager->errors;
268 if (empty($this->items)) {
274 foreach ($this->items as $item) {
275 if ($item->getType() ==
'yesno' && !empty($conf->use_javascript_ajax)) {
279 $res = $item->setValueFromPost();
281 $item->saveConfValue();
282 } elseif ($res < 0) {
290 if (empty($noMessageInUpdate)) {
295 $this->db->rollback();
296 if (empty($noMessageInUpdate)) {
314 if ($item->enabled==1) {
315 $trClass =
'oddeven';
316 if ($item->getType() ==
'title') {
317 $trClass =
'liste_titre';
320 $this->setupNotEmpty++;
321 $out.=
'<tr class="'.$trClass.
'">';
323 $out.=
'<td class="col-setup-title">';
324 $out.=
'<span id="helplink'.$item->confKey.
'" class="spanforparamtooltip">';
325 $out.= $this->form->textwithpicto($item->getNameText(), $item->getHelpText(), 1,
'info',
'', 0, 3,
'tootips'.$item->confKey);
332 $out.= $item->generateInputField();
334 $out.= $item->generateOutputField();
337 if (!empty($item->errors)) {
358 if (!is_array($params) || empty($params)) {
return false; }
359 foreach ($params as $confKey => $param) {
376 if (empty($confKey) || empty($params[
'type'])) {
return false; }
392 $item->setTypeFromTypeString($params['type']);
394 if (!empty($params[
'enabled'])) {
395 $item->enabled = $params[
'enabled'];
398 if (!empty($params[
'css'])) {
399 $item->cssClass = $params[
'css'];
402 $this->items[$item->confKey] = $item;
415 $arrayofparameters = array();
416 foreach ($this->items as $item) {
417 $arrayofparameters[$item->confKey] = array(
418 'type' => $item->getType(),
419 'enabled' => $item->enabled
423 return $arrayofparameters;
435 if (!array($this->items)) {
return false; }
436 foreach ($this->items as $item) {
437 $item->loadValueFromConf();
453 public function newItem($confKey, $targetItemKey =
false, $insertAfterTarget =
false)
457 $item->entity = $this->entity;
460 if (empty($item->rank)) {
466 if (!empty($targetItemKey)) {
467 if (isset($this->items[$targetItemKey])) {
468 $targetItem = $this->items[$targetItemKey];
469 $item->rank = $targetItem->rank;
470 if ($targetItem->rank >= 0 && $insertAfterTarget) {
476 foreach ($this->items as $fItem) {
477 if ($item->rank <= $fItem->rank) {
478 $fItem->rank = $fItem->rank + 1;
484 $this->items[$item->confKey] = $item;
485 return $this->items[$item->confKey];
496 return uasort($this->items, array($this,
'itemSort'));
507 if (empty($this->items)) {
511 if ($cache && $this->maxItemRank > 0) {
512 return $this->maxItemRank;
515 $this->maxItemRank = 0;
516 foreach ($this->items as $item) {
517 $this->maxItemRank = max($this->maxItemRank, $item->rank);
520 return $this->maxItemRank;
532 $this->maxItemRank = max($this->maxItemRank, $rank);
544 if (!isset($this->items[$itemKey]->rank)) {
547 return $this->items[$itemKey]->rank;
560 if (empty($a->rank)) {
563 if (empty($b->rank)) {
566 if ($a->rank == $b->rank) {
569 return ($a->rank < $b->rank) ? -1 : 1;
608 public $fieldAttr = array();
611 public $fieldOverride =
false;
614 public $fieldInputOverride =
false;
617 public $fieldOutputOverride =
false;
623 public $fieldOptions = array();
634 public $errors = array();
642 protected $type =
'string';
646 public $cssClass =
'';
655 global $langs, $db, $conf, $form;
658 if (!empty($form) && is_object($form) && get_class($form) ==
'Form') {
661 $this->form =
new Form($this->db);
664 $this->langs = $langs;
665 $this->entity = (is_null($this->entity) ? $conf->entity : ((int) $this->entity));
667 $this->confKey = $confKey;
678 if (isset($conf->global->{$this->confKey})) {
682 $this->fieldValue =
null;
694 return $this->loadValueFromConf();
707 $parameters = array();
708 $reshook = $hookmanager->executeHooks(
'formSetupBeforeSaveConfValue', $parameters, $this);
710 $this->setErrors($hookmanager->errors);
719 if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) {
720 return call_user_func($this->saveCallBack, $this);
724 if ($this->
type !=
'title') {
725 $result =
dolibarr_set_const($this->db, $this->confKey, $this->fieldValue,
'chaine', 0,
'', $this->entity);
744 $this->saveCallBack = $callBack;
754 $this->setValueFromPostCallBack = $callBack;
763 if (!empty($this->setValueFromPostCallBack) && is_callable($this->setValueFromPostCallBack)) {
764 return call_user_func($this->setValueFromPostCallBack);
768 if ($this->
type !=
'title') {
769 if (preg_match(
'/category:/', $this->
type)) {
770 if (
GETPOST($this->confKey,
'int') ==
'-1') {
773 $val_const =
GETPOST($this->confKey,
'int');
775 } elseif ($this->
type ==
'multiselect') {
776 $val =
GETPOST($this->confKey,
'array');
777 if ($val && is_array($val)) {
778 $val_const = implode(
',', $val);
782 } elseif ($this->
type ==
'html') {
783 $val_const =
GETPOST($this->confKey,
'restricthtml');
785 $val_const =
GETPOST($this->confKey,
'alpha');
789 $this->fieldValue = $val_const;
803 if (!empty($this->helpText)) {
return $this->helpText; }
804 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
813 if (!empty($this->nameText)) {
return $this->nameText; }
814 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
825 if (!empty($this->fieldOverride)) {
826 return $this->fieldOverride;
829 if (!empty($this->fieldInputOverride)) {
830 return $this->fieldInputOverride;
834 if (is_null($this->fieldValue)) {
835 $this->fieldValue = $this->defaultFieldValue;
839 $this->fieldAttr[
'name'] = $this->confKey;
840 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
841 $this->fieldAttr[
'value'] = $this->fieldValue;
845 if ($this->
type ==
'title') {
846 $out.= $this->generateOutputField();
847 } elseif ($this->
type ==
'multiselect') {
848 $out.= $this->generateInputFieldMultiSelect();
849 } elseif ($this->
type ==
'select') {
850 $out.= $this->generateInputFieldSelect();
851 } elseif ($this->
type ==
'selectUser') {
852 $out.= $this->generateInputFieldSelectUser();
853 } elseif ($this->
type ==
'textarea') {
854 $out.= $this->generateInputFieldTextarea();
855 } elseif ($this->
type==
'html') {
856 $out.= $this->generateInputFieldHtml();
857 } elseif ($this->
type==
'color') {
858 $out.= $this->generateInputFieldColor();
859 } elseif ($this->
type ==
'yesno') {
860 if (!empty($conf->use_javascript_ajax)) {
861 $out.= ajax_constantonoff($this->confKey);
863 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
865 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
866 $out.= $this->generateInputFieldEmailTemplate();
867 } elseif (preg_match(
'/category:/', $this->
type)) {
868 $out.=$this->generateInputFieldCategories();
869 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
870 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
872 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
873 } elseif ($this->
type ==
'securekey') {
874 $out.= $this->generateInputFieldSecureKey();
875 } elseif ($this->
type ==
'product') {
876 if (isModEnabled(
"product") || isModEnabled(
"service")) {
877 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
878 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
881 $out.= $this->generateInputFieldText();
893 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
894 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
903 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
905 $out.=
"</textarea>\n";
916 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
917 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, isModEnabled(
'fckeditor'), ROWS_5,
'90%');
918 return $doleditor->Create(1);
928 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
929 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
932 $tmp = explode(
':', $this->
type);
933 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
934 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
946 if (preg_match(
'/emailtemplate:/', $this->
type)) {
947 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
948 $formmail =
new FormMail($this->db);
950 $tmp = explode(
':', $this->
type);
951 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
952 $arrayOfMessageName = array();
953 if (is_array($formmail->lines_model)) {
954 foreach ($formmail->lines_model as $modelMail) {
956 if (!empty($arrayOfMessageName[$modelMail->label])) {
957 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
960 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
963 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
977 $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">';
978 if (!empty($conf->use_javascript_ajax)) {
979 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
983 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
995 $TSelected = array();
996 if ($this->fieldValue) {
997 $TSelected = explode(
',', $this->fieldValue);
1000 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
1009 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1017 return $this->form->select_dolusers($this->fieldValue, $this->confKey);
1043 $this->
type = $type;
1056 if (is_array($errors)) {
1057 if (!empty($errors)) {
1058 foreach ($errors as $error) {
1059 $this->setErrors($error);
1062 } elseif (!empty($errors)) {
1063 $this->errors[] = $errors;
1074 global $conf, $user, $langs;
1076 if (!empty($this->fieldOverride)) {
1077 return $this->fieldOverride;
1080 if (!empty($this->fieldOutputOverride)) {
1081 return $this->fieldOutputOverride;
1086 if ($this->
type ==
'title') {
1088 } elseif ($this->
type ==
'textarea') {
1090 } elseif ($this->
type ==
'multiselect') {
1091 $out.= $this->generateOutputFieldMultiSelect();
1092 } elseif ($this->
type ==
'select') {
1093 $out.= $this->generateOutputFieldSelect();
1094 } elseif ($this->
type ==
'selectUser') {
1095 $out.= $this->generateOutputFieldSelectUser();
1096 } elseif ($this->
type==
'html') {
1097 $out.= $this->fieldValue;
1098 } elseif ($this->
type==
'color') {
1099 $out.= $this->generateOutputFieldColor();
1100 } elseif ($this->
type ==
'yesno') {
1101 if (!empty($conf->use_javascript_ajax)) {
1102 $out.= ajax_constantonoff($this->confKey, array(), $this->entity);
1104 if ($this->fieldValue == 1) {
1105 $out.= $langs->trans(
'yes');
1107 $out.= $langs->trans(
'no');
1110 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1111 if ($this->fieldValue > 0) {
1112 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1113 $formmail =
new FormMail($this->db);
1115 $tmp = explode(
':', $this->
type);
1117 $template = $formmail->getEMailTemplate($this->db, $tmp[1], $user, $this->langs, $this->fieldValue);
1118 if (is_numeric($template) && $template < 0) {
1119 $this->setErrors($formmail->errors);
1121 $out.= $this->langs->trans($template->label);
1123 } elseif (preg_match(
'/category:/', $this->
type)) {
1124 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1126 $result = $c->fetch($this->fieldValue);
1128 $this->setErrors($c->errors);
1130 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1132 foreach ($ways as $way) {
1133 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1135 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1136 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1137 if ($this->fieldValue==2) {
1138 $out.= $this->langs->trans(
"Prospect");
1139 } elseif ($this->fieldValue==3) {
1140 $out.= $this->langs->trans(
"ProspectCustomer");
1141 } elseif ($this->fieldValue==1) {
1142 $out.= $this->langs->trans(
"Customer");
1143 } elseif ($this->fieldValue==0) {
1144 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1146 } elseif ($this->
type ==
'product') {
1147 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1149 $product =
new Product($this->db);
1150 $resprod = $product->fetch($this->fieldValue);
1152 $out.= $product->ref;
1153 } elseif ($resprod < 0) {
1154 $this->setErrors($product->errors);
1157 $out.= $this->fieldValue;
1172 $TSelected = array();
1173 if (!empty($this->fieldValue)) {
1174 $TSelected = explode(
',', $this->fieldValue);
1177 if (!empty($TSelected)) {
1178 foreach ($TSelected as $selected) {
1179 if (!empty($this->fieldOptions[$selected])) {
1180 $outPut.= dolGetBadge(
'', $this->fieldOptions[$selected],
'info').
' ';
1194 $this->fieldAttr[
'disabled']=
null;
1195 return $this->generateInputField();
1204 $this->fieldAttr[
'type']=
'color';
1205 return $this->generateInputFieldText();
1216 if (!empty($this->fieldOptions[$this->fieldValue])) {
1217 $outPut = $this->fieldOptions[$this->fieldValue];
1231 $user =
new User($this->db);
1232 $user->fetch($this->fieldValue);
1233 $outPut = $user->firstname .
" " . $user->lastname;
1248 $this->
type =
'string';
1259 $this->
type =
'color';
1270 $this->
type =
'textarea';
1281 $this->
type =
'html';
1293 $this->
type =
'emailtemplate:'.$templateType;
1304 $this->
type =
'thirdparty_type';
1315 $this->
type =
'yesno';
1326 $this->
type =
'securekey';
1337 $this->
type =
'product';
1350 $this->
type =
'category:'.$catType;
1361 $this->
type =
'title';
1374 if (is_array($fieldOptions)) {
1375 $this->fieldOptions = $fieldOptions;
1378 $this->
type =
'multiselect';
1390 if (is_array($fieldOptions)) {
1391 $this->fieldOptions = $fieldOptions;
1394 $this->
type =
'select';
1405 $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.