dolibarr 18.0.6
objectonoff.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
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}
39
40// Load Dolibarr environment
41require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
43
44$action = GETPOST('action', 'aZ09');
45$backtopage = GETPOST('backtopage');
46
47$id = GETPOST('id', 'int');
48$element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule)
49$field = GETPOST('field', 'alpha');
50$value = GETPOST('value', 'int');
51$format = 'int';
52
53// Load object according to $id and $element
54$object = fetchObjectByElement($id, $element);
55if (!is_object($object)) {
56 httponly_accessforbidden("Bad value for combination of parameters element/field: Object not found."); // This includes the exit.
57}
58
59$object->fields[$field] = array('type' => $format, 'enabled' => 1);
60
61$module = $object->module;
62$element = $object->element;
63$usesublevelpermission = ($module != $element ? $element : '');
64if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly
65 $usesublevelpermission = '';
66}
67
68//print $object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
69
70// Security check
71if (!empty($user->socid)) {
72 $socid = $user->socid;
73 if (!empty($object->socid) && $socid != $object->socid) {
74 httponly_accessforbidden("Access on object not allowed for this external user."); // This includes the exit.
75 }
76}
77
78// We check permission.
79// Check is done on $user->rights->element->create or $user->rights->element->subelement->create (because $action = 'set')
80if (preg_match('/statu[st]$/', $field) || ($field == 'evenunsubscribe' && $object->table_element == 'mailing')) {
81 restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission);
82} elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
83 restrictedArea($user, 'produit|service', $object, 'product&product', '', '', 'rowid');
84} else {
85 httponly_accessforbidden("Bad value for combination of parameters element/field: Field not supported."); // This includes the exit.
86}
87
88
89/*
90 * View
91 */
92
94
95print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
96
97// Registering new values
98if (($action == 'set') && !empty($id)) {
99 $triggerkey = strtoupper(($module != $element ? $module.'_' : '').$element).'_UPDATE';
100 // Special case
101 if ($triggerkey == 'SOCIETE_UPDATE') {
102 $triggerkey = 'COMPANY_MODIFY';
103 }
104 if ($triggerkey == 'PRODUCT_UPDATE') {
105 $triggerkey = 'PRODUCT_MODIFY';
106 }
107
108 $result = $object->setValueFrom($field, $value, $object->table_element, $id, $format, '', $user, $triggerkey);
109
110 if ($result < 0) {
111 print $object->error;
112 http_response_code(500);
113 exit;
114 }
115
116 if ($backtopage) {
117 header('Location: '.$backtopage);
118 exit;
119 }
120}
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
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...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.