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