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