Commit fd593ea7 authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #6357 - savePdf first functional version

parent fef1a122
......@@ -233,6 +233,7 @@ const ERROR_MULTIPLE_URL_PAGE_MAILTO_DEFINITION = 1406;
const ERROR_UNKNOWN_TOKEN = 1407;
const ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL = 1408;
const ERROR_TOO_MANY_PARAMETER = 1409;
const ERROR_INVALID_SAVE_PDF_FILENAME = 1410;
// Upload
const ERROR_UPLOAD = 1500;
......@@ -1296,6 +1297,7 @@ const COLUMN_PAGEN = 'pagen';
const COLUMN_PAGES = 'pages';
const COLUMN_PDF = 'pdf';
const COLUMN_SAVE_PDF = 'savePdf';
const COLUMN_FILE = 'file';
const COLUMN_ZIP = 'zip';
const COLUMN_MONITOR = 'monitor';
......@@ -1328,6 +1330,7 @@ const FORM_LOG_ACTIVE = 'formLogActive';
const DOWNLOAD_MODE = 'mode';
const DOWNLOAD_MODE_FILE = 'file';
const DOWNLOAD_MODE_PDF = 'pdf';
const DOWNLOAD_MODE_SAVE_PDF = 'save-pdf';
const DOWNLOAD_MODE_EXCEL = 'excel';
const DOWNLOAD_MODE_ZIP = 'zip';
const DOWNLOAD_MODE_THUMBNAIL = 'thumbnail';
......
......@@ -627,21 +627,8 @@ class Save {
throw new UserFormException("Upload failed, no target '" . FE_FILE_DESTINATION . "' specified.", ERROR_NO_TARGET_PATH_FILE_NAME);
}
if (file_exists($pathFileName)) {
if (isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS) {
if (!unlink($pathFileName)) {
throw new UserFormException('Copy upload failed - file exist and unlink() failed: ' . $pathFileName, ERROR_IO_UNLINK);
}
} else {
throw new UserFormException('Copy upload failed - file already exist: ' . $pathFileName, ERROR_IO_FILE_EXIST);
}
}
Support::mkDirParent($pathFileName);
if (!rename($srcFile, $pathFileName)) {
throw new UserFormException("Rename file: '$srcFile' > '$pathFileName'", ERROR_IO_RENAME);
}
$overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS;
Support::copyFile($srcFile, $pathFileName, $overwrite);
$this->splitUpload($formElement, $pathFileName);
......
......@@ -1258,6 +1258,30 @@ class Support {
}
}
/**
* @param $srcFile
* @param $pathFileName
* @param bool $overwrite
* @throws UserFormException
*/
public static function copyFile($srcFile, $pathFileName, $overwrite = false) {
if (file_exists($pathFileName)) {
if ($overwrite) {
if (!unlink($pathFileName)) {
throw new UserFormException('Copy upload failed - file exist and unlink() failed: ' . $pathFileName, ERROR_IO_UNLINK);
}
} else {
throw new UserFormException('Copy upload failed - file already exist: ' . $pathFileName, ERROR_IO_FILE_EXIST);
}
}
Support::mkDirParent($pathFileName);
if (!rename($srcFile, $pathFileName)) {
throw new UserFormException("Rename file: '$srcFile' > '$pathFileName'", ERROR_IO_RENAME);
}
}
/**
*
*/
......
......@@ -405,32 +405,24 @@ class Link {
// 1: 'text'
case '1':
$link = $this->wrapLinkTextOnly($vars, FINAL_CONTENT);
break;
case '11':
$link = $this->wrapLinkTextOnly($vars, FINAL_CONTENT);
break;
// 2: 'url'
case '2':
$link = $this->wrapLinkTextOnly($vars, FINAL_HREF);
break;
case '12':
$link = $this->wrapLinkTextOnly($vars, FINAL_HREF);
break;
// 3: <a href=url ...>url</a>
case '3':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_HREF]);
break;
case '13':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_HREF]);
break;
// 4: <a href=url ...>Text</a>
case '4':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_CONTENT]);
break;
case '14':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_CONTENT]);
break;
......@@ -505,7 +497,7 @@ class Link {
* @throws UserFormException
* @throws UserReportException
*/
private function fillParameter($str, array &$tokenGiven) {
public function fillParameter($str, array &$tokenGiven) {
// Define all possible vars: no more isset().
$vars = $this->initVars();
......@@ -794,6 +786,7 @@ class Link {
// Do some checks.
switch ($mode) {
case DOWNLOAD_MODE_PDF:
case DOWNLOAD_MODE_SAVE_PDF:
case DOWNLOAD_MODE_ZIP:
case DOWNLOAD_MODE_EXCEL:
break;
......
......@@ -755,6 +755,26 @@ class Report {
$content .= $this->link->renderLink($linkValue);
break;
case COLUMN_SAVE_PDF:
$tokenGiven = [];
$vars = $this->link->fillParameter($columnValue, $tokenGiven);
$vars[DOWNLOAD_MODE] = DOWNLOAD_MODE_PDF;
$vars[SIP_DOWNLOAD_PARAMETER] = implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]);
$download = new Download();
// Save file with specified export filename
$pathFileName = $vars[DOWNLOAD_EXPORT_FILENAME];
$sanitizedFileName = Sanitize::safeFilename($pathFileName, false, true);
if ($pathFileName !== $sanitizedFileName) {
throw new UserReportException("The provided filename '$pathFileName' does not meet sanitize criteria. Use '$sanitizedFileName' instead.", ERROR_INVALID_SAVE_PDF_FILENAME);
} elseif(substr($pathFileName, 0, strlen("fileadmin/")) !== "fileadmin/") {
throw new UserReportException( "savePdf filenames need to be in the fileadmin/ directory for security reasons.", ERROR_INVALID_SAVE_PDF_FILENAME);
} else {
$file = $download->process($vars, OUTPUT_MODE_FILE);
Support::copyFile($file, $pathFileName, true);
}
break;
case COLUMN_THUMBNAIL:
if ($this->thumbnail == null) {
$this->thumbnail = new Thumbnail();
......@@ -1189,6 +1209,7 @@ class Report {
}
$columNameToMode = [COLUMN_PDF => DOWNLOAD_MODE_PDF,
COLUMN_SAVE_PDF => DOWNLOAD_MODE_PDF,
COLUMN_FILE => DOWNLOAD_MODE_FILE,
COLUMN_ZIP => DOWNLOAD_MODE_ZIP,
COLUMN_EXCEL => DOWNLOAD_MODE_EXCEL];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment