dolibarr/htdocs/core/actions_addupdatedelete.inc.php

521 lines
18 KiB
PHP
Raw Normal View History

2017-10-24 17:30:05 +02:00
<?php
/* Copyright (C) 2017-2019 Laurent Destailleur <eldy@users.sourceforge.net>
2017-10-24 17:30:05 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
2017-10-24 17:30:05 +02:00
*/
/**
* \file htdocs/core/actions_addupdatedelete.inc.php
2019-10-16 01:36:07 +02:00
* \brief Code for common actions cancel / add / update / update_extras / delete / deleteline / validate / cancel / reopen / clone
2017-10-24 17:30:05 +02:00
*/
// $action or $cancel must be defined
// $object must be defined
// $permissiontoadd must be defined
// $permissiontodelete must be defined
2022-02-08 16:01:18 +01:00
// $backurlforlist must be defined
2017-10-24 17:30:05 +02:00
// $backtopage may be defined
2022-02-08 15:54:31 +01:00
// $noback may be defined
// $triggermodname may be defined
2017-10-24 17:30:05 +02:00
$hidedetails = isset($hidedetails) ? $hidedetails : '';
$hidedesc = isset($hidedesc) ? $hidedesc : '';
$hideref = isset($hideref) ? $hideref : '';
2021-02-23 22:03:23 +01:00
if (!empty($permissionedit) && empty($permissiontoadd)) {
$permissiontoadd = $permissionedit; // For backward compatibility
}
2019-11-05 19:41:30 +01:00
2021-02-23 22:03:23 +01:00
if ($cancel) {
2021-08-29 19:36:11 +02:00
/*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
2021-02-23 22:03:23 +01:00
if (!empty($backtopageforcancel)) {
2020-01-08 17:56:02 +01:00
header("Location: ".$backtopageforcancel);
exit;
2021-02-23 22:03:23 +01:00
} elseif (!empty($backtopage)) {
2017-10-24 17:30:05 +02:00
header("Location: ".$backtopage);
exit;
}
$action = '';
2017-10-24 17:30:05 +02:00
}
2019-12-08 23:45:06 +01:00
2017-10-24 17:30:05 +02:00
// Action to add record
2021-02-23 22:03:23 +01:00
if ($action == 'add' && !empty($permissiontoadd)) {
foreach ($object->fields as $key => $val) {
if ($object->fields[$key]['type'] == 'duration') {
2021-02-23 22:03:23 +01:00
if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') {
continue; // The field was not submited to be saved
2021-02-23 22:03:23 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if (!GETPOSTISSET($key)) {
continue; // The field was not submited to be saved
2021-02-23 22:03:23 +01:00
}
}
// Ignore special fields
2021-02-23 22:03:23 +01:00
if (in_array($key, array('rowid', 'entity', 'import_key'))) {
continue;
}
2020-12-14 20:40:47 +01:00
if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
2021-02-23 22:03:23 +01:00
if (!in_array(abs($val['visible']), array(1, 3))) {
continue; // Only 1 and 3 that are case to create
}
2020-12-14 20:40:47 +01:00
}
2017-10-24 17:30:05 +02:00
2017-12-13 13:19:15 +01:00
// Set value to insert
if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
2020-09-18 01:29:17 +02:00
$value = GETPOST($key, 'restricthtml');
} elseif ($object->fields[$key]['type'] == 'date') {
$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
} elseif ($object->fields[$key]['type'] == 'datetime') {
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
} elseif ($object->fields[$key]['type'] == 'duration') {
$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
2020-09-18 01:29:17 +02:00
$value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
} elseif ($object->fields[$key]['type'] == 'boolean') {
2020-12-14 20:40:47 +01:00
$value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0);
} elseif ($object->fields[$key]['type'] == 'reference') {
$tmparraykey = array_keys($object->param_list);
$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
} else {
2021-08-04 11:25:23 +02:00
if ($key == 'lang') {
$value = GETPOST($key, 'aZ09') ?GETPOST($key, 'aZ09') : "";
2021-08-04 11:25:23 +02:00
} else {
$value = GETPOST($key, 'alphanohtml');
}
}
2021-02-23 22:03:23 +01:00
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
$value = ''; // This is an implicit foreign key field
}
if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
$value = ''; // This is an explicit foreign key field
}
2019-11-22 12:40:17 +01:00
//var_dump($key.' '.$value.' '.$object->fields[$key]['type']);
$object->$key = $value;
2022-05-18 12:31:09 +02:00
if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && isset($val['default']) && $val['default'] == '(PROV)') {
$object->$key = '(PROV)';
2019-03-12 19:20:01 +01:00
}
2022-05-18 12:31:09 +02:00
if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && !isset($val['default'])) {
2017-10-24 17:30:05 +02:00
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
2017-10-24 17:30:05 +02:00
}
// Validation of fields values
2021-11-01 13:32:19 +01:00
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
if (!$object->validateField($object->fields, $key, $value)) {
$error++;
}
}
}
2017-10-24 17:30:05 +02:00
}
// Fill array 'array_options' with data from add form
if (!$error) {
$ret = $extrafields->setOptionalsFromPost(null, $object, '', 1);
2021-02-23 22:03:23 +01:00
if ($ret < 0) {
$error++;
}
}
2021-02-23 22:03:23 +01:00
if (!$error) {
$result = $object->create($user);
2021-02-23 22:03:23 +01:00
if ($result > 0) {
// Creation OK
2022-06-09 22:41:59 +02:00
if (isModEnabled('categorie') && method_exists($object, 'setCategories')) {
$categories = GETPOST('categories', 'array:int');
$object->setCategories($categories);
}
$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
2022-02-08 15:54:31 +01:00
2022-06-14 10:41:32 +02:00
if (empty($noback)) {
2022-02-08 15:54:31 +01:00
header("Location: " . $urltogo);
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2017-10-24 17:30:05 +02:00
// Creation KO
2021-02-23 22:03:23 +01:00
if (!empty($object->errors)) {
setEventMessages(null, $object->errors, 'errors');
} else {
setEventMessages($object->error, null, 'errors');
}
$action = 'create';
2017-10-24 17:30:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
$action = 'create';
2017-10-24 17:30:05 +02:00
}
}
// Action to update record
2021-02-23 22:03:23 +01:00
if ($action == 'update' && !empty($permissiontoadd)) {
2022-06-16 11:37:28 +02:00
foreach ($object->fields as $key => $val) {
// Check if field was submited to be edited
if ($object->fields[$key]['type'] == 'duration') {
if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) {
continue; // The field was not submited to be saved
}
} elseif ($object->fields[$key]['type'] == 'boolean') {
if (!GETPOSTISSET($key)) {
$object->$key = 0; // use 0 instead null if the field is defined as not null
continue;
}
} else {
if (!GETPOSTISSET($key)) {
continue; // The field was not submited to be saved
}
}
2022-06-16 11:37:28 +02:00
// Ignore special fields
if (in_array($key, array('rowid', 'entity', 'import_key'))) {
2021-02-23 22:03:23 +01:00
continue;
}
2022-06-16 11:37:28 +02:00
if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
if (!in_array(abs($val['visible']), array(1, 3, 4))) {
continue; // Only 1 and 3 and 4, that are cases to update
}
2020-12-14 20:40:47 +01:00
}
2022-06-16 11:37:28 +02:00
// Set value to update
if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) {
$tmparray = explode(':', $object->fields[$key]['type']);
if (!empty($tmparray[1])) {
$value = GETPOST($key, $tmparray[1]);
} else {
$value = GETPOST($key, 'restricthtml');
}
} elseif ($object->fields[$key]['type'] == 'date') {
$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
} elseif ($object->fields[$key]['type'] == 'datetime') {
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
} elseif ($object->fields[$key]['type'] == 'duration') {
if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') {
$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
} else {
$value = '';
}
} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
$value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
} elseif ($object->fields[$key]['type'] == 'boolean') {
$value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
} elseif ($object->fields[$key]['type'] == 'reference') {
$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
2018-03-09 14:25:37 +01:00
} else {
2022-06-16 11:37:28 +02:00
if ($key == 'lang') {
$value = GETPOST($key, 'aZ09');
} else {
$value = GETPOST($key, 'alphanohtml');
}
2018-03-09 14:25:37 +01:00
}
2022-06-16 11:37:28 +02:00
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
$value = ''; // This is an implicit foreign key field
2021-02-23 22:03:23 +01:00
}
2022-06-16 11:37:28 +02:00
if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
$value = ''; // This is an explicit foreign key field
2021-02-23 22:03:23 +01:00
}
2022-06-16 11:37:28 +02:00
$object->$key = $value;
if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
}
2022-06-16 11:37:28 +02:00
// Validation of fields values
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
if (!$object->validateField($object->fields, $key, $value)) {
$error++;
}
}
}
2022-06-16 11:37:28 +02:00
if (isModEnabled('categorie')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}
2017-10-24 17:30:05 +02:00
}
// Fill array 'array_options' with data from add form
2022-06-16 11:37:28 +02:00
if (!$error) {
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
if ($ret < 0) {
$error++;
}
}
2022-06-16 11:37:28 +02:00
if (!$error) {
$result = $object->update($user);
if ($result > 0) {
$action = 'view';
$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
if ($urltogo && !$noback) {
header("Location: " . $urltogo);
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2017-10-24 17:30:05 +02:00
// Creation KO
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit';
2017-10-24 17:30:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
$action = 'edit';
2017-10-24 17:30:05 +02:00
}
}
// Action to update one extrafield
2021-02-23 22:03:23 +01:00
if ($action == "update_extras" && !empty($permissiontoadd)) {
$object->fetch(GETPOST('id', 'int'));
2019-01-03 14:18:02 +01:00
$attributekey = GETPOST('attribute', 'alpha');
$attributekeylong = 'options_'.$attributekey;
if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
// This is properties of a date
$object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
//var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
} else {
2020-07-30 14:57:33 +02:00
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
}
$result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
2021-02-23 22:03:23 +01:00
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
$action = 'view';
2020-05-21 15:05:19 +02:00
} else {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit_extras';
}
}
2017-10-24 17:30:05 +02:00
// Action to delete
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
if (!($object->id > 0)) {
dol_print_error('', 'Error, object must be fetched before being deleted');
exit;
}
2019-01-03 14:18:02 +01:00
$result = $object->delete($user);
2021-10-06 12:55:07 +02:00
2021-02-23 22:03:23 +01:00
if ($result > 0) {
2017-10-24 17:30:05 +02:00
// Delete OK
setEventMessages("RecordDeleted", null, 'mesgs');
2022-06-14 10:41:32 +02:00
if (empty($noback)) {
2022-02-08 15:54:31 +01:00
header("Location: " . $backurlforlist);
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2021-02-23 22:03:23 +01:00
if (!empty($object->errors)) {
setEventMessages(null, $object->errors, 'errors');
} else {
setEventMessages($object->error, null, 'errors');
}
2017-10-24 17:30:05 +02:00
}
$action = '';
2017-10-24 17:30:05 +02:00
}
2018-06-19 08:51:25 +02:00
2019-06-03 20:46:11 +02:00
// Remove a line
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) {
if (method_exists($object, 'deleteline')) {
$result = $object->deleteline($user, $lineid); // For backward compatibility
} else {
$result = $object->deleteLine($user, $lineid);
}
2021-02-23 22:03:23 +01:00
if ($result > 0) {
2019-06-03 20:46:11 +02:00
// Define output language
$outputlangs = $langs;
$newlang = '';
2021-02-23 22:03:23 +01:00
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
2019-06-03 20:46:11 +02:00
$newlang = GETPOST('lang_id', 'aZ09');
}
2021-02-23 22:03:23 +01:00
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($object->thirdparty)) {
2019-06-03 20:46:11 +02:00
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang)) {
2019-06-03 20:46:11 +02:00
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
if (method_exists($object, 'generateDocument')) {
$ret = $object->fetch($object->id); // Reload to get new records
2020-09-10 01:49:09 +02:00
$object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
2019-06-03 20:46:11 +02:00
}
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
2022-06-14 10:41:32 +02:00
if (empty($noback)) {
2022-02-08 15:54:31 +01:00
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2019-06-03 20:46:11 +02:00
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
2019-06-03 20:46:11 +02:00
}
2019-10-16 01:36:07 +02:00
// Action validate object
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
2019-10-16 02:05:23 +02:00
$result = $object->validate($user);
2021-02-23 22:03:23 +01:00
if ($result >= 0) {
2019-10-16 01:36:07 +02:00
// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2020-08-05 12:25:26 +02:00
if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs;
$newlang = '';
if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
2021-02-23 22:03:23 +01:00
$newlang = GETPOST('lang_id', 'aZ09');
}
if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
2021-02-23 22:03:23 +01:00
$newlang = $object->thirdparty->default_lang;
}
2020-08-05 12:25:26 +02:00
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
2020-12-14 20:40:47 +01:00
2020-08-05 12:25:26 +02:00
$ret = $object->fetch($id); // Reload to get new records
2019-10-16 01:36:07 +02:00
2020-12-14 20:40:47 +01:00
$model = $object->model_pdf;
$retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($retgen < 0) {
setEventMessages($object->error, $object->errors, 'warnings');
}
2020-08-05 12:25:26 +02:00
}
2019-10-16 01:36:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2019-10-16 01:36:07 +02:00
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
2019-10-16 01:36:07 +02:00
}
// Action close object
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
2019-10-16 01:36:07 +02:00
$result = $object->cancel($user);
2021-02-23 22:03:23 +01:00
if ($result >= 0) {
2019-10-16 01:36:07 +02:00
// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs;
$newlang = '';
2021-02-23 22:03:23 +01:00
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
}
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
2020-09-10 01:49:09 +02:00
$model = $object->model_pdf;
$ret = $object->fetch($id); // Reload to get new records
2019-10-16 01:36:07 +02:00
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
2019-10-16 01:36:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2019-10-16 01:36:07 +02:00
setEventMessages($object->error, $object->errors, 'errors');
2019-10-16 18:35:15 +02:00
}
$action = '';
2019-10-16 18:35:15 +02:00
}
// Action setdraft object
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
2019-10-16 18:35:15 +02:00
$result = $object->setDraft($user);
2021-02-23 22:03:23 +01:00
if ($result >= 0) {
2019-10-16 18:35:15 +02:00
// Nothing else done
2020-05-21 15:05:19 +02:00
} else {
$error++;
2019-10-16 18:35:15 +02:00
setEventMessages($object->error, $object->errors, 'errors');
2019-10-16 01:36:07 +02:00
}
$action = '';
2019-10-16 01:36:07 +02:00
}
// Action reopen object
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
2019-10-16 01:36:07 +02:00
$result = $object->reopen($user);
2021-02-23 22:03:23 +01:00
if ($result >= 0) {
2019-10-16 01:36:07 +02:00
// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs;
$newlang = '';
2021-02-23 22:03:23 +01:00
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
}
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
2020-09-10 01:49:09 +02:00
$model = $object->model_pdf;
$ret = $object->fetch($id); // Reload to get new records
2019-10-16 01:36:07 +02:00
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
2019-10-16 01:36:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
2019-10-16 01:36:07 +02:00
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
2019-10-16 01:36:07 +02:00
}
2019-06-03 20:46:11 +02:00
2018-06-19 08:51:25 +02:00
// Action clone object
2021-02-23 22:03:23 +01:00
if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
2018-06-19 08:51:25 +02:00
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
2020-05-21 15:05:19 +02:00
} else {
$objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
//$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));
// ...
$result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
2021-02-23 22:03:23 +01:00
if (is_object($result) || $result > 0) {
$newid = 0;
2021-02-23 22:03:23 +01:00
if (is_object($result)) {
$newid = $result->id;
} else {
$newid = $result;
}
2022-06-14 10:41:32 +02:00
if (empty($noback)) {
2022-02-08 15:54:31 +01:00
header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$error++;
setEventMessages($objectutil->error, $objectutil->errors, 'errors');
$action = '';
2018-06-19 08:51:25 +02:00
}
}
}