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