dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
25if (!defined('NOTOKENRENEWAL')) {
26 define('NOTOKENRENEWAL', '1'); // Disables token renewal
27}
28if (!defined('NOREQUIREMENU')) {
29 define('NOREQUIREMENU', '1');
30}
31if (!defined('NOREQUIREHTML')) {
32 define('NOREQUIREHTML', '1');
33}
34if (!defined('NOREQUIREAJAX')) {
35 define('NOREQUIREAJAX', '1');
36}
37if (!defined('NOREQUIRESOC')) {
38 define('NOREQUIRESOC', '1');
39}
40if (!defined('NOREQUIRETRAN')) {
41 define('NOREQUIRETRAN', '1');
42}
43if (!defined('CSRFCHECK_WITH_TOKEN')) {
44 define('CSRFCHECK_WITH_TOKEN', '1'); // Token is required even in GET mode
45}
46
47// Load Dolibarr environment
48require '../../main.inc.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
50
59$action = GETPOST('action', 'aZ09'); // set or del
60$name = GETPOST('name', 'alpha');
61$entity = GETPOSTINT('entity');
62$value = (GETPOST('value', 'aZ09') != '' ? GETPOST('value', 'aZ09') : 1);
63$userconst = GETPOSTINT('userconst');
64
65
66// Security check
67if (empty($user->admin) && empty($userconst)) {
68 httponly_accessforbidden('This ajax component can be called by admin user only');
69}
70
71
72/*
73 * Actions
74 */
75
76// Registering the new value of constant
77if (!empty($action) && !empty($name)) {
78 if ($userconst) {
79 $tmpuser = new User($db);
80 $tmpuser->id = $userconst;
81 if ($tmpuser->id == $user->id || $user->hasRight('user', 'user', 'creer')) {
82 if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header.
83 dol_set_user_param($db, $conf, $tmpuser, array($name => $value));
84 } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header.
85 dol_set_user_param($db, $conf, $tmpuser, array($name => ''));
86 }
87 }
88 } else {
89 if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header.
90 dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
91 } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header.
92 dolibarr_del_const($db, $name, $entity);
93 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
94 dolibarr_del_const($db, $name, 0);
95 }
96 }
97 }
98} else {
99 httponly_accessforbidden('Param action and name is required', 403);
100}
101
102
103/*
104 * View
105 */
106
108
109//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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.