dolibarr 21.0.0-beta
myobject.php
1<?php
2/* Copyright (C) 2022 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) ---Replace with your own copyright and developer email---
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('NOCSRFCHECK')) {
41 define('NOCSRFCHECK', '1');
42}
43if (!defined('NOREQUIREHTML')) {
44 define('NOREQUIREHTML', '1');
45}
46
47// Load Dolibarr environment
48$res = 0;
49if (!$res && file_exists("../../main.inc.php")) {
50 $res = @include "../../main.inc.php";
51}
52if (!$res && file_exists("../../../main.inc.php")) {
53 $res = @include "../../../main.inc.php";
54}
55if (!$res) {
56 die("Include of main fails");
57}
58dol_include_once('/mymodule/class/myobject.class.php');
59
68$mode = GETPOST('mode', 'aZ09');
69$objectId = GETPOST('objectId', 'aZ09');
70$field = GETPOST('field', 'aZ09');
71$value = GETPOST('value', 'aZ09');
72
73// @phan-suppress-next-line PhanUndeclaredClass
74$object = new MyObject($db);
75
76// Security check
77if (!$user->hasRight('mymodule', 'myobject', 'write')) {
79}
80
81/*
82 * View
83 */
84
85dol_syslog("Call ajax mymodule/ajax/myobject.php");
86
88
89// Update the object field with the new value
90if ($objectId && $field && isset($value)) {
91 $object->fetch($objectId);
92 if ($object->id > 0) {
93 $object->$field = $value;
94 }
95 $result = $object->update($user);
96
97 if ($result < 0) {
98 print json_encode(['status' => 'error', 'message' => 'Error updating '. $field]);
99 } else {
100 print json_encode(['status' => 'success', 'message' => $field . ' updated successfully']);
101 }
102}
103
104$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.