dolibarr  17.0.4
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 // Load Dolibarr environment
37 require '../../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
39 
40 $field = GETPOST('field', 'alpha');
41 $element = GETPOST('element', 'alpha');
42 $table_element = GETPOST('table_element', 'alpha');
43 $fk_element = GETPOST('fk_element', 'alpha');
44 
45 /*
46  * View
47  */
48 
49 top_httphead();
50 
51 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
52 
53 // Load original field value
54 if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
55  $ext_element = GETPOST('ext_element', 'alpha');
56  $field = substr($field, 8); // remove prefix val_
57  $type = GETPOST('type', 'alpha');
58  $loadmethod = (GETPOST('loadmethod', 'alpha') ? GETPOST('loadmethod', 'alpha') : 'getValueFrom');
59 
60  if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) {
61  $element = $regs[1];
62  $subelement = $regs[2];
63  }
64 
65  if ($element == 'propal') {
66  $element = 'propale';
67  } elseif ($element == 'fichinter') {
68  $element = 'ficheinter';
69  } elseif ($element == 'product') {
70  $element = 'produit';
71  } elseif ($element == 'member') {
72  $element = 'adherent';
73  } elseif ($element == 'order_supplier') {
74  $element = 'fournisseur';
75  $subelement = 'commande';
76  } elseif ($element == 'invoice_supplier') {
77  $element = 'fournisseur';
78  $subelement = 'facture';
79  }
80 
81  if ($user->rights->$element->lire || $user->rights->$element->read
82  || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
83  || ($element == 'payment' && $user->rights->facture->lire)
84  || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire)) {
85  if ($type == 'select') {
86  $methodname = 'load_cache_'.$loadmethod;
87  $cachename = 'cache_'.GETPOST('loadmethod', 'alpha');
88 
89  $form = new Form($db);
90  if (method_exists($form, $methodname)) {
91  $ret = $form->$methodname();
92  if ($ret > 0) {
93  echo json_encode($form->$cachename);
94  }
95  } elseif (!empty($ext_element)) {
96  $module = $subelement = $ext_element;
97  if (preg_match('/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
98  $module = $regs[1];
99  $subelement = $regs[2];
100  }
101 
102  dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
103  $classname = 'Actions'.ucfirst($subelement);
104  $object = new $classname($db);
105  $ret = $object->$methodname($fk_element);
106  if ($ret > 0) {
107  echo json_encode($object->$cachename);
108  }
109  }
110  } else {
111  $object = new GenericObject($db);
112  $value = $object->$loadmethod($table_element, $fk_element, $field);
113  echo $value;
114  }
115  } else {
116  echo $langs->transnoentities('NotEnoughPermissions');
117  }
118 }
Class to manage generation of HTML components Only common components must be here.
Class of a generic business object.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440