Skip to content

Commit

Permalink
PDF Export working in printanswers controller. Emailtemplate controll…
Browse files Browse the repository at this point in the history
…er implemented.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10791 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Aug 20, 2011
1 parent cfcf44c commit 38aa45e
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 33 deletions.
8 changes: 4 additions & 4 deletions application/config/lsconfig.php
Expand Up @@ -342,11 +342,11 @@
* At this point no support can be given - if you want to help to fix it please get in touch with us
*/

$config['usepdfexport'] = 0; //Set 0 to disable; 1 to enable
$config['pdfdefaultfont'] = 'freemono'; //Default font for the pdf Export
$config['pdffontsize'] = 9; //Fontsize for normal text; Surveytitle is +4; grouptitle is +2
$config['usepdfexport'] = 1; //Set 0 to disable; 1 to enable
//$config['pdfdefaultfont'] = 'freemono'; //Default font for the pdf Export
//$config['pdffontsize'] = 9; //Fontsize for normal text; Surveytitle is +4; grouptitle is +2
$config['notsupportlanguages'] = array('zh-Hant-TW','zh-Hant-HK','zh-Hans','ja','th');
$config['pdforientation'] = 'P'; // Set L for Landscape or P for portrait format
//$config['pdforientation'] = 'P'; // Set L for Landscape or P for portrait format



Expand Down
4 changes: 2 additions & 2 deletions application/config/tcpdf_config_ci.php
Expand Up @@ -194,8 +194,8 @@
* HTML <small> font size ratio
***********************************************************/

$tcpdf['page_font'] = 'helvetica';
$tcpdf['page_font_size'] = 10;
$tcpdf['page_font'] = 'freemono';
$tcpdf['page_font_size'] = 9;

$tcpdf['small_font_ratio'] = 2/3;

Expand Down
252 changes: 252 additions & 0 deletions application/controllers/admin/emailtemplates.php

Large diffs are not rendered by default.

72 changes: 48 additions & 24 deletions application/controllers/printanswers.php
Expand Up @@ -14,27 +14,48 @@
*
*/

/**
* printanswers
*
* @package LimeSurvey_CI
* @copyright 2011
* @version $Id$
* @access public
*/
class printanswers extends LS_Controller {

/**
* printanswers::__construct()
* Constructor
* @return
*/
function __construct()
{
parent::__construct();
}

/**
* printanswers::view()
* View answers at the end of a survey in one place. To export as pdf, set 'usepdfexport' = 1 in lsconfig.php and $printableexport='pdf'.
* @param mixed $surveyid
* @param bool $printableexport
* @return
*/
function view($surveyid,$printableexport=FALSE)
{

global $siteadminname, $siteadminemail;

if($this->config->item('usepdfexport'))
{
require_once($pdfexportdir."/extensiontcpdf.php");
//require_once($pdfexportdir."/extensiontcpdf.php");
$this->load->library('admin/pdf');
}

//if (!isset($surveyid)) {$surveyid=returnglobal('sid');}
//else {
//This next line ensures that the $surveyid value is never anything but a number.
$surveyid=sanitize_int($surveyid);
$surveyid=sanitize_int($surveyid);
//}
$this->load->helper('database');
//$clang = $this->limesurvey_lang;
Expand Down Expand Up @@ -81,14 +102,14 @@ function view($surveyid,$printableexport=FALSE)
sendcacheheaders();
doHeader();

echo templatereplace(file_get_contents(sGetTemplatePath(validate_templatedir("default"))."/startpage.pstpl"));
echo templatereplace(file_get_contents(sGetTemplatePath(validate_templatedir("default"))."/startpage.pstpl"),array(),array());
echo "<center><br />\n"
."\t<font color='RED'><strong>".$clang->gT("ERROR")."</strong></font><br />\n"
."\t".$clang->gT("We are sorry but your session has expired.")."<br />".$clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.")."<br />\n"
."\t".sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$siteadminname,$siteadminemail)."\n"
."</center><br />\n";

echo templatereplace(file_get_contents(sGetTemplatePath(validate_templatedir("default"))."/endpage.pstpl"));
echo templatereplace(file_get_contents(sGetTemplatePath(validate_templatedir("default"))."/endpage.pstpl"),array(),array());
doFooter();
exit;
};
Expand Down Expand Up @@ -176,16 +197,19 @@ function view($surveyid,$printableexport=FALSE)
//OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK.
//SHOW HEADER
$printoutput = '';
if(isset($usepdfexport) && $usepdfexport == 1)
if($this->config->item('usepdfexport') == 1)
{
$printoutput .= "<form action='".site_url('printanswers/view/'.$surveyid.'/pdf')."' method='post'>\n<center><input type='submit' value='".$clang->gT("PDF Export")."'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>";
}
if($printableexport)
if($printableexport=='pdf')
{
$pdf = new PDF($pdforientation);
$pdf->SetFont($pdfdefaultfont,'',$pdffontsize);
$pdf->AddPage();
$pdf->titleintopdf($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})");
//$pdf = new PDF($pdforientation);
require ($this->config->item('rootdir').'/application/config/tcpdf_config_ci.php');
$this->_config = $tcpdf;
//$this->pdf->SetFont($pdfdefaultfont,'',$pdffontsize);
$this->pdf->AddPage();
//$pdf->titleintopdf($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})");
$this->pdf->SetTitle($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})");
}
$printoutput .= "\t<div class='printouttitle'><strong>".$clang->gT("Survey name (ID):")."</strong> $surveyname ($surveyid)</div><p>&nbsp;\n";

