34$hidedetails = isset($hidedetails) ? $hidedetails :
'';
35$hidedesc = isset($hidedesc) ? $hidedesc :
'';
36$hideref = isset($hideref) ? $hideref :
'';
39if (!empty($permissionedit) && empty($permissiontoadd)) {
40 $permissiontoadd = $permissionedit;
45 if (!empty($backtopageforcancel)) {
46 header(
"Location: ".$backtopageforcancel);
48 } elseif (!empty($backtopage)) {
49 header(
"Location: ".$backtopage);
57if ($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 (preg_match(
'/^text/', $object->fields[$key][
'type'])) {
80 $tmparray = explode(
':', $object->fields[$key][
'type']);
81 if (!empty($tmparray[1])) {
82 $value =
GETPOST($key, $tmparray[1]);
84 $value =
GETPOST($key,
'nohtml');
86 } elseif (preg_match(
'/^html/', $object->fields[$key][
'type'])) {
87 $tmparray = explode(
':', $object->fields[$key][
'type']);
88 if (!empty($tmparray[1])) {
89 $value =
GETPOST($key, $tmparray[1]);
91 $value =
GETPOST($key,
'restricthtml');
93 } elseif ($object->fields[$key][
'type'] ==
'date') {
95 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
96 $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');
97 } elseif ($object->fields[$key][
'type'] ==
'duration') {
98 $hour = intval(
GETPOST($key.
'hour',
'int'));
99 $min = intval(
GETPOST($key.
'min',
'int'));
100 $value = 60 * 60 * $hour + 60 * $min;
101 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
103 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
104 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
105 } elseif ($object->fields[$key][
'type'] ==
'reference') {
106 $tmparraykey = array_keys($object->param_list);
108 } elseif (preg_match(
'/^chkbxlst:(.*)/', $object->fields[$key][
'type'])) {
110 $values_arr =
GETPOST($key,
'array');
111 if (!empty($values_arr)) {
112 $value = implode(
',', $values_arr);
115 if ($key ==
'lang') {
118 $value =
GETPOST($key,
'alphanohtml');
121 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
124 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
129 $object->$key = $value;
130 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
131 $object->$key =
'(PROV)';
133 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && !isset($val[
'default'])) {
135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
139 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
140 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
141 if (!$object->validateField($object->fields, $key, $value)) {
150 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'', 1);
159 $result = $object->create($user);
162 if (isModEnabled(
'categorie') && method_exists($object,
'setCategories')) {
163 $categories =
GETPOST(
'categories',
'array:int');
164 $object->setCategories($categories);
167 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
168 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
172 if (empty($noback)) {
173 header(
"Location: " . $urltogo);
181 if (!empty($object->errors)) {
194if ($action ==
'update' && !empty($permissiontoadd)) {
195 foreach ($object->fields as $key => $val) {
197 if ($object->fields[$key][
'type'] ==
'duration') {
198 if (!GETPOSTISSET($key.
'hour') || !GETPOSTISSET($key.
'min')) {
201 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
202 if (!GETPOSTISSET($key)) {
207 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
212 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
215 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
216 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
222 if (preg_match(
'/^text/', $object->fields[$key][
'type'])) {
223 $tmparray = explode(
':', $object->fields[$key][
'type']);
224 if (!empty($tmparray[1])) {
225 $value =
GETPOST($key, $tmparray[1]);
227 $value =
GETPOST($key,
'nohtml');
229 } elseif (preg_match(
'/^html/', $object->fields[$key][
'type'])) {
230 $tmparray = explode(
':', $object->fields[$key][
'type']);
231 if (!empty($tmparray[1])) {
232 $value =
GETPOST($key, $tmparray[1]);
234 $value =
GETPOST($key,
'restricthtml');
236 } elseif ($object->fields[$key][
'type'] ==
'date') {
238 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
239 $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');
240 } elseif ($object->fields[$key][
'type'] ==
'duration') {
241 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
242 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
246 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
248 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
249 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
250 } elseif ($object->fields[$key][
'type'] ==
'reference') {
251 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
252 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
254 $values_arr =
GETPOST($key,
'array');
255 if (!empty($values_arr)) {
256 $value = implode(
',', $values_arr);
259 if ($key ==
'lang') {
260 $value =
GETPOST($key,
'aZ09');
262 $value =
GETPOST($key,
'alphanohtml');
265 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
268 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
272 $object->$key = $value;
273 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
275 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
279 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
280 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
281 if (!$object->validateField($object->fields, $key, $value)) {
287 if (isModEnabled(
'categorie')) {
288 $categories =
GETPOST(
'categories',
'array');
289 if (method_exists($object,
'setCategories')) {
290 $object->setCategories($categories);
297 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
304 $result = $object->update($user);
307 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
308 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
309 if ($urltogo && empty($noback)) {
310 header(
"Location: " . $urltogo);
326if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
327 $object->fetch(
GETPOST(
'id',
'int'));
329 $keyforfield = $reg[1];
330 if (property_exists($object, $keyforfield)) {
331 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
334 $object->$keyforfield =
GETPOST($keyforfield);
337 $result = $object->update($user);
345 $action =
'edit'.$reg[1];
351if ($action ==
"update_extras" &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
352 $object->fetch(
GETPOST(
'id',
'int'));
356 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
360 $action =
'edit_extras';
362 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
369 $action =
'edit_extras';
375if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
376 if (!($object->id > 0)) {
377 dol_print_error(
'',
'Error, object must be fetched before being deleted');
381 $result = $object->delete($user);
387 if (empty($noback)) {
388 header(
"Location: " . $backurlforlist);
393 if (!empty($object->errors)) {
404if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
405 if (method_exists($object,
'deleteline')) {
406 $result = $object->deleteline($user, $lineid);
408 $result = $object->deleteLine($user, $lineid);
412 $outputlangs = $langs;
415 $newlang =
GETPOST(
'lang_id',
'aZ09');
417 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
418 $newlang = $object->thirdparty->default_lang;
420 if (!empty($newlang)) {
422 $outputlangs->setDefaultLang($newlang);
424 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
425 if (method_exists($object,
'generateDocument')) {
426 $ret = $object->fetch($object->id);
427 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
433 if (empty($noback)) {
434 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.$object->id : $backtopage));
445if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
446 $result = $object->validate($user);
449 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
450 if (method_exists($object,
'generateDocument')) {
451 $outputlangs = $langs;
454 $newlang =
GETPOST(
'lang_id',
'aZ09');
457 $newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang :
"";
459 if (!empty($newlang)) {
461 $outputlangs->setDefaultLang($newlang);
464 $ret = $object->fetch($id);
466 $model = $object->model_pdf;
468 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
482if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
483 $result = $object->cancel($user);
486 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
487 if (method_exists($object,
'generateDocument')) {
488 $outputlangs = $langs;
491 $newlang =
GETPOST(
'lang_id',
'aZ09');
494 $newlang = $object->thirdparty->default_lang;
496 if (!empty($newlang)) {
498 $outputlangs->setDefaultLang($newlang);
500 $model = $object->model_pdf;
501 $ret = $object->fetch($id);
503 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
514if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
515 $result = $object->setDraft($user);
526if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
527 $result = $object->reopen($user);
530 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
531 if (method_exists($object,
'generateDocument')) {
532 $outputlangs = $langs;
535 $newlang =
GETPOST(
'lang_id',
'aZ09');
538 $newlang = $object->thirdparty->default_lang;
540 if (!empty($newlang)) {
542 $outputlangs->setDefaultLang($newlang);
544 $model = $object->model_pdf;
545 $ret = $object->fetch($id);
547 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
558if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
559 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
565 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
566 if (is_object($result) || $result > 0) {
568 if (is_object($result)) {
569 $newid = $result->id;
574 if (empty($noback)) {
575 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...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.