dolibarr  16.0.5
objectonoff.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <https://www.gnu.org/licenses/>.
15  */
16 
23 if (!defined('NOTOKENRENEWAL')) {
24  define('NOTOKENRENEWAL', '1'); // Disables token renewal
25 }
26 if (!defined('NOREQUIREMENU')) {
27  define('NOREQUIREMENU', '1');
28 }
29 if (!defined('NOREQUIREHTML')) {
30  define('NOREQUIREHTML', '1');
31 }
32 if (!defined('NOREQUIREAJAX')) {
33  define('NOREQUIREAJAX', '1');
34 }
35 if (!defined('NOREQUIRESOC')) {
36  define('NOREQUIRESOC', '1');
37 }
38 if (!defined('NOREQUIRETRAN')) {
39  define('NOREQUIRETRAN', '1');
40 }
41 
42 require '../../main.inc.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
44 
45 $action = GETPOST('action', 'aZ09');
46 $id = GETPOST('id', 'int');
47 $value = GETPOST('value', 'int');
48 $field = GETPOST('field', 'alpha');
49 $element = GETPOST('element', 'alpha');
50 $format = 'int';
51 
52 $object = new GenericObject($db);
53 
54 $tablename = $element;
55 if ($tablename == 'websitepage') {
56  $tablename = 'website_page';
57 }
58 
59 $object->table_element = $tablename;
60 $object->id = $id;
61 $object->fields[$field] = array('type' => $format, 'enabled' => 1);
62 
63 // Security check
64 if (!empty($user->socid)) {
65  $socid = $user->socid;
66 }
67 
68 if (in_array($field, array('status'))) {
69  restrictedArea($user, $element, $id);
70 } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
71  restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid');
72 } else {
73  accessforbidden("Bad value for combination of parameters element/field.", 0, 0, 1);
74  exit;
75 }
76 
77 
78 /*
79  * View
80  */
81 
82 top_httphead();
83 
84 print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
85 
86 // Registering new values
87 if (($action == 'set') && !empty($id)) {
88  $triggerkey = strtoupper($element).'_UPDATE';
89  // Special case
90  if ($triggerkey == 'SOCIETE_UPDATE') {
91  $triggerkey = 'COMPANY_MODIFY';
92  }
93  if ($triggerkey == 'PRODUCT_UPDATE') {
94  $triggerkey = 'PRODUCT_MODIFY';
95  }
96 
97  $object->setValueFrom($field, $value, $tablename, $id, $format, '', $user, $triggerkey);
98 }
dol_escape_htmltag
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.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
GenericObject
Class of a generic business object.
Definition: genericobject.class.php:30
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933