openstamanager/view.php

121 lines
3.6 KiB
PHP
Raw Normal View History

2019-01-17 16:11:10 +01:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-01-17 16:11:10 +01:00
include_once __DIR__.'/core.php';
$file_id = filter('file_id');
$file = Models\Upload::find($file_id);
if (empty($file)) {
return;
}
$file_content = $file->get_contents();
2019-01-17 16:11:10 +01:00
// Force download of the file
2021-07-07 08:03:25 +02:00
if (get('download') == '1') {
header('Content-Type: application/octet-stream');
2021-07-07 07:57:10 +02:00
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename="'.basename($file->original_name).'"');
echo $file_content;
exit;
}
// Force preview of the file
if (get('preview') == '1') {
if ($file->isImage()) {
$finfo = finfo_open();
$mime_type = finfo_buffer($finfo, $file_content, FILEINFO_MIME_TYPE);
finfo_close($finfo);
header('Content-Type: '.$mime_type);
echo $file_content;
} elseif ($file->isPDF()) {
2024-03-22 15:52:24 +01:00
header('Content-type: application/pdf');
echo $file_content;
}
2024-01-15 15:30:45 +01:00
exit;
2021-07-07 08:03:25 +02:00
}
if ($file->isFatturaElettronica()) {
// Individuazione stylesheet
$default_stylesheet = 'asso-invoice';
2019-01-17 16:11:10 +01:00
2021-07-07 08:03:25 +02:00
$name = basename($file->original_name);
$filename = explode('.', $name)[0];
$pieces = explode('_', $filename);
$stylesheet = $pieces[2];
2019-02-20 16:07:42 +01:00
2021-07-07 08:03:25 +02:00
$stylesheet = base_dir().'/plugins/xml/'.$stylesheet.'.xsl';
$stylesheet = file_exists($stylesheet) ? $stylesheet : base_dir().'/plugins/xml/'.$default_stylesheet.'.xsl';
2019-02-25 13:10:11 +01:00
2021-07-07 08:03:25 +02:00
// XML
$xml = new DOMDocument();
$xml->loadXML($file_content);
2019-01-17 16:11:10 +01:00
2021-07-07 08:03:25 +02:00
// XSL
$xsl = new DOMDocument();
$xsl->load($stylesheet);
2019-02-20 16:07:42 +01:00
2021-07-07 08:03:25 +02:00
// XSLT
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
2019-01-17 16:11:10 +01:00
2021-07-07 08:03:25 +02:00
echo '
<style>
#notifica {
min-width: 860px !important;
}
</style>';
echo $xslt->transformToXML($xml);
} else {
echo '
<style>
body, iframe, img{
border: 0;
margin: 0;
max-width: 100%;
}
iframe{
width:100%;
height:100%;
min-height: 500px;
}
</style>';
2019-01-17 16:11:10 +01:00
2021-07-07 08:03:25 +02:00
if ($file->isImage()) {
2019-01-17 16:11:10 +01:00
echo '
<iframe src="'.base_path().'/view.php?file_id='.$file_id.'&preview=1">
<a src="'.base_path().'/view.php?file_id='.$file_id.'&download=1">'.tr('Il browser non supporta i contenuti iframe: clicca qui per raggiungere il file originale').'</a>
</iframe>';
2021-08-03 14:51:53 +02:00
} elseif ($file->isPDF()) {
echo '
<iframe src="'.base_path().'/view.php?file_id='.$file_id.'&preview=1">
<a src="'.base_path().'/view.php?file_id='.$file_id.'&download=1">'.tr('Il browser non supporta i contenuti iframe: clicca qui per raggiungere il file originale').'</a>
2021-08-03 14:51:53 +02:00
</iframe>';
} else {
2019-01-17 16:11:10 +01:00
echo '
2021-07-07 08:03:25 +02:00
<iframe src="'.base_path().'/view.php?file_id='.$file_id.'&download=1">
<a src="'.base_path().'/view.php?file_id='.$file_id.'&download=1">'.tr('Il browser non supporta i contenuti iframe: clicca qui per raggiungere il file originale').'</a>
</iframe>';
2019-01-17 16:11:10 +01:00
}
}