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