23if (!defined(
'NOTOKENRENEWAL')) {
24 define(
'NOTOKENRENEWAL',
'1');
26if (!defined(
'NOREQUIREMENU')) {
27 define(
'NOREQUIREMENU',
'1');
29if (!defined(
'NOREQUIREAJAX')) {
30 define(
'NOREQUIREAJAX',
'1');
32if (!defined(
'NOREQUIRESOC')) {
33 define(
'NOREQUIRESOC',
'1');
37require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
40$field =
GETPOST(
'field',
'alpha', 2);
41$element =
GETPOST(
'element',
'alpha', 2);
42$table_element =
GETPOST(
'table_element',
'alpha', 2);
43$fk_element =
GETPOST(
'fk_element',
'alpha', 2);
61$module = $object->module;
62$element = $object->element;
63$usesublevelpermission = ($module != $element ? $element :
'');
64if ($usesublevelpermission && !isset($user->rights->$module->$element)) {
65 $usesublevelpermission =
'';
71$result =
restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission,
'fk_soc',
'rowid', 0, 1);
91if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
92 $ext_element =
GETPOST(
'ext_element',
'alpha', 2);
93 $field = substr($field, 8);
94 $type =
GETPOST(
'type',
'alpha', 2);
95 $value = ($type ==
'ckeditor' ?
GETPOST(
'value',
'', 2) :
GETPOST(
'value',
'alpha', 2));
96 $loadmethod =
GETPOST(
'loadmethod',
'alpha', 2);
97 $savemethod =
GETPOST(
'savemethod',
'alpha', 2);
98 $savemethodname = (!empty($savemethod) ? $savemethod :
'setValueFrom');
99 $newelement = $element;
106 if ($element !=
'order_supplier' && $element !=
'invoice_supplier' && preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
108 $subelement = $regs[2];
111 if ($element ==
'propal') {
112 $newelement =
'propale';
113 } elseif ($element ==
'fichinter') {
114 $newelement =
'ficheinter';
115 } elseif ($element ==
'product') {
116 $newelement =
'produit';
117 } elseif ($element ==
'member') {
118 $newelement =
'adherent';
119 } elseif ($element ==
'order_supplier') {
120 $newelement =
'fournisseur';
121 $subelement =
'commande';
122 } elseif ($element ==
'invoice_supplier') {
123 $newelement =
'fournisseur';
124 $subelement =
'facture';
126 $newelement = $element;
129 $_POST[
'action'] =
'update';
131 $feature = $newelement;
132 $feature2 = $subelement;
133 $object_id = $fk_element;
134 if ($feature ==
'expedition' || $feature ==
'shipping') {
135 $feature =
'commande';
138 if ($feature ==
'shipping') {
139 $feature =
'commande';
141 if ($feature ==
'payment') {
142 $feature =
'facture';
144 if ($feature ==
'payment_supplier') {
145 $feature =
'fournisseur';
146 $feature2 =
'facture';
150 $check_access =
restrictedArea($user, $feature, $object_id,
'', $feature2);
161 $newvalue = trim($value);
163 if ($type ==
'numeric') {
167 if (!is_numeric($newvalue)) {
169 $return[
'error'] = $langs->trans(
'ErrorBadValue');
171 } elseif ($type ==
'datepicker') {
172 $timestamp =
GETPOST(
'timestamp',
'int', 2);
174 $newvalue = ($timestamp / 1000);
175 } elseif ($type ==
'select') {
176 $loadmethodname =
'load_cache_'.$loadmethod;
177 $loadcachename =
'cache_'.$loadmethod;
178 $loadviewname =
'view_'.$loadmethod;
180 $form =
new Form($db);
181 if (method_exists($form, $loadmethodname)) {
182 $ret = $form->$loadmethodname();
184 $loadcache = $form->$loadcachename;
185 $value = $loadcache[$newvalue];
187 if (!empty($form->$loadviewname)) {
188 $loadview = $form->$loadviewname;
189 $view = $loadview[$newvalue];
193 $return[
'error'] = $form->error;
196 $module = $subelement = $ext_element;
197 if (preg_match(
'/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
199 $subelement = $regs[2];
203 $classname =
'Actions'.ucfirst($subelement);
204 $object =
new $classname($db);
205 $ret = $object->$loadmethodname();
207 $loadcache = $object->$loadcachename;
208 $value = $loadcache[$newvalue];
210 if (!empty($object->$loadviewname)) {
211 $loadview = $object->$loadviewname;
212 $view = $loadview[$newvalue];
216 $return[
'error'] = $object->error;
222 if ((isset($object) && !is_object($object)) || empty($savemethod)) {
228 $object->ext_fk_element = $newvalue;
229 $object->ext_element = $ext_element;
230 $object->fk_element = $fk_element;
231 $object->element = $element;
233 $ret = $object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format);
235 if ($type ==
'numeric') {
236 $value =
price($newvalue);
237 } elseif ($type ==
'textarea') {
241 $return[
'value'] = $value;
242 $return[
'view'] = (!empty($view) ? $view : $value);
244 $return[
'error'] = $object->error;
248 echo json_encode($return);
250 echo $langs->trans(
'NotEnoughPermissions');
Class of a generic business object.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
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.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.