dolibarr 19.0.4
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';
87 $massaction = '';
88}
89if (!GETPOST('confirmmassaction', 'alpha') && !empty($massaction) && $massaction != 'presend' && $massaction != 'confirm_presend') {
90 $massaction = '';
91}
92
93$parameters = array();
94$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
95if ($reshook < 0) {
96 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
97}
98
99include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
100
101// Purge search criteria
102if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
103 $defaulturl = '';
104 $defaultkey = '';
105 $defaultvalue = '';
106 $toselect = array();
107 $search_array_options = array();
108}
109
110if ($action == 'setMAIN_ENABLE_DEFAULT_VALUES') {
111 if (GETPOST('value')) {
112 dolibarr_set_const($db, 'MAIN_ENABLE_DEFAULT_VALUES', 1, 'chaine', 0, '', $conf->entity);
113 } else {
114 dolibarr_set_const($db, 'MAIN_ENABLE_DEFAULT_VALUES', 0, 'chaine', 0, '', $conf->entity);
115 }
116}
117
118if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('actionmodify')) {
119 $error = 0;
120
121 if (($action == 'add' || (GETPOST('add') && $action != 'update'))) {
122 if (empty($defaulturl)) {
123 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Url")), null, 'errors');
124 $error++;
125 }
126 if (empty($defaultkey)) {
127 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Field")), null, 'errors');
128 $error++;
129 }
130 }
131 if (GETPOST('actionmodify')) {
132 if (empty($urlpage)) {
133 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Url")), null, 'errors');
134 $error++;
135 }
136 if (empty($key)) {
137 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Field")), null, 'errors');
138 $error++;
139 }
140 }
141
142 if (!$error) {
143 if ($action == 'add' || (GETPOST('add') && $action != 'update')) {
144 $object->type=$mode;
145 $object->user_id=0;
146 $object->page=$defaulturl;
147 $object->param=$defaultkey;
148 $object->value=$defaultvalue;
149 $object->entity=$conf->entity;
150 $result=$object->create($user);
151 if ($result < 0) {
152 $action = '';
153 setEventMessages($object->error, $object->errors, 'errors');
154 } else {
155 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
156 $action = '';
157 $defaulturl = '';
158 $defaultkey = '';
159 $defaultvalue = '';
160 }
161 }
162 if (GETPOST('actionmodify')) {
163 $object->id=$id;
164 $object->type=$mode;
165 $object->page=$urlpage;
166 $object->param=$key;
167 $object->value=$value;
168 $object->entity=$conf->entity;
169 $result=$object->update($user);
170 if ($result<0) {
171 $action = '';
172 setEventMessages($object->error, $object->errors, 'errors');
173 } else {
174 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
175 $action = "";
176 $defaulturl = '';
177 $defaultkey = '';
178 $defaultvalue = '';
179 }
180 }
181 }
182}
183
184// Delete line from delete picto
185if ($action == 'delete') {
186 $object->id=$id;
187 $result=$object->delete($user);
188 if ($result<0) {
189 $action = '';
190 setEventMessages($object->error, $object->errors, 'errors');
191 }
192}
193
194
195
196/*
197 * View
198 */
199
200$form = new Form($db);
201$formadmin = new FormAdmin($db);
202
203$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
204llxHeader('', $langs->trans("Setup"), $wikihelp);
205
206$param = '&mode='.$mode;
207
208$enabledisablehtml = $langs->trans("EnableDefaultValues").' ';
209if (!getDolGlobalString('MAIN_ENABLE_DEFAULT_VALUES')) {
210 // Button off, click to enable
211 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.newToken().'&value=1'.$param.'">';
212 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
213 $enabledisablehtml .= '</a>';
214} else {
215 // Button on, click to disable
216 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_DEFAULT_VALUES&token='.newToken().'&value=0'.$param.'">';
217 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
218 $enabledisablehtml .= '</a>';
219}
220
221print load_fiche_titre($langs->trans("DefaultValues"), $enabledisablehtml, 'title_setup');
222
223print '<span class="opacitymedium">'.$langs->trans("DefaultValuesDesc")."</span><br>\n";
224print "<br>\n";
225
226if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
227 $param .= '&contextpage='.urlencode($contextpage);
228}
229if ($limit > 0 && $limit != $conf->liste_limit) {
230 $param .= '&limit='.((int) $limit);
231}
232if ($optioncss != '') {
233 $param .= '&optioncss='.urlencode($optioncss);
234}
235if ($defaulturl) {
236 $param .= '&defaulturl='.urlencode($defaulturl);
237}
238if ($defaultkey) {
239 $param .= '&defaultkey='.urlencode($defaultkey);
240}
241if ($defaultvalue) {
242 $param .= '&defaultvalue='.urlencode($defaultvalue);
243}
244
245
246print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
247if ($optioncss != '') {
248 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
249}
250print '<input type="hidden" name="token" value="'.newToken().'">';
251print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
252print '<input type="hidden" name="action" value="list">';
253print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
254print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
255print '<input type="hidden" name="page" value="'.$page.'">';
256
258
259print dol_get_fiche_head($head, $mode, '', -1, '');
260
261if ($mode == 'sortorder') {
262 print info_admin($langs->trans("WarningSettingSortOrder")).'<br>';
263}
264if ($mode == 'mandatory') {
265 print info_admin($langs->trans("FeatureSupportedOnTextFieldsOnly")).'<br>';
266}
267
268print '<input type="hidden" name="token" value="'.newToken().'">';
269print '<input type="hidden" id="action" name="action" value="">';
270print '<input type="hidden" id="mode" name="mode" value="'.dol_escape_htmltag($mode).'">';
271
272print '<div class="div-table-responsive-no-min">';
273print '<table class="noborder centpercent">';
274print '<tr class="liste_titre">';
275// Page
276$texthelp = $langs->trans("PageUrlForDefaultValues");
277if ($mode == 'createform') {
278 $texthelp .= $langs->trans("PageUrlForDefaultValuesCreate", 'societe/card.php', 'societe/card.php?abc=val1&def=val2');
279} else {
280 $texthelp .= $langs->trans("PageUrlForDefaultValuesList", 'societe/list.php', 'societe/list.php?abc=val1&def=val2');
281}
282$texthelp .= '<br><br>'.$langs->trans("AlsoDefaultValuesAreEffectiveForActionCreate");
283$texturl = $form->textwithpicto($langs->trans("RelativeURL"), $texthelp);
284print_liste_field_titre($texturl, $_SERVER["PHP_SELF"], 'page,param', '', $param, '', $sortfield, $sortorder);
285// Field
286$texthelp = $langs->trans("TheKeyIsTheNameOfHtmlField");
287if ($mode != 'sortorder') {
288 $textkey = $form->textwithpicto($langs->trans("Field"), $texthelp);
289} else {
290 $texthelp = 'field or alias.field';
291 $textkey = $form->textwithpicto($langs->trans("Field"), $texthelp);
292}
293print_liste_field_titre($textkey, $_SERVER["PHP_SELF"], 'param', '', $param, '', $sortfield, $sortorder);
294// Value
295if ($mode != 'focus' && $mode != 'mandatory') {
296 if ($mode != 'sortorder') {
297 $substitutionarray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount')); // Must match list into GETPOST
298 unset($substitutionarray['__USER_SIGNATURE__']);
299 unset($substitutionarray['__SENDEREMAIL_SIGNATURE__']);
300 $texthelp = $langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
301 foreach ($substitutionarray as $key => $val) {
302 $texthelp .= $key.' -> '.$val.'<br>';
303 }
304 $textvalue = $form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, 'subsitutiontooltip');
305 } else {
306 $texthelp = 'ASC or DESC';
307 $textvalue = $form->textwithpicto($langs->trans("SortOrder"), $texthelp);
308 }
309 print_liste_field_titre($textvalue, $_SERVER["PHP_SELF"], 'value', '', $param, '', $sortfield, $sortorder);
310}
311// Entity
312if (isModEnabled('multicompany') && !$user->entity) {
313 print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,page', '', $param, '', $sortfield, $sortorder);
314} else {
315 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
316}
317// Actions
318print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
319print "</tr>\n";
320
321
322// Line to add new record
323print "\n";
324
325print '<tr class="oddeven">';
326// Page
327print '<td>';
328print '<input type="text" class="flat minwidth200 maxwidthonsmartphone" name="defaulturl" value="'.dol_escape_htmltag($defaulturl).'">';
329print '</td>'."\n";
330// Field
331print '<td>';
332print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="'.dol_escape_htmltag($defaultkey).'">';
333print '</td>';
334// Value
335if ($mode != 'focus' && $mode != 'mandatory') {
336 print '<td>';
337 print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultvalue" value="'.dol_escape_htmltag($defaultvalue).'">';
338 print '</td>';
339}
340// Limit to superadmin
341if (isModEnabled('multicompany') && !$user->entity) {
342 print '<td>';
343 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
344 print '</td>';
345} else {
346 print '<td class="center">';
347 print '<input type="hidden" name="entity" value="' . $conf->entity . '">';
348 print '</td>';
349}
350print '<td class="center">';
351$disabled = '';
352if (!getDolGlobalString('MAIN_ENABLE_DEFAULT_VALUES')) {
353 $disabled = ' disabled="disabled"';
354}
355print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add">';
356print '</td>'."\n";
357print '</tr>'."\n";
358
359$result = $object->fetchAll($sortorder, $sortfield, 0, 0, array('t.type'=>$mode,'t.entity'=>array($user->entity,$conf->entity)));
360
361if (!is_array($result) && $result < 0) {
362 setEventMessages($object->error, $object->errors, 'errors');
363} elseif (is_array($result) && count($result) > 0) {
364 foreach ($result as $key => $defaultvalue) {
365 print '<tr class="oddeven">';
366
367 // Page
368 print '<td>';
369 if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->id) {
370 print $defaultvalue->page;
371 } else {
372 print '<input type="text" name="urlpage" value="'.dol_escape_htmltag($defaultvalue->page).'">';
373 }
374 print '</td>'."\n";
375
376 // Field
377 print '<td>';
378 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
379 print $defaultvalue->param;
380 } else {
381 print '<input type="text" name="key" value="'.dol_escape_htmltag($defaultvalue->param).'">';
382 }
383 print '</td>'."\n";
384
385 // Value
386 if ($mode != 'focus' && $mode != 'mandatory') {
387 print '<td>';
388 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
389 print dol_escape_htmltag($defaultvalue->value);
390 } else {
391 print '<input type="text" name="value" value="'.dol_escape_htmltag($defaultvalue->value).'">';
392 }
393 print '</td>';
394 }
395
396 // Multicompany
397 print '<td>';
398 if (isModEnabled('multicompany')) {
399 print dol_escape_htmltag($defaultvalue->entity);
400 }
401 print '</td>';
402
403 // Actions
404 print '<td class="center">';
405 if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) {
406 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>';
407 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$defaultvalue->id.'&entity='.$defaultvalue->entity.'&mode='.$mode.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
408 } else {
409 print '<input type="hidden" name="page" value="'.$page.'">';
410 print '<input type="hidden" name="rowid" value="'.$id.'">';
411 print '<div name="'.(!empty($defaultvalue->id) ? $defaultvalue->id : 'none').'"></div>';
412 print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
413 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
414 }
415 print '</td>';
416
417 print "</tr>\n";
418 }
419}
420
421print '</table>';
422print '</div>';
423
424print dol_get_fiche_end();
425
426print "</form>\n";
427
428// End of page
429llxFooter();
430$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.