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