Skip to content

Commit

Permalink
Merge branch 'answers_html' of https://github.com/LimeSurvey/LimeSurvey
Browse files Browse the repository at this point in the history
… into answers_html
  • Loading branch information
Tammo ter Hark committed Oct 26, 2016
2 parents a018be8 + fa1ce9f commit a37850a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 46 deletions.
79 changes: 42 additions & 37 deletions application/controllers/PrintanswersController.php
Expand Up @@ -20,7 +20,16 @@
* @access public
*/
class PrintanswersController extends LSYii_Controller {

/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout= 'survey';
/* @var string the template name to be used when using layout */
public $sTemplate= 'default';
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData= array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
public $aGlobalData= array();
/* @var boolean did we need survey.pstpl when using layout */
public $bStartSurvey= false;


/**
Expand Down Expand Up @@ -76,19 +85,27 @@ function actionView($surveyid,$printableexport=FALSE)
if (!isset($_SESSION['survey_'.$iSurveyID]['finished']) || !isset($_SESSION['survey_'.$iSurveyID]['srid']))
//display "sorry but your session has expired"
{
sendCacheHeaders();
doHeader();

/// $oTemplate is a global variable defined in controller/survey/index
echo templatereplace(file_get_contents($oTemplate->viewPath.'/startpage.pstpl'),array());
echo "<center><br />\n"
."\t<font color='RED'><strong>".gT("Error")."</strong></font><br />\n"
."\t".gT("We are sorry but your session has expired.")."<br />".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(gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail"))."\n"
."</center><br />\n";
echo templatereplace(file_get_contents($oTemplate->viewPath.'/endpage.pstpl'),array());
doFooter();
exit;
$oTemplate = Template::model()->getInstance('', $iSurveyID);
$this->sTemplate=$oTemplate->sTemplateName;
$error=$this->renderPartial("/survey/system/errorWarning",array(
'aErrors'=>array(
gT("We are sorry but your session has expired."),
),
),true);
$message=$this->renderPartial("/survey/system/message",array(
'aMessage'=>array(
gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection."),
),
),true);
/* Set the data for templatereplace */
$this->aGlobalData['thissurvey']=getSurveyInfo($iSurveyID);
$this->aReplacementData=$aReplacementData['MESSAGEID']='session-timeout';
$aReplacementData['MESSAGE']=$message;
$aReplacementData['URL']='';
$this->aReplacementData=$aReplacementData['ERROR']=$error; // Adding this to replacement data : allow to update title (for example) : @see https://bugs.limesurvey.org/view.php?id=9106 (but need more)
$content=templatereplace(file_get_contents($oTemplate->viewPath."message.pstpl"),$aReplacementData,$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$content));
App()->end();
}
//Fin session time out
$sSRID = $_SESSION['survey_'.$iSurveyID]['srid']; //I want to see the answers with this id
Expand All @@ -109,8 +126,8 @@ function actionView($surveyid,$printableexport=FALSE)
if ($sExportType != 'pdf')
{
$sOutput = CHtml::form(array("printanswers/view/surveyid/{$iSurveyID}/printableexport/pdf"), 'post')
."<center><input class='btn btn-default' type='submit' value='".gT("PDF export")."'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>";
$sOutput .= "\t<div class='printouttitle'><strong>".gT("Survey name (ID):")."</strong> $sSurveyName ($iSurveyID)</div><p>&nbsp;\n";
."<div class='text-center'><input class='btn btn-default' type='submit' value='".gT("PDF export")."'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></div></form>";
$sOutput .= "\t<div class='h3 printouttitle'>".gT("Survey name (ID):")." $sSurveyName ($iSurveyID)</div>";
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
LimeExpressionManager::StartProcessingGroup(1,($aSurveyInfo['anonymized']!="N"),$iSurveyID);
Expand All @@ -127,44 +144,32 @@ function actionView($surveyid,$printableexport=FALSE)
unset ($aFullResponseTable['startlanguage']);
unset ($aFullResponseTable['datestamp']);
unset ($aFullResponseTable['startdate']);
$sOutput .= "<table class='printouttable' >\n";
$sOutput .= "<table class='printouttable table table-bordered table-striped table-condensed' >\n";
foreach ($aFullResponseTable as $sFieldname=>$fname)
{
if (substr($sFieldname,0,4) == 'gid_')
{
$sOutput .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
$sOutput .= "\t<tr class='printanswersgroupdesc'><td colspan='2'>{$fname[1]}</td></tr>\n";
$sOutput .= "\t<tr class='printanswersgroup info'><th colspan='2'>{$fname[0]}</th></tr>\n";
$sOutput .= "\t<tr class='printanswersgroupdesc info'><td colspan='2'>{$fname[1]}</td></tr>\n";
}
elseif ($sFieldname=='submitdate')
{
if($sAnonymized != 'Y')
{
$sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
$sOutput .= "\t<tr class='printanswersquestion'><th>{$fname[0]} {$fname[1]}</th><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
}
}
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>";
$sOutput .= "\t<tr class='printanswersquestion'><th>{$fname[0]} {$fname[1]}</th><td class='printanswersanswertext'>".flattenText($fname[2])."</td></tr>";
}
}
$sOutput .= "</table>\n";
$sData['thissurvey']=$aSurveyInfo;
$this->aGlobalData['thissurvey']=$aSurveyInfo;
$sOutput=templatereplace($sOutput, array() , $sData, '', $aSurveyInfo['anonymized']=="Y",NULL, array(), true);// Do a static replacement
ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);

