dolibarr 21.0.0-beta
defaultvalues.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2017-2018 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'products', 'admin', 'sms', 'other', 'errors'));
48
49if (!$user->admin) {
51}
52
53$id = GETPOSTINT('rowid');
54$action = GETPOST('action', 'aZ09');
55$optioncss = GETPOST('optionscss', 'alphanohtml');
56
57$mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus'
58
59$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60$sortfield = GETPOST('sortfield', 'aZ09comma');
61$sortorder = GETPOST('sortorder', 'aZ09comma');
62$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63if (empty($page) || $page == -1) {
64 $page = 0;
65} // If $page is not defined, or '' or -1
66$offset = $limit * $page;
67$pageprev = $page - 1;
68$pagenext = $page + 1;
69if (!$sortfield) {
70 $sortfield = 'page,param';
71}
72if (!$sortorder) {
73 $sortorder = 'ASC';
74}
75
76$defaulturl = GETPOST('defaulturl', 'alphanohtml');
77$defaultkey = GETPOST('defaultkey', 'alphanohtml');
78$defaultvalue = GETPOST('defaultvalue', 'restricthtml');
79
80$defaulturl = preg_replace('/^\//', '', $defaulturl);
81
82$urlpage = GETPOST('urlpage', 'alphanohtml');
83$key = GETPOST('key', 'alphanohtml');
84$value = GETPOST('value', 'restricthtml');
85
86// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
87$hookmanager->initHooks(array('admindefaultvalues', 'globaladmin'));
88
89
90$object = new DefaultValues($db);
91/*
92 * Actions
93 */
94
95if (GETPOST('cancel', 'alpha')) {
96 $action = 'list';
97 $massaction = '';
98}
99if (!GETPOST('confirmmassaction', 'alpha') && !empty($massaction) && $massaction != 'presend' && $massaction != 'confirm_presend') {
100 $massaction = '';
101}
102
103$parameters = array();
104$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105if ($reshook < 0) {
106 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107}
108
109include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
110
111// Purge search criteria
112if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
113 $defaulturl = '';
114 $defaultkey = '';
115 $defaultvalue = '';
116 $toselect = array();
117 $search_array_options = array();
118}
119
120if ($action == 'setMAIN_ENABLE_DEFAULT_VALUES') {
121 if (GETPOST('value')) {
122 dolibarr_set_const($db, 'MAIN_ENABLE_DEFAULT_VALUES', 1, 'chaine', 0, '', $conf->entity);
123 } else {
124 dolibarr_set_const($db, 'MAIN_ENABLE_DEFAULT_VALUES', 0, 'chaine', 0, '', $conf->entity);
125 }
126}
127
128if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('actionmodify')) {
129 $error = 0;
130
131 if (($action == 'add' || (GETPOST('add') && $action != 'update'))) {
132 if (empty($defaulturl)) {
133 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Url")), null, 'errors');
134 $error++;
135 }
136 if (empty($defaultkey)) {
137 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Field")), null, 'errors');
138 $error++;
139 }
140 }
141 if (GETPOST('actionmodify')) {
142 if (empty($urlpage)) {
143 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Url")), null, 'errors');
144 $error++;
145 }
146 if (empty($key)) {
147 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Field")), null, 'errors');
148 $error++;
149 }
150 }
151
152 if (!$error) {
153 if ($action == 'add' || (GETPOST('add') && $action != 'update')) {
154 $object->type = $mode;
155 $object->user_id = 0;
156 $object->page = $defaulturl;
157 $object->param = $defaultkey;
158 $object->value = $defaultvalue;
159 $object->entity = $conf->entity;
160 $result = $object->create($user);
161 if ($result < 0) {
162 $action = '';
163 setEventMessages($object->error, $object->errors, 'errors');
164 } else {
165 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
166 $action = '';
167 $defaulturl = '';
168 $defaultkey = '';
169 $defaultvalue = '';
170 }
171 }
172 if (GETPOST('actionmodify')) {
173 $object->id = $id;
174 $object->type = $mode;
175 $object->page = $urlpage;
176 $object->param = $key;
177 $object->value = $value;
178 $object->entity = $conf->entity;
179 $result = $object->update($user);
180 if ($result < 0) {
181 $action = '';
182 setEventMessages($object->error, $object->errors, 'errors');
183 } else {
184 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
185 $action = "";
186 $defaulturl = '';
187 $defaultkey = '';
188 $defaultvalue = '';
189 }
190 }
191 }
192}
193
194// Delete line from delete picto
195if ($action == 'delete') {
196 $object->id = $id;
197 $result = $object->delete($user);
198 if ($result < 0) {
199 $action = '';
200 setEventMessages($object->error, $object->errors, 'errors');
201 }
202}
203
204
205
206/*
207 * View
208 */
209
210$form = new Form($db);
211$formadmin = new FormAdmin($db);
212
213$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
214llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-defaultvalues');
215
216$param = '&mode='.$mode;
217
218$enabledisablehtml = $langs->trans("EnableDefaultValues").' ';
219if (!getDolGlobalString('MAIN_ENABLE_DEFAULT_VALUES')) {
220 // Button off, click to enable
221 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.newToken().'&value=1'.$param.'">';
222 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
223 $enabledisablehtml .= '</a>';
224} else {
225 // Button on, click to disable
226 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.newToken().'&value=0'.$param.'">';
227 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
228 $enabledisablehtml .= '</a>';
229}
230
231print load_fiche_titre($langs->trans("DefaultValues"), $enabledisablehtml, 'title_setup');
232
233print '<span class="opacitymedium">'.$langs->trans("DefaultValuesDesc")."</span><br>\n";
234print "<br>\n";
235
236if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
237 $param .= '&contextpage='.urlencode($contextpage);
238}
239if ($limit > 0 && $limit != $conf->liste_limit) {
240 $param .= '&limit='.((int) $limit);
241}
242if ($optioncss != '') {
243 $param .= '&optioncss='.urlencode($optioncss);
244}
245if ($defaulturl) {
246 $param .= '&defaulturl='.urlencode($defaulturl);
247}
248if ($defaultkey) {
249 $param .= '&defaultkey='.urlencode($defaultkey);
250}
251if ($defaultvalue) {
252 $param .= '&defaultvalue='.urlencode($defaultvalue);
253}
254
255
256print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
257if ($optioncss != '') {
258 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
259}
260print '<input type="hidden" name="token" value="'.newToken().'">';
261print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
262print '<input type="hidden" name="action" value="list">';
263print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
264print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
265print '<input type="hidden" name="page" value="'.$page.'">';
266
268
269print dol_get_fiche_head($head, $mode, '', -1, '');
270
271if ($mode == 'sortorder') {
272 print info_admin($langs->trans("WarningSettingSortOrder")).'<br>';
273}
274if ($mode == 'mandatory') {
275 print info_admin($langs->trans("FeatureSupportedOnTextFieldsOnly")).'<br>';
276}
277
278print '<input type="hidden" name="token" value="'.newToken().'">';
279print '<input type="hidden" id="action" name="action" value="">';
280print '<input type="hidden" id="mode" name="mode" value="'.dol_escape_htmltag($mode).'">';
281
282print '<div class="div-table-responsive-no-min">';
283print '<table class="noborder centpercent">';
284print '<tr class="liste_titre">';
285// Page
286$texthelp = $langs->trans("PageUrlForDefaultValues");
287if ($mode == 'createform') {
288 $texthelp .= $langs->trans("PageUrlForDefaultValuesCreate", 'societe/card.php', 'societe/card.php?abc=val1&def=val2');
289} else {
290 $texthelp .= $langs->trans("PageUrlForDefaultValuesList", 'societe/list.php', 'societe/list.php?abc=val1&def=val2');
291}
292$texthelp .= '<br><br>'.$langs->trans("AlsoDefaultValuesAreEffectiveForActionCreate");
293$texturl = $form->textwithpicto($langs->trans("RelativeURL"), $texthelp);
294print_liste_field_titre($texturl, $_SERVER["PHP_SELF"], 'page,param', '', $param, '', $sortfield, $sortorder);
295// Field
296$texthelp = $langs->trans("TheKeyIsTheNameOfHtmlField");
297if ($mode != 'sortorder') {
298 $textkey = $form->textwithpicto($langs->trans("Field"), $texthelp);
299} else {
300 $texthelp = 'field or alias.field';
301 $textkey = $form->textwithpicto($langs->trans("Field"), $texthelp);
302}
303print_liste_field_titre($textkey, $_SERVER["PHP_SELF"], 'param', '', $param, '', $sortfield, $sortorder);
304// Value
305if ($mode != 'focus' && $mode != 'mandatory') {
306 if ($mode != 'sortorder') {
307 $substitutionarray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount')); // Must match list into GETPOST
308 unset($substitutionarray['__USER_SIGNATURE__']);
309 unset($substitutionarray['__SENDEREMAIL_SIGNATURE__']);
310 $texthelp = $langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
311 foreach ($substitutionarray as $key => $val) {
312 $texthelp .= $key.' -> '.$val.'<br>';
313 }
314 $textvalue = $form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, 'subsitutiontooltip');
315 } else {
316 $texthelp = 'ASC or DESC';
317 $textvalue = $form->textwithpicto($langs->trans("SortOrder"), $texthelp);
318 }
319 print_liste_field_titre($textvalue, $_SERVER["PHP_SELF"], 'value', '', $param, '', $sortfield, $sortorder);
320}
321// Entity
322if (isModEnabled('multicompany') && !$user->entity) {
323 print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,page', '', $param, '', $sortfield, $sortorder);
324} else {
325 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
326}
327// Actions
328print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
329print "</tr>\n";
330
331
332// Line to add new record
333print "\n";
334
335print '<tr class="oddeven">';
336// Page
337print '<td>';
338print '<input type="text" class="flat minwidth200 maxwidthonsmartphone" name="defaulturl" value="'.dol_escape_htmltag($defaulturl).'">';
339print '</td>'."\n";
340// Field
341print '<td>';
342print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="'.dol_escape_htmltag($defaultkey).'">';
343print '</td>';
344// Value
345if ($mode != 'focus' && $mode != 'mandatory') {
346 print '<td>';
347 print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultvalue" value="'.dol_escape_htmltag($defaultvalue).'">';
348 print '</td>';
349}
350// Limit to superadmin
351if (isModEnabled('multicompany') && !$user->entity) {
352 print '<td>';
353 print '<input type="text" class="flat" size="1" disabled name="entity" value="' . $conf->entity . '">'; // We see environment, but to change it we must switch on other entity
354 print '</td>';
355} else {
356 print '<td class="center">';
357 print '<input type="hidden" name="entity" value="' . $conf->entity . '">';
358 print '</td>';
359}
360print '<td class="center">';
361$disabled = '';
362if (!getDolGlobalString('MAIN_ENABLE_DEFAULT_VALUES')) {
363 $disabled = ' disabled="disabled"';
364}
365print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add">';
366print '</td>'."\n";
367print '</tr>'."\n";
368
369$result = $object->fetchAll($sortorder, $sortfield, 0, 0, array('t.type' => $mode, 't.entity' => array($user->entity,$conf->entity)));
370
371if (!is_array($result) && $result < 0) {
372 setEventMessages($object->error, $object->errors, 'errors');
373} elseif (is_array($result) && count($result) > 0) {
374 foreach ($result as $key => $defaultvalue) {
375 print '<tr class="oddeven">';
376
377 // Page
378 print '<td>';
379 if ($action != 'edit' || GETPOSTINT('rowid') != $defaultvalue->id) {
380 print $defaultvalue->page;
381 } else {
382 print '<input type="text" name="urlpage" value="'.dol_escape_htmltag($defaultvalue->page).'">';
383 }
384 print '</td>'."\n";
385
386 // Field
387 print '<td>';
388 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
389 print $defaultvalue->param;
390 } else {
391 print '<input type="text" name="key" value="'.dol_escape_htmltag($defaultvalue->param).'">';
392 }
393 print '</td>'."\n";
394
395 // Value
396 if ($mode != 'focus' && $mode != 'mandatory') {
397 print '<td>';
398 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
399 print dol_escape_htmltag($defaultvalue->value);
400 } else {
401 print '<input type="text" name="value" value="'.dol_escape_htmltag($defaultvalue->value).'">';
402 }
403 print '</td>';
404 }
405
406 // Multicompany
407 print '<td>';
408 if (isModEnabled('multicompany')) {
409 print dol_escape_htmltag((string) $defaultvalue->entity);
410 }
411 print '</td>';
412
413 // Actions
414 print '<td class="center">';
415 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
416 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>';
417 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$defaultvalue->id.'&entity='.$defaultvalue->entity.'&mode='.$mode.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
418 } else {
419 print '<input type="hidden" name="page" value="'.$page.'">';
420 print '<input type="hidden" name="rowid" value="'.$id.'">';
421 print '<div name="'.(!empty($defaultvalue->id) ? $defaultvalue->id : 'none').'"></div>';
422 print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
423 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
424 }
425 print '</td>';
426
427 print "</tr>\n";
428 }
429}
430
431print '</table>';
432print '</div>';
433
434print dol_get_fiche_end();
435
436print "</form>\n";
437
438// End of page
439llxFooter();
440$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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).
defaultvalues_prepare_head()
Prepare array with list of tabs.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class for MyObject.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.