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