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