dolibarr 21.0.0-alpha
editextrafield.php
Go to the documentation of this file.
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
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}
39if (!defined('NOCSRFCHECK')) {
40 define('NOCSRFCHECK', '1');
41}
42if (!defined('NOREQUIREHTML')) {
43 define('NOREQUIREHTML', '1');
44}
45
46// Load Dolibarr environment
47include '../../main.inc.php';
48
49$objectType = GETPOST('objectType', 'aZ09');
50$objectId = GETPOST('objectId', 'aZ09');
51$field = GETPOST('field', 'aZ09');
52$value = GETPOST('value', 'aZ09');
53
54$module = getElementProperties($objectType)['module'];
55$element_ref = '';
56if (is_numeric($objectId)) {
57 $objectId = (int) $objectId;
58} else {
59 $element_ref = $objectId;
60 $objectId = 0;
61}
62$object = fetchObjectByElement($objectId, $objectType, $element_ref);
63
64// Security check
65if (!$user->hasRight($module, $object->element, 'write') && !$user->hasRight($module, 'write')) {
67}
68
69/*
70 * View
71 */
72
73dol_syslog("Call ajax core/ajax/editextrafield.php");
74
76
77// Update the object field with the new value
78if ($object->id > 0 && $field && isset($value)) {
79 $object->array_options['options_'.$field] = $value;
80 $result = $object->update($user);
81 if ($result < 0) {
82 print json_encode(['status' => 'error', 'message' => 'Error updating '. $field]);
83 } else {
84 print json_encode(['status' => 'success', 'message' => $field . ' updated successfully']);
85 }
86}
87
88$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
getElementProperties($elementType)
Get an array with properties of an element.
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='', $useCache=0, $maxCacheByType=10)
Fetch an object from its id and element_type Inclusion of classes is automatic.
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.