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 $check = $tmparray[1];
130 $security_check =
'alphanohtml';
132 $security_check = $check;
134 if (!empty($tmparray[1])) {
135 $value =
GETPOST($key, $security_check);
137 $value =
GETPOST($key, $security_check);
138 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
139 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
140 foreach ($tmparraymultiselect as $tmpvalue) {
141 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
145 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
146 $tmparray = explode(
':',
$object->fields[$key][
'type']);
147 if (!empty($tmparray[1])) {
148 $value =
GETPOST($key, $tmparray[1]);
150 $value =
GETPOST($key,
'restricthtml');
152 } elseif (
$object->fields[$key][
'type'] ==
'date') {
154 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
156 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
158 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
160 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
161 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
162 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
163 $tmparraykey = array_keys(
$object->param_list);
165 } elseif (preg_match(
'/^chkbxlst:(.*)/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
167 $values_arr =
GETPOST($key,
'array');
168 if (!empty($values_arr)) {
169 $value = implode(
',', $values_arr);
171 } elseif (isset(
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] ==
'password') {
172 $value =
GETPOST($key,
'password');
174 if ($key ==
'lang') {
177 $value =
GETPOST($key,
'alphanohtml');
182 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
185 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
188 if ((preg_match(
'/^sellist/i',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'select') && $value ===
'0') {
195 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ===
'(PROV)') {
198 if ($key ==
'pass_crypted') {
202 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && !isset($val[
'default'])) {
204 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
210 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
221 if (!empty($model_pdf) && property_exists(
$object,
'model_pdf')) {
222 $object->model_pdf = $model_pdf;
227 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'', 1);
236 $result =
$object->create($user);
240 $categories =
GETPOST(
'categories',
'array:int');
241 $object->setCategories($categories);
244 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
245 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
249 if (empty($noback)) {
250 header(
"Location: " . $urltogo);
258 setEventMessages(
null,
$object->errors,
'errors');
260 setEventMessages(
$object->error,
null,
'errors');
270if ($action ==
'update' && !empty($permissiontoadd)) {
271 foreach (
$object->fields as $key => $val) {
273 if (
$object->fields[$key][
'type'] ==
'duration') {
277 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
283 if (!
GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] !==
'checkbox') {
288 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
291 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
292 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
298 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
299 $tmparray = explode(
':',
$object->fields[$key][
'type']);
300 if (!empty($tmparray[1])) {
301 $check = $tmparray[1];
306 $security_check =
'alphanohtml';
308 $security_check = $check;
310 if (!empty($tmparray[1])) {
311 $value =
GETPOST($key, $security_check);
313 $value =
GETPOST($key, $security_check);
314 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
315 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
316 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
317 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
321 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
322 $tmparray = explode(
':',
$object->fields[$key][
'type']);
323 if (!empty($tmparray[1])) {
324 $value =
GETPOST($key, $tmparray[1]);
326 $value =
GETPOST($key,
'restricthtml');
328 } elseif (
$object->fields[$key][
'type'] ==
'date') {
330 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
332 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
338 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
340 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
341 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
342 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
344 } elseif (preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
346 $values_arr =
GETPOST($key,
'array');
347 if (!empty($values_arr)) {
348 $value = implode(
',', $values_arr);
350 } elseif (isset(
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] ==
'password') {
351 $value =
GETPOST($key,
'password');
353 if ($key ==
'lang') {
354 $value =
GETPOST($key,
'aZ09');
356 $value =
GETPOST($key,
'alphanohtml');
361 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
364 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
367 if ((preg_match(
'/^sellist/i',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'select') && $value ===
'0') {
373 if ($key ==
'pass_crypted' && property_exists(
$object,
'pass')) {
374 if (
GETPOST(
"pass",
"password")) {
379 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
381 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
387 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
395 $categories =
GETPOST(
'categories',
'array');
396 if (method_exists(
$object,
'setCategories')) {
397 $object->setCategories($categories);
405 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'@GETPOSTISSET');
412 $result =
$object->update($user);
415 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $result, $backtopage) : $backurlforlist;
416 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
417 if ($urltogo && empty($noback)) {
418 header(
"Location: " . $urltogo);
434if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
437 $keyforfield = $reg[1];
438 if (property_exists(
$object, $keyforfield)) {
439 if (!empty(
$object->fields[$keyforfield]) && in_array(
$object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
445 $result =
$object->update($user);
448 setEventMessages($langs->trans(
'RecordSaved'),
null,
'mesgs');
453 $action =
'edit'.$reg[1];
459$permissiontoeditextra = $permissiontoadd;
460if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
462 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
465if ($action ==
"update_extras" &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoeditextra)) {
470 $attribute =
GETPOST(
'attribute',
'aZ09');
475 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
478 setEventMessages($extrafields->error,
$object->errors,
'errors');
479 $action =
'edit_extras';
481 $result =
$object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
483 setEventMessages($langs->trans(
'RecordSaved'),
null,
'mesgs');
488 $action =
'edit_extras';
494if ($action ==
'confirm_delete' && $confirm ==
'yes' && !empty($permissiontodelete)) {
496 dol_print_error(
null,
'Error, object must be fetched before being deleted');
502 $result =
$object->delete($user);
508 setEventMessages(
"RecordDeleted",
null,
'mesgs');
510 if (empty($noback)) {
511 if (empty($backurlforlist)) {
512 print
'Error backurlforlist is not defined';
515 header(
"Location: " . $backurlforlist);
523 setEventMessages(
null,
$object->errors,
'errors');
525 setEventMessages(
$object->error,
null,
'errors');
533if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
536 $result =
$object->deleteLine($user, $lineid, 0, $fk_movement);
538 $result =
$object->deleteLine($user, $lineid);
543 $outputlangs = $langs;
546 $newlang =
GETPOST(
'lang_id',
'aZ09');
549 $newlang =
$object->thirdparty->default_lang;
551 if (!empty($newlang)) {
553 $outputlangs->setDefaultLang($newlang);
556 if (method_exists(
$object,
'generateDocument')) {
558 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
562 setEventMessages($langs->trans(
'RecordDeleted'),
null,
'mesgs');
564 if (empty($noback)) {
565 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.
$object->id : $backtopage));
576if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
577 if (
$object->element ==
'inventory') {
580 $result =
$object->validate($user,
false, (empty($include_sub_warehouse) ? 0 : $include_sub_warehouse), (empty($startmode) ?
'' : $startmode));
582 $result =
$object->validate($user);
588 if (method_exists(
$object,
'generateDocument')) {
589 $outputlangs = $langs;
592 $newlang =
GETPOST(
'lang_id',
'aZ09');
595 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang :
"";
597 if (!empty($newlang)) {
599 $outputlangs->setDefaultLang($newlang);
606 $retgen =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
620if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
621 $result =
$object->cancel($user);
625 if (method_exists(
$object,
'generateDocument')) {
626 $outputlangs = $langs;
629 $newlang =
GETPOST(
'lang_id',
'aZ09');
632 $newlang =
$object->thirdparty->default_lang;
634 if (!empty($newlang)) {
636 $outputlangs->setDefaultLang($newlang);
641 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
652if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
653 $result =
$object->setDraft($user);
664if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
665 $result =
$object->reopen($user);
669 if (method_exists(
$object,
'generateDocument')) {
670 $outputlangs = $langs;
673 $newlang =
GETPOST(
'lang_id',
'aZ09');
676 $newlang =
$object->thirdparty->default_lang;
678 if (!empty($newlang)) {
680 $outputlangs->setDefaultLang($newlang);
685 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
696if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
698 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
699 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
706 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
707 if (is_object($result) || $result > 0) {
709 if (is_object($result)) {
710 $newid = $result->id;
715 if (empty($noback)) {
716 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $newid);
721 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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, $currencycode='')
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.