dolibarr 23.0.3
actions_addupdatedelete.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
27'
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
42';
68// $action or $cancel must be defined
69// $object must be defined
70// $permissiontoadd must be defined
71// $permissiontodelete must be defined
72// $backurlforlist must be defined
73// $backtopage may be defined
74// $noback may be defined
75// $triggermodname may be defined
76
77$hidedetails = isset($hidedetails) ? $hidedetails : '';
78$hidedesc = isset($hidedesc) ? $hidedesc : '';
79$hideref = isset($hideref) ? $hideref : '';
80$error = 0;
81
82if (!empty($permissionedit) && empty($permissiontoadd)) {
83 $permissiontoadd = $permissionedit; // For backward compatibility
84}
85
86if (!empty($cancel)) {
87 /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
88 if (!empty($backtopageforcancel)) {
89 header("Location: ".$backtopageforcancel);
90 exit;
91 } elseif (!empty($backtopage)) {
92 header("Location: ".$backtopage);
93 exit;
94 }
95 $action = '';
96}
97
98
99// Action to add record
100if ($action == 'add' && !empty($permissiontoadd)) {
101 foreach ($object->fields as $key => $val) {
102 // Ignore special cases
103 if ($object->fields[$key]['type'] == 'duration') {
104 if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') {
105 continue; // The field was not submitted to be saved
106 }
107 } else {
108 if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
109 continue; // The field was not submitted to be saved
110 }
111 }
112
113 // Ignore special fields
114 if (in_array($key, array('rowid', 'entity', 'import_key'))) {
115 continue;
116 }
117 if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
118 if (!in_array(abs($val['visible']), array(1, 3))) {
119 continue; // Only 1 and 3 that are case to create
120 }
121 }
122
123 // Set value to insert
124 if (preg_match('/^text/', $object->fields[$key]['type'])) {
125 $tmparray = explode(':', $object->fields[$key]['type']);
126 if (!empty($tmparray[1])) {
127 $value = GETPOST($key, $tmparray[1]);
128 } else {
129 $value = GETPOST($key, 'nohtml');
130 if (!empty($object->fields[$key]['arrayofkeyval']) && !empty($object->fields[$key]['multiinput'])) {
131 $tmparraymultiselect = GETPOST($key.'_multiselect', 'array');
132 foreach ($tmparraymultiselect as $tmpvalue) {
133 $value .= (!empty($value) ? "," : "").$tmpvalue;
134 }
135 }
136 }
137 } elseif (preg_match('/^html/', $object->fields[$key]['type'])) {
138 $tmparray = explode(':', $object->fields[$key]['type']);
139 if (!empty($tmparray[1])) {
140 $value = GETPOST($key, $tmparray[1]);
141 } else {
142 $value = GETPOST($key, 'restricthtml');
143 }
144 } elseif ($object->fields[$key]['type'] == 'date') {
145 $value = dol_mktime(12, 0, 0, GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year')); // for date without hour, we use gmt
146 } elseif ($object->fields[$key]['type'] == 'datetime') {
147 $value = dol_mktime(GETPOSTINT($key.'hour'), GETPOSTINT($key.'min'), GETPOSTINT($key.'sec'), GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year'), 'tzuserrel');
148 } elseif ($object->fields[$key]['type'] == 'duration') {
149 $value = 60 * 60 * GETPOSTINT($key.'hour') + 60 * GETPOSTINT($key.'min');
150 } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
151 $value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
152 } elseif ($object->fields[$key]['type'] == 'boolean') {
153 $value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0);
154 } elseif ($object->fields[$key]['type'] == 'reference') {
155 $tmparraykey = array_keys($object->param_list);
156 $value = $tmparraykey[(int) GETPOST($key)].','.GETPOST($key.'2');
157 } elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') {
158 $value = '';
159 $values_arr = GETPOST($key, 'array');
160 if (!empty($values_arr)) {
161 $value = implode(',', $values_arr);
162 }
163 } else {
164 if ($key == 'lang') {
165 $value = GETPOST($key, 'aZ09') ? GETPOST($key, 'aZ09') : "";
166 } else {
167 $value = GETPOST($key, 'alphanohtml');
168 }
169 }
170 if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
171 $value = ''; // This is an implicit foreign key field
172 }
173 if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
174 $value = ''; // This is an explicit foreign key field
175 }
176 if (preg_match('/^sellist:/i', $object->fields[$key]['type']) && $value == '0') {
177 $value = ''; // sellist blank option posts "0"; normalize to '' so notnull check works on PHP 8.0+ (see github.com/Dolibarr/dolibarr/issues/38199)
178 }
179
180 //var_dump($key.' '.$value.' '.$object->fields[$key]['type'].' '.$object->fields[$key]['notnull']);
181
182 $object->$key = $value;
183 if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && isset($val['default']) && $val['default'] === '(PROV)') {
184 $object->$key = '(PROV)';
185 }
186 if ($key == 'pass_crypted') {
187 $object->pass = GETPOST("pass", "password");
188 // TODO Manadatory for password not yet managed
189 } else {
190 if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && !isset($val['default'])) {
191 $error++;
192 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
193 }
194 }
195
196 // Validation of fields values
197 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
198 if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
199 if (!$object->validateField($object->fields, $key, $value)) {
200 $error++;
201 setEventMessages($object->error, $object->errors, 'errors');
202 }
203 }
204 }
205 }
206
207 // Special field
208 $model_pdf = GETPOST('model');
209 if (!empty($model_pdf) && property_exists($object, 'model_pdf')) {
210 $object->model_pdf = $model_pdf;
211 }
212
213 // Fill array 'array_options' with data from add form
214 if (!$error) {
215 $ret = $extrafields->setOptionalsFromPost(null, $object, '', 1);
216 if ($ret < 0) {
217 $error++;
218 }
219 }
220
221 if (!$error) {
222 $db->begin();
223
224 $result = $object->create($user);
225 if ($result > 0) {
226 // Creation OK
227 if (isModEnabled('category') && method_exists($object, 'setCategories')) {
228 $categories = GETPOST('categories', 'array:int');
229 $object->setCategories($categories);
230 }
231
232 $urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
233 $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $urltogo); // New method to autoselect field created after a New on another form object creation
234
235 $db->commit();
236
237 if (empty($noback)) {
238 header("Location: " . $urltogo);
239 exit;
240 }
241 } else {
242 $db->rollback();
243 $error++;
244 // Creation KO
245 if (!empty($object->errors)) {
246 setEventMessages(null, $object->errors, 'errors');
247 } else {
248 setEventMessages($object->error, null, 'errors');
249 }
250 $action = 'create';
251 }
252 } else {
253 $action = 'create';
254 }
255}
256
257// Action to update record
258if ($action == 'update' && !empty($permissiontoadd)) {
259 foreach ($object->fields as $key => $val) {
260 // Check if field was submitted to be edited
261 if ($object->fields[$key]['type'] == 'duration') {
262 if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) {
263 continue; // The field was not submitted to be saved
264 }
265 } elseif ($object->fields[$key]['type'] == 'boolean') {
266 if (!GETPOSTISSET($key)) {
267 $object->$key = 0; // use 0 instead null if the field is defined as not null
268 continue;
269 }
270 } else {
271 if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type']) && $object->fields[$key]['type'] !== 'checkbox') {
272 continue; // The field was not submitted to be saved
273 }
274 }
275 // Ignore special fields
276 if (in_array($key, array('rowid', 'entity', 'import_key'))) {
277 continue;
278 }
279 if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
280 if (!in_array(abs($val['visible']), array(1, 3, 4))) {
281 continue; // Only 1 and 3 and 4, that are cases to update
282 }
283 }
284
285 // Set value to update
286 if (preg_match('/^text/', $object->fields[$key]['type'])) {
287 $tmparray = explode(':', $object->fields[$key]['type']);
288 if (!empty($tmparray[1])) {
289 $value = GETPOST($key, $tmparray[1]);
290 } else {
291 $value = GETPOST($key, 'nohtml');
292 if (!empty($object->fields[$key]['arrayofkeyval']) && !empty($object->fields[$key]['multiinput'])) {
293 $tmparraymultiselect = GETPOST($key.'_multiselect', 'array');
294 foreach ($tmparraymultiselect as $keytmp => $tmpvalue) {
295 $value .= (!empty($value) ? "," : "").$tmpvalue;
296 }
297 }
298 }
299 } elseif (preg_match('/^html/', $object->fields[$key]['type'])) {
300 $tmparray = explode(':', $object->fields[$key]['type']);
301 if (!empty($tmparray[1])) {
302 $value = GETPOST($key, $tmparray[1]);
303 } else {
304 $value = GETPOST($key, 'restricthtml');
305 }
306 } elseif ($object->fields[$key]['type'] == 'date') {
307 $value = dol_mktime(12, 0, 0, GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year')); // for date without hour, we use gmt
308 } elseif ($object->fields[$key]['type'] == 'datetime') {
309 $value = dol_mktime(GETPOSTINT($key.'hour'), GETPOSTINT($key.'min'), GETPOSTINT($key.'sec'), GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year'), 'tzuserrel');
310 } elseif ($object->fields[$key]['type'] == 'duration') {
311 if (GETPOSTINT($key.'hour') != '' || GETPOSTINT($key.'min') != '') {
312 $value = 60 * 60 * GETPOSTINT($key.'hour') + 60 * GETPOSTINT($key.'min');
313 } else {
314 $value = '';
315 }
316 } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
317 $value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
318 } elseif ($object->fields[$key]['type'] == 'boolean') {
319 $value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
320 } elseif ($object->fields[$key]['type'] == 'reference') {
321 $value = array_keys($object->param_list)[(int) GETPOST($key)].','.GETPOST($key.'2');
322 } elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') {
323 $value = '';
324 $values_arr = GETPOST($key, 'array');
325 if (!empty($values_arr)) {
326 $value = implode(',', $values_arr);
327 }
328 } else {
329 if ($key == 'lang') {
330 $value = GETPOST($key, 'aZ09');
331 } else {
332 $value = GETPOST($key, 'alphanohtml');
333 }
334 }
335 if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
336 $value = ''; // This is an implicit foreign key field
337 }
338 if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
339 $value = ''; // This is an explicit foreign key field
340 }
341 if (preg_match('/^sellist:/i', $object->fields[$key]['type']) && $value == '0') {
342 $value = ''; // sellist blank option posts "0"; normalize to '' so notnull check works on PHP 8.0+ (see github.com/Dolibarr/dolibarr/issues/38199)
343 }
344
345 $object->$key = $value;
346
347 if ($key == 'pass_crypted' && property_exists($object, 'pass')) {
348 if (GETPOST("pass", "password")) { // If not provided, we do not change it. We never erase a password with empty.
349 $object->pass = GETPOST("pass", "password");
350 }
351 // TODO Manadatory for password not yet managed
352 } else {
353 if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && (!isset($val['default']) || is_null($val['default']))) {
354 $error++;
355 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
356 }
357 }
358
359 // Validation of fields values
360 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
361 if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
362 if (!$object->validateField($object->fields, $key, $value)) {
363 $error++;
364 }
365 }
366 }
367
368 if (isModEnabled('category')) {
369 $categories = GETPOST('categories', 'array');
370 if (method_exists($object, 'setCategories')) {
371 $object->setCategories($categories);
372 }
373 }
374 }
375
376
377 // Fill array 'array_options' with data from add form
378 if (!$error) {
379 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
380 if ($ret < 0) {
381 $error++;
382 }
383 }
384
385 if (!$error) {
386 $result = $object->update($user);
387 if ($result > 0) {
388 $action = 'view';
389 $urltogo = $backtopage ? str_replace('__ID__', (string) $result, $backtopage) : $backurlforlist;
390 $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
391 if ($urltogo && empty($noback)) {
392 header("Location: " . $urltogo);
393 exit;
394 }
395 } else {
396 $error++;
397 // Creation KO
398 setEventMessages($object->error, $object->errors, 'errors');
399 $action = 'edit';
400 }
401 } else {
402 $action = 'edit';
403 }
404}
405
406// Action to update one modulebuilder field
407$reg = array();
408if (preg_match('/^set(\w+)$/', $action, $reg) && GETPOSTINT('id') > 0 && !empty($permissiontoadd)) {
409 $object->fetch(GETPOSTINT('id'));
410
411 $keyforfield = $reg[1];
412 if (property_exists($object, $keyforfield)) {
413 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield]['type'], array('date', 'datetime', 'timestamp'))) {
414 $object->$keyforfield = dol_mktime(GETPOSTINT($keyforfield.'hour'), GETPOSTINT($keyforfield.'min'), GETPOSTINT($keyforfield.'sec'), GETPOSTINT($keyforfield.'month'), GETPOSTINT($keyforfield.'day'), GETPOSTINT($keyforfield.'year'));
415 } else {
416 $object->$keyforfield = GETPOST($keyforfield);
417 }
418
419 $result = $object->update($user);
420
421 if ($result > 0) {
422 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
423 $action = 'view';
424 } else {
425 $error++;
426 setEventMessages($object->error, $object->errors, 'errors');
427 $action = 'edit'.$reg[1];
428 }
429 }
430}
431
432// Action to update one extrafield
433$permissiontoeditextra = $permissiontoadd;
434if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
435 // For action 'update_extras', is there a specific permission set for the attribute to update
436 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
437}
438
439if ($action == "update_extras" && GETPOSTINT('id') > 0 && !empty($permissiontoeditextra)) {
440 $object->fetch(GETPOSTINT('id'));
441
442 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
443
444 $attribute = GETPOST('attribute', 'aZ09');
445
446 $error = 0;
447
448 // Fill array 'array_options' with data from update form
449 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute);
450 if ($ret < 0) {
451 $error++;
452 setEventMessages($extrafields->error, $object->errors, 'errors');
453 $action = 'edit_extras';
454 } else {
455 $result = $object->updateExtraField($attribute, empty($triggermodname) ? '' : $triggermodname, $user); // TODO Remove $triggermodname to use $object->TRIGGER_PREFIX.'_MODIFY' instead
456 if ($result > 0) {
457 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
458 $action = 'view';
459 } else {
460 $error++;
461 setEventMessages($object->error, $object->errors, 'errors');
462 $action = 'edit_extras';
463 }
464 }
465}
466
467// Action to delete
468if ($action == 'confirm_delete' && $confirm == 'yes' && !empty($permissiontodelete)) {
469 if (!($object->id > 0)) {
470 dol_print_error(null, 'Error, object must be fetched before being deleted');
471 exit;
472 }
473
474 $db->begin();
475
476 $result = $object->delete($user);
477
478 if ($result > 0) {
479 $db->commit();
480
481 // Delete OK
482 setEventMessages("RecordDeleted", null, 'mesgs');
483
484 if (empty($noback)) {
485 if (empty($backurlforlist)) {
486 print 'Error backurlforlist is not defined';
487 exit;
488 }
489 header("Location: " . $backurlforlist);
490 exit;
491 }
492 } else {
493 $db->rollback();
494
495 $error++;
496 if (!empty($object->errors)) {
497 setEventMessages(null, $object->errors, 'errors');
498 } else {
499 setEventMessages($object->error, null, 'errors');
500 }
501 }
502
503 $action = '';
504}
505
506// Remove a line
507if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) {
508 if (!empty($object->element) && $object->element == 'mo') {
509 $fk_movement = GETPOSTINT('fk_movement');
510 $result = $object->deleteLine($user, $lineid, 0, $fk_movement);
511 } else {
512 $result = $object->deleteLine($user, $lineid);
513 }
514
515 if ($result > 0) {
516 // Define output language
517 $outputlangs = $langs;
518 $newlang = '';
519 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
520 $newlang = GETPOST('lang_id', 'aZ09');
521 }
522 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
523 $newlang = $object->thirdparty->default_lang;
524 }
525 if (!empty($newlang)) {
526 $outputlangs = new Translate("", $conf);
527 $outputlangs->setDefaultLang($newlang);
528 }
529 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
530 if (method_exists($object, 'generateDocument')) {
531 $ret = $object->fetch($object->id); // Reload to get new records
532 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
533 }
534 }
535
536 setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
537
538 if (empty($noback)) {
539 header('Location: '.((empty($backtopage)) ? $_SERVER["PHP_SELF"].'?id='.$object->id : $backtopage));
540 exit;
541 }
542 } else {
543 $error++;
544 setEventMessages($object->error, $object->errors, 'errors');
545 }
546 $action = '';
547}
548
549// Action validate object
550if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
551 if ($object->element == 'inventory' && !empty($include_sub_warehouse)) {
552 // Can happen when the conf INVENTORY_INCLUDE_SUB_WAREHOUSE is set
553 $result = $object->validate($user, false, $include_sub_warehouse);
554 } else {
555 $result = $object->validate($user);
556 }
557
558 if ($result >= 0) {
559 // Define output language
560 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
561 if (method_exists($object, 'generateDocument')) {
562 $outputlangs = $langs;
563 $newlang = '';
564 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
565 $newlang = GETPOST('lang_id', 'aZ09');
566 }
567 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
568 $newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang : "";
569 }
570 if (!empty($newlang)) {
571 $outputlangs = new Translate("", $conf);
572 $outputlangs->setDefaultLang($newlang);
573 }
574
575 $ret = $object->fetch($id); // Reload to get new records
576
577 $model = $object->model_pdf;
578
579 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
580 if ($retgen < 0) {
581 setEventMessages($object->error, $object->errors, 'warnings');
582 }
583 }
584 }
585 } else {
586 $error++;
587 setEventMessages($object->error, $object->errors, 'errors');
588 }
589 $action = '';
590}
591
592// Action close object
593if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
594 $result = $object->cancel($user);
595 if ($result >= 0) {
596 // Define output language
597 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
598 if (method_exists($object, 'generateDocument')) {
599 $outputlangs = $langs;
600 $newlang = '';
601 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
602 $newlang = GETPOST('lang_id', 'aZ09');
603 }
604 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
605 $newlang = $object->thirdparty->default_lang;
606 }
607 if (!empty($newlang)) {
608 $outputlangs = new Translate("", $conf);
609 $outputlangs->setDefaultLang($newlang);
610 }
611 $model = $object->model_pdf;
612 $ret = $object->fetch($id); // Reload to get new records
613
614 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
615 }
616 }
617 } else {
618 $error++;
619 setEventMessages($object->error, $object->errors, 'errors');
620 }
621 $action = '';
622}
623
624// Action setdraft object
625if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
626 $result = $object->setDraft($user);
627 if ($result >= 0) {
628 // Nothing else done
629 } else {
630 $error++;
631 setEventMessages($object->error, $object->errors, 'errors');
632 }
633 $action = '';
634}
635
636// Action reopen object
637if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
638 $result = $object->reopen($user);
639 if ($result >= 0) {
640 // Define output language
641 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
642 if (method_exists($object, 'generateDocument')) {
643 $outputlangs = $langs;
644 $newlang = '';
645 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
646 $newlang = GETPOST('lang_id', 'aZ09');
647 }
648 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
649 $newlang = $object->thirdparty->default_lang;
650 }
651 if (!empty($newlang)) {
652 $outputlangs = new Translate("", $conf);
653 $outputlangs->setDefaultLang($newlang);
654 }
655 $model = $object->model_pdf;
656 $ret = $object->fetch($id); // Reload to get new records
657
658 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
659 }
660 }
661 } else {
662 $error++;
663 setEventMessages($object->error, $object->errors, 'errors');
664 }
665 $action = '';
666}
667
668// Action clone object
669if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
670 // @phan-suppress-next-line PhanPluginBothLiteralsBinaryOp
671 if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
672 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
673 } else {
674 // We clone object to avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object.
675 $objectutil = dol_clone($object, 1);
676 // We used native clone to keep this->db valid and allow to use later all the methods of object.
677 // $objectutil->date = dol_mktime(12, 0, 0, GETPOSTINT('newdatemonth', 'int'), GETPOSTINT('newdateday', 'int'), GETPOSTINT('newdateyear', 'int'));
678 // ...
679 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
680 if (is_object($result) || $result > 0) {
681 $newid = 0;
682 if (is_object($result)) {
683 $newid = $result->id;
684 } else {
685 $newid = $result;
686 }
687
688 if (empty($noback)) {
689 header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object
690 exit;
691 }
692 } else {
693 $error++;
694 setEventMessages($objectutil->error, $objectutil->errors, 'errors');
695 $action = '';
696 }
697 }
698}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 '.
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)
Return value of a param into GET or POST supervariable.
dol_clone($srcobject, $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.
isModEnabled($module)
Is Dolibarr module enabled.