dolibarr 21.0.0-alpha
constantonoff.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
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
24if (!defined('NOTOKENRENEWAL')) {
25 define('NOTOKENRENEWAL', '1'); // Disables token renewal
26}
27if (!defined('NOREQUIREMENU')) {
28 define('NOREQUIREMENU', '1');
29}
30if (!defined('NOREQUIREHTML')) {
31 define('NOREQUIREHTML', '1');
32}
33if (!defined('NOREQUIREAJAX')) {
34 define('NOREQUIREAJAX', '1');
35}
36if (!defined('NOREQUIRESOC')) {
37 define('NOREQUIRESOC', '1');
38}
39if (!defined('NOREQUIRETRAN')) {
40 define('NOREQUIRETRAN', '1');
41}
42if (!defined('CSRFCHECK_WITH_TOKEN')) {
43 define('CSRFCHECK_WITH_TOKEN', '1'); // Token is required even in GET mode
44}
45
46// Load Dolibarr environment
47require '../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
49
50$action = GETPOST('action', 'aZ09'); // set or del
51$name = GETPOST('name', 'alpha');
52$entity = GETPOSTINT('entity');
53$value = (GETPOST('value', 'aZ09') != '' ? GETPOST('value', 'aZ09') : 1);
54$userconst = GETPOSTINT('userconst');
55
56
57// Security check
58if (empty($user->admin) && empty($userconst)) {
59 httponly_accessforbidden('This ajax component can be called by admin user only');
60}
61
62
63/*
64 * Actions
65 */
66
67// Registering the new value of constant
68if (!empty($action) && !empty($name)) {
69 if ($userconst) {
70 $tmpuser = new User($db);
71 $tmpuser->id = $userconst;
72 if ($tmpuser->id == $user->id || $user->hasRight('user', 'user', 'creer')) {
73 if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header.
74 dol_set_user_param($db, $conf, $tmpuser, array($name => $value));
75 } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header.
76 dol_set_user_param($db, $conf, $tmpuser, array($name => ''));
77 }
78 }
79 } else {
80 if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header.
81 dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
82 } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header.
83 dolibarr_del_const($db, $name, $entity);
84 if ($entity == 1) { // Sometimes the param was saved in both entity 0 and 1. When we work on master entity, we should clean also if entity is 0
85 dolibarr_del_const($db, $name, 0);
86 }
87 }
88 }
89} else {
90 httponly_accessforbidden('Param action and name is required', 403);
91}
92
93
94/*
95 * View
96 */
97
99
100//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Class to manage Dolibarr users.
dol_set_user_param($db, $conf, &$user, $tab)
Save personal parameter.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.