dolibarr 23.0.3
ajaxfield.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2024 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
25if (!defined('NOTOKENRENEWAL')) {
26 // Disables token renewal
27 define('NOTOKENRENEWAL', 1);
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38if (!defined('NOHEADERNOFOOTER')) {
39 define('NOHEADERNOFOOTER', '1');
40}
41
42require_once '../webportal.main.inc.php';
43require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
44require_once DOL_DOCUMENT_ROOT . '/core/class/fieldsmanager.class.php';
45
53// object id
54$objectid = GETPOST('objectid', 'aZ09');
55// 'module' or 'myobject@mymodule', 'mymodule_myobject'
56$objecttype = GETPOST('objecttype', 'aZ09arobase');
57$objectkey = GETPOST('objectkey', 'restricthtml');
58$search = GETPOST('search', 'restricthtml');
59$page = GETPOSTINT('page');
60$mode = GETPOST('mode', 'aZ09');
61$value = GETPOST('value', 'alphanohtml');
62$dependencyvalue = GETPOST('dependencyvalue', 'alphanohtml');
63$limit = 10;
64$element_ref = '';
65if (is_numeric($objectid)) {
66 $objectid = (int) $objectid;
67} else {
68 $element_ref = $objectid;
69 $objectid = 0;
70}
71// Load object according to $element
72$object = fetchObjectByElement($objectid, $objecttype, $element_ref);
73if (empty($object->element)) {
74 httponly_accessforbidden('Failed to get object with fetchObjectByElement(id=' . $objectid . ', objecttype=' . $objecttype . ')');
75}
76
77$module = $object->module;
78$element = $object->element;
79
80$usesublevelpermission = ($module != $element ? $element : '');
81if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly
82 $usesublevelpermission = '';
83}
84
85// print $object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
86
87// Security check
88restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission);
89if (!isModEnabled('webportal')) {
91}
92
93
94/*
95 * View
96 */
97
99
100$data = [
101 'results' => [],
102 'pagination' => [
103 'more' => true,
104 ]
105];
106$nbResult = 0;
107if ($object instanceof CommonObject) {
108 $extrafields = new ExtraFields($db);
109 $extrafields->fetch_name_optionals_label($object->table_element);
110
111 $fieldManager = new FieldsManager($db);
112 $fieldInfos = $fieldManager->getFieldsInfos($objectkey, $object, $extrafields, $mode);
113 $field = $fieldManager->getFieldClass($fieldInfos->type);
114 if (isset($field)) {
115 if (method_exists($field, 'getOptions')) {
116 $fieldInfos->optionsSqlPage = $page;
117 $fieldInfos->optionsSqlLimit = $limit;
118 if ($dependencyvalue !== '') {
119 $fieldInfos->optionsSqlDependencyValue = $dependencyvalue;
120 }
121
125 '@phan-var-force CommonSellistField $field';
126 $options = $field->getOptions($fieldInfos, $objectkey, $page == 1, true);
127 if (is_array($options)) {
128 $nbResult = count($options);
129 foreach ($options as $key => $option) {
130 $data['results'][] = [
131 'id' => $key,
132 'text' => $option['label'],
133 ];
134 }
135 } else {
136 dol_syslog('htdocs/core/ajax/ajaxfield.php ' . $field->errorsToString(), LOG_ERR);
137 }
138 } else {
139 dol_syslog('htdocs/core/ajax/ajaxfield.php method getOptions() don\'t exist in class ' . get_class($field), LOG_ERR);
140 }
141 } else {
142 dol_syslog('htdocs/core/ajax/ajaxfield.php ' . $fieldManager->errorsToString(), LOG_ERR);
143 }
144}
145
146if ($page > 1 && $nbResult < 10) {
147 $data['pagination'] = [
148 'more' => false,
149 ];
150}
151print json_encode($data);
152
153$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage standard extra fields.
Class to manage fields.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
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.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.