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') {
99 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
101 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
102 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
103 } elseif ($object->fields[$key][
'type'] ==
'reference') {
104 $tmparraykey = array_keys($object->param_list);
106 } elseif (preg_match(
'/^chkbxlst:(.*)/', $object->fields[$key][
'type']) || $object->fields[$key][
'type'] ==
'checkbox') {
108 $values_arr =
GETPOST($key,
'array');
109 if (!empty($values_arr)) {
110 $value = implode(
',', $values_arr);
113 if ($key ==
'lang') {
116 $value =
GETPOST($key,
'alphanohtml');
119 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
122 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
128 $object->$key = $value;
129 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
130 $object->$key =
'(PROV)';
132 if ($key ==
'pass_crypted') {
133 $object->pass =
GETPOST(
"pass",
"none");
136 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && !isset($val[
'default'])) {
138 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
144 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
145 if (!$object->validateField($object->fields, $key, $value)) {
154 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'', 1);
163 $result = $object->create($user);
166 if (isModEnabled(
'categorie') && method_exists($object,
'setCategories')) {
167 $categories =
GETPOST(
'categories',
'array:int');
168 $object->setCategories($categories);
171 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
172 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
176 if (empty($noback)) {
177 header(
"Location: " . $urltogo);
185 if (!empty($object->errors)) {
198if ($action ==
'update' && !empty($permissiontoadd)) {
199 foreach ($object->fields as $key => $val) {
201 if ($object->fields[$key][
'type'] ==
'duration') {
202 if (!GETPOSTISSET($key.
'hour') || !GETPOSTISSET($key.
'min')) {
205 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
206 if (!GETPOSTISSET($key)) {
211 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) && $object->fields[$key][
'type']!==
'checkbox') {
216 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
219 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
220 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
226 if (preg_match(
'/^text/', $object->fields[$key][
'type'])) {
227 $tmparray = explode(
':', $object->fields[$key][
'type']);
228 if (!empty($tmparray[1])) {
229 $value =
GETPOST($key, $tmparray[1]);
231 $value =
GETPOST($key,
'nohtml');
233 } elseif (preg_match(
'/^html/', $object->fields[$key][
'type'])) {
234 $tmparray = explode(
':', $object->fields[$key][
'type']);
235 if (!empty($tmparray[1])) {
236 $value =
GETPOST($key, $tmparray[1]);
238 $value =
GETPOST($key,
'restricthtml');
240 } elseif ($object->fields[$key][
'type'] ==
'date') {
242 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
243 $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');
244 } elseif ($object->fields[$key][
'type'] ==
'duration') {
245 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
246 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
250 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
252 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
253 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
254 } elseif ($object->fields[$key][
'type'] ==
'reference') {
255 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
256 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) || $object->fields[$key][
'type'] ==
'checkbox') {
258 $values_arr =
GETPOST($key,
'array');
259 if (!empty($values_arr)) {
260 $value = implode(
',', $values_arr);
263 if ($key ==
'lang') {
264 $value =
GETPOST($key,
'aZ09');
266 $value =
GETPOST($key,
'alphanohtml');
269 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
272 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
276 $object->$key = $value;
277 if ($val[
'notnull'] > 0 && $object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
279 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
284 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
285 if (!$object->validateField($object->fields, $key, $value)) {
291 if (isModEnabled(
'categorie')) {
292 $categories =
GETPOST(
'categories',
'array');
293 if (method_exists($object,
'setCategories')) {
294 $object->setCategories($categories);
302 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
309 $result = $object->update($user);
312 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
313 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
314 if ($urltogo && empty($noback)) {
315 header(
"Location: " . $urltogo);
331if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
332 $object->fetch(
GETPOST(
'id',
'int'));
334 $keyforfield = $reg[1];
335 if (property_exists($object, $keyforfield)) {
336 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
339 $object->$keyforfield =
GETPOST($keyforfield);
342 $result = $object->update($user);
350 $action =
'edit'.$reg[1];
356if ($action ==
"update_extras" &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
357 $object->fetch(
GETPOST(
'id',
'int'));
359 $object->oldcopy =
dol_clone($object, 2);
361 $attribute =
GETPOST(
'attribute',
'alphanohtml');
366 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute);
370 $action =
'edit_extras';
372 $result = $object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
379 $action =
'edit_extras';
385if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
386 if (!($object->id > 0)) {
387 dol_print_error(
'',
'Error, object must be fetched before being deleted');
393 $result = $object->delete($user);
401 if (empty($noback)) {
402 if (empty($backurlforlist)) {
403 print
'Error backurlforlist is not defined';
406 header(
"Location: " . $backurlforlist);
413 if (!empty($object->errors)) {
424if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
425 if (method_exists($object,
'deleteline')) {
426 $result = $object->deleteline($user, $lineid);
428 $result = $object->deleteLine($user, $lineid);
432 $outputlangs = $langs;
435 $newlang =
GETPOST(
'lang_id',
'aZ09');
437 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
438 $newlang = $object->thirdparty->default_lang;
440 if (!empty($newlang)) {
442 $outputlangs->setDefaultLang($newlang);
445 if (method_exists($object,
'generateDocument')) {
446 $ret = $object->fetch($object->id);
447 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
453 if (empty($noback)) {
454 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.$object->id : $backtopage));
465if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
466 if ($object->element ==
'inventory' && !empty($include_sub_warehouse)) {
468 $result = $object->validate($user,
false, $include_sub_warehouse);
470 $result = $object->validate($user);
476 if (method_exists($object,
'generateDocument')) {
477 $outputlangs = $langs;
480 $newlang =
GETPOST(
'lang_id',
'aZ09');
483 $newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang :
"";
485 if (!empty($newlang)) {
487 $outputlangs->setDefaultLang($newlang);
490 $ret = $object->fetch($id);
492 $model = $object->model_pdf;
494 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
508if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
509 $result = $object->cancel($user);
513 if (method_exists($object,
'generateDocument')) {
514 $outputlangs = $langs;
517 $newlang =
GETPOST(
'lang_id',
'aZ09');
520 $newlang = $object->thirdparty->default_lang;
522 if (!empty($newlang)) {
524 $outputlangs->setDefaultLang($newlang);
526 $model = $object->model_pdf;
527 $ret = $object->fetch($id);
529 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
540if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
541 $result = $object->setDraft($user);
552if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
553 $result = $object->reopen($user);
557 if (method_exists($object,
'generateDocument')) {
558 $outputlangs = $langs;
561 $newlang =
GETPOST(
'lang_id',
'aZ09');
564 $newlang = $object->thirdparty->default_lang;
566 if (!empty($newlang)) {
568 $outputlangs->setDefaultLang($newlang);
570 $model = $object->model_pdf;
571 $ret = $object->fetch($id);
573 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
584if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
585 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
593 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
594 if (is_object($result) || $result > 0) {
596 if (is_object($result)) {
597 $newid = $result->id;
602 if (empty($noback)) {
603 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...
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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 a 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.