27@phan-var-force CommonObject $this
28@phan-var-force ?string $action
29@phan-var-force ?string $cancel
30@phan-var-force CommonObject $object
31@phan-var-force string $permissiontoadd
32@phan-var-force ?string $permissionedit
33@phan-var-force string $permissiontodelete
34@phan-var-force string $backurlforlist
35@phan-var-force ?string $backtopage
36@phan-var-force ?string $noback
37@phan-var-force ?string $triggermodname
38@phan-var-force string $hidedetails
39@phan-var-force string $hidedesc
40@phan-var-force string $hideref
52$hidedetails = isset($hidedetails) ? $hidedetails :
'';
53$hidedesc = isset($hidedesc) ? $hidedesc :
'';
54$hideref = isset($hideref) ? $hideref :
'';
57if (!empty($permissionedit) && empty($permissiontoadd)) {
58 $permissiontoadd = $permissionedit;
63 if (!empty($backtopageforcancel)) {
64 header(
"Location: ".$backtopageforcancel);
66 } elseif (!empty($backtopage)) {
67 header(
"Location: ".$backtopage);
75if ($action ==
'add' && !empty($permissiontoadd)) {
76 foreach (
$object->fields as $key => $val) {
78 if (
$object->fields[$key][
'type'] ==
'duration') {
83 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type'])) {
89 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
92 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
93 if (!in_array(abs($val[
'visible']), array(1, 3))) {
99 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
100 $tmparray = explode(
':',
$object->fields[$key][
'type']);
101 if (!empty($tmparray[1])) {
102 $value =
GETPOST($key, $tmparray[1]);
104 $value =
GETPOST($key,
'nohtml');
105 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
106 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
107 foreach ($tmparraymultiselect as $tmpvalue) {
108 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
112 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
113 $tmparray = explode(
':',
$object->fields[$key][
'type']);
114 if (!empty($tmparray[1])) {
115 $value =
GETPOST($key, $tmparray[1]);
117 $value =
GETPOST($key,
'restricthtml');
119 } elseif (
$object->fields[$key][
'type'] ==
'date') {
121 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
123 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
125 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
127 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
128 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
129 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
130 $tmparraykey = array_keys(
$object->param_list);
132 } elseif (preg_match(
'/^chkbxlst:(.*)/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
134 $values_arr =
GETPOST($key,
'array');
135 if (!empty($values_arr)) {
136 $value = implode(
',', $values_arr);
139 if ($key ==
'lang') {
142 $value =
GETPOST($key,
'alphanohtml');
145 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
148 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
155 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
158 if ($key ==
'pass_crypted') {
162 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && !isset($val[
'default'])) {
164 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
170 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
181 if (!empty($model_pdf) && property_exists(
$object,
'model_pdf')) {
182 $object->model_pdf = $model_pdf;
187 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'', 1);
196 $result =
$object->create($user);
199 if (isModEnabled(
'category') && method_exists(
$object,
'setCategories')) {
200 $categories =
GETPOST(
'categories',
'array:int');
201 $object->setCategories($categories);
204 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
205 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
209 if (empty($noback)) {
210 header(
"Location: " . $urltogo);
230if ($action ==
'update' && !empty($permissiontoadd)) {
231 foreach (
$object->fields as $key => $val) {
233 if (
$object->fields[$key][
'type'] ==
'duration') {
234 if (!GETPOSTISSET($key.
'hour') || !GETPOSTISSET($key.
'min')) {
237 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
238 if (!GETPOSTISSET($key)) {
243 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] !==
'checkbox') {
248 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
251 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
252 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
258 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
259 $tmparray = explode(
':',
$object->fields[$key][
'type']);
260 if (!empty($tmparray[1])) {
261 $value =
GETPOST($key, $tmparray[1]);
263 $value =
GETPOST($key,
'nohtml');
264 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
265 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
266 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
267 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
271 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
272 $tmparray = explode(
':',
$object->fields[$key][
'type']);
273 if (!empty($tmparray[1])) {
274 $value =
GETPOST($key, $tmparray[1]);
276 $value =
GETPOST($key,
'restricthtml');
278 } elseif (
$object->fields[$key][
'type'] ==
'date') {
280 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
282 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
288 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
290 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
291 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
292 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
294 } elseif (preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
296 $values_arr =
GETPOST($key,
'array');
297 if (!empty($values_arr)) {
298 $value = implode(
',', $values_arr);
301 if ($key ==
'lang') {
302 $value =
GETPOST($key,
'aZ09');
304 $value =
GETPOST($key,
'alphanohtml');
307 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
310 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
315 if ($val[
'notnull'] > 0 &&
$object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
317 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
322 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
329 if (isModEnabled(
'category')) {
330 $categories =
GETPOST(
'categories',
'array');
331 if (method_exists(
$object,
'setCategories')) {
332 $object->setCategories($categories);
340 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'@GETPOSTISSET');
347 $result =
$object->update($user);
350 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $result, $backtopage) : $backurlforlist;
351 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
352 if ($urltogo && empty($noback)) {
353 header(
"Location: " . $urltogo);
369if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
372 $keyforfield = $reg[1];
373 if (property_exists(
$object, $keyforfield)) {
374 if (!empty(
$object->fields[$keyforfield]) && in_array(
$object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
380 $result =
$object->update($user);
388 $action =
'edit'.$reg[1];
394if ($action ==
"update_extras" &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
399 $attribute =
GETPOST(
'attribute',
'alphanohtml');
404 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
408 $action =
'edit_extras';
410 $result =
$object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
417 $action =
'edit_extras';
423if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
425 dol_print_error(
null,
'Error, object must be fetched before being deleted');
431 $result =
$object->delete($user);
439 if (empty($noback)) {
440 if (empty($backurlforlist)) {
441 print
'Error backurlforlist is not defined';
444 header(
"Location: " . $backurlforlist);
462if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
465 $result =
$object->deleteLine($user, $lineid, 0, $fk_movement);
467 $result =
$object->deleteLine($user, $lineid);
472 $outputlangs = $langs;
475 $newlang =
GETPOST(
'lang_id',
'aZ09');
478 $newlang =
$object->thirdparty->default_lang;
480 if (!empty($newlang)) {
482 $outputlangs->setDefaultLang($newlang);
485 if (method_exists(
$object,
'generateDocument')) {
487 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
493 if (empty($noback)) {
494 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.
$object->id : $backtopage));
505if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
506 if (
$object->element ==
'inventory' && !empty($include_sub_warehouse)) {
508 $result =
$object->validate($user,
false, $include_sub_warehouse);
510 $result =
$object->validate($user);
516 if (method_exists(
$object,
'generateDocument')) {
517 $outputlangs = $langs;
520 $newlang =
GETPOST(
'lang_id',
'aZ09');
523 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang :
"";
525 if (!empty($newlang)) {
527 $outputlangs->setDefaultLang($newlang);
534 $retgen =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
548if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
549 $result =
$object->cancel($user);
553 if (method_exists(
$object,
'generateDocument')) {
554 $outputlangs = $langs;
557 $newlang =
GETPOST(
'lang_id',
'aZ09');
560 $newlang =
$object->thirdparty->default_lang;
562 if (!empty($newlang)) {
564 $outputlangs->setDefaultLang($newlang);
569 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
580if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
581 $result =
$object->setDraft($user);
592if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
593 $result =
$object->reopen($user);
597 if (method_exists(
$object,
'generateDocument')) {
598 $outputlangs = $langs;
601 $newlang =
GETPOST(
'lang_id',
'aZ09');
604 $newlang =
$object->thirdparty->default_lang;
606 if (!empty($newlang)) {
608 $outputlangs->setDefaultLang($newlang);
613 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
624if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
625 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
633 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id : $id));
634 if (is_object($result) || $result > 0) {
636 if (is_object($result)) {
637 $newid = $result->id;
642 if (empty($noback)) {
643 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $newid);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.