Commit 4d06aa7f authored by Aestu's avatar Aestu

Updated feature: Answers export to PDF (user and admin gui)

Dev: Survey user: New header and questions and answers in tables (single answer export)
Dev: Admin user: New header in multiple answers export
Dev: Admin user: New config params in Global config -> Presentation
parent e3a99cd2
......@@ -367,6 +367,12 @@ $config['notsupportlanguages'] = array(
);
$config['pdffontsize'] = 9; //Fontsize for normal text; Surveytitle is +4; grouptitle is +2
$config['pdforientation'] = 'P'; // Set L for Landscape or P for portrait format
$config['pdfshowheader'] = 'N'; // Show header in pdf answer export
$config['pdflogofile'] = 'logo_pdf.png'; // File name of logo for single answer export. Path is template path, i.e. template/default/logo_pdf.png.
// If not found, resulting pdf doesn't have header. A large image implies slower pdf generation.
$config['pdflogowidth'] = '50'; // Logo width
$config['pdfheadertitle'] = ''; // Header title (bold font). If this config param is empty and header is enabled, site name is used
$config['pdfheaderstring'] = ''; // Header string (under title). If this config param is empty and header is enabled, survey name is used
// QueXML-PDF: If set to true, the printable_help attribute will be visible on the exported PDF questionnaires
// If used, the appearance (font size, justification, etc.) may be adjusted by editing td.questionHelpBefore and $helpBeforeBorderBottom of quexml.
......
......@@ -71,7 +71,6 @@ class GlobalSettings extends Survey_Common_Action
'admin/user/sa/adduser'=>'admin/user/sa/index',
'admin/user/sa/setusertemplates'=>'admin/user/sa/index',
'admin/user/setusertemplates'=>'admin/user/sa/index'
);
$refurl= str_replace(array_keys($aReplacements),array_values($aReplacements),$refurl);
Yii::app()->session['refurl'] = htmlspecialchars($refurl); //just to be safe!
......@@ -120,6 +119,18 @@ class GlobalSettings extends Survey_Common_Action
}
Yii::app()->loadHelper('surveytranslator');
$iPDFFontSize = sanitize_int(App()->request->getPost('pdffontsize'));
if ($iPDFFontSize < 1)
{
$iPDFFontSize = 9;
}
$iPDFLogoWigth = sanitize_int(App()->request->getPost('pdflogowidth'));
if ($iPDFLogoWigth < 1)
{
$iPDFLogoWigth = 50;
}
$maxemails = (int)App()->request->getPost('maxemails');
if ($maxemails < 1) {
$maxemails = 1;
......@@ -196,6 +207,11 @@ class GlobalSettings extends Survey_Common_Action
setGlobalSetting('GeoNamesUsername', App()->request->getPost('GeoNamesUsername'));
setGlobalSetting('googleMapsAPIKey', App()->request->getPost('googleMapsAPIKey'));
setGlobalSetting('ipInfoDbAPIKey', App()->request->getPost('ipInfoDbAPIKey'));
setGlobalSetting('pdffontsize', $iPDFFontSize);
setGlobalSetting('pdfshowheader', App()->request->getPost('pdfshowheader'));
setGlobalSetting('pdflogowidth', $iPDFLogoWigth);
setGlobalSetting('pdfheadertitle', App()->request->getPost('pdfheadertitle'));
setGlobalSetting('pdfheaderstring', App()->request->getPost('pdfheaderstring'));
setGlobalSetting('googleanalyticsapikey',App()->request->getPost('googleanalyticsapikey'));
setGlobalSetting('googletranslateapikey',App()->request->getPost('googletranslateapikey'));
setGlobalSetting('force_ssl', App()->request->getPost('force_ssl'));
......
......@@ -11,7 +11,6 @@ class PdfWriter extends Writer
{
parent::init($survey, $sLanguageCode, $oOptions);
$pdforientation=Yii::app()->getConfig('pdforientation');
$this->clang = new limesurvey_lang($sLanguageCode);
if ($oOptions->output=='file')
{
......@@ -25,7 +24,9 @@ class PdfWriter extends Writer
// create new PDF document
$this->pdf = new pdf();
$this->surveyName = $survey->languageSettings['surveyls_title'];
$this->pdf->SetFont($aPdfLanguageSettings['pdffont'], '', $aPdfLanguageSettings['pdffontsize']);
$this->pdf->addHeader($aPdfLanguageSettings, Yii::app()->getConfig('sitename'), $this->surveyName);
$this->pdf->AddPage();
$this->pdf->intopdf("PDF export ".date("Y.m.d-H:i", time()));
$this->pdf->setLanguageArray($aPdfLanguageSettings['lg']);
......@@ -33,7 +34,6 @@ class PdfWriter extends Writer
$this->separator="\t";
$this->rowCounter = 0;
$this->surveyName = $survey->languageSettings['surveyls_title'];
$this->pdf->titleintopdf($this->surveyName, $survey->languageSettings['surveyls_description']);
}
......@@ -43,7 +43,7 @@ class PdfWriter extends Writer
if ($oOptions->answerFormat == 'short')
{
$pdfstring = '';
$this->pdf->titleintopdf($this->clang->gT("Survey response"));
$this->pdf->titleintopdf(gT("Survey response"));
foreach ($values as $value)
{
$pdfstring .= $value.' | ';
......@@ -87,4 +87,4 @@ class PdfWriter extends Writer
}
$this->pdf->Output($filename, $this->pdfDestination);
}
}
\ No newline at end of file
}
......@@ -194,6 +194,22 @@ class pdf extends TCPDF {
*/
private $_config = array();
/**
* Base font size for answer PDF export
*
* @var int
* @access private
*/
private $ibaseAnswerFontSize = 12;
/**
* Cell height for answer PDF export
*
* @var int
* @access private
*/
private $iCellHeight = 6;
/**
* Set _config for pdf
* @access public
......@@ -602,4 +618,171 @@ class pdf extends TCPDF {
$text = str_replace("\t",' ',$text);
return strip_tags($text);
}
}
\ No newline at end of file
/**
*
* Create Answer PDF document, set metadata and set title
* @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)
{
$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->setLanguageArray($aPdfLanguageSettings['lg']);
$this->addHeader($aPdfLanguageSettings, $sSiteName, $sDefaultHeaderString);
$this->AddPage();
$this->SetFillColor(220, 220, 220);
if(!empty($sSurveyName))
{
$this->ln(1);
$this->SetFontSize($this->ibaseAnswerFontSize + 6);
$this->MultiCell('','',$sSurveyName,'','C',0);
$this->ln(6);
}
}
/**
*
* Add header to pdf
* @param $aPdfLanguageSettings - Pdf language settings
* @param $sSiteName - LimeSurvey site name (header and metadata)
* @param $sDefaultHeaderString - TCPDF header string
* @return unknown_type
*/
function addHeader($aPdfLanguageSettings, $sSiteName, $sDefaultHeaderString)
{
$sLogoFileName = Yii::app()->getConfig('pdflogofile');
if (Yii::app()->getConfig('pdfshowheader')=='Y' && file_exists(K_PATH_IMAGES.$sLogoFileName))
{
$sHeaderTitle = Yii::app()->getConfig('pdfheadertitle');
if ($sHeaderTitle == '') $sHeaderTitle = $sSiteName;
$sHeaderString = Yii::app()->getConfig('pdfheaderstring');
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));
}
}
/**
*
* Add GID text to PDF
* @param $sFname - Answer field text
* @param $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addGidAnswer($sFname, $bAllowBreakPage=false)
{
$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->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
$this->rollbackTransaction(true);
$this->AddPage();
$this->addGidAnswer($sFname,true); // Second param = true avoid an endless loop if a cell is longer than a page
}
else
{
$this->commitTransaction();
}
}
/**
*
* 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)
{
$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->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 submit date to PDF
* @param $sFname - Answer field text array
* @param $sSubmitDate - submit date
* @param $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addSubmitDate($sFname, $sFieldName, $bAllowBreakPage=false)
{
$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->ln(2);
if ($this->getPage() != $startPage && !$bAllowBreakPage)
{
$this->rollbackTransaction(true);
$this->AddPage();
$this->addSubmitDate($sFname,$sFieldName,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 $bAllowBreakPage - Allow break cell in two pages
* @return unknown_type
*/
function addAnswer($sFname, $bAllowBreakPage=false)
{
$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->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
{
$this->commitTransaction();
}
}
}
......@@ -268,6 +268,34 @@
<li><label for="showqnumcode"><?php eT('Show question number and/or question code'); ?></label>
<?php echo CHtml::dropDownList('showqnumcode',getGlobalSetting('showqnumcode'),array('choose'=>gT('Survey admin can choose'),'show'=>gT('Show both'),'number'=>gT('Show question number only'),'code'=>gT('Show question code only'),'none'=>gT('Hide both'))) ?>
</li>
<li><label for='pdffontsize'><?php eT("Font size of answers export PDFs"); ?></label>
<input type='text' size='5' id='pdffontsize' name='pdffontsize' value="<?php echo htmlspecialchars(getGlobalSetting('pdffontsize')); ?>" />
</li>
<li><label for='pdfshowheader'><?php eT("Show header in answers export PDFs?") ; ?></label>
<select id='pdfshowheader' name='pdfshowheader'>
<option value='Y'
<?php if (getGlobalSetting('pdfshowheader') == "Y") { ?>
selected='selected'
<?php } ?>
><?php eT("Yes") ; ?>
</option>
<option value='N'
<?php if (getGlobalSetting('pdfshowheader') != "Y") { ?>
selected='selected'
<?php } ?>
><?php eT("No") ; ?>
</option>
</select>
</li>
<li><label for='pdflogowidth'><?php eT("Wigth of PDF header logo"); ?></label>
<input type='text' size='5' id='pdflogowidth' name='pdflogowidth' value="<?php echo htmlspecialchars(getGlobalSetting('pdflogowidth')); ?>" />
</li>
<li><label for='pdfheadertitle'><?php eT("PDF header title (if empty, site name will be used)"); ?></label>
<input type='text' id='pdfheadertitle' size='50' maxlength='256' name='pdfheadertitle' value="<?php echo htmlspecialchars(getGlobalSetting('pdfheadertitle')); ?>" />
</li>
<li><label for='pdfheaderstring'><?php eT("PDF header string (if empty, survey name will be used)"); ?></label>
<input type='text' id='pdfheaderstring' size='50' maxlength='256' name='pdfheaderstring' value="<?php echo htmlspecialchars(getGlobalSetting('pdfheaderstring')); ?>" />
</li>
</ul>
</div>
<div id='language'>
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
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