-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c383b9
commit 7bf38bd
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/* Copyright (C) 2022-2023 EVARISK <technique@evarisk.com> | ||
* | ||
* 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 | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* \file core/tpl/documents/documents_action.tpl.php | ||
* \ingroup saturne | ||
* \brief Template page for documents action. | ||
*/ | ||
|
||
/** | ||
* The following vars must be defined: | ||
* Global : $conf, $db, $langs, $user, | ||
* Parameters : $action, | ||
* Objects : $object, $document | ||
* Variable : $permissiontoadd, $permissiontodelete | ||
*/ | ||
|
||
// Build doc action. | ||
if (($action == 'builddoc' || GETPOST('forcebuilddoc')) && $permissiontoadd) { | ||
$outputLangs = $langs; | ||
$newLang = ''; | ||
|
||
if ($conf->global->MAIN_MULTILANGS && empty($newLang) && GETPOST('lang_id', 'aZ09')) { | ||
$newLang = GETPOST('lang_id', 'aZ09'); | ||
} | ||
if (!empty($newLang)) { | ||
$outputLangs = new Translate('', $conf); | ||
$outputLangs->setDefaultLang($newLang); | ||
} | ||
|
||
// To be sure vars is defined. | ||
if (empty($hideDetails)){ | ||
$hideDetails = 0; | ||
} | ||
if (empty($hideDesc)) { | ||
$hideDesc = 0; | ||
} | ||
if (empty($hideRef)) { | ||
$hideRef = 0; | ||
} | ||
if (empty($moreParams)) { | ||
$moreParams = []; | ||
} | ||
|
||
if (GETPOST('forcebuilddoc')) { | ||
$model = ''; | ||
$modelList = saturne_get_list_of_models($db, $object->element . 'document'); | ||
if (!empty($modelList)) { | ||
asort($modelList); | ||
$modelList = array_filter($modelList, 'saturne_remove_index'); | ||
if (is_array($modelList)) { | ||
$models = array_keys($modelList); | ||
} | ||
} | ||
} else { | ||
$model = GETPOST('model', 'alpha'); | ||
} | ||
|
||
$moreparams['object'] = $object; | ||
$moreparams['user'] = $user; | ||
|
||
if ($object->status < $object::STATUS_LOCKED) { | ||
$moreparams['specimen'] = 1; | ||
$moreparams['zone'] = 'private'; | ||
} else { | ||
$moreparams['specimen'] = 0; | ||
} | ||
|
||
$result = $document->generateDocument((!empty($models) ? $models[0] : $model), $outputLangs, $hideDetails, $hideDesc, $hideRef, $moreParams); | ||
if ($result <= 0) { | ||
setEventMessages($document->error, $document->errors, 'errors'); | ||
$action = ''; | ||
} else { | ||
setEventMessages($langs->transnoentities('FileGenerated') . ' - ' . $document->last_main_doc, []); | ||
$urlToRedirect = $_SERVER['REQUEST_URI']; | ||
$urlToRedirect = preg_replace('/#builddoc$/', '', $urlToRedirect); | ||
$urlToRedirect = preg_replace('/action=builddoc&?/', '', $urlToRedirect); // To avoid infinite loop. | ||
$urlToRedirect = preg_replace('/forcebuilddoc=1&?/', '', $urlToRedirect); // To avoid infinite loop. | ||
header('Location: ' . $urlToRedirect . '#builddoc'); | ||
exit; | ||
} | ||
} | ||
|
||
// Remove file action. | ||
if ($action == 'remove_file' && $permissiontodelete) { | ||
if (!empty($upload_dir)) { | ||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; | ||
|
||
$fileToDelete = GETPOST('file', 'alpha'); | ||
$file = $upload_dir . '/' . $fileToDelete; | ||
$result = dol_delete_file($file, 0, 0, 0, $object); | ||
if ($result > 0) { | ||
setEventMessages($langs->trans('FileWasRemoved', $fileToDelete), []); | ||
} else { | ||
setEventMessages($langs->trans('ErrorFailToDeleteFile', $fileToDelete), [], 'errors'); | ||
} | ||
|
||
// Make a redirect to avoid to keep the remove_file into the url that create side effects. | ||
$urlToRedirect = $_SERVER['REQUEST_URI']; | ||
$urlToRedirect = preg_replace('/#builddoc$/', '', $urlToRedirect); | ||
$urlToRedirect = preg_replace('/action=remove_file&?/', '', $urlToRedirect); | ||
|
||
header('Location: ' . $urlToRedirect); | ||
exit; | ||
} else { | ||
setEventMessages('BugFoundVarUploaddirnotDefined', [], 'errors'); | ||
} | ||
} |