Expand All @@ -201,9 +225,9 @@ function view($surveyid,$printableexport=FALSE)
unset ($aFullResponseTable['startdate']);

$printoutput .= "<table class='printouttable' >\n";
if($printableexport)
if($printableexport=='pdf')
{
$pdf->intopdf($clang->gT("Question",'unescaped').": ".$clang->gT("Your answer",'unescaped'));
$this->pdf->intopdf($clang->gT("Question",'unescaped').": ".$clang->gT("Your answer",'unescaped'));
}

$oldgid = 0;
Expand All @@ -215,8 +239,8 @@ function view($surveyid,$printableexport=FALSE)

if($printableexport)
{
$pdf->intopdf(FlattenText($fname[0],true));
$pdf->ln(2);
$this->pdf->intopdf(FlattenText($fname[0],true));
$this->pdf->ln(2);
}
else
{
Expand All @@ -225,10 +249,10 @@ function view($surveyid,$printableexport=FALSE)
}
elseif (substr($sFieldname,0,4)=='qid_')
{
if($printableexport)
if($printableexport=='pdf')
{
$pdf->intopdf(FlattenText($fname[0].$fname[1],true).": ".$fname[2]);
$pdf->ln(2);
$this->pdf->intopdf(FlattenText($fname[0].$fname[1],true).": ".$fname[2]);
$this->pdf->ln(2);
}
else
{
Expand All @@ -237,10 +261,10 @@ function view($surveyid,$printableexport=FALSE)
}
else
{
if($printableexport)
if($printableexport=='pdf')
{
$pdf->intopdf(FlattenText($fname[0].$fname[1],true).": ".$fname[2]);
$pdf->ln(2);
$this->pdf->intopdf(FlattenText($fname[0].$fname[1],true).": ".$fname[2]);
$this->pdf->ln(2);
}
else
{
Expand All @@ -250,7 +274,7 @@ function view($surveyid,$printableexport=FALSE)
}

$printoutput .= "</table>\n";
if($printableexport)
if($printableexport=='pdf')
{

header("Pragma: public");
Expand All @@ -273,15 +297,15 @@ function view($surveyid,$printableexport=FALSE)

header("Content-Disposition: Attachment; filename=\"". $sExportFileName ."-".$surveyid.".pdf\"");

$pdf->Output($this->config->item('tempdir').'/'.$clang->gT($surveyname)."-".$surveyid.".pdf", "F");
header("Content-Length: ". filesize($tempdir.'/'.$sExportFileName."-".$surveyid.".pdf"));
$this->pdf->Output($this->config->item('tempdir').'/'.$clang->gT($surveyname)."-".$surveyid.".pdf", "F");
header("Content-Length: ". filesize($this->config->item('tempdir').'/'.$sExportFileName."-".$surveyid.".pdf"));
readfile($this->config->item('tempdir').'/'.$sExportFileName."-".$surveyid.".pdf");
unlink($this->config->item('tempdir').'/'.$sExportFileName."-".$surveyid.".pdf");

}
else
{
$pdf->Output($sExportFileName."-".$surveyid.".pdf","D");
$this->pdf->Output($sExportFileName."-".$surveyid.".pdf","D");
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/core/Survey_Common_Controller.php
Expand Up @@ -1075,7 +1075,7 @@ function _surveysummary($surveyid,$action=null)
//$gid || $qid ||


if ($action=="deactivate"|| $action=="activate" || $action=="surveysecurity" || $action=="editdefaultvalues"
if ($action=="deactivate"|| $action=="activate" || $action=="surveysecurity" || $action=="editdefaultvalues" || $action == "editemailtemplates"
|| $action=="surveyrights" || $action=="addsurveysecurity" || $action=="addusergroupsurveysecurity"
|| $action=="setsurveysecurity" || $action=="setusergroupsurveysecurity" || $action=="delsurveysecurity"
|| $action=="editsurveysettings"|| $action=="editsurveylocalesettings" || $action=="updatesurveysettingsandeditlocalesettings" || $action=="addgroup" || $action=="importgroup"
Expand Down
7 changes: 6 additions & 1 deletion application/third_party/tcpdf/tcpdf.php
Expand Up @@ -10333,15 +10333,20 @@ protected function _putresources() {
protected function _putinfo() {
$oid = $this->_newobj();
$out = '<<';
if (!$this->empty_string($this->title)) {

if (!$this->empty_string($this->title)) {
// The document's title.
$out .= ' /Title '.$this->_textstring($this->title, $oid);
}

if (!$this->empty_string($this->author)) {

// The name of the person who created the document.
$out .= ' /Author '.$this->_textstring($this->author, $oid);
}

if (!$this->empty_string($this->subject)) {

// The subject of the document.
$out .= ' /Subject '.$this->_textstring($this->subject, $oid);
}
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/Survey/surveybar.php
Expand Up @@ -86,7 +86,7 @@
<img src='<?php echo $imageurl;?>/assessments_30.png' /> <?php echo $clang->gT("Assessments");?></a></li>
<?php } ?>
<?php if($surveylocale) { ?>
<li><a href='<?php echo site_url("admin/emailtemplates/index/$surveyid");?>' >
<li><a href='<?php echo site_url("admin/emailtemplates/edit/$surveyid");?>' >
<img src='<?php echo $imageurl;?>/emailtemplates_30.png' name='EditEmailTemplates' /> <?php echo $clang->gT("Email templates");?></a></li>
<?php } ?>
</ul></li>
Expand Down

0 comments on commit 38aa45e

Please sign in to comment.