sendCacheHeaders();
doHeader();
echo templatereplace(file_get_contents($oTemplate->viewPath.'/startpage.pstpl'),array(),$sData);
echo templatereplace(file_get_contents($oTemplate->viewPath.'/printanswers.pstpl'),array('ANSWERTABLE'=>$sOutput),$sData);
echo templatereplace(file_get_contents($oTemplate->viewPath.'/endpage.pstpl'),array(),$sData);
echo "</body></html>";

ob_flush();
$content=templatereplace(file_get_contents($oTemplate->viewPath.'/printanswers.pstpl'),array('ANSWERTABLE'=>$sOutput),$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$sOutput));
App()->end();
}
if($sExportType == 'pdf')
{
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/survey/index.php
Expand Up @@ -148,7 +148,7 @@ function action()
$asMessage = array(gT('The token you provided doesn\'t match the one in your session.'));
$aUrl=array(
'url'=>$sReloadUrl,
'type'=>'restartsurvey',
'type'=>'restart-survey',
'description'=>gT("Click here to start the survey.")
);
killSurveySession($surveyid);
Expand All @@ -173,7 +173,7 @@ function action()
);
$aUrl=array(
'url'=>$this->getController()->createUrl("/survey/index/sid/{$surveyid}",$aReloadUrlParam),
'type'=>'restartsurvey',
'type'=>'restart-survey',
'description'=>gT("Click here to start the survey.")
);
killSurveySession($surveyid);
Expand All @@ -198,7 +198,7 @@ function action()
);
App()->getController()->renderExitMessage(
$surveyid,
'norights-410',
'norights-401',
$aMessage,
null,
$aErrors
Expand Down
17 changes: 11 additions & 6 deletions application/core/packages/limesurvey/survey.js
Expand Up @@ -4,15 +4,19 @@
* @copyright LimeSurvey <http://www.limesurvey.org/>
* @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
*/

/**
* Always set an empty LSvar
*/
var LSvar=LSvar || { }
/**
* Manage the index
*/

function manageIndex(){
$("#index").on('click','li,.row',function(e){
if(!$(e.target).is('button')){
$(this).children("[name='move']").click();
/* only needed if it's not inside form (form#limesurvey) */
$(".ls-index-buttons").on('click','[name="move"]',function(e){
if(!$(this).closest('form').length && $('form#limesurvey').length==1){
$(this).clone().addClass("hidden").appendTo('form#limesurvey').click();
}
});
}
Expand Down Expand Up @@ -67,11 +71,12 @@ function activateLanguageChanger(){
function activateActionLink(){
/* If no limesurvey form : don't need it */
if(!$('form#limesurvey').length){
$('[data-limesurvey-submit]').remove();
$(document).remove('[data-limesurvey-submit]');
}
/* Submit limesurvey form on click */
else{
$('[data-limesurvey-submit]').on('click',function() {
$('[data-limesurvey-submit]').on('click',function(event) {
event.preventDefault();
var submit=$(this).data('limesurvey-submit');
var confirmedby=$(this).data('confirmedby');
if(!confirmedby || confirm($(this).data('confirmlabel')))
Expand Down
4 changes: 4 additions & 0 deletions application/views/layouts/survey.php
Expand Up @@ -31,6 +31,10 @@
<?php
$oTemplate = Template::model()->getInstance($this->sTemplate);
App()->getClientScript()->registerPackage('fontawesome');
foreach($oTemplate->packages as $package)
{
App()->getClientScript()->registerPackage((string) $package);
}
// Maybe can add language changer here
/* Add head by template + star body (if template start body here ....) */
echo templatereplace(file_get_contents($oTemplate->viewPath."startpage.pstpl"),$this->aReplacementData,$this->aGlobalData);
Expand Down
Binary file added templates/basic/basic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/basic/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a37850a

Please sign in to comment.