Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 21, 2013
2 parents e36f352 + e4b44bb commit 59d19bf
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 276 deletions.
2 changes: 1 addition & 1 deletion application/config/config-defaults.php
Expand Up @@ -333,7 +333,7 @@
* Some langage are not tested : need translation for Yes,No and Gender : ckb, swh
*/
$config['alternatepdffontfile']=array(
'ar'=>'freesans',// 'dejavusans' work too but maybe more characters in aealarabiya or almohanad: but then need a dynamic font size too
'ar'=>'dejavusans',// 'dejavusans' work but maybe more characters in aealarabiya or almohanad: but then need a dynamic font size too
'be'=>'dejavusans',
'bg'=>'dejavusans',
'zh-Hans'=>'chinese',
Expand Down
16 changes: 11 additions & 5 deletions application/controllers/PrintanswersController.php
Expand Up @@ -115,14 +115,20 @@ function actionView($surveyid,$printableexport=FALSE)
."<center><input type='submit' value='".$clang->gT("PDF export")."'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>";
if($printableexport == 'pdf')
{
require (Yii::app()->getConfig('rootdir').'/application/config/tcpdf.php');
//require (Yii::app()->getConfig('rootdir').'/application/config/tcpdf.php');
Yii::import('application.libraries.admin.pdf', true);
Yii::import('application.helpers.pdfHelper');
$aPdfLanguageSettings=pdfHelper::getPdfLanguageSettings($clang->langcode);
$pdf = new pdf();
$pdf->setConfig($tcpdf);
//$pdf->SetFont($pdfdefaultfont,'',$pdffontsize);
$pdf->AddPage();
//$pdf->titleintopdf($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})");
// set document information
$pdf->SetTitle($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})");
$pdf->SetSubject($surveyname);
$pdf->SetDisplayMode('fullpage', 'two');
$pdf->setLanguageArray($aPdfLanguageSettings['lg']);
$pdf->setHeaderFont(Array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_DATA));
$pdf->SetFont($aPdfLanguageSettings['pdffont'], '', $aPdfLanguageSettings['pdffontsize']);
$pdf->AddPage();
}
$printoutput .= "\t<div class='printouttitle'><strong>".$clang->gT("Survey name (ID):")."</strong> $surveyname ($surveyid)</div><p>&nbsp;\n";

Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/useraction.php
Expand Up @@ -95,7 +95,7 @@ function adduser()
if (empty($new_user)) {
$aViewUrls['message'] = array('title' => $clang->gT("Failed to add user"), 'message' => $clang->gT("A username was not supplied or the username is invalid."), 'class'=> 'warningheader');
}
elseif (User::model()->find("users_name='$new_user'")) {
elseif (User::model()->find("users_name=:users_name",array(':users_name'=>$new_user))) {
$aViewUrls['message'] = array('title' => $clang->gT("Failed to add user"), 'message' => $clang->gT("The username already exists."), 'class'=> 'warningheader');
}
elseif ($valid_email)
Expand Down
8 changes: 4 additions & 4 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -891,21 +891,21 @@ function checkconditions(value, name, type, evt_type)
// -->
</script>
END;

$showpopups=Yii::app()->getConfig('showpopups');
//Display the "mandatory" message on page if necessary
if (isset($showpopups) && $showpopups == 0 && $stepInfo['mandViolation'] && $okToShowErrors)
if (!$showpopups && $stepInfo['mandViolation'] && $okToShowErrors)
{
echo "<p><span class='errormandatory'>" . $clang->gT("One or more mandatory questions have not been answered. You cannot proceed until these have been completed.") . "</span></p>";
}

//Display the "validation" message on page if necessary
if (isset($showpopups) && $showpopups == 0 && !$stepInfo['valid'] && $okToShowErrors)
if (!$showpopups && !$stepInfo['valid'] && $okToShowErrors)
{
echo "<p><span class='errormandatory'>" . $clang->gT("One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid.") . "</span></p>";
}

//Display the "file validation" message on page if necessary
if (isset($showpopups) && $showpopups == 0 && isset($filenotvalidated) && $filenotvalidated == true && $okToShowErrors)
if (!$showpopups && isset($filenotvalidated) && $filenotvalidated == true && $okToShowErrors)
{
echo "<p><span class='errormandatory'>" . $clang->gT("One or more uploaded files are not in proper format/size. You cannot proceed until these files are valid.") . "</span></p>";
}
Expand Down
44 changes: 4 additions & 40 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -1616,8 +1616,6 @@ class PdfWriter extends Writer
public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
{
parent::init($survey, $sLanguageCode, $oOptions);
$pdfdefaultfont=Yii::app()->getConfig('pdfdefaultfont');
$pdffontsize=Yii::app()->getConfig('pdffontsize');
$pdforientation=Yii::app()->getConfig('pdforientation');
$clang = new limesurvey_lang($sLanguageCode);

Expand All @@ -1628,48 +1626,14 @@ public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOpti
$this->pdfDestination = 'D';
}
Yii::import('application.libraries.admin.pdf', true);
if($pdfdefaultfont=='auto')
{
$pdfdefaultfont=PDF_FONT_NAME_DATA;
}
// Array of PDF core fonts: are replaced by according fonts according to the alternatepdffontfile array.Maybe just courier,helvetica and times but if a user want symbol: why not ....
$pdfcorefont=array("courier","helvetica","symbol","times","zapfdingbats");
$pdffontsize=Yii::app()->getConfig('pdffontsize');
Yii::import('application.helpers.pdfHelper');
$aPdfLanguageSettings=pdfHelper::getPdfLanguageSettings($sLanguageCode);

// create new PDF document
$this->pdf = new pdf();
if (in_array($pdfdefaultfont,$pdfcorefont))
{
$alternatepdffontfile=Yii::app()->getConfig('alternatepdffontfile');
if(array_key_exists($sLanguageCode,$alternatepdffontfile))
{
$pdfdefaultfont = $alternatepdffontfile[$sLanguageCode];// Actually use only core font
}
}
if ($pdffontsize=='auto')
{
$pdffontsize=PDF_FONT_SIZE_MAIN;
}

$this->pdf = new pdf();
$this->pdf->SetFont($pdfdefaultfont, '', $pdffontsize);
$this->pdf->SetFont($aPdfLanguageSettings['pdffont'], '', $aPdfLanguageSettings['pdffontsize']);
$this->pdf->AddPage();
$this->pdf->intopdf("PDF export ".date("Y.m.d-H:i", time()));
//Set some pdf metadata
Yii::app()->loadHelper('surveytranslator');
$lg=array();
$lg['a_meta_charset'] = 'UTF-8';
if (getLanguageRTL($sLanguageCode))
{
$lg['a_meta_dir'] = 'rtl';
}
else
{
$lg['a_meta_dir'] = 'ltr';
}
$lg['a_meta_language'] = $sLanguageCode;
$lg['w_page']=$clang->gT("page");
$this->pdf->setLanguageArray($lg);
$this->pdf->setLanguageArray($aPdfLanguageSettings['lg']);

$this->separator="\t";

Expand Down
45 changes: 6 additions & 39 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -3157,29 +3157,10 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
{
//require_once('classes/tcpdf/mypdf.php');
Yii::import('application.libraries.admin.pdf', true);
$pdfdefaultfont=Yii::app()->getConfig('pdfdefaultfont');
if($pdfdefaultfont=='auto')
{
$pdfdefaultfont=PDF_FONT_NAME_DATA;
}
// Array of PDF core fonts: are replaced by according fonts according to the alternatepdffontfile array.Maybe just courier,helvetica and times but if a user want symbol: why not ....
$pdfcorefont=array("courier","helvetica","symbol","times","zapfdingbats");
$pdffontsize=Yii::app()->getConfig('pdffontsize');
Yii::import('application.helpers.pdfHelper');
$aPdfLanguageSettings=pdfHelper::getPdfLanguageSettings($language);

// create new PDF document
$this->pdf = new pdf();
if (in_array($pdfdefaultfont,$pdfcorefont))
{
$alternatepdffontfile=Yii::app()->getConfig('alternatepdffontfile');
if(array_key_exists($statlangcode,$alternatepdffontfile))
{
$pdfdefaultfont = $alternatepdffontfile[$statlangcode];// Actually use only core font
}
}
if ($pdffontsize=='auto')
{
$pdffontsize=PDF_FONT_SIZE_MAIN;
}

$surveyInfo = getSurveyInfo($surveyid,$language);

Expand All @@ -3190,31 +3171,17 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
$this->pdf->SetSubject($surveyInfo['surveyls_title']);
$this->pdf->SetKeywords('LimeSurvey,'.$statlang->gT("Statistics").', '.sprintf($statlang->gT("Survey %s"),$surveyid));
$this->pdf->SetDisplayMode('fullpage', 'two');

//Set some pdf metadata
$lg=array();
$lg['a_meta_charset'] = 'UTF-8';
if (getLanguageRTL($statlangcode))
{
$lg['a_meta_dir'] = 'rtl';
}
else
{
$lg['a_meta_dir'] = 'ltr';
}
$lg['a_meta_language'] = $statlangcode;
$lg['w_page']=$statlang->gT("page");
$this->pdf->setLanguageArray($lg);
$this->pdf->setLanguageArray($aPdfLanguageSettings['lg']);

// set header and footer fonts
$this->pdf->setHeaderFont(Array($pdfdefaultfont, '', PDF_FONT_SIZE_MAIN));
$this->pdf->setFooterFont(Array($pdfdefaultfont, '', PDF_FONT_SIZE_DATA));
$this->pdf->setHeaderFont(Array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_MAIN));
$this->pdf->setFooterFont(Array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_DATA));

