dolibarr  16.0.5
loadinplace.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Regis Houssin <regis.houssin@inodbox.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
23 if (!defined('NOTOKENRENEWAL')) {
24  define('NOTOKENRENEWAL', '1'); // Disables token renewal
25 }
26 if (!defined('NOREQUIREMENU')) {
27  define('NOREQUIREMENU', '1');
28 }
29 if (!defined('NOREQUIREAJAX')) {
30  define('NOREQUIREAJAX', '1');
31 }
32 if (!defined('NOREQUIRESOC')) {
33  define('NOREQUIRESOC', '1');
34 }
35 
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
38 
39 $field = GETPOST('field', 'alpha');
40 $element = GETPOST('element', 'alpha');
41 $table_element = GETPOST('table_element', 'alpha');
42 $fk_element = GETPOST('fk_element', 'alpha');
43 
44 /*
45  * View
46  */
47 
48 top_httphead();
49 
50 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
51 
52 // Load original field value
53 if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
54  $ext_element = GETPOST('ext_element', 'alpha');
55  $field = substr($field, 8); // remove prefix val_
56  $type = GETPOST('type', 'alpha');
57  $loadmethod = (GETPOST('loadmethod', 'alpha') ? GETPOST('loadmethod', 'alpha') : 'getValueFrom');
58 
59  if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) {
60  $element = $regs[1];
61  $subelement = $regs[2];
62  }
63 
64  if ($element == 'propal') {
65  $element = 'propale';
66  } elseif ($element == 'fichinter') {
67  $element = 'ficheinter';
68  } elseif ($element == 'product') {
69  $element = 'produit';
70  } elseif ($element == 'member') {
71  $element = 'adherent';
72  } elseif ($element == 'order_supplier') {
73  $element = 'fournisseur';
74  $subelement = 'commande';
75  } elseif ($element == 'invoice_supplier') {
76  $element = 'fournisseur';
77  $subelement = 'facture';
78  }
79 
80  if ($user->rights->$element->lire || $user->rights->$element->read
81  || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
82  || ($element == 'payment' && $user->rights->facture->lire)
83  || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire)) {
84  if ($type == 'select') {
85  $methodname = 'load_cache_'.$loadmethod;
86  $cachename = 'cache_'.GETPOST('loadmethod', 'alpha');
87 
88  $form = new Form($db);
89  if (method_exists($form, $methodname)) {
90  $ret = $form->$methodname();
91  if ($ret > 0) {
92  echo json_encode($form->$cachename);
93  }
94  } elseif (!empty($ext_element)) {
95  $module = $subelement = $ext_element;
96  if (preg_match('/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
97  $module = $regs[1];
98  $subelement = $regs[2];
99  }
100 
101  dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
102  $classname = 'Actions'.ucfirst($subelement);
103  $object = new $classname($db);
104  $ret = $object->$methodname($fk_element);
105  if ($ret > 0) {
106  echo json_encode($object->$cachename);
107  }
108  }
109  } else {
110  $object = new GenericObject($db);
111  $value = $object->$loadmethod($table_element, $fk_element, $field);
112  echo $value;
113  }
114  } else {
115  echo $langs->transnoentities('NotEnoughPermissions');
116  }
117 }
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
GenericObject
Class of a generic business object.
Definition: genericobject.class.php:30