mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°3785 - Use DownloadPage to download documents
This commit is contained in:
@@ -35,7 +35,7 @@ try
|
||||
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
|
||||
$oPage = new AjaxPage("");
|
||||
$oPage = new DownloadPage("");
|
||||
|
||||
$operation = utils::ReadParam('operation', '');
|
||||
$sClass = utils::ReadParam('class', 'MissingAjaxParam', false, 'class');
|
||||
@@ -88,10 +88,8 @@ try
|
||||
|
||||
case 'dict':
|
||||
$sSignature = Utils::ReadParam('s', ''); // Sanitization prevents / and ..
|
||||
$oPage = new AjaxPage(""); // New page to cleanup the no_cache done above
|
||||
$oPage->SetContentType('text/javascript');
|
||||
$oPage->add_header('Cache-control: public, max-age=86400'); // Cache for 24 hours
|
||||
$oPage->add_header("Pragma: cache"); // Reset the value set .... where ?
|
||||
$oPage->set_cache(86400); // Cache for 24 hours
|
||||
|
||||
// X-Frame http header : set in page constructor, but we need to allow frame integration for this specific page
|
||||
// so we're resetting its value ! (see N°3416)
|
||||
|
||||
@@ -1943,12 +1943,12 @@ EOF
|
||||
break;
|
||||
|
||||
case 'xlsx_download':
|
||||
$oPage = new DownloadPage();
|
||||
$oPage = new DownloadPage('');
|
||||
$sToken = utils::ReadParam('token', '', false, 'raw_data');
|
||||
$oPage->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
$oPage->SetContentDisposition('attachment', 'export.xlsx');
|
||||
$sFileContent = ExcelExporter::GetExcelFileFromToken($sToken);
|
||||
$oPage->SetContent($sFileContent);
|
||||
$oPage->add($sFileContent);
|
||||
ExcelExporter::CleanupFromToken($sToken);
|
||||
break;
|
||||
|
||||
@@ -2331,10 +2331,10 @@ EOF
|
||||
if (substr($sMimeType, 0, 5) == 'text/') {
|
||||
$sMimeType .= ';charset='.strtolower($oExporter->GetCharacterSet());
|
||||
}
|
||||
$oPage = new DownloadPage();
|
||||
$oPage = new DownloadPage('');
|
||||
$oPage->SetContentType($sMimeType);
|
||||
$oPage->SetContentDisposition('attachment', $oExporter->GetDownloadFileName());
|
||||
$oPage->SetContent(file_get_contents($oExporter->GetTmpFilePath()));
|
||||
$oPage->add(file_get_contents($oExporter->GetTmpFilePath()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
@@ -293,14 +292,13 @@ EOF
|
||||
* @inheritDoc
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add($sHtml): ?iUIBlock
|
||||
public function add($sHtml)
|
||||
{
|
||||
if (($this->m_oTabs->GetCurrentTabContainer() != '') && ($this->m_oTabs->GetCurrentTab() != '')) {
|
||||
$this->m_oTabs->AddToTab($this->m_oTabs->GetCurrentTabContainer(), $this->m_oTabs->GetCurrentTab(), $sHtml);
|
||||
} else {
|
||||
return parent::add($sHtml);
|
||||
parent::add($sHtml);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
use \Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
/**
|
||||
* CLI page
|
||||
* The page adds the content-type text/XML and the encoding into the headers
|
||||
@@ -39,20 +37,17 @@ class CLIPage implements Page
|
||||
|
||||
public function output()
|
||||
{
|
||||
if (class_exists('DBSearch'))
|
||||
{
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
if (class_exists('ExecutionKPI'))
|
||||
{
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
if (class_exists('ExecutionKPI')) {
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
}
|
||||
|
||||
public function add($sText): ?iUIBlock
|
||||
public function add($sText)
|
||||
{
|
||||
echo $sText;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function p($sText)
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
/**
|
||||
* Simple web page with no includes or fancy formatting, useful to generateXML documents
|
||||
* The page adds the content-type text/XML and the encoding into the headers
|
||||
@@ -56,26 +54,24 @@ class CSVPage extends WebPage
|
||||
{
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
if (class_exists('ExecutionKPI'))
|
||||
{
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
if (class_exists('ExecutionKPI')) {
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
}
|
||||
|
||||
public function small_p($sText)
|
||||
{
|
||||
}
|
||||
|
||||
public function add($sText): ?iUIBlock
|
||||
public function add($sText)
|
||||
{
|
||||
$this->s_content .= $sText;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function p($sText)
|
||||
{
|
||||
$this->s_content .= $sText."\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function add_comment($sText)
|
||||
{
|
||||
|
||||
@@ -5,68 +5,37 @@
|
||||
*/
|
||||
|
||||
|
||||
class DownloadPage
|
||||
class DownloadPage extends AjaxPage
|
||||
{
|
||||
/** @var string */
|
||||
protected $sContentType;
|
||||
/** @var string */
|
||||
protected $sContentDisposition;
|
||||
/**@var string */
|
||||
protected $sContent;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sContentFileName;
|
||||
|
||||
/**
|
||||
* @param string $sContentType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContentType(string $sContentType)
|
||||
public function __construct($s_title)
|
||||
{
|
||||
$this->sContentType = $sContentType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content-disposition (mime type) for the page's content
|
||||
*
|
||||
* @param $sDisposition string The disposition: 'inline' or 'attachment'
|
||||
* @param $sFileName string The original name of the file
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContentDisposition($sDisposition, $sFileName)
|
||||
{
|
||||
$this->sContentDisposition = $sDisposition;
|
||||
$this->sContentFileName = $sFileName;
|
||||
|
||||
return $this;
|
||||
parent::__construct($s_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContent(string $sContent)
|
||||
public function add($sContent)
|
||||
{
|
||||
$this->sContent = $sContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
if (!empty($this->sContentType)) {
|
||||
header('Content-type: '.$this->sContentType);
|
||||
$this->add_header('Content-type: '.$this->sContentType);
|
||||
}
|
||||
if (!empty($this->sContentDisposition)) {
|
||||
header('Content-Disposition: '.$this->sContentDisposition.'; filename="'.$this->sContentFileName.'"');
|
||||
$this->add_header('Content-Disposition: '.$this->sContentDisposition.'; filename="'.$this->sContentFileName.'"');
|
||||
}
|
||||
foreach ($this->a_headers as $s_header) {
|
||||
header($s_header);
|
||||
}
|
||||
|
||||
echo $this->sContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
|
||||
/**
|
||||
* Generic interface common to CLI and Web pages
|
||||
@@ -26,7 +24,7 @@ interface Page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($sText): ?iUIBlock;
|
||||
public function add($sText);
|
||||
|
||||
/**
|
||||
* Add a paragraph to the body of the page
|
||||
|
||||
@@ -202,9 +202,9 @@ class WebPage implements Page
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function add($s_html): ?iUIBlock
|
||||
public function add($s_html)
|
||||
{
|
||||
return $this->oContentLayout->AddHtml($s_html);
|
||||
$this->oContentLayout->AddHtml($s_html);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1172,7 +1172,7 @@ class WebPage implements Page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function SetContentType($sContentType)
|
||||
public function SetContentType(string $sContentType)
|
||||
{
|
||||
$this->sContentType = $sContentType;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
/**
|
||||
* Class XMLPage
|
||||
*
|
||||
@@ -64,22 +62,17 @@ class XMLPage extends WebPage
|
||||
}
|
||||
echo $this->s_content;
|
||||
}
|
||||
if (class_exists('DBSearch'))
|
||||
{
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public function add($sText): ?iUIBlock
|
||||
public function add($sText)
|
||||
{
|
||||
if (!$this->m_bPassThrough)
|
||||
{
|
||||
if (!$this->m_bPassThrough) {
|
||||
parent::add($sText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->m_bHeaderSent)
|
||||
{
|
||||
} else {
|
||||
if ($this->m_bHeaderSent) {
|
||||
echo $sText;
|
||||
}
|
||||
else
|
||||
@@ -97,7 +90,6 @@ class XMLPage extends WebPage
|
||||
$this->m_bHeaderSent = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function small_p($sText)
|
||||
|
||||
@@ -1092,14 +1092,13 @@ EOF
|
||||
* @inheritDoc
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add($sHtml): ?iUIBlock
|
||||
public function add($sHtml)
|
||||
{
|
||||
if (($this->m_oTabs->GetCurrentTabContainer() != '') && ($this->m_oTabs->GetCurrentTab() != '')) {
|
||||
$this->m_oTabs->AddToCurrentTab($sHtml);
|
||||
} else {
|
||||
return parent::add($sHtml);
|
||||
parent::add($sHtml);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function AddUiBlock(?iUIBlock $oBlock): ?iUIBlock
|
||||
|
||||
Reference in New Issue
Block a user