28@phan-var-force CommonObject $this
29@phan-var-force ?string $action
30@phan-var-force ?string $cancel
31@phan-var-force CommonObject $object
32@phan-var-force string $permissiontoadd
33@phan-var-force ?string $permissionedit
34@phan-var-force string $permissiontodelete
35@phan-var-force string $backurlforlist
36@phan-var-force ?string $backtopage
37@phan-var-force ?string $noback
38@phan-var-force ?string $triggermodname
39@phan-var-force string $hidedetails
40@phan-var-force string $hidedesc
41@phan-var-force string $hideref
53$hidedetails = isset($hidedetails) ? $hidedetails :
'';
54$hidedesc = isset($hidedesc) ? $hidedesc :
'';
55$hideref = isset($hideref) ? $hideref :
'';
58if (!empty($permissionedit) && empty($permissiontoadd)) {
59 $permissiontoadd = $permissionedit;
64 if (!empty($backtopageforcancel)) {
65 header(
"Location: ".$backtopageforcancel);
67 } elseif (!empty($backtopage)) {
68 header(
"Location: ".$backtopage);
76if ($action ==
'add' && !empty($permissiontoadd)) {
77 foreach (
$object->fields as $key => $val) {
79 if (
$object->fields[$key][
'type'] ==
'duration') {
84 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type'])) {
90 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
93 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
94 if (!in_array(abs($val[
'visible']), array(1, 3))) {
100 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
101 $tmparray = explode(
':',
$object->fields[$key][
'type']);
102 if (!empty($tmparray[1])) {
103 $value =
GETPOST($key, $tmparray[1]);
105 $value =
GETPOST($key,
'nohtml');
106 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
107 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
108 foreach ($tmparraymultiselect as $tmpvalue) {
109 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
113 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
114 $tmparray = explode(
':',
$object->fields[$key][
'type']);
115 if (!empty($tmparray[1])) {
116 $value =
GETPOST($key, $tmparray[1]);
118 $value =
GETPOST($key,
'restricthtml');
120 } elseif (
$object->fields[$key][
'type'] ==
'date') {
122 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
124 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
126 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
128 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
129 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
130 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
131 $tmparraykey = array_keys(
$object->param_list);
133 } elseif (preg_match(
'/^chkbxlst:(.*)/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
135 $values_arr =
GETPOST($key,
'array');
136 if (!empty($values_arr)) {
137 $value = implode(
',', $values_arr);
140 if ($key ==
'lang') {
143 $value =
GETPOST($key,
'alphanohtml');
146 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
149 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
156 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
159 if ($key ==
'pass_crypted') {
163 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && !isset($val[
'default'])) {
165 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
171 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
182 if (!empty($model_pdf) && property_exists(
$object,
'model_pdf')) {
183 $object->model_pdf = $model_pdf;
188 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'', 1);
197 $result =
$object->create($user);
200 if (isModEnabled(
'category') && method_exists(
$object,
'setCategories')) {
201 $categories =
GETPOST(
'categories',
'array:int');
202 $object->setCategories($categories);
205 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
206 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
210 if (empty($noback)) {
211 header(
"Location: " . $urltogo);
231if ($action ==
'update' && !empty($permissiontoadd)) {
232 foreach (
$object->fields as $key => $val) {
234 if (
$object->fields[$key][
'type'] ==
'duration') {
235 if (!GETPOSTISSET($key.
'hour') || !GETPOSTISSET($key.
'min')) {
238 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
239 if (!GETPOSTISSET($key)) {
244 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] !==
'checkbox') {
249 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
252 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
253 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
259 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
260 $tmparray = explode(
':',
$object->fields[$key][
'type']);
261 if (!empty($tmparray[1])) {
262 $value =
GETPOST($key, $tmparray[1]);
264 $value =
GETPOST($key,
'nohtml');
265 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
266 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
267 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
268 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
272 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
273 $tmparray = explode(
':',
$object->fields[$key][
'type']);
274 if (!empty($tmparray[1])) {
275 $value =
GETPOST($key, $tmparray[1]);
277 $value =
GETPOST($key,
'restricthtml');
279 } elseif (
$object->fields[$key][
'type'] ==
'date') {
281 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
283 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
289 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
291 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
292 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
293 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
295 } elseif (preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
297 $values_arr =
GETPOST($key,
'array');
298 if (!empty($values_arr)) {
299 $value = implode(
',', $values_arr);
302 if ($key ==
'lang') {
303 $value =
GETPOST($key,
'aZ09');
305 $value =
GETPOST($key,
'alphanohtml');
308 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
311 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
316 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
318 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
323 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
330 if (isModEnabled(
'category')) {
331 $categories =
GETPOST(
'categories',
'array');
332 if (method_exists(
$object,
'setCategories')) {
333 $object->setCategories($categories);
341 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'@GETPOSTISSET');
348 $result =
$object->update($user);
351 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $result, $backtopage) : $backurlforlist;
352 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
353 if ($urltogo && empty($noback)) {
354 header(
"Location: " . $urltogo);
370if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
373 $keyforfield = $reg[1];
374 if (property_exists(
$object, $keyforfield)) {
375 if (!empty(
$object->fields[$keyforfield]) && in_array(
$object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
381 $result =
$object->update($user);
389 $action =
'edit'.$reg[1];
395if ($action ==
"update_extras" &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
400 $attribute =
GETPOST(
'attribute',
'alphanohtml');
405 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
409 $action =
'edit_extras';
411 $result =
$object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
418 $action =
'edit_extras';
424if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
426 dol_print_error(
null,
'Error, object must be fetched before being deleted');
432 $result =
$object->delete($user);
440 if (empty($noback)) {
441 if (empty($backurlforlist)) {
442 print
'Error backurlforlist is not defined';
445 header(
"Location: " . $backurlforlist);
463if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
466 $result =
$object->deleteLine($user, $lineid, 0, $fk_movement);
468 $result =
$object->deleteLine($user, $lineid);
473 $outputlangs = $langs;
476 $newlang =
GETPOST(
'lang_id',
'aZ09');
479 $newlang =
$object->thirdparty->default_lang;
481 if (!empty($newlang)) {
483 $outputlangs->setDefaultLang($newlang);
486 if (method_exists(
$object,
'generateDocument')) {
488 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
494 if (empty($noback)) {
495 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.
$object->id : $backtopage));
506if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
507 if (
$object->element ==
'inventory' && !empty($include_sub_warehouse)) {
509 $result =
$object->validate($user,
false, $include_sub_warehouse);
511 $result =
$object->validate($user);
517 if (method_exists(
$object,
'generateDocument')) {
518 $outputlangs = $langs;
521 $newlang =
GETPOST(
'lang_id',
'aZ09');
524 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang :
"";
526 if (!empty($newlang)) {
528 $outputlangs->setDefaultLang($newlang);
535 $retgen =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
549if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
550 $result =
$object->cancel($user);
554 if (method_exists(
$object,
'generateDocument')) {
555 $outputlangs = $langs;
558 $newlang =
GETPOST(
'lang_id',
'aZ09');
561 $newlang =
$object->thirdparty->default_lang;
563 if (!empty($newlang)) {
565 $outputlangs->setDefaultLang($newlang);
570 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
581if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
582 $result =
$object->setDraft($user);
593if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
594 $result =
$object->reopen($user);
598 if (method_exists(
$object,
'generateDocument')) {
599 $outputlangs = $langs;
602 $newlang =
GETPOST(
'lang_id',
'aZ09');
605 $newlang =
$object->thirdparty->default_lang;
607 if (!empty($newlang)) {
609 $outputlangs->setDefaultLang($newlang);
614 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
625if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
626 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
634 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
635 if (is_object($result) || $result > 0) {
637 if (is_object($result)) {
638 $newid = $result->id;
643 if (empty($noback)) {
644 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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 a Dolibarr global constant string value.