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') {
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);
98 $value =
GETPOST($key,
'alphanohtml');
101 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
104 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
109 $object->$key = $value;
110 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
111 $object->$key =
'(PROV)';
113 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && !isset($val[
'default'])) {
115 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
119 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
120 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
121 if (!$object->validateField($object->fields, $key, $value)) {
130 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'', 1);
137 $result = $object->create($user);
140 if (
isModEnabled(
'categorie') && method_exists($object,
'setCategories')) {
141 $categories =
GETPOST(
'categories',
'array:int');
142 $object->setCategories($categories);
144 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
145 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
147 if (empty($noback)) {
148 header(
"Location: " . $urltogo);
154 if (!empty($object->errors)) {
167 if ($action ==
'update' && !empty($permissiontoadd)) {
168 foreach ($object->fields as $key => $val) {
170 if ($object->fields[$key][
'type'] ==
'duration') {
174 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
185 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
188 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
189 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
195 if (preg_match(
'/^(text|html)/', $object->fields[$key][
'type'])) {
196 $tmparray = explode(
':', $object->fields[$key][
'type']);
197 if (!empty($tmparray[1])) {
198 $value =
GETPOST($key, $tmparray[1]);
200 $value =
GETPOST($key,
'restricthtml');
202 } elseif ($object->fields[$key][
'type'] ==
'date') {
204 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
205 $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');
206 } elseif ($object->fields[$key][
'type'] ==
'duration') {
207 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
208 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
212 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
214 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
215 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
216 } elseif ($object->fields[$key][
'type'] ==
'reference') {
217 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
219 if ($key ==
'lang') {
220 $value =
GETPOST($key,
'aZ09');
222 $value =
GETPOST($key,
'alphanohtml');
225 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
228 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
232 $object->$key = $value;
233 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
235 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
239 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
240 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
241 if (!$object->validateField($object->fields, $key, $value)) {
248 $categories =
GETPOST(
'categories',
'array');
249 if (method_exists($object,
'setCategories')) {
250 $object->setCategories($categories);
257 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
264 $result = $object->update($user);
267 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
268 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
269 if ($urltogo && !$noback) {
270 header(
"Location: " . $urltogo);
285 if ($action ==
"update_extras" && !empty($permissiontoadd)) {
286 $object->fetch(
GETPOST(
'id',
'int'));
288 $attributekey =
GETPOST(
'attribute',
'alpha');
289 $attributekeylong =
'options_'.$attributekey;
293 $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'));
296 $object->array_options[
'options_'.$attributekey] =
GETPOST($attributekeylong,
'alpha');
299 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
306 $action =
'edit_extras';
311 if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
312 if (!($object->id > 0)) {
313 dol_print_error(
'',
'Error, object must be fetched before being deleted');
317 $result = $object->delete($user);
323 if (empty($noback)) {
324 header(
"Location: " . $backurlforlist);
329 if (!empty($object->errors)) {
340 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
341 if (method_exists($object,
'deleteline')) {
342 $result = $object->deleteline($user, $lineid);
344 $result = $object->deleteLine($user, $lineid);
348 $outputlangs = $langs;
350 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
351 $newlang =
GETPOST(
'lang_id',
'aZ09');
353 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($object->thirdparty)) {
354 $newlang = $object->thirdparty->default_lang;
356 if (!empty($newlang)) {
358 $outputlangs->setDefaultLang($newlang);
360 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
361 if (method_exists($object,
'generateDocument')) {
362 $ret = $object->fetch($object->id);
363 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
369 if (empty($noback)) {
370 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id);
381 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
382 $result = $object->validate($user);
385 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
386 if (method_exists($object,
'generateDocument')) {
387 $outputlangs = $langs;
389 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
390 $newlang =
GETPOST(
'lang_id',
'aZ09');
392 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
393 $newlang = $object->thirdparty->default_lang;
395 if (!empty($newlang)) {
397 $outputlangs->setDefaultLang($newlang);
400 $ret = $object->fetch($id);
402 $model = $object->model_pdf;
404 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
418 if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
419 $result = $object->cancel($user);
422 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
423 if (method_exists($object,
'generateDocument')) {
424 $outputlangs = $langs;
426 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
427 $newlang =
GETPOST(
'lang_id',
'aZ09');
429 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
430 $newlang = $object->thirdparty->default_lang;
432 if (!empty($newlang)) {
434 $outputlangs->setDefaultLang($newlang);
436 $model = $object->model_pdf;
437 $ret = $object->fetch($id);
439 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
450 if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
451 $result = $object->setDraft($user);
462 if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
463 $result = $object->reopen($user);
466 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
467 if (method_exists($object,
'generateDocument')) {
468 $outputlangs = $langs;
470 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
471 $newlang =
GETPOST(
'lang_id',
'aZ09');
473 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
474 $newlang = $object->thirdparty->default_lang;
476 if (!empty($newlang)) {
478 $outputlangs->setDefaultLang($newlang);
480 $model = $object->model_pdf;
481 $ret = $object->fetch($id);
483 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
494 if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
495 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
501 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
502 if (is_object($result) || $result > 0) {
504 if (is_object($result)) {
505 $newid = $result->id;
510 if (empty($noback)) {
511 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $newid);