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 (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 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
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'])) {
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') {
127 $object->$key = $value;
128 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
129 $object->$key =
'(PROV)';
131 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && !isset($val[
'default'])) {
133 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
137 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
138 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
139 if (!$object->validateField($object->fields, $key, $value)) {
148 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'', 1);
157 $result = $object->create($user);
160 if (
isModEnabled(
'categorie') && method_exists($object,
'setCategories')) {
161 $categories =
GETPOST(
'categories',
'array:int');
162 $object->setCategories($categories);
165 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
166 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
170 if (empty($noback)) {
171 header(
"Location: " . $urltogo);
179 if (!empty($object->errors)) {
192 if ($action ==
'update' && !empty($permissiontoadd)) {
193 foreach ($object->fields as $key => $val) {
195 if ($object->fields[$key][
'type'] ==
'duration') {
199 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
205 if (!
GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
210 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
213 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
214 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
220 if (preg_match(
'/^text/', $object->fields[$key][
'type'])) {
221 $tmparray = explode(
':', $object->fields[$key][
'type']);
222 if (!empty($tmparray[1])) {
223 $value =
GETPOST($key, $tmparray[1]);
225 $value =
GETPOST($key,
'nohtml');
227 } elseif (preg_match(
'/^html/', $object->fields[$key][
'type'])) {
228 $tmparray = explode(
':', $object->fields[$key][
'type']);
229 if (!empty($tmparray[1])) {
230 $value =
GETPOST($key, $tmparray[1]);
232 $value =
GETPOST($key,
'restricthtml');
234 } elseif ($object->fields[$key][
'type'] ==
'date') {
236 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
237 $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');
238 } elseif ($object->fields[$key][
'type'] ==
'duration') {
239 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
240 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
244 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
246 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
247 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
248 } elseif ($object->fields[$key][
'type'] ==
'reference') {
249 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
250 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type'])) {
252 $values_arr =
GETPOST($key,
'array');
253 if (!empty($values_arr)) {
254 $value = implode(
',', $values_arr);
257 if ($key ==
'lang') {
258 $value =
GETPOST($key,
'aZ09');
260 $value =
GETPOST($key,
'alphanohtml');
263 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
266 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
270 $object->$key = $value;
271 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
273 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
277 if (
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
278 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
279 if (!$object->validateField($object->fields, $key, $value)) {
286 $categories =
GETPOST(
'categories',
'array');
287 if (method_exists($object,
'setCategories')) {
288 $object->setCategories($categories);
295 $ret = $extrafields->setOptionalsFromPost(
null, $object,
'@GETPOSTISSET');
302 $result = $object->update($user);
305 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
306 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
307 if ($urltogo && empty($noback)) {
308 header(
"Location: " . $urltogo);
324 if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
325 $object->fetch(
GETPOST(
'id',
'int'));
327 $keyforfield = $reg[1];
328 if (property_exists($object, $keyforfield)) {
329 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
332 $object->$keyforfield =
GETPOST($keyforfield);
335 $result = $object->update($user);
343 $action =
'edit'.$reg[1];
349 if ($action ==
"update_extras" &&
GETPOST(
'id',
'int') > 0 && !empty($permissiontoadd)) {
350 $object->fetch(
GETPOST(
'id',
'int'));
352 $attributekey =
GETPOST(
'attribute',
'alpha');
353 $attributekeylong =
'options_'.$attributekey;
357 $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'));
360 $object->array_options[
'options_'.$attributekey] =
GETPOST($attributekeylong,
'alpha');
363 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
370 $action =
'edit_extras';
375 if ($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)) {
404 if ($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));
445 if ($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);
482 if ($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);
514 if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
515 $result = $object->setDraft($user);
526 if ($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);
558 if ($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.
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.