Skip to content

Commit

Permalink
Fixed issue #9409 : PDF export by user contains html tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Aestu committed Dec 16, 2014
1 parent 8090188 commit 4c18d76
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion application/controllers/PrintanswersController.php
Expand Up @@ -174,7 +174,7 @@ function actionView($surveyid,$printableexport=FALSE)

$oPDF = new pdf();
$sDefaultHeaderString = $sSurveyName." (".gT("ID",'unescaped').":".$iSurveyID.")";
$oPDF->initAnswerPDF($aPdfLanguageSettings, Yii::app()->getConfig('sitename'), $sLanguage, $sSurveyName, $sDefaultHeaderString);
$oPDF->initAnswerPDF($aSurveyInfo, $aPdfLanguageSettings, Yii::app()->getConfig('sitename'), $sSurveyName, $sDefaultHeaderString);

LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page
// Since all data are loaded, and don't need JavaScript, pretend all from Group 1
Expand Down
65 changes: 46 additions & 19 deletions application/libraries/admin/pdf.php
Expand Up @@ -200,15 +200,23 @@ class pdf extends TCPDF {
* @var int
* @access private
*/
private $ibaseAnswerFontSize = 12;
private $_ibaseAnswerFontSize = 12;

/**
* Cell height for answer PDF export
*
* @var int
* @access private
*/
private $iCellHeight = 6;
private $_iCellHeight = 6;

/**
* Survey Information (preventing from passing to methods every time)
*
* @var array
* @access private
*/
private $_aSurveyInfo = array();

/**
* Set _config for pdf
Expand Down Expand Up @@ -621,23 +629,24 @@ function delete_html($text)
/**
*
* Create Answer PDF document, set metadata and set title
* @param $aSurveyInfo - Survey Information (preventing from passing to methods every time)
* @param $aPdfLanguageSettings - Pdf language settings
* @param $sSiteName - LimeSurvey site name (header and metadata)
* @param $sLanguage - Survey language
* @param $sSurveyName - Survey name (header, metadata and title),
* @param $sDefaultHeaderString - TCPDF header string
* @return unknown_type
*/
function initAnswerPDF($aPdfLanguageSettings, $sSiteName, $sLanguage, $sSurveyName, $sDefaultHeaderString)
function initAnswerPDF($aSurveyInfo, $aPdfLanguageSettings, $sSiteName, $sSurveyName, $sDefaultHeaderString)
{
$this->_aSurveyInfo = $aSurveyInfo;
$this->SetAuthor($sSiteName);
$this->SetTitle($sSurveyName);
$this->SetSubject($sSurveyName);
$this->SetKeywords($sSurveyName);

$this->SetFont($aPdfLanguageSettings['pdffont']);
$this->ibaseAnswerFontSize = $aPdfLanguageSettings['pdffontsize'];
$this->iCellHeight = ceil($this->ibaseAnswerFontSize / 2);
$this->_ibaseAnswerFontSize = $aPdfLanguageSettings['pdffontsize'];
$this->_iCellHeight = ceil($this->_ibaseAnswerFontSize / 2);
$this->setLanguageArray($aPdfLanguageSettings['lg']);

$this->addHeader($aPdfLanguageSettings, $sSiteName, $sDefaultHeaderString);
Expand All @@ -647,7 +656,7 @@ function initAnswerPDF($aPdfLanguageSettings, $sSiteName, $sLanguage, $sSurveyNa
if(!empty($sSurveyName))
{
$this->ln(1);
$this->SetFontSize($this->ibaseAnswerFontSize + 6);
$this->SetFontSize($this->_ibaseAnswerFontSize + 6);
$this->MultiCell('','',$sSurveyName,'','C',0);
$this->ln(6);
}
Expand All @@ -672,8 +681,8 @@ function addHeader($aPdfLanguageSettings, $sSiteName, $sDefaultHeaderString)
if ($sHeaderString == '') $sHeaderString = $sDefaultHeaderString;

$this->SetHeaderData($sLogoFileName, Yii::app()->getConfig('pdflogowidth'), $sHeaderTitle, $sHeaderString);
$this->SetHeaderFont(Array($aPdfLanguageSettings['pdffont'], '', $this->ibaseAnswerFontSize - 2));
$this->SetFooterFont(Array($aPdfLanguageSettings['pdffont'], '', $this->ibaseAnswerFontSize - 2));
$this->SetHeaderFont(Array($aPdfLanguageSettings['pdffont'], '', $this->_ibaseAnswerFontSize - 2));
$this->SetFooterFont(Array($aPdfLanguageSettings['pdffont'], '', $this->_ibaseAnswerFontSize - 2));
}
}

Expand All @@ -686,11 +695,15 @@ function addHeader($aPdfLanguageSettings, $sSiteName, $sDefaultHeaderString)
*/
function addGidAnswer($sFname, $bAllowBreakPage=false)
{
$sAnswerHTML = html_entity_decode(stripJavaScript($sFname,ENT_COMPAT));
$sData['thissurvey']=$aSurveyInfo;
$sAnswerHTML = templatereplace($sAnswerHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);

$startPage = $this->getPage();
$this->startTransaction();
$this->ln(6);
$this->SetFontSize($this->ibaseAnswerFontSize + 2);
$this->MultiCell('', $this->iCellHeight, html_entity_decode($sFname,ENT_COMPAT), 0, 'L', 0, 1, '', '', true);
$this->SetFontSize($this->_ibaseAnswerFontSize + 2);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sAnswerHTML, 0, 1, false, true, 'L');
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
Expand All @@ -713,11 +726,15 @@ function addGidAnswer($sFname, $bAllowBreakPage=false)
*/
function addQidAnswer($sFname, $bAllowBreakPage=false)
{
$sAnswerHTML = html_entity_decode(stripJavaScript($sFname,ENT_COMPAT));
$sData['thissurvey']=$aSurveyInfo;
$sAnswerHTML = templatereplace($sAnswerHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);

$startPage = $this->getPage();
$this->startTransaction();
$this->ln(6);
$this->SetFontSize($this->ibaseAnswerFontSize);
$this->MultiCell('', $this->iCellHeight, html_entity_decode($sFname,ENT_COMPAT), 0, 'L', 0, 1, '', '', true);
$this->SetFontSize($this->_ibaseAnswerFontSize);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sAnswerHTML, 0, 1, false, true, 'L');
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
Expand All @@ -741,11 +758,16 @@ function addQidAnswer($sFname, $bAllowBreakPage=false)
*/
function addSubmitDate($sFname, $sFieldName, $bAllowBreakPage=false)
{
$sAnswerHTML = html_entity_decode(stripJavaScript($sFname[0]." ".$sFname[1]." ".$sFieldName,ENT_COMPAT));
$sData['thissurvey']=$aSurveyInfo;
$sAnswerHTML = templatereplace($sAnswerHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);
$sResponse = html_entity_decode($sFname[2],ENT_COMPAT);

$startPage = $this->getPage();
$this->startTransaction();
$this->SetFontSize($this->ibaseAnswerFontSize);
$this->MultiCell(0, $this->iCellHeight, html_entity_decode($sFname[0]." ".$sFname[1]." ".$sFieldName,ENT_COMPAT), 1, 'L', 1, 1, '', '', true);
$this->MultiCell(0, $this->iCellHeight, html_entity_decode($sFname[2],ENT_COMPAT), 1, 'L', 0, 1, '', '', true);
$this->SetFontSize($this->_ibaseAnswerFontSize);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sAnswerHTML, 1, 1, true, true, 'L');
$this->MultiCell(0, $this->_iCellHeight, $sResponse, 1, 'L', 0, 1, '', '', true);
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
Expand All @@ -768,11 +790,16 @@ function addSubmitDate($sFname, $sFieldName, $bAllowBreakPage=false)
*/
function addAnswer($sFname, $bAllowBreakPage=false)
{
$sAnswerHTML = html_entity_decode(stripJavaScript($sFname[0]." ".$sFname[1],ENT_COMPAT));
$sData['thissurvey']=$aSurveyInfo;
$sAnswerHTML = templatereplace($sAnswerHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);
$sResponse = html_entity_decode($sFname[2],ENT_COMPAT);

$startPage = $this->getPage();
$this->startTransaction();
$this->SetFontSize($this->ibaseAnswerFontSize);
$this->MultiCell(0, $this->iCellHeight, html_entity_decode($sFname[0]." ".$sFname[1],ENT_COMPAT), 1, 'L', 1, 1, '', '', true);
$this->MultiCell(0, $this->iCellHeight, html_entity_decode($sFname[2],ENT_COMPAT), 1, 'L', 0, 1, '', '', true);
$this->SetFontSize($this->_ibaseAnswerFontSize);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sAnswerHTML, 1, 1, true, true, 'L');
$this->MultiCell(0, $this->_iCellHeight, $sResponse, 1, 'L', 0, 1, '', '', true);
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
Expand Down

0 comments on commit 4c18d76

Please sign in to comment.