dolibarr  17.0.4
objectonoff.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2022 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 
24 if (!defined('NOTOKENRENEWAL')) {
25  define('NOTOKENRENEWAL', '1'); // Disables token renewal
26 }
27 if (!defined('NOREQUIREMENU')) {
28  define('NOREQUIREMENU', '1');
29 }
30 if (!defined('NOREQUIREHTML')) {
31  define('NOREQUIREHTML', '1');
32 }
33 if (!defined('NOREQUIREAJAX')) {
34  define('NOREQUIREAJAX', '1');
35 }
36 if (!defined('NOREQUIRESOC')) {
37  define('NOREQUIRESOC', '1');
38 }
39 if (!defined('NOREQUIRETRAN')) {
40  define('NOREQUIRETRAN', '1');
41 }
42 
43 // Load Dolibarr environment
44 require '../../main.inc.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
46 
47 $action = GETPOST('action', 'aZ09');
48 $id = GETPOST('id', 'int');
49 $value = GETPOST('value', 'int');
50 $field = GETPOST('field', 'alpha');
51 $element = GETPOST('element', 'alpha');
52 $format = 'int';
53 
54 $object = new GenericObject($db);
55 
56 $tablename = $element;
57 if ($tablename == 'websitepage') {
58  $tablename = 'website_page';
59 }
60 
61 $object->table_element = $tablename;
62 $object->id = $id;
63 $object->fields[$field] = array('type' => $format, 'enabled' => 1);
64 
65 // Security check
66 if (!empty($user->socid)) {
67  $socid = $user->socid;
68 }
69 
70 //$user->hasRight('societe', 'lire') = 0;$user->rights->fournisseur->lire = 0;
71 //restrictedArea($user, 'societe', $id);
72 
73 if (in_array($field, array('status'))) {
74  restrictedArea($user, $element, $id);
75 } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
76  restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid');
77 } else {
78  httponly_accessforbidden("Bad value for combination of parameters element/field.");
79 }
80 
81 
82 /*
83  * View
84  */
85 
86 top_httphead();
87 
88 print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
89 
90 // Registering new values
91 if (($action == 'set') && !empty($id)) {
92  $triggerkey = strtoupper($element).'_UPDATE';
93  // Special case
94  if ($triggerkey == 'SOCIETE_UPDATE') {
95  $triggerkey = 'COMPANY_MODIFY';
96  }
97  if ($triggerkey == 'PRODUCT_UPDATE') {
98  $triggerkey = 'PRODUCT_MODIFY';
99  }
100 
101  $object->setValueFrom($field, $value, $tablename, $id, $format, '', $user, $triggerkey);
102 }
Class of a generic business object.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
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.