Skip to content

Commit

Permalink
Fixed issue #9425: Absence of delimeter at the end of a question group
Browse files Browse the repository at this point in the history
  • Loading branch information
Aestu committed Dec 27, 2014
1 parent 255b201 commit c4f083e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 91 deletions.
16 changes: 4 additions & 12 deletions application/controllers/PrintanswersController.php
Expand Up @@ -131,18 +131,14 @@ function actionView($surveyid,$printableexport=FALSE)
{
$sOutput .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
elseif (substr($sFieldname,0,4)=='qid_')
{
$sOutput .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
elseif ($sFieldname=='submitdate')
{
if($sAnonymized != 'Y')
{
$sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]} {$sFieldname}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
}
}
else
elseif (substr($sFieldname,0,4) != 'qid_') // Question text is already in subquestion text, skipping it
{
$sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>".flattenText($fname[2])."</td></tr>";
}
Expand Down Expand Up @@ -201,20 +197,16 @@ function actionView($surveyid,$printableexport=FALSE)
{
$oPDF->addGidAnswer($fname[0]);
}
elseif (substr($sFieldname,0,4)=='qid_')
{
$oPDF->addQidAnswer($fname[0]);
}
elseif ($sFieldname=='submitdate')
{
if($sAnonymized != 'Y')
{
$oPDF->addAnswer($fname);
$oPDF->addAnswer($fname[0]." ".$fname[1], $fname[2]);
}
}
else
elseif (substr($sFieldname,0,4) != 'qid_') // Question text is already in subquestion text, skipping it
{
$oPDF->addAnswer($fname);
$oPDF->addAnswer($fname[0]." ".$fname[1], $fname[2]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/helpers/admin/export/PdfWriter.php
Expand Up @@ -70,7 +70,7 @@ public function outputRecord($headers, $values, FormattingOptions $oOptions)
{
if (isset($values[$question['index']]) && isset($headers[$question['index']]))
{
$this->pdf->addValue($headers[$question['index']], $values[$question['index']]);
$this->pdf->addAnswer($headers[$question['index']], $values[$question['index']], false);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/common_helper.php
Expand Up @@ -5601,16 +5601,16 @@ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorC
continue;
}
if (isset($fname['subquestion']))
$subquestion = "{$fname['subquestion']}";
$subquestion = "[{$fname['subquestion']}]";

if (isset($fname['subquestion1']))
$subquestion = "{$fname['subquestion1']}";
$subquestion = "[{$fname['subquestion1']}]";

if (isset($fname['subquestion2']))
$subquestion .= "[{$fname['subquestion2']}]";

$answer = getExtendedAnswer($iSurveyID,$fname['fieldname'], $idrow[$fname['fieldname']],$oLanguage);
$aResultTable[$fname['fieldname']]=array('',$subquestion,$answer);
$aResultTable[$fname['fieldname']]=array($question,$subquestion,$answer);
}
return $aResultTable;
}
Expand Down
91 changes: 16 additions & 75 deletions application/libraries/admin/pdf.php
Expand Up @@ -743,100 +743,41 @@ function addGidAnswer($sFname, $bAllowBreakPage=false)
}
}

/**
*
* Add QID text to PDF
* @param $sFname - Answer field text
* @param $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addQidAnswer($sFname, $bAllowBreakPage=false)
{
$oPurifier = new CHtmlPurifier();
$sAnswerHTML = html_entity_decode(stripJavaScript($oPurifier->purify($sFname)),ENT_COMPAT);
$sData['thissurvey']=$this->_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->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sAnswerHTML, 0, 1, false, true, 'L');
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
$this->rollbackTransaction(true);
$this->AddPage();
$this->addQidAnswer($sFname,true); // Second param = true avoid an endless loop if a cell is longer than a page
}
else
{
$this->commitTransaction();
}
}

/**
*
* Add answer to PDF
* @param $sFname - Answer field text array
*
* @param $sQuestion - Question field text array
* @param $sResponse - Answer field text array
* @param $bReplaceExpressions - Try to replace LimeSurvey Expressions. This is false when exporting answers PDF from admin GUI
* because we can not interpret expressions so just purify.
* TODO: Find a universal valid method to interpret expressions
* @param $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addAnswer($sFname, $bAllowBreakPage=false)
function addAnswer($sQuestion, $sResponse, $bReplaceExpressions=true, $bAllowBreakPage=false)
{
$oPurifier = new CHtmlPurifier();
$sAnswerHTML = html_entity_decode(stripJavaScript($oPurifier->purify($sFname[0]." ".$sFname[1])),ENT_COMPAT);
$sData['thissurvey']=$this->_aSurveyInfo;
$sAnswerHTML = templatereplace($sAnswerHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);
$sResponse = flattenText($sFname[2], false, true, 'UTF-8', false);

$startPage = $this->getPage();
$this->startTransaction();
$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)
{
$this->rollbackTransaction(true);
$this->AddPage();
$this->addAnswer($sFname,true); // Second param = true avoid an endless loop if a cell is longer than a page
}
else
$sQuestionHTML = str_replace('-oth-','',$sQuestion); // Copied from Writer::stripTagsFull. Really necessary?
$sQuestionHTML = html_entity_decode(stripJavaScript($oPurifier->purify($sQuestionHTML)),ENT_COMPAT);
if ($bReplaceExpressions)
{
$this->commitTransaction();
$sData['thissurvey']=$this->_aSurveyInfo;
$sQuestionHTML = templatereplace($sQuestionHTML, array() , $sData, '', $this->_aSurveyInfo['anonymized']=="Y",NULL, array(), true);
}
}

/**
*
* Add pair (header,value) to PDF
* @param $sHeader - Header
* @param $sValue - Value
* @param $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addValue($sHeader, $sValue, $bAllowBreakPage=false)
{
$oPurifier = new CHtmlPurifier();
// We use this method when exporting answers PDF from admin GUI, we can not interpret expressions so just purify
// TODO: Find a way to interpret expressions in this situation
$sHeaderHTML = str_replace('-oth-','',$sHeader);
$sHeaderHTML = html_entity_decode(stripJavaScript($oPurifier->purify($sHeaderHTML)),ENT_COMPAT);
$sData['thissurvey']=$this->_aSurveyInfo;
$sValueHTML = flattenText($sValue, false, true, 'UTF-8', false);
$sResponse = flattenText($sResponse, false, true, 'UTF-8', false);

$startPage = $this->getPage();
$this->startTransaction();
$this->SetFontSize($this->_ibaseAnswerFontSize);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sHeaderHTML, 1, 1, true, true, 'L');
$this->MultiCell(0, $this->_iCellHeight, $sValueHTML, 1, 'L', 0, 1, '', '', true);
$this->WriteHTMLCell(0, $this->_iCellHeight, $this->getX(), $this->getY(), $sQuestionHTML, 1, 1, true, true, 'L');
$this->MultiCell(0, $this->_iCellHeight, $sResponse, 1, 'L', 0, 1, '', '', true);
$this->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
$this->rollbackTransaction(true);
$this->AddPage();
$this->addValue($sHeader,$sValue,true); // Last param = true avoid an endless loop if a cell is longer than a page
$this->addAnswer($sQuestion,$sResponse,$bReplaceExpressions,true); // "Last param = true" prevents an endless loop if a cell is longer than a page
}
else
{
Expand Down

0 comments on commit c4f083e

Please sign in to comment.