From fa1ce9f5ed4c56e147350723ee2a6efd8dbd96f3 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 26 Oct 2016 01:51:58 +0200 Subject: [PATCH] Dev: review print answer (public) quick : adding bs class + use layout Dev: fix layout survey Dev: review some url class --- .../controllers/PrintanswersController.php | 79 ++++++++++--------- application/controllers/survey/index.php | 6 +- .../core/packages/limesurvey/survey.js | 17 ++-- application/views/layouts/survey.php | 4 + 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/application/controllers/PrintanswersController.php b/application/controllers/PrintanswersController.php index 7064bc1a3ca..d5756f5a299 100644 --- a/application/controllers/PrintanswersController.php +++ b/application/controllers/PrintanswersController.php @@ -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; /** @@ -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 "

\n" - ."\t".gT("Error")."
\n" - ."\t".gT("We are sorry but your session has expired.")."
".gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.")."
\n" - ."\t".sprintf(gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail"))."\n" - ."

\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 @@ -109,8 +126,8 @@ function actionView($surveyid,$printableexport=FALSE) if ($sExportType != 'pdf') { $sOutput = CHtml::form(array("printanswers/view/surveyid/{$iSurveyID}/printableexport/pdf"), 'post') - ."
"; - $sOutput .= "\t
".gT("Survey name (ID):")." $sSurveyName ($iSurveyID)

 \n"; + ."

"; + $sOutput .= "\t
".gT("Survey name (ID):")." $sSurveyName ($iSurveyID)
"; 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); @@ -127,44 +144,32 @@ function actionView($surveyid,$printableexport=FALSE) unset ($aFullResponseTable['startlanguage']); unset ($aFullResponseTable['datestamp']); unset ($aFullResponseTable['startdate']); - $sOutput .= "\n"; + $sOutput .= "
\n"; foreach ($aFullResponseTable as $sFieldname=>$fname) { if (substr($sFieldname,0,4) == 'gid_') { - $sOutput .= "\t\n"; - $sOutput .= "\t\n"; + $sOutput .= "\t\n"; + $sOutput .= "\t\n"; } elseif ($sFieldname=='submitdate') { if($sAnonymized != 'Y') { - $sOutput .= "\t"; + $sOutput .= "\t"; } } elseif (substr($sFieldname,0,4) != 'qid_') // Question text is already in subquestion text, skipping it { - $sOutput .= "\t"; + $sOutput .= "\t"; } } $sOutput .= "
{$fname[0]}
{$fname[1]}
{$fname[0]}
{$fname[1]}
{$fname[0]} {$fname[1]}{$fname[2]}
{$fname[0]} {$fname[1]}{$fname[2]}
{$fname[0]} {$fname[1]}".flattenText($fname[2])."
{$fname[0]} {$fname[1]}".flattenText($fname[2])."
\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 ""; - - 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') { diff --git a/application/controllers/survey/index.php b/application/controllers/survey/index.php index 325816cd84d..3ae6aac380c 100644 --- a/application/controllers/survey/index.php +++ b/application/controllers/survey/index.php @@ -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); @@ -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); @@ -198,7 +198,7 @@ function action() ); App()->getController()->renderExitMessage( $surveyid, - 'norights-410', + 'norights-401', $aMessage, null, $aErrors diff --git a/application/core/packages/limesurvey/survey.js b/application/core/packages/limesurvey/survey.js index a09c96ace1d..d9172b66218 100644 --- a/application/core/packages/limesurvey/survey.js +++ b/application/core/packages/limesurvey/survey.js @@ -4,15 +4,19 @@ * @copyright LimeSurvey * @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(); } }); } @@ -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'))) diff --git a/application/views/layouts/survey.php b/application/views/layouts/survey.php index 5e52b169581..6532c7373b9 100644 --- a/application/views/layouts/survey.php +++ b/application/views/layouts/survey.php @@ -31,6 +31,10 @@ 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);