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