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