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