34 $hidedetails = isset($hidedetails) ? $hidedetails :
'';
35 $hidedesc = isset($hidedesc) ? $hidedesc :
'';
36 $hideref = isset($hideref) ? $hideref :
'';
39 if (!empty($permissionedit) && empty($permissiontoadd)) {
40 $permissiontoadd = $permissionedit;
45 if (!empty($backtopageforcancel)) {
46 header(
"Location: ".$backtopageforcancel);
48 } elseif (!empty($backtopage)) {
49 header(
"Location: ".$backtopage);
57 if ($action ==
'add' && !empty($permissiontoadd)) {
58 foreach ($object->fields as $key => $val) {
59 if ($object->fields[$key][
'type'] ==
'duration') {
64 if (!
GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
69 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
72 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
73 if (!in_array(abs($val[
'visible']), array(1, 3))) {
79 if (in_array($object->fields[$key][
'type'], array(
'text',
'html'))) {
80 $value =
GETPOST($key,
'restricthtml');
81 } elseif ($object->fields[$key][
'type'] ==
'date') {
83 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
84 $value =
dol_mktime(
GETPOST($key.
'hour',
'int'),
GETPOST($key.
'min',
'int'),
GETPOST($key.
'sec',
'int'),
GETPOST($key.
'month',
'int'),
GETPOST($key.
'day',
'int'),
GETPOST($key.
'year',
'int'),
'tzuserrel');
85 } elseif ($object->fields[$key][
'type'] ==
'duration') {
86 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
87 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
89 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
90 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
91 } elseif ($object->fields[$key][
'type'] ==
'reference') {
92 $tmparraykey = array_keys($object->param_list);
94 } elseif (preg_match(
'/^chkbxlst:(.*)/', $object->fields[$key][
'type'])) {
96 $values_arr =
GETPOST($key,
'array');
97 if (!empty($values_arr)) {
98 $value = implode(
',', $values_arr);
101 if ($key ==
'lang') {
104 $value =
GETPOST($key,
'alphanohtml');
107 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
110 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
115 $object->$key = $value;
116 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
117 $object->$key =
'(PROV)';
119 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && !isset($val[
'default'])) {
121 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
125 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
126 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
127 if (!$object->validateField($object->fields, $key, $value)) {
136 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'', 1);
145 $result = $object->create($user);
148 if (
isModEnabled(
'categorie') && method_exists($object,
'setCategories')) {
149 $categories =
GETPOST(
'categories',
'array:int');
150 $object->setCategories($categories);
153 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
154 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
158 if (empty($noback)) {
159 header(
"Location: " . $urltogo);
167 if (!empty($object->errors)) {
180 if ($action ==
'update' && !empty($permissiontoadd)) {
181 foreach ($object->fields as $key => $val) {
183 if ($object->fields[$key][
'type'] ==
'duration') {
187 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
193 if (!
GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
198 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
201 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
202 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
208 if (preg_match(
'/^(text|html)/', $object->fields[$key][
'type'])) {
209 $tmparray = explode(
':', $object->fields[$key][
'type']);
210 if (!empty($tmparray[1])) {
211 $value =
GETPOST($key, $tmparray[1]);
213 $value =
GETPOST($key,
'restricthtml');
215 } elseif ($object->fields[$key][
'type'] ==
'date') {
217 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
218 $value =
dol_mktime(
GETPOST($key.
'hour',
'int'),
GETPOST($key.
'min',
'int'),
GETPOST($key.
'sec',
'int'),
GETPOST($key.
'month',
'int'),
GETPOST($key.
'day',
'int'),
GETPOST($key.
'year',
'int'),
'tzuserrel');
219 } elseif ($object->fields[$key][
'type'] ==
'duration') {
220 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
221 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
225 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
227 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
228 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
229 } elseif ($object->fields[$key][
'type'] ==
'reference') {
230 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
231 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
233 $values_arr =
GETPOST($key,
'array');
234 if (!empty($values_arr)) {
235 $value = implode(
',', $values_arr);
238 if ($key ==
'lang') {
239 $value =
GETPOST($key,
'aZ09');
241 $value =
GETPOST($key,
'alphanohtml');
244 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
247 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
251 $object->$key = $value;
252 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
254 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
258 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
259 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
260 if (!$object->validateField($object->fields, $key, $value)) {
267 $categories =
GETPOST(
'categories',
'array');
268 if (method_exists($object,
'setCategories')) {
269 $object->setCategories($categories);
276 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
283 $result = $object->update($user);
286 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
287 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
288 if ($urltogo && !$noback) {
289 header(
"Location: " . $urltogo);
305 if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
306 $object->fetch(
GETPOST(
'id',
'int'));
308 $keyforfield = $reg[1];
309 if (property_exists($object, $keyforfield)) {
310 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
313 $object->$keyforfield =
GETPOST($keyforfield);
316 $result = $object->update($user);
324 $action =
'edit'.$reg[1];
330 if ($action ==
"update_extras" &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
331 $object->fetch(
GETPOST(
'id',
'int'));
333 $attributekey =
GETPOST(
'attribute',
'alpha');
334 $attributekeylong =
'options_'.$attributekey;
338 $object->array_options[
'options_'.$attributekey] =
dol_mktime(
GETPOST($attributekeylong.
'hour',
'int'),
GETPOST($attributekeylong.
'min',
'int'),
GETPOST($attributekeylong.
'sec',
'int'),
GETPOST($attributekeylong.
'month',
'int'),
GETPOST($attributekeylong.
'day',
'int'),
GETPOST($attributekeylong.
'year',
'int'));
341 $object->array_options[
'options_'.$attributekey] =
GETPOST($attributekeylong,
'alpha');
344 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
351 $action =
'edit_extras';
356 if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
357 if (!($object->id > 0)) {
358 dol_print_error(
'',
'Error, object must be fetched before being deleted');
362 $result = $object->delete($user);
368 if (empty($noback)) {
369 header(
"Location: " . $backurlforlist);
374 if (!empty($object->errors)) {
385 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
386 if (method_exists($object,
'deleteline')) {
387 $result = $object->deleteline($user, $lineid);
389 $result = $object->deleteLine($user, $lineid);
393 $outputlangs = $langs;
396 $newlang =
GETPOST(
'lang_id',
'aZ09');
398 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
399 $newlang = $object->thirdparty->default_lang;
401 if (!empty($newlang)) {
403 $outputlangs->setDefaultLang($newlang);
405 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
406 if (method_exists($object,
'generateDocument')) {
407 $ret = $object->fetch($object->id);
408 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
414 if (empty($noback)) {
415 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.$object->id : $backtopage));
426 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
427 $result = $object->validate($user);
430 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
431 if (method_exists($object,
'generateDocument')) {
432 $outputlangs = $langs;
435 $newlang =
GETPOST(
'lang_id',
'aZ09');
438 $newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang :
"";
440 if (!empty($newlang)) {
442 $outputlangs->setDefaultLang($newlang);
445 $ret = $object->fetch($id);
447 $model = $object->model_pdf;
449 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
463 if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
464 $result = $object->cancel($user);
467 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
468 if (method_exists($object,
'generateDocument')) {
469 $outputlangs = $langs;
472 $newlang =
GETPOST(
'lang_id',
'aZ09');
475 $newlang = $object->thirdparty->default_lang;
477 if (!empty($newlang)) {
479 $outputlangs->setDefaultLang($newlang);
481 $model = $object->model_pdf;
482 $ret = $object->fetch($id);
484 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
495 if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
496 $result = $object->setDraft($user);
507 if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
508 $result = $object->reopen($user);
511 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
512 if (method_exists($object,
'generateDocument')) {
513 $outputlangs = $langs;
516 $newlang =
GETPOST(
'lang_id',
'aZ09');
519 $newlang = $object->thirdparty->default_lang;
521 if (!empty($newlang)) {
523 $outputlangs->setDefaultLang($newlang);
525 $model = $object->model_pdf;
526 $ret = $object->fetch($id);
528 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
539 if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
540 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
546 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
547 if (is_object($result) || $result > 0) {
549 if (is_object($result)) {
550 $newid = $result->id;
555 if (empty($noback)) {
556 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $newid);
Class to manage translations.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.