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';
49$field =
GETPOST(
'field',
'alpha', 2);
50$element =
GETPOST(
'element',
'alpha', 2);
51$table_element =
GETPOST(
'table_element',
'alpha', 2);
52$fk_element =
GETPOST(
'fk_element',
'alpha', 2);
69if (is_numeric($fk_element)) {
70 $id = (int) $fk_element;
72 $element_ref = $fk_element;
79$usesublevelpermission = ($module != $element ? $element :
'');
80if ($usesublevelpermission && !$user->hasRight($module, $element)) {
81 $usesublevelpermission =
'';
107if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
108 $ext_element =
GETPOST(
'ext_element',
'alpha', 2);
109 $field = substr($field, 8);
110 $type =
GETPOST(
'type',
'alpha', 2);
111 $value = ($type ==
'ckeditor' ?
GETPOST(
'value',
'', 2) :
GETPOST(
'value',
'alpha', 2));
112 $loadmethod =
GETPOST(
'loadmethod',
'alpha', 2);
113 $savemethod =
GETPOST(
'savemethod',
'alpha', 2);
114 $savemethodname = (!empty($savemethod) ? $savemethod :
'setValueFrom');
115 $newelement = $element;
123 if ($element !=
'order_supplier' && $element !=
'invoice_supplier' && preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
125 $subelement = $regs[2];
128 if ($element ==
'propal') {
129 $newelement =
'propale';
130 } elseif ($element ==
'fichinter') {
131 $newelement =
'ficheinter';
132 } elseif ($element ==
'product') {
133 $newelement =
'produit';
134 } elseif ($element ==
'member') {
135 $newelement =
'adherent';
136 } elseif ($element ==
'order_supplier') {
137 $newelement =
'fournisseur';
138 $subelement =
'commande';
139 } elseif ($element ==
'invoice_supplier') {
140 $newelement =
'fournisseur';
141 $subelement =
'facture';
143 $newelement = $element;
146 $_POST[
'action'] =
'update';
148 $feature = $newelement;
149 $feature2 = $subelement;
150 $object_id = $fk_element;
151 if ($feature ==
'expedition' || $feature ==
'shipping') {
152 $feature =
'commande';
155 if ($feature ==
'shipping') {
156 $feature =
'commande';
158 if ($feature ==
'payment') {
159 $feature =
'facture';
161 if ($feature ==
'payment_supplier') {
162 $feature =
'fournisseur';
163 $feature2 =
'facture';
167 $check_access =
restrictedArea($user, $feature, $object_id,
'', $feature2);
178 $newvalue = trim($value);
180 if ($type ==
'numeric') {
184 if (!is_numeric($newvalue)) {
186 $return[
'error'] = $langs->trans(
'ErrorBadValue');
188 } elseif ($type ==
'datepicker') {
191 $newvalue = ($timestamp / 1000);
192 } elseif ($type ==
'select') {
193 $loadmethodname =
'load_cache_'.$loadmethod;
194 $loadcachename =
'cache_'.$loadmethod;
195 $loadviewname =
'view_'.$loadmethod;
197 $form =
new Form($db);
198 if (method_exists($form, $loadmethodname)) {
199 $ret = $form->$loadmethodname();
201 $loadcache = $form->$loadcachename;
202 $value = $loadcache[$newvalue];
204 if (!empty($form->$loadviewname)) {
205 $loadview = $form->$loadviewname;
206 $view = $loadview[$newvalue];
210 $return[
'error'] = $form->error;
213 $module = $subelement = $ext_element;
214 if (preg_match(
'/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
216 $subelement = $regs[2];
220 $classname =
'Actions'.ucfirst($subelement);
222 '@phan-var-force CommonHookActions $object';
223 $ret =
$object->$loadmethodname();
225 $loadcache =
$object->$loadcachename;
226 $value = $loadcache[$newvalue];
228 if (!empty(
$object->$loadviewname)) {
229 $loadview =
$object->$loadviewname;
230 $view = $loadview[$newvalue];
234 $return[
'error'] =
$object->error;
240 if ((isset($object) && !is_object($object)) || empty($savemethod)) {
246 $object->ext_fk_element = $newvalue;
247 $object->ext_element = $ext_element;
248 $object->fk_element = $fk_element;
251 $ret =
$object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format);
253 if ($type ==
'numeric') {
254 $value =
price($newvalue);
255 } elseif ($type ==
'textarea') {
259 $return[
'value'] = $value;
260 $return[
'view'] = (!empty($view) ? $view : $value);
262 $return[
'error'] =
$object->error;
266 echo json_encode($return);
268 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.