29@phan-var-force CommonObject $this
30@phan-var-force ?string $action
31@phan-var-force ?string $cancel
32@phan-var-force CommonObject $object
33@phan-var-force string $permissiontoadd
34@phan-var-force ?string $permissionedit
35@phan-var-force string $permissiontodelete
36@phan-var-force string $backurlforlist
37@phan-var-force ?string $backtopage
38@phan-var-force ?string $noback
39@phan-var-force ?string $triggermodname
40@phan-var-force string $hidedetails
41@phan-var-force string $hidedesc
42@phan-var-force string $hideref
43@phan-var-force ?string $confirm
44@phan-var-force ?int $lineid
45@phan-var-force ?int $id
75$hidedetails = isset($hidedetails) ? $hidedetails :
'';
76$hidedesc = isset($hidedesc) ? $hidedesc :
'';
77$hideref = isset($hideref) ? $hideref :
'';
80if (!empty($permissionedit) && empty($permissiontoadd)) {
81 $permissiontoadd = $permissionedit;
86 if (!empty($backtopageforcancel)) {
87 header(
"Location: ".$backtopageforcancel);
89 } elseif (!empty($backtopage)) {
90 header(
"Location: ".$backtopage);
98if ($action ==
'add' && !empty($permissiontoadd)) {
99 foreach (
$object->fields as $key => $val) {
101 if (
$object->fields[$key][
'type'] ==
'duration') {
112 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
115 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
116 if (!in_array(abs($val[
'visible']), array(1, 3))) {
122 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
123 $tmparray = explode(
':',
$object->fields[$key][
'type']);
124 if (!empty($tmparray[1])) {
125 $value =
GETPOST($key, $tmparray[1]);
127 $value =
GETPOST($key,
'nohtml');
128 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
129 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
130 foreach ($tmparraymultiselect as $tmpvalue) {
131 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
135 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
136 $tmparray = explode(
':',
$object->fields[$key][
'type']);
137 if (!empty($tmparray[1])) {
138 $value =
GETPOST($key, $tmparray[1]);
140 $value =
GETPOST($key,
'restricthtml');
142 } elseif (
$object->fields[$key][
'type'] ==
'date') {
144 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
146 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
148 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
150 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
151 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
152 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
153 $tmparraykey = array_keys(
$object->param_list);
155 } elseif (preg_match(
'/^chkbxlst:(.*)/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
157 $values_arr =
GETPOST($key,
'array');
158 if (!empty($values_arr)) {
159 $value = implode(
',', $values_arr);
161 } elseif (isset(
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] ==
'password') {
162 $value =
GETPOST($key,
'password');
164 if ($key ==
'lang') {
167 $value =
GETPOST($key,
'alphanohtml');
172 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
175 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
178 if ((preg_match(
'/^sellist/i',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'select') && $value ===
'0') {
185 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ===
'(PROV)') {
188 if ($key ==
'pass_crypted') {
192 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && !isset($val[
'default'])) {
194 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
200 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
211 if (!empty($model_pdf) && property_exists(
$object,
'model_pdf')) {
212 $object->model_pdf = $model_pdf;
217 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'', 1);
226 $result =
$object->create($user);
230 $categories =
GETPOST(
'categories',
'array:int');
231 $object->setCategories($categories);
234 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
235 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
239 if (empty($noback)) {
240 header(
"Location: " . $urltogo);
248 setEventMessages(
null,
$object->errors,
'errors');
250 setEventMessages(
$object->error,
null,
'errors');
260if ($action ==
'update' && !empty($permissiontoadd)) {
261 foreach (
$object->fields as $key => $val) {
263 if (
$object->fields[$key][
'type'] ==
'duration') {
267 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
273 if (!
GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] !==
'checkbox') {
278 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
281 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
282 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
288 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
289 $tmparray = explode(
':',
$object->fields[$key][
'type']);
290 if (!empty($tmparray[1])) {
291 $value =
GETPOST($key, $tmparray[1]);
293 $value =
GETPOST($key,
'nohtml');
294 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
295 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
296 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
297 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
301 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
302 $tmparray = explode(
':',
$object->fields[$key][
'type']);
303 if (!empty($tmparray[1])) {
304 $value =
GETPOST($key, $tmparray[1]);
306 $value =
GETPOST($key,
'restricthtml');
308 } elseif (
$object->fields[$key][
'type'] ==
'date') {
310 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
312 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
318 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
320 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
321 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
322 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
324 } elseif (preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
326 $values_arr =
GETPOST($key,
'array');
327 if (!empty($values_arr)) {
328 $value = implode(
',', $values_arr);
330 } elseif (isset(
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] ==
'password') {
331 $value =
GETPOST($key,
'password');
333 if ($key ==
'lang') {
334 $value =
GETPOST($key,
'aZ09');
336 $value =
GETPOST($key,
'alphanohtml');
341 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
344 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
347 if ((preg_match(
'/^sellist/i',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'select') && $value ===
'0') {
353 if ($key ==
'pass_crypted' && property_exists(
$object,
'pass')) {
354 if (
GETPOST(
"pass",
"password")) {
359 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
361 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
367 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
375 $categories =
GETPOST(
'categories',
'array');
376 if (method_exists(
$object,
'setCategories')) {
377 $object->setCategories($categories);
385 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'@GETPOSTISSET');
392 $result =
$object->update($user);
395 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $result, $backtopage) : $backurlforlist;
396 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
397 if ($urltogo && empty($noback)) {
398 header(
"Location: " . $urltogo);
414if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
417 $keyforfield = $reg[1];
418 if (property_exists(
$object, $keyforfield)) {
419 if (!empty(
$object->fields[$keyforfield]) && in_array(
$object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
425 $result =
$object->update($user);
428 setEventMessages($langs->trans(
'RecordSaved'),
null,
'mesgs');
433 $action =
'edit'.$reg[1];
439$permissiontoeditextra = $permissiontoadd;
440if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
442 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
445if ($action ==
"update_extras" &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoeditextra)) {
450 $attribute =
GETPOST(
'attribute',
'aZ09');
455 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
458 setEventMessages($extrafields->error,
$object->errors,
'errors');
459 $action =
'edit_extras';
461 $result =
$object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
463 setEventMessages($langs->trans(
'RecordSaved'),
null,
'mesgs');
468 $action =
'edit_extras';
474if ($action ==
'confirm_delete' && $confirm ==
'yes' && !empty($permissiontodelete)) {
476 dol_print_error(
null,
'Error, object must be fetched before being deleted');
482 $result =
$object->delete($user);
488 setEventMessages(
"RecordDeleted",
null,
'mesgs');
490 if (empty($noback)) {
491 if (empty($backurlforlist)) {
492 print
'Error backurlforlist is not defined';
495 header(
"Location: " . $backurlforlist);
503 setEventMessages(
null,
$object->errors,
'errors');
505 setEventMessages(
$object->error,
null,
'errors');
513if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
516 $result =
$object->deleteLine($user, $lineid, 0, $fk_movement);
518 $result =
$object->deleteLine($user, $lineid);
523 $outputlangs = $langs;
526 $newlang =
GETPOST(
'lang_id',
'aZ09');
529 $newlang =
$object->thirdparty->default_lang;
531 if (!empty($newlang)) {
533 $outputlangs->setDefaultLang($newlang);
536 if (method_exists(
$object,
'generateDocument')) {
538 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
542 setEventMessages($langs->trans(
'RecordDeleted'),
null,
'mesgs');
544 if (empty($noback)) {
545 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.
$object->id : $backtopage));
556if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
557 if (
$object->element ==
'inventory') {
560 $result =
$object->validate($user,
false, (empty($include_sub_warehouse) ? 0 : $include_sub_warehouse), (empty($startmode) ?
'' : $startmode));
562 $result =
$object->validate($user);
568 if (method_exists(
$object,
'generateDocument')) {
569 $outputlangs = $langs;
572 $newlang =
GETPOST(
'lang_id',
'aZ09');
575 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang :
"";
577 if (!empty($newlang)) {
579 $outputlangs->setDefaultLang($newlang);
586 $retgen =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
600if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
601 $result =
$object->cancel($user);
605 if (method_exists(
$object,
'generateDocument')) {
606 $outputlangs = $langs;
609 $newlang =
GETPOST(
'lang_id',
'aZ09');
612 $newlang =
$object->thirdparty->default_lang;
614 if (!empty($newlang)) {
616 $outputlangs->setDefaultLang($newlang);
621 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
632if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
633 $result =
$object->setDraft($user);
644if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
645 $result =
$object->reopen($user);
649 if (method_exists(
$object,
'generateDocument')) {
650 $outputlangs = $langs;
653 $newlang =
GETPOST(
'lang_id',
'aZ09');
656 $newlang =
$object->thirdparty->default_lang;
658 if (!empty($newlang)) {
660 $outputlangs->setDefaultLang($newlang);
665 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
676if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
678 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
679 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
686 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
687 if (is_object($result) || $result > 0) {
689 if (is_object($result)) {
690 $newid = $result->id;
695 if (empty($noback)) {
696 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $newid);
701 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage translations.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.