25if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL',
'1');
28if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31if (!defined(
'NOREQUIREAJAX')) {
32 define(
'NOREQUIREAJAX',
'1');
34if (!defined(
'NOREQUIRESOC')) {
35 define(
'NOREQUIRESOC',
'1');
39require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
42$field =
GETPOST(
'field',
'alpha', 2);
43$element =
GETPOST(
'element',
'alpha', 2);
44$table_element =
GETPOST(
'table_element',
'alpha', 2);
45$fk_element =
GETPOST(
'fk_element',
'alpha', 2);
62if (is_numeric($fk_element)) {
63 $id = (int) $fk_element;
65 $element_ref = $fk_element;
72$usesublevelpermission = ($module != $element ? $element :
'');
73if ($usesublevelpermission && !$user->hasRight($module, $element)) {
74 $usesublevelpermission =
'';
100if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
101 $ext_element =
GETPOST(
'ext_element',
'alpha', 2);
102 $field = substr($field, 8);
103 $type =
GETPOST(
'type',
'alpha', 2);
104 $value = ($type ==
'ckeditor' ?
GETPOST(
'value',
'', 2) :
GETPOST(
'value',
'alpha', 2));
105 $loadmethod =
GETPOST(
'loadmethod',
'alpha', 2);
106 $savemethod =
GETPOST(
'savemethod',
'alpha', 2);
107 $savemethodname = (!empty($savemethod) ? $savemethod :
'setValueFrom');
108 $newelement = $element;
116 if ($element !=
'order_supplier' && $element !=
'invoice_supplier' && preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
118 $subelement = $regs[2];
121 if ($element ==
'propal') {
122 $newelement =
'propale';
123 } elseif ($element ==
'fichinter') {
124 $newelement =
'ficheinter';
125 } elseif ($element ==
'product') {
126 $newelement =
'produit';
127 } elseif ($element ==
'member') {
128 $newelement =
'adherent';
129 } elseif ($element ==
'order_supplier') {
130 $newelement =
'fournisseur';
131 $subelement =
'commande';
132 } elseif ($element ==
'invoice_supplier') {
133 $newelement =
'fournisseur';
134 $subelement =
'facture';
136 $newelement = $element;
139 $_POST[
'action'] =
'update';
141 $feature = $newelement;
142 $feature2 = $subelement;
143 $object_id = $fk_element;
144 if ($feature ==
'expedition' || $feature ==
'shipping') {
145 $feature =
'commande';
148 if ($feature ==
'shipping') {
149 $feature =
'commande';
151 if ($feature ==
'payment') {
152 $feature =
'facture';
154 if ($feature ==
'payment_supplier') {
155 $feature =
'fournisseur';
156 $feature2 =
'facture';
160 $check_access =
restrictedArea($user, $feature, $object_id,
'', $feature2);
171 $newvalue = trim($value);
173 if ($type ==
'numeric') {
177 if (!is_numeric($newvalue)) {
179 $return[
'error'] = $langs->trans(
'ErrorBadValue');
181 } elseif ($type ==
'datepicker') {
184 $newvalue = ($timestamp / 1000);
185 } elseif ($type ==
'select') {
186 $loadmethodname =
'load_cache_'.$loadmethod;
187 $loadcachename =
'cache_'.$loadmethod;
188 $loadviewname =
'view_'.$loadmethod;
190 $form =
new Form($db);
191 if (method_exists($form, $loadmethodname)) {
192 $ret = $form->$loadmethodname();
194 $loadcache = $form->$loadcachename;
195 $value = $loadcache[$newvalue];
197 if (!empty($form->$loadviewname)) {
198 $loadview = $form->$loadviewname;
199 $view = $loadview[$newvalue];
203 $return[
'error'] = $form->error;
206 $module = $subelement = $ext_element;
207 if (preg_match(
'/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
209 $subelement = $regs[2];
213 $classname =
'Actions'.ucfirst($subelement);
215 '@phan-var-force CommonHookActions $object';
216 $ret =
$object->$loadmethodname();
218 $loadcache =
$object->$loadcachename;
219 $value = $loadcache[$newvalue];
221 if (!empty(
$object->$loadviewname)) {
222 $loadview =
$object->$loadviewname;
223 $view = $loadview[$newvalue];
227 $return[
'error'] =
$object->error;
233 if ((isset($object) && !is_object($object)) || empty($savemethod)) {
239 $object->ext_fk_element = $newvalue;
240 $object->ext_element = $ext_element;
241 $object->fk_element = $fk_element;
244 $ret =
$object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format);
246 if ($type ==
'numeric') {
247 $value =
price($newvalue);
248 } elseif ($type ==
'textarea') {
252 $return[
'value'] = $value;
253 $return[
'view'] = (!empty($view) ? $view : $value);
255 $return[
'error'] =
$object->error;
259 echo json_encode($return);
261 echo $langs->trans(
'NotEnoughPermissions');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class of a generic business object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
fetchObjectByElement($element_id, $element_type, $element_ref='', $useCache=0, $maxCacheByType=10)
Fetch an object from its id and element_type Inclusion of classes is automatic.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
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.