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
74$hidedetails = isset($hidedetails) ? $hidedetails :
'';
75$hidedesc = isset($hidedesc) ? $hidedesc :
'';
76$hideref = isset($hideref) ? $hideref :
'';
79if (!empty($permissionedit) && empty($permissiontoadd)) {
80 $permissiontoadd = $permissionedit;
85 if (!empty($backtopageforcancel)) {
86 header(
"Location: ".$backtopageforcancel);
88 } elseif (!empty($backtopage)) {
89 header(
"Location: ".$backtopage);
97if ($action ==
'add' && !empty($permissiontoadd)) {
98 foreach (
$object->fields as $key => $val) {
100 if (
$object->fields[$key][
'type'] ==
'duration') {
105 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type'])) {
111 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
114 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
115 if (!in_array(abs($val[
'visible']), array(1, 3))) {
121 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
122 $tmparray = explode(
':',
$object->fields[$key][
'type']);
123 if (!empty($tmparray[1])) {
124 $value =
GETPOST($key, $tmparray[1]);
126 $value =
GETPOST($key,
'nohtml');
127 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
128 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
129 foreach ($tmparraymultiselect as $tmpvalue) {
130 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
134 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
135 $tmparray = explode(
':',
$object->fields[$key][
'type']);
136 if (!empty($tmparray[1])) {
137 $value =
GETPOST($key, $tmparray[1]);
139 $value =
GETPOST($key,
'restricthtml');
141 } elseif (
$object->fields[$key][
'type'] ==
'date') {
143 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
145 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
147 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
149 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
150 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
151 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
152 $tmparraykey = array_keys(
$object->param_list);
154 } elseif (preg_match(
'/^chkbxlst:(.*)/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
156 $values_arr =
GETPOST($key,
'array');
157 if (!empty($values_arr)) {
158 $value = implode(
',', $values_arr);
161 if ($key ==
'lang') {
164 $value =
GETPOST($key,
'alphanohtml');
167 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
170 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
177 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && isset($val[
'default']) && $val[
'default'] ==
'(PROV)') {
180 if ($key ==
'pass_crypted') {
184 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && !isset($val[
'default'])) {
186 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
192 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
203 if (!empty($model_pdf) && property_exists(
$object,
'model_pdf')) {
204 $object->model_pdf = $model_pdf;
209 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'', 1);
218 $result =
$object->create($user);
221 if (isModEnabled(
'category') && method_exists(
$object,
'setCategories')) {
222 $categories =
GETPOST(
'categories',
'array:int');
223 $object->setCategories($categories);
226 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
227 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
231 if (empty($noback)) {
232 header(
"Location: " . $urltogo);
252if ($action ==
'update' && !empty($permissiontoadd)) {
253 foreach (
$object->fields as $key => $val) {
255 if (
$object->fields[$key][
'type'] ==
'duration') {
256 if (!GETPOSTISSET($key.
'hour') || !GETPOSTISSET($key.
'min')) {
259 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
260 if (!GETPOSTISSET($key)) {
265 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) &&
$object->fields[$key][
'type'] !==
'checkbox') {
270 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
273 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
274 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
280 if (preg_match(
'/^text/',
$object->fields[$key][
'type'])) {
281 $tmparray = explode(
':',
$object->fields[$key][
'type']);
282 if (!empty($tmparray[1])) {
283 $value =
GETPOST($key, $tmparray[1]);
285 $value =
GETPOST($key,
'nohtml');
286 if (!empty(
$object->fields[$key][
'arrayofkeyval']) && !empty(
$object->fields[$key][
'multiinput'])) {
287 $tmparraymultiselect =
GETPOST($key.
'_multiselect',
'array');
288 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
289 $value .= (!empty($value) ?
"," :
"").$tmpvalue;
293 } elseif (preg_match(
'/^html/',
$object->fields[$key][
'type'])) {
294 $tmparray = explode(
':',
$object->fields[$key][
'type']);
295 if (!empty($tmparray[1])) {
296 $value =
GETPOST($key, $tmparray[1]);
298 $value =
GETPOST($key,
'restricthtml');
300 } elseif (
$object->fields[$key][
'type'] ==
'date') {
302 } elseif (
$object->fields[$key][
'type'] ==
'datetime') {
304 } elseif (
$object->fields[$key][
'type'] ==
'duration') {
310 } elseif (preg_match(
'/^(integer|price|real|double)/',
$object->fields[$key][
'type'])) {
312 } elseif (
$object->fields[$key][
'type'] ==
'boolean') {
313 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
314 } elseif (
$object->fields[$key][
'type'] ==
'reference') {
316 } elseif (preg_match(
'/^chkbxlst:/',
$object->fields[$key][
'type']) ||
$object->fields[$key][
'type'] ==
'checkbox') {
318 $values_arr =
GETPOST($key,
'array');
319 if (!empty($values_arr)) {
320 $value = implode(
',', $values_arr);
323 if ($key ==
'lang') {
324 $value =
GETPOST($key,
'aZ09');
326 $value =
GETPOST($key,
'alphanohtml');
329 if (preg_match(
'/^integer:/i',
$object->fields[$key][
'type']) && $value ==
'-1') {
332 if (!empty(
$object->fields[$key][
'foreignkey']) && $value ==
'-1') {
337 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 &&
$object->$key ==
'' && (!isset($val[
'default']) || is_null($val[
'default']))) {
339 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
344 if (!$error && !empty($val[
'validate']) && is_callable(array(
$object,
'validateField'))) {
351 if (isModEnabled(
'category')) {
352 $categories =
GETPOST(
'categories',
'array');
353 if (method_exists(
$object,
'setCategories')) {
354 $object->setCategories($categories);
362 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
'@GETPOSTISSET');
369 $result =
$object->update($user);
372 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $result, $backtopage) : $backurlforlist;
373 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string)
$object->id, $urltogo);
374 if ($urltogo && empty($noback)) {
375 header(
"Location: " . $urltogo);
391if (preg_match(
'/^set(\w+)$/', $action, $reg) &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
394 $keyforfield = $reg[1];
395 if (property_exists(
$object, $keyforfield)) {
396 if (!empty(
$object->fields[$keyforfield]) && in_array(
$object->fields[$keyforfield][
'type'], array(
'date',
'datetime',
'timestamp'))) {
402 $result =
$object->update($user);
410 $action =
'edit'.$reg[1];
416if ($action ==
"update_extras" &&
GETPOSTINT(
'id') > 0 && !empty($permissiontoadd)) {
421 $attribute =
GETPOST(
'attribute',
'alphanohtml');
426 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
430 $action =
'edit_extras';
432 $result =
$object->updateExtraField($attribute, empty($triggermodname) ?
'' : $triggermodname, $user);
439 $action =
'edit_extras';
445if ($action ==
'confirm_delete' && !empty($permissiontodelete)) {
447 dol_print_error(
null,
'Error, object must be fetched before being deleted');
453 $result =
$object->delete($user);
461 if (empty($noback)) {
462 if (empty($backurlforlist)) {
463 print
'Error backurlforlist is not defined';
466 header(
"Location: " . $backurlforlist);
484if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd)) {
487 $result =
$object->deleteLine($user, $lineid, 0, $fk_movement);
489 $result =
$object->deleteLine($user, $lineid);
494 $outputlangs = $langs;
497 $newlang =
GETPOST(
'lang_id',
'aZ09');
500 $newlang =
$object->thirdparty->default_lang;
502 if (!empty($newlang)) {
504 $outputlangs->setDefaultLang($newlang);
507 if (method_exists(
$object,
'generateDocument')) {
509 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
515 if (empty($noback)) {
516 header(
'Location: '.((empty($backtopage)) ? $_SERVER[
"PHP_SELF"].
'?id='.
$object->id : $backtopage));
527if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd) {
528 if (
$object->element ==
'inventory' && !empty($include_sub_warehouse)) {
530 $result =
$object->validate($user,
false, $include_sub_warehouse);
532 $result =
$object->validate($user);
538 if (method_exists(
$object,
'generateDocument')) {
539 $outputlangs = $langs;
542 $newlang =
GETPOST(
'lang_id',
'aZ09');
545 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang :
"";
547 if (!empty($newlang)) {
549 $outputlangs->setDefaultLang($newlang);
556 $retgen =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
570if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd) {
571 $result =
$object->cancel($user);
575 if (method_exists(
$object,
'generateDocument')) {
576 $outputlangs = $langs;
579 $newlang =
GETPOST(
'lang_id',
'aZ09');
582 $newlang =
$object->thirdparty->default_lang;
584 if (!empty($newlang)) {
586 $outputlangs->setDefaultLang($newlang);
591 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
602if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd) {
603 $result =
$object->setDraft($user);
614if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd) {
615 $result =
$object->reopen($user);
619 if (method_exists(
$object,
'generateDocument')) {
620 $outputlangs = $langs;
623 $newlang =
GETPOST(
'lang_id',
'aZ09');
626 $newlang =
$object->thirdparty->default_lang;
628 if (!empty($newlang)) {
630 $outputlangs->setDefaultLang($newlang);
635 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
646if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
648 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
656 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
657 if (is_object($result) || $result > 0) {
659 if (is_object($result)) {
660 $newid = $result->id;
665 if (empty($noback)) {
666 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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...