29 require
'../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
36 $langs->loadLangs(array(
'companies',
'products',
'admin',
'sms',
'other',
'errors'));
43 $action =
GETPOST(
'action',
'aZ09');
44 $optioncss =
GETPOST(
'optionscss',
'alphanohtml');
46 $mode =
GETPOST(
'mode',
'aZ09') ?
GETPOST(
'mode',
'aZ09') :
'createform';
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) {
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
59 $sortfield =
'page,param';
65 $defaulturl =
GETPOST(
'defaulturl',
'alphanohtml');
66 $defaultkey =
GETPOST(
'defaultkey',
'alphanohtml');
67 $defaultvalue =
GETPOST(
'defaultvalue',
'restricthtml');
69 $defaulturl = preg_replace(
'/^\//',
'', $defaulturl);
71 $urlpage =
GETPOST(
'urlpage',
'alphanohtml');
72 $key =
GETPOST(
'key',
'alphanohtml');
73 $value =
GETPOST(
'value',
'restricthtml');
76 $hookmanager->initHooks(array(
'admindefaultvalues',
'globaladmin'));
84 if (
GETPOST(
'cancel',
'alpha')) {
85 $action =
'list'; $massaction =
'';
87 if (!
GETPOST(
'confirmmassaction',
'alpha') && !empty($massaction) && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
91 $parameters = array();
92 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
97 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
100 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
105 $search_array_options = array();
108 if ($action ==
'setMAIN_ENABLE_DEFAULT_VALUES') {
110 dolibarr_set_const($db,
'MAIN_ENABLE_DEFAULT_VALUES', 1,
'chaine', 0,
'', $conf->entity);
112 dolibarr_set_const($db,
'MAIN_ENABLE_DEFAULT_VALUES', 0,
'chaine', 0,
'', $conf->entity);
116 if (($action ==
'add' || (
GETPOST(
'add') && $action !=
'update')) ||
GETPOST(
'actionmodify')) {
119 if (($action ==
'add' || (
GETPOST(
'add') && $action !=
'update'))) {
120 if (empty($defaulturl)) {
121 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Url")),
null,
'errors');
124 if (empty($defaultkey)) {
125 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Field")),
null,
'errors');
130 if (empty($urlpage)) {
131 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Url")),
null,
'errors');
135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Field")),
null,
'errors');
141 if ($action ==
'add' || (
GETPOST(
'add') && $action !=
'update')) {
144 $object->page=$defaulturl;
145 $object->param=$defaultkey;
146 $object->value=$defaultvalue;
147 $object->entity=$conf->entity;
148 $result=$object->create($user);
163 $object->page=$urlpage;
165 $object->value=$value;
166 $object->entity=$conf->entity;
167 $result=$object->update($user);
183 if ($action ==
'delete') {
185 $result=$object->delete($user);
201 $wikihelp =
'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
204 $param =
'&mode='.$mode;
206 $enabledisablehtml = $langs->trans(
"EnableDefaultValues").
' ';
207 if (empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
209 $enabledisablehtml .=
'<a class="reposition valignmiddle" href="'.$_SERVER[
"PHP_SELF"].
'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.
newToken().
'&value=1'.$param.
'">';
210 $enabledisablehtml .=
img_picto($langs->trans(
"Disabled"),
'switch_off');
211 $enabledisablehtml .=
'</a>';
214 $enabledisablehtml .=
'<a class="reposition valignmiddle" href="'.$_SERVER[
"PHP_SELF"].
'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.
newToken().
'&value=0'.$param.
'">';
215 $enabledisablehtml .=
img_picto($langs->trans(
"Activated"),
'switch_on');
216 $enabledisablehtml .=
'</a>';
219 print
load_fiche_titre($langs->trans(
"DefaultValues"), $enabledisablehtml,
'title_setup');
221 print
'<span class="opacitymedium">'.$langs->trans(
"DefaultValuesDesc").
"</span><br>\n";
224 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
225 $param .=
'&contextpage='.urlencode($contextpage);
227 if ($limit > 0 && $limit != $conf->liste_limit) {
228 $param .=
'&limit='.urlencode($limit);
230 if ($optioncss !=
'') {
231 $param .=
'&optioncss='.urlencode($optioncss);
234 $param .=
'&defaulturl='.urlencode($defaulturl);
237 $param .=
'&defaultkey='.urlencode($defaultkey);
240 $param .=
'&defaultvalue='.urlencode($defaultvalue);
244 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
245 if ($optioncss !=
'') {
246 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
248 print
'<input type="hidden" name="token" value="'.newToken().
'">';
249 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
250 print
'<input type="hidden" name="action" value="list">';
251 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
252 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
253 print
'<input type="hidden" name="page" value="'.$page.
'">';
259 if ($mode ==
'sortorder') {
260 print
info_admin($langs->trans(
"WarningSettingSortOrder")).
'<br>';
262 if ($mode ==
'mandatory') {
263 print
info_admin($langs->trans(
"FeatureSupportedOnTextFieldsOnly")).
'<br>';
266 print
'<input type="hidden" name="token" value="'.newToken().
'">';
267 print
'<input type="hidden" id="action" name="action" value="">';
268 print
'<input type="hidden" id="mode" name="mode" value="'.dol_escape_htmltag($mode).
'">';
270 print
'<div class="div-table-responsive-no-min">';
271 print
'<table class="noborder centpercent">';
272 print
'<tr class="liste_titre">';
274 $texthelp = $langs->trans(
"PageUrlForDefaultValues");
275 if ($mode ==
'createform') {
276 $texthelp .= $langs->trans(
"PageUrlForDefaultValuesCreate",
'societe/card.php',
'societe/card.php?abc=val1&def=val2');
278 $texthelp .= $langs->trans(
"PageUrlForDefaultValuesList",
'societe/list.php',
'societe/list.php?abc=val1&def=val2');
280 $texthelp .=
'<br><br>'.$langs->trans(
"AlsoDefaultValuesAreEffectiveForActionCreate");
281 $texturl =
$form->textwithpicto($langs->trans(
"RelativeURL"), $texthelp);
284 $texthelp = $langs->trans(
"TheKeyIsTheNameOfHtmlField");
285 if ($mode !=
'sortorder') {
286 $textkey =
$form->textwithpicto($langs->trans(
"Field"), $texthelp);
288 $texthelp =
'field or alias.field';
289 $textkey =
$form->textwithpicto($langs->trans(
"Field"), $texthelp);
293 if ($mode !=
'focus' && $mode !=
'mandatory') {
294 if ($mode !=
'sortorder') {
296 unset($substitutionarray[
'__USER_SIGNATURE__']);
297 $texthelp = $langs->trans(
"FollowingConstantsWillBeSubstituted").
'<br>';
298 foreach ($substitutionarray as $key => $val) {
299 $texthelp .= $key.
' -> '.$val.
'<br>';
301 $textvalue =
$form->textwithpicto($langs->trans(
"Value"), $texthelp, 1,
'help',
'', 0, 2,
'subsitutiontooltip');
303 $texthelp =
'ASC or DESC';
304 $textvalue =
$form->textwithpicto($langs->trans(
"SortOrder"), $texthelp);
309 if (!empty($conf->multicompany->enabled) && !$user->entity) {
310 print_liste_field_titre(
"Entity", $_SERVER[
"PHP_SELF"],
'entity,page',
'', $param,
'', $sortfield, $sortorder);
322 print
'<tr class="oddeven">';
325 print
'<input type="text" class="flat minwidth200 maxwidthonsmartphone" name="defaulturl" value="'.dol_escape_htmltag(
GETPOST(
'defaulturl',
'alphanohtml')).
'">';
329 print
'<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="'.dol_escape_htmltag(
GETPOST(
'defaultkey',
'alphanohtml')).
'">';
332 if ($mode !=
'focus' && $mode !=
'mandatory') {
334 print
'<input type="text" class="flat maxwidth100onsmartphone" name="defaultvalue" value="">';
338 if (!empty($conf->multicompany->enabled) && !$user->entity) {
340 print
'<input type="text" class="flat" size="1" disabled name="entity" value="'.$conf->entity.
'">';
343 print
'<td class="center">';
344 print
'<input type="hidden" name="entity" value="'.$conf->entity.
'">';
347 print
'<td class="center">';
349 if (empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
350 $disabled =
' disabled="disabled"';
352 print
'<input type="submit" class="button"'.$disabled.
' value="'.$langs->trans(
"Add").
'" name="add">';
356 $result = $object->fetchAll($sortorder, $sortfield, 0, 0, array(
't.type'=>$mode,
't.entity'=>array($user->entity,$conf->entity)));
358 if (!is_array($result) && $result < 0) {
360 } elseif (is_array($result) && count($result) > 0) {
361 foreach ($result as $key => $defaultvalue) {
362 print
'<tr class="oddeven">';
366 if ($action !=
'edit' ||
GETPOST(
'rowid',
'int') != $defaultvalue->id) print $defaultvalue->page;
367 else print
'<input type="text" name="urlpage" value="'.dol_escape_htmltag($defaultvalue->page).
'">';
372 if ($action !=
'edit' ||
GETPOST(
'rowid') != $defaultvalue->id) print $defaultvalue->param;
373 else print
'<input type="text" name="key" value="'.dol_escape_htmltag($defaultvalue->param).
'">';
377 if ($mode !=
'focus' && $mode !=
'mandatory') {
380 else print
'<input type="text" name="value" value="'.dol_escape_htmltag($defaultvalue->value).
'">';
387 print
'<td class="center">';
388 if ($action !=
'edit' ||
GETPOST(
'rowid') != $defaultvalue->id) {
389 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$defaultvalue->id.
'&entity='.$defaultvalue->entity.
'&mode='.$mode.
'&action=edit&token='.
newToken().
'">'.
img_edit().
'</a>';
390 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?rowid='.$defaultvalue->id.
'&entity='.$defaultvalue->entity.
'&mode='.$mode.
'&action=delete&token='.
newToken().
'">'.
img_delete().
'</a>';
392 print
'<input type="hidden" name="page" value="'.$page.
'">';
393 print
'<input type="hidden" name="rowid" value="'.$id.
'">';
394 print
'<div name="'.(!empty($defaultvalue->id) ? $defaultvalue->id :
'none').
'"></div>';
395 print
'<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
396 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';