dolibarr 21.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 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 if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && (!isset($val['default']) || is_null($val['default']))) {
338 $error++;
339 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
340 }
341
342 // Validation of fields values
343 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
344 if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
345 if (!$object->validateField($object->fields, $key, $value)) {
346 $error++;
347 }
348 }
349 }
350
351 if (isModEnabled('category')) {
352 $categories = GETPOST('categories', 'array');
353 if (method_exists($object, 'setCategories')) {
354 $object->setCategories($categories);
355 }
356 }
357 }
358
359
360 // Fill array 'array_options' with data from add form
361 if (!$error) {
362 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
363 if ($ret < 0) {
364 $error++;
365 }
366 }
367
368 if (!$error) {
369 $result = $object->update($user);
370 if ($result > 0) {
371 $action = 'view';
372 $urltogo = $backtopage ? str_replace('__ID__', (string) $result, $backtopage) : $backurlforlist;
373 $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
374 if ($urltogo && empty($noback)) {
375 header("Location: " . $urltogo);
376 exit;
377 }
378 } else {
379 $error++;
380 // Creation KO
381 setEventMessages($object->error, $object->errors, 'errors');
382 $action = 'edit';
383 }
384 } else {
385 $action = 'edit';
386 }
387}
388
389// Action to update one modulebuilder field
390$reg = array();
391if (preg_match('/^set(\w+)$/', $action, $reg) && GETPOSTINT('id') > 0 && !empty($permissiontoadd)) {
392 $object->fetch(GETPOSTINT('id'));
393
394 $keyforfield = $reg[1];
395 if (property_exists($object, $keyforfield)) {
396 if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield]['type'], array('date', 'datetime', 'timestamp'))) {
397 $object->$keyforfield = dol_mktime(GETPOSTINT($keyforfield.'hour'), GETPOSTINT($keyforfield.'min'), GETPOSTINT($keyforfield.'sec'), GETPOSTINT($keyforfield.'month'), GETPOSTINT($keyforfield.'day'), GETPOSTINT($keyforfield.'year'));
398 } else {
399 $object->$keyforfield = GETPOST($keyforfield);
400 }
401
402 $result = $object->update($user);
403
404 if ($result > 0) {
405 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
406 $action = 'view';
407 } else {
408 $error++;
409 setEventMessages($object->error, $object->errors, 'errors');
410 $action = 'edit'.$reg[1];
411 }
412 }
413}
414
415// Action to update one extrafield
416if ($action == "update_extras" && GETPOSTINT('id') > 0 && !empty($permissiontoadd)) {
417 $object->fetch(GETPOSTINT('id'));
418
419 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
420
421 $attribute = GETPOST('attribute', 'alphanohtml');
422
423 $error = 0;
424
425 // Fill array 'array_options' with data from update form
426 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute);
427 if ($ret < 0) {
428 $error++;
429 setEventMessages($extrafields->error, $object->errors, 'errors');
430 $action = 'edit_extras';
431 } else {
432 $result = $object->updateExtraField($attribute, empty($triggermodname) ? '' : $triggermodname, $user);
433 if ($result > 0) {
434 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
435 $action = 'view';
436 } else {
437 $error++;
438 setEventMessages($object->error, $object->errors, 'errors');
439 $action = 'edit_extras';
440 }
441 }
442}
443
444// Action to delete
445if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
446 if (!($object->id > 0)) {
447 dol_print_error(null, 'Error, object must be fetched before being deleted');
448 exit;
449 }
450
451 $db->begin();
452
453 $result = $object->delete($user);
454
455 if ($result > 0) {
456 $db->commit();
457
458 // Delete OK
459 setEventMessages("RecordDeleted", null, 'mesgs');
460
461 if (empty($noback)) {
462 if (empty($backurlforlist)) {
463 print 'Error backurlforlist is not defined';
464 exit;
465 }
466 header("Location: " . $backurlforlist);
467 exit;
468 }
469 } else {
470 $db->rollback();
471
472 $error++;
473 if (!empty($object->errors)) {
474 setEventMessages(null, $object->errors, 'errors');
475 } else {
476 setEventMessages($object->error, null, 'errors');
477 }
478 }
479
480 $action = '';
481}
482
483// Remove a line
484if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) {
485 if (!empty($object->element) && $object->element == 'mo') {
486 $fk_movement = GETPOSTINT('fk_movement');
487 $result = $object->deleteLine($user, $lineid, 0, $fk_movement);
488 } else {
489 $result = $object->deleteLine($user, $lineid);
490 }
491
492 if ($result > 0) {
493 // Define output language
494 $outputlangs = $langs;
495 $newlang = '';
496 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
497 $newlang = GETPOST('lang_id', 'aZ09');
498 }
499 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
500 $newlang = $object->thirdparty->default_lang;
501 }
502 if (!empty($newlang)) {
503 $outputlangs = new Translate("", $conf);
504 $outputlangs->setDefaultLang($newlang);
505 }
506 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
507 if (method_exists($object, 'generateDocument')) {
508 $ret = $object->fetch($object->id); // Reload to get new records
509 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
510 }
511 }
512
513 setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
514
515 if (empty($noback)) {
516 header('Location: '.((empty($backtopage)) ? $_SERVER["PHP_SELF"].'?id='.$object->id : $backtopage));
517 exit;
518 }
519 } else {
520 $error++;
521 setEventMessages($object->error, $object->errors, 'errors');
522 }
523 $action = '';
524}
525
526// Action validate object
527if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
528 if ($object->element == 'inventory' && !empty($include_sub_warehouse)) {
529 // Can happen when the conf INVENTORY_INCLUDE_SUB_WAREHOUSE is set
530 $result = $object->validate($user, false, $include_sub_warehouse);
531 } else {
532 $result = $object->validate($user);
533 }
534
535 if ($result >= 0) {
536 // Define output language
537 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
538 if (method_exists($object, 'generateDocument')) {
539 $outputlangs = $langs;
540 $newlang = '';
541 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
542 $newlang = GETPOST('lang_id', 'aZ09');
543 }
544 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
545 $newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang : "";
546 }
547 if (!empty($newlang)) {
548 $outputlangs = new Translate("", $conf);
549 $outputlangs->setDefaultLang($newlang);
550 }
551
552 $ret = $object->fetch($id); // Reload to get new records
553
554 $model = $object->model_pdf;
555
556 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
557 if ($retgen < 0) {
558 setEventMessages($object->error, $object->errors, 'warnings');
559 }
560 }
561 }
562 } else {
563 $error++;
564 setEventMessages($object->error, $object->errors, 'errors');
565 }
566 $action = '';
567}
568
569// Action close object
570if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
571 $result = $object->cancel($user);
572 if ($result >= 0) {
573 // Define output language
574 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
575 if (method_exists($object, 'generateDocument')) {
576 $outputlangs = $langs;
577 $newlang = '';
578 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
579 $newlang = GETPOST('lang_id', 'aZ09');
580 }
581 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
582 $newlang = $object->thirdparty->default_lang;
583 }
584 if (!empty($newlang)) {
585 $outputlangs = new Translate("", $conf);
586 $outputlangs->setDefaultLang($newlang);
587 }
588 $model = $object->model_pdf;
589 $ret = $object->fetch($id); // Reload to get new records
590
591 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
592 }
593 }
594 } else {
595 $error++;
596 setEventMessages($object->error, $object->errors, 'errors');
597 }
598 $action = '';
599}
600
601// Action setdraft object
602if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
603 $result = $object->setDraft($user);
604 if ($result >= 0) {
605 // Nothing else done
606 } else {
607 $error++;
608 setEventMessages($object->error, $object->errors, 'errors');
609 }
610 $action = '';
611}
612
613// Action reopen object
614if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
615 $result = $object->reopen($user);
616 if ($result >= 0) {
617 // Define output language
618 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
619 if (method_exists($object, 'generateDocument')) {
620 $outputlangs = $langs;
621 $newlang = '';
622 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
623 $newlang = GETPOST('lang_id', 'aZ09');
624 }
625 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
626 $newlang = $object->thirdparty->default_lang;
627 }
628 if (!empty($newlang)) {
629 $outputlangs = new Translate("", $conf);
630 $outputlangs->setDefaultLang($newlang);
631 }
632 $model = $object->model_pdf;
633 $ret = $object->fetch($id); // Reload to get new records
634
635 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
636 }
637 }
638 } else {
639 $error++;
640 setEventMessages($object->error, $object->errors, 'errors');
641 }
642 $action = '';
643}
644
645// Action clone object
646if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
647 // @phan-suppress-next-line PhanPluginBothLiteralsBinaryOp
648 if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
649 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
650 } else {
651 // We clone object to avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object.
652 $objectutil = dol_clone($object, 1);
653 // We used native clone to keep this->db valid and allow to use later all the methods of object.
654 // $objectutil->date = dol_mktime(12, 0, 0, GETPOSTINT('newdatemonth', 'int'), GETPOSTINT('newdateday', 'int'), GETPOSTINT('newdateyear', 'int'));
655 // ...
656 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
657 if (is_object($result) || $result > 0) {
658 $newid = 0;
659 if (is_object($result)) {
660 $newid = $result->id;
661 } else {
662 $newid = $result;
663 }
664
665 if (empty($noback)) {
666 header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object
667 exit;
668 }
669 } else {
670 $error++;
671 setEventMessages($objectutil->error, $objectutil->errors, 'errors');
672 $action = '';
673 }
674 }
675}
$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