dolibarr  7.0.0-beta
loadinplace.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Regis Houssin <regis.houssin@capnetworks.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 <http://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('NOREQUIREHTML')) define('NOREQUIREHTML','1');
26 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
27 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
28 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
29 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
32 
33 $field = GETPOST('field','alpha');
34 $element = GETPOST('element','alpha');
35 $table_element = GETPOST('table_element','alpha');
36 $fk_element = GETPOST('fk_element','alpha');
37 
38 /*
39  * View
40  */
41 
42 top_httphead();
43 
44 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
45 
46 // Load original field value
47 if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($fk_element))
48 {
49  $ext_element = GETPOST('ext_element','alpha');
50  $field = substr($field, 8); // remove prefix val_
51  $type = GETPOST('type','alpha');
52  $loadmethod = (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
53 
54  if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
55  {
56  $element = $regs[1];
57  $subelement = $regs[2];
58  }
59 
60  if ($element == 'propal') $element = 'propale';
61  else if ($element == 'fichinter') $element = 'ficheinter';
62  else if ($element == 'product') $element = 'produit';
63  else if ($element == 'member') $element = 'adherent';
64  else if ($element == 'order_supplier') {
65  $element = 'fournisseur';
66  $subelement = 'commande';
67  }
68  else if ($element == 'invoice_supplier') {
69  $element = 'fournisseur';
70  $subelement = 'facture';
71  }
72 
73  if ($user->rights->$element->lire || $user->rights->$element->read
74  || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
75  || ($element == 'payment' && $user->rights->facture->lire)
76  || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire))
77  {
78  if ($type == 'select')
79  {
80  $methodname = 'load_cache_'.$loadmethod;
81  $cachename = 'cache_'.GETPOST('loadmethod','alpha');
82 
83  $form = new Form($db);
84  if (method_exists($form, $methodname))
85  {
86  $ret = $form->$methodname();
87  if ($ret > 0) echo json_encode($form->$cachename);
88  }
89  else if (! empty($ext_element))
90  {
91  $module = $subelement = $ext_element;
92  if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
93  {
94  $module = $regs[1];
95  $subelement = $regs[2];
96  }
97 
98  dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
99  $classname = 'Actions'.ucfirst($subelement);
100  $object = new $classname($db);
101  $ret = $object->$methodname($fk_element);
102  if ($ret > 0) echo json_encode($object->$cachename);
103  }
104  }
105  else
106  {
107  $object = new GenericObject($db);
108  $value=$object->$loadmethod($table_element, $fk_element, $field);
109  echo $value;
110  }
111  }
112  else
113  {
114  echo $langs->transnoentities('NotEnoughPermissions');
115  }
116 }
117 
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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='')
Return a prefix to use for this Dolibarr instance, for session/cookie names or email id...
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052