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;
582 public $nameText =
false;
585 public $helpText =
'';
591 public $defaultFieldValue =
null;
594 public $fieldAttr = array();
597 public $fieldOverride =
false;
600 public $fieldInputOverride =
false;
603 public $fieldOutputOverride =
false;
609 public $fieldOptions = array();
612 public $saveCallBack;
615 public $setValueFromPostCallBack;
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})) {
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);
764 } elseif ($this->
type ==
'html') {
765 $val_const =
GETPOST($this->confKey,
'restricthtml');
767 $val_const =
GETPOST($this->confKey,
'alpha');
771 $this->fieldValue = $val_const;
785 if (!empty($this->helpText)) {
return $this->helpText; }
786 return (($this->langs->trans($this->confKey .
'Tooltip') != $this->confKey .
'Tooltip') ? $this->langs->trans($this->confKey .
'Tooltip') :
'');
795 if (!empty($this->nameText)) {
return $this->nameText; }
796 return (($this->langs->trans($this->confKey) != $this->confKey) ? $this->langs->trans($this->confKey) : $this->langs->trans(
'MissingTranslationForConfKey', $this->confKey));
807 if (!empty($this->fieldOverride)) {
808 return $this->fieldOverride;
811 if (!empty($this->fieldInputOverride)) {
812 return $this->fieldInputOverride;
816 if (is_null($this->fieldValue)) {
817 $this->fieldValue = $this->defaultFieldValue;
821 $this->fieldAttr[
'name'] = $this->confKey;
822 $this->fieldAttr[
'id'] =
'setup-'.$this->confKey;
823 $this->fieldAttr[
'value'] = $this->fieldValue;
827 if ($this->
type ==
'title') {
828 $out.= $this->generateOutputField();
829 } elseif ($this->
type ==
'multiselect') {
830 $out.= $this->generateInputFieldMultiSelect();
831 } elseif ($this->
type ==
'select') {
832 $out.= $this->generateInputFieldSelect();
833 } elseif ($this->
type ==
'textarea') {
834 $out.= $this->generateInputFieldTextarea();
835 } elseif ($this->
type==
'html') {
836 $out.= $this->generateInputFieldHtml();
837 } elseif ($this->
type==
'color') {
838 $out.= $this->generateInputFieldColor();
839 } elseif ($this->
type ==
'yesno') {
840 if (!empty($conf->use_javascript_ajax)) {
843 $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
845 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
846 $out.= $this->generateInputFieldEmailTemplate();
847 } elseif (preg_match(
'/category:/', $this->
type)) {
848 $out.=$this->generateInputFieldCategories();
849 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
850 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
852 $out.= $formcompany->selectProspectCustomerType($this->fieldValue, $this->confKey);
853 } elseif ($this->
type ==
'securekey') {
854 $out.= $this->generateInputFieldSecureKey();
855 } elseif ($this->
type ==
'product') {
857 $selected = (empty($this->fieldValue) ?
'' : $this->fieldValue);
858 $out.= $this->form->select_produits($selected, $this->confKey,
'', 0, 0, 1, 2,
'', 0, array(), 0,
'1', 0, $this->cssClass, 0,
'',
null, 1);
861 $out.= $this->generateInputFieldText();
873 if (empty($this->fieldAttr)) { $this->fieldAttr[
'class'] =
'flat '.(empty($this->cssClass) ?
'minwidth200' : $this->cssClass); }
874 return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).
' />';
883 $out =
'<textarea class="flat" name="'.$this->confKey.
'" id="'.$this->confKey.
'" cols="50" rows="5" wrap="soft">' .
"\n";
885 $out.=
"</textarea>\n";
896 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
897 $doleditor =
new DolEditor($this->confKey, $this->fieldValue,
'', 160,
'dolibarr_notes',
'',
false,
false, $conf->fckeditor->enabled, ROWS_5,
'90%');
898 return $doleditor->Create(1);
908 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
909 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
912 $tmp = explode(
':', $this->
type);
913 $out=
img_picto(
'',
'category',
'class="pictofixedwidth"');
914 $out.= $formother->select_categories($tmp[1], $this->fieldValue, $this->confKey, 0, $this->langs->trans(
'CustomersProspectsCategoriesShort'));
926 if (preg_match(
'/emailtemplate:/', $this->
type)) {
927 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
930 $tmp = explode(
':', $this->
type);
931 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
932 $arrayOfMessageName = array();
933 if (is_array($formmail->lines_model)) {
934 foreach ($formmail->lines_model as $modelMail) {
936 if (!empty($arrayOfMessageName[$modelMail->label])) {
937 $moreonlabel =
' <span class="opacitymedium">(' . $this->langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
940 $arrayOfMessageName[$modelMail->id] = $this->langs->trans(preg_replace(
'/\(|\)/',
'', $modelMail->label)) . $moreonlabel;
943 $out .= $this->form->selectarray($this->confKey, $arrayOfMessageName, $this->fieldValue,
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
957 $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">';
958 if (!empty($conf->use_javascript_ajax)) {
959 $out.=
' '.img_picto($this->langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$this->confKey.
'" class="linkobject"');
963 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
975 $TSelected = array();
976 if ($this->fieldValue) {
977 $TSelected = explode(
',', $this->fieldValue);
980 return $this->form->multiselectarray($this->confKey, $this->fieldOptions, $TSelected, 0, 0,
'', 0, 0,
'style="min-width:100px"');
989 return $this->form->selectarray($this->confKey, $this->fieldOptions, $this->fieldValue);
1014 $this->
type = $type;
1025 if (is_array($errors)) {
1026 if (!empty($errors)) {
1027 foreach ($errors as $error) {
1028 $this->setErrors($error);
1031 } elseif (!empty($errors)) {
1032 $this->errors[] = $errors;
1041 global $conf, $user, $langs;
1043 if (!empty($this->fieldOverride)) {
1044 return $this->fieldOverride;
1047 if (!empty($this->fieldOutputOverride)) {
1048 return $this->fieldOutputOverride;
1053 if ($this->
type ==
'title') {
1055 } elseif ($this->
type ==
'textarea') {
1057 } elseif ($this->
type ==
'multiselect') {
1058 $out.= $this->generateOutputFieldMultiSelect();
1059 } elseif ($this->
type ==
'select') {
1060 $out.= $this->generateOutputFieldSelect();
1061 } elseif ($this->
type==
'html') {
1062 $out.= $this->fieldValue;
1063 } elseif ($this->
type==
'color') {
1064 $out.= $this->generateOutputFieldColor();
1065 } elseif ($this->
type ==
'yesno') {
1066 if (!empty($conf->use_javascript_ajax)) {
1069 if ($this->fieldValue == 1) {
1070 $out.= $langs->trans(
'yes');
1072 $out.= $langs->trans(
'no');
1075 } elseif (preg_match(
'/emailtemplate:/', $this->
type)) {
1076 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1079 $tmp = explode(
':', $this->
type);
1081 $template = $formmail->getEMailTemplate($this->
db, $tmp[1], $user, $this->langs, $this->fieldValue);
1082 if (is_numeric($template) && $template < 0) {
1083 $this->setErrors($formmail->errors);
1085 $out.= $this->langs->trans($template->label);
1086 } elseif (preg_match(
'/category:/', $this->
type)) {
1087 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1089 $result = $c->fetch($this->fieldValue);
1091 $this->setErrors($c->errors);
1093 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
1095 foreach ($ways as $way) {
1096 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
1098 $out.=
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
1099 } elseif (preg_match(
'/thirdparty_type/', $this->
type)) {
1100 if ($this->fieldValue==2) {
1101 $out.= $this->langs->trans(
"Prospect");
1102 } elseif ($this->fieldValue==3) {
1103 $out.= $this->langs->trans(
"ProspectCustomer");
1104 } elseif ($this->fieldValue==1) {
1105 $out.= $this->langs->trans(
"Customer");
1106 } elseif ($this->fieldValue==0) {
1107 $out.= $this->langs->trans(
"NorProspectNorCustomer");
1109 } elseif ($this->
type ==
'product') {
1110 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';
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).
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='')
On/off button for constant.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage products or services.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dolGetBadge($label, $html='', $type='primary', $mode='', $url='', $params=array())
Function dolGetBadge.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token')
Ouput javacript to autoset a generated password using default module into a HTML element.
$conf db
API class for accounts.