23 if (!defined(
'NOTOKENRENEWAL')) {
24 define(
'NOTOKENRENEWAL',
'1');
26 if (!defined(
'NOREQUIREMENU')) {
27 define(
'NOREQUIREMENU',
'1');
29 if (!defined(
'NOREQUIREAJAX')) {
30 define(
'NOREQUIREAJAX',
'1');
32 if (!defined(
'NOREQUIRESOC')) {
33 define(
'NOREQUIRESOC',
'1');
37 require
'../../main.inc.php';
38 require_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);
68 if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
69 $ext_element =
GETPOST(
'ext_element',
'alpha', 2);
70 $field = substr($field, 8);
71 $type =
GETPOST(
'type',
'alpha', 2);
72 $value = ($type ==
'ckeditor' ?
GETPOST(
'value',
'', 2) :
GETPOST(
'value',
'alpha', 2));
73 $loadmethod =
GETPOST(
'loadmethod',
'alpha', 2);
74 $savemethod =
GETPOST(
'savemethod',
'alpha', 2);
75 $savemethodname = (!empty($savemethod) ? $savemethod :
'setValueFrom');
76 $newelement = $element;
83 if ($element !=
'order_supplier' && $element !=
'invoice_supplier' && preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
85 $subelement = $regs[2];
88 if ($element ==
'propal') {
89 $newelement =
'propale';
90 } elseif ($element ==
'fichinter') {
91 $newelement =
'ficheinter';
92 } elseif ($element ==
'product') {
93 $newelement =
'produit';
94 } elseif ($element ==
'member') {
95 $newelement =
'adherent';
96 } elseif ($element ==
'order_supplier') {
97 $newelement =
'fournisseur';
98 $subelement =
'commande';
99 } elseif ($element ==
'invoice_supplier') {
100 $newelement =
'fournisseur';
101 $subelement =
'facture';
103 $newelement = $element;
106 $_POST[
'action'] =
'update';
108 $feature = $newelement;
109 $feature2 = $subelement;
110 $object_id = $fk_element;
111 if ($feature ==
'expedition' || $feature ==
'shipping') {
112 $feature =
'commande';
115 if ($feature ==
'shipping') {
116 $feature =
'commande';
118 if ($feature ==
'payment') {
119 $feature =
'facture';
121 if ($feature ==
'payment_supplier') {
122 $feature =
'fournisseur';
123 $feature2 =
'facture';
127 $check_access =
restrictedArea($user, $feature, $object_id,
'', $feature2);
138 $newvalue = trim($value);
140 if ($type ==
'numeric') {
144 if (!is_numeric($newvalue)) {
146 $return[
'error'] = $langs->trans(
'ErrorBadValue');
148 } elseif ($type ==
'datepicker') {
149 $timestamp =
GETPOST(
'timestamp',
'int', 2);
151 $newvalue = ($timestamp / 1000);
152 } elseif ($type ==
'select') {
153 $loadmethodname =
'load_cache_'.$loadmethod;
154 $loadcachename =
'cache_'.$loadmethod;
155 $loadviewname =
'view_'.$loadmethod;
158 if (method_exists(
$form, $loadmethodname)) {
159 $ret =
$form->$loadmethodname();
161 $loadcache =
$form->$loadcachename;
162 $value = $loadcache[$newvalue];
164 if (!empty(
$form->$loadviewname)) {
165 $loadview =
$form->$loadviewname;
166 $view = $loadview[$newvalue];
170 $return[
'error'] =
$form->error;
173 $module = $subelement = $ext_element;
174 if (preg_match(
'/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
176 $subelement = $regs[2];
180 $classname =
'Actions'.ucfirst($subelement);
181 $object =
new $classname($db);
182 $ret = $object->$loadmethodname();
184 $loadcache = $object->$loadcachename;
185 $value = $loadcache[$newvalue];
187 if (!empty($object->$loadviewname)) {
188 $loadview = $object->$loadviewname;
189 $view = $loadview[$newvalue];
193 $return[
'error'] = $object->error;
199 if ((isset($object) && !is_object($object)) || empty($savemethod)) {
205 $object->ext_fk_element = $newvalue;
206 $object->ext_element = $ext_element;
207 $object->fk_element = $fk_element;
208 $object->element = $element;
210 $ret = $object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format);
212 if ($type ==
'numeric') {
213 $value =
price($newvalue);
214 } elseif ($type ==
'textarea') {
218 $return[
'value'] = $value;
219 $return[
'view'] = (!empty($view) ? $view : $value);
221 $return[
'error'] = $object->error;
225 echo json_encode($return);
227 echo $langs->trans(
'NotEnoughPermissions');
Class of a generic business object.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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.
if(!defined('NOREQUIREMENU')) 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.