dolibarr 23.0.3
loadinplace.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2014 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1'); // Disables token renewal
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREAJAX')) {
33 define('NOREQUIREAJAX', '1');
34}
35if (!defined('NOREQUIRESOC')) {
36 define('NOREQUIRESOC', '1');
37}
38
39// Load Dolibarr environment
40require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
42
51$field = GETPOST('field', 'alpha');
52$element = GETPOST('element', 'alpha');
53$table_element = GETPOST('table_element', 'alpha');
54$fk_element = GETPOST('fk_element', 'alpha');
55
56// Load object according to $id and $element
57$element_ref = '';
58if (is_numeric($fk_element)) {
59 $id = (int) $fk_element;
60} else {
61 $element_ref = $fk_element;
62 $id = 0;
63}
64$object = fetchObjectByElement($id, $element, $element_ref);
65
66$module = $object->module;
67$element = $object->element;
68$usesublevelpermission = ($module != $element ? $element : '');
69if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly
70 $usesublevelpermission = '';
71}
72
73//print $object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
74
75// Security check
76$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return
77if (!$result) {
78 httponly_accessforbidden('Not allowed by restrictArea');
79}
80
81if (!getDolGlobalString('MAIN_USE_JQUERY_JEDITABLE')) {
82 httponly_accessforbidden('Can be used only when option MAIN_USE_JQUERY_JEDITABLE is set');
83}
84
85
86/*
87 * View
88 */
89
91
92//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
93
94// Load original field value
95if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
96 $ext_element = GETPOST('ext_element', 'alpha');
97 $field = substr($field, 8); // remove prefix val_
98 $type = GETPOST('type', 'alpha');
99 $loadmethod = (GETPOST('loadmethod', 'alpha') ? GETPOST('loadmethod', 'alpha') : 'getValueFrom');
100
101 if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) {
102 $element = $regs[1];
103 $subelement = $regs[2];
104 }
105
106 if ($element == 'propal') {
107 $element = 'propale';
108 } elseif ($element == 'fichinter') {
109 $element = 'ficheinter';
110 } elseif ($element == 'product') {
111 $element = 'produit';
112 } elseif ($element == 'member') {
113 $element = 'adherent';
114 } elseif ($element == 'order_supplier') {
115 $element = 'fournisseur';
116 $subelement = 'commande';
117 } elseif ($element == 'invoice_supplier') {
118 $element = 'fournisseur';
119 $subelement = 'facture';
120 }
121
122 if ($user->hasRight($element, 'lire') || $user->hasRight($element, 'read')
123 || (isset($subelement) && ($user->hasRight($element, $subelement, 'lire') || $user->hasRight($element, $subelement, 'read')))
124 || ($element == 'payment' && $user->hasRight('facture', 'lire'))
125 || ($element == 'payment_supplier' && $user->hasRight('fournisseur', 'facture', 'lire'))) {
126 if ($type == 'select') {
127 $methodname = 'load_cache_'.$loadmethod;
128 $cachename = 'cache_'.GETPOST('loadmethod', 'alpha');
129
130 $form = new Form($db);
131 if (method_exists($form, $methodname)) {
132 $ret = $form->$methodname();
133 if ($ret > 0) {
134 echo json_encode($form->$cachename);
135 }
136 } elseif (!empty($ext_element)) {
137 $module = $subelement = $ext_element;
138 $regs = array();
139 if (preg_match('/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
140 $module = $regs[1];
141 $subelement = $regs[2];
142 }
143
144 dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
145 $classname = 'Actions'.ucfirst($subelement);
146 $object = new $classname($db);
147 '@phan-var-force ActionsMulticompany|ActionsAdherentCardCommon|ActionsContactCardCommon|CommonHookActions|ActionsCardProduct|ActionsCardService|ActionsCardCommon $object';
148 $ret = $object->$methodname($fk_element);
149 if ($ret > 0) {
150 echo json_encode($object->$cachename);
151 }
152 }
153 } else {
154 $object = new GenericObject($db);
155 $value = $object->$loadmethod($table_element, (int) $fk_element, $field);
156 echo $value;
157 }
158 } else {
159 echo $langs->transnoentities('NotEnoughPermissions');
160 }
161}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage generation of HTML components Only common components must be here.
Class of a generic business object.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.