// set default header data
// Since png crashes some servers (and we can not try/catch that) we use .gif (or .jpg) instead
$headerlogo = 'statistics.gif';
$this->pdf->SetHeaderData($headerlogo, 10, $statlang->gT("Quick statistics",'unescaped') , $statlang->gT("Survey")." ".$surveyid." '".flattenText($surveyInfo['surveyls_title'],false,true,'UTF-8')."'");
$this->pdf->SetFont($pdfdefaultfont, '', $pdffontsize);
$this->pdf->SetFont($aPdfLanguageSettings['pdffont'], '', $aPdfLanguageSettings['pdffontsize']);
// set default monospaced font
$this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
}
Expand Down
70 changes: 70 additions & 0 deletions application/helpers/pdfHelper.php
@@ -0,0 +1,70 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/

/**
* General helper class for generating pdf.
*/
class pdfHelper
{

/**
* getPdfLanguageSettings
*
* Usage: getPdfLanguageSettings($language)
*
* @return array ('pdffont','pdffontsize','lg'=>array('a_meta_charset','a_meta_dir','a_meta_language','w_page')
* @param string $language : language code for the PDF
*/
public static function getPdfLanguageSettings($language)
{
Yii::import('application.libraries.admin.pdf', true);
Yii::import('application.helpers.surveytranslator_helper',true);

$pdffont=Yii::app()->getConfig('pdfdefaultfont');
if($pdffont=='auto')
{
$pdffont=PDF_FONT_NAME_DATA;
}
$pdfcorefont=array("courier","helvetica","symbol","times","zapfdingbats");
$pdffontsize=Yii::app()->getConfig('pdffontsize');
if (in_array($pdffont,$pdfcorefont))
{
$alternatepdffontfile=Yii::app()->getConfig('alternatepdffontfile');
if(array_key_exists($language,$alternatepdffontfile))
{
$pdffont = $alternatepdffontfile[$language];// Actually use only core font
}
}
if ($pdffontsize=='auto')
{
$pdffontsize=PDF_FONT_SIZE_MAIN;
}
$lg=array();
$lg['a_meta_charset'] = 'UTF-8';
if (getLanguageRTL($language))
{
$lg['a_meta_dir'] = 'rtl';
}
else
{
$lg['a_meta_dir'] = 'ltr';
}
$lg['a_meta_language'] = $language;
$pdflang = new Limesurvey_lang($language);
$lg['w_page']=$pdflang->gT("page");

return array('pdffont'=>$pdffont,'pdffontsize'=>$pdffontsize,'lg'=>$lg);
}

}
12 changes: 6 additions & 6 deletions application/helpers/qanda_helper.php
Expand Up @@ -450,13 +450,13 @@ function file_validation_message($ia)
// TMSW Validation -> EM
function mandatory_popup($ia, $notanswered=null)
{
global $showpopups;
$showpopups=Yii::app()->getConfig('showpopups');

$clang = Yii::app()->lang;
//This sets the mandatory popup message to show if required
//Called from question.php, group.php or survey.php
if ($notanswered === null) {unset($notanswered);}
if (isset($notanswered) && is_array($notanswered) && isset($showpopups) && $showpopups == 1) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED
if (isset($notanswered) && is_array($notanswered) && $showpopups) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED
{
global $mandatorypopup, $popup;
//POPUP WARNING
Expand Down Expand Up @@ -486,14 +486,14 @@ function mandatory_popup($ia, $notanswered=null)
// TMSW Validation -> EM
function validation_popup($ia, $notvalidated=null)
{
global $showpopups;
$showpopups=Yii::app()->getConfig('showpopups');

$clang = Yii::app()->lang;
//This sets the validation popup message to show if required
//Called from question.php, group.php or survey.php
if ($notvalidated === null) {unset($notvalidated);}
$qtitle="";
if (isset($notvalidated) && is_array($notvalidated) && isset($showpopups) && $showpopups == 1) //ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID
if (isset($notvalidated) && is_array($notvalidated) && $showpopups) //ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID
{
global $validationpopup, $vpopup;
//POPUP WARNING
Expand All @@ -516,11 +516,11 @@ function validation_popup($ia, $notvalidated=null)
// TMSW Validation -> EM
function file_validation_popup($ia, $filenotvalidated = null)
{
global $showpopups;
$showpopups=Yii::app()->getConfig('showpopups');

$clang = Yii::app()->lang;
if ($filenotvalidated === null) { unset($filenotvalidated); }
if (isset($filenotvalidated) && is_array($filenotvalidated) && isset($showpopups) && $showpopups == 1)
if (isset($filenotvalidated) && is_array($filenotvalidated) && $showpopups)
{
global $filevalidationpopup, $fpopup;

Expand Down
2 changes: 1 addition & 1 deletion application/helpers/viewHelper.php
Expand Up @@ -10,7 +10,6 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/

/**
Expand Down Expand Up @@ -138,4 +137,5 @@ public static function getFieldCode($field, $option=array())
}
return $questioncode;
}

}

0 comments on commit 59d19bf

Please sign in to comment.