dolibarr 21.0.0-alpha
myobject.php
1<?php
2/* Copyright (C) 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
23if (!defined('NOTOKENRENEWAL')) {
24 define('NOTOKENRENEWAL', 1); // Disables token renewal
25}
26if (!defined('NOREQUIREMENU')) {
27 define('NOREQUIREMENU', '1');
28}
29if (!defined('NOREQUIREHTML')) {
30 define('NOREQUIREHTML', '1');
31}
32if (!defined('NOREQUIREAJAX')) {
33 define('NOREQUIREAJAX', '1');
34}
35if (!defined('NOREQUIRESOC')) {
36 define('NOREQUIRESOC', '1');
37}
38if (!defined('NOCSRFCHECK')) {
39 define('NOCSRFCHECK', '1');
40}
41if (!defined('NOREQUIREHTML')) {
42 define('NOREQUIREHTML', '1');
43}
44
45// Load Dolibarr environment
46$res = 0;
47if (!$res && file_exists("../../main.inc.php")) {
48 $res = @include "../../main.inc.php";
49}
50if (!$res && file_exists("../../../main.inc.php")) {
51 $res = @include "../../../main.inc.php";
52}
53if (!$res) {
54 die("Include of main fails");
55}
56dol_include_once('/mymodule/class/myobject.class.php');
57
58$mode = GETPOST('mode', 'aZ09');
59$objectId = GETPOST('objectId', 'aZ09');
60$field = GETPOST('field', 'aZ09');
61$value = GETPOST('value', 'aZ09');
62
63// @phan-suppress-next-line PhanUndeclaredClass
64$object = new MyObject($db);
65
66// Security check
67if (!$user->hasRight('mymodule', 'myobject', 'write')) {
69}
70
71/*
72 * View
73 */
74
75dol_syslog("Call ajax mymodule/ajax/myobject.php");
76
78
79// Update the object field with the new value
80if ($objectId && $field && isset($value)) {
81 $object->fetch($objectId);
82 if ($object->id > 0) {
83 $object->$field = $value;
84 }
85 $result = $object->update($user);
86
87 if ($result < 0) {
88 print json_encode(['status' => 'error', 'message' => 'Error updating '. $field]);
89 } else {
90 print json_encode(['status' => 'success', 'message' => $field . ' updated successfully']);
91 }
92}
93
94$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class for MyObject.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.