Skip to content

Commit

Permalink
Dev: Fixed issue : javascript error in Statistics_userController
Browse files Browse the repository at this point in the history
Dev: child of SurveyController with public layout
  • Loading branch information
Shnoulle committed Oct 31, 2016
1 parent bb494ef commit 9731f64
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 54 deletions.
3 changes: 2 additions & 1 deletion application/controllers/PrintanswersController.php
Expand Up @@ -43,7 +43,6 @@ function actionView($surveyid,$printableexport=FALSE)
{
Yii::app()->loadHelper("frontend");
Yii::import('application.libraries.admin.pdf');

$iSurveyID = (int)$surveyid;
$sExportType = $printableexport;

Expand Down Expand Up @@ -73,6 +72,8 @@ function actionView($surveyid,$printableexport=FALSE)
$sLanguage = Yii::app()->getConfig("defaultlang");
}
SetSurveyLanguage($iSurveyID, $sLanguage);
SurveyRuntimeHelper->setJavascriptVar($iSurveyID);

$aSurveyInfo = getSurveyInfo($iSurveyID,$sLanguage);
$oTemplate = Template::model()->getInstance(null, $iSurveyID);
if($oTemplate->cssFramework == 'bootstrap')
Expand Down
76 changes: 28 additions & 48 deletions application/controllers/Statistics_userController.php
Expand Up @@ -24,7 +24,7 @@
*
*/

class Statistics_userController extends LSYii_Controller {
class Statistics_userController extends SurveyController {

/**
* @var int
Expand Down Expand Up @@ -55,23 +55,15 @@ public function actionAction($surveyid,$language=null)
{
$sLanguage = $language;
$this->sLanguage = $language;
ob_start(function($buffer) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);

$iSurveyID = (int) $surveyid;
$this->iSurveyID = (int) $surveyid;

//$postlang = returnglobal('lang');
Yii::import('application.libraries.admin.progressbar',true);
//~ Yii::import('application.libraries.admin.progressbar',true);
Yii::app()->loadHelper("userstatistics");
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('surveytranslator');
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
$data = array();

if(!isset($iSurveyID))
Expand All @@ -85,14 +77,14 @@ public function actionAction($surveyid,$language=null)
if (!$iSurveyID)
{
//This next line ensures that the $iSurveyID value is never anything but a number.
safeDie('You have to provide a valid survey ID.');
throw new CHttpException(404,'You have to provide a valid survey ID.');
}


$actresult = Survey::model()->findAll('sid = :sid AND active = :active', array(':sid' => $iSurveyID, ':active' => 'Y')); //Checked
if (count($actresult) == 0)
{
safeDie('You have to provide a valid survey ID.');
throw new CHttpException(404, 'You have to provide a valid survey ID.');
}
else
{
Expand All @@ -103,7 +95,7 @@ public function actionAction($surveyid,$language=null)
$thisSurveyCssPath = getTemplateURL($surveyinfo["template"]);
if ($surveyinfo['publicstatistics']!='Y')
{
safeDie('The public statistics for this survey are deactivated.');
throw new CHttpException(404, 'The public statistics for this survey are deactivated.');
}

//check if graphs should be shown for this survey
Expand Down Expand Up @@ -156,7 +148,6 @@ public function actionAction($surveyid,$language=null)
//set survey language for translations
SetSurveyLanguage($iSurveyID, $sLanguage);
//Create header
sendCacheHeaders();
$condition = false;
$sitename = Yii::app()->getConfig("sitename");

Expand Down Expand Up @@ -251,37 +242,30 @@ public function actionAction($surveyid,$language=null)
$thissurvey = getSurveyInfo($surveyid,$sLanguage);

//SET THE TEMPLATE DIRECTORY
$data['sTemplatePath'] = $surveyinfo['template'];// surveyinfo=getSurveyInfo and if survey don't exist : stop before.

//---------- CREATE STATISTICS ----------
$redata = compact(array_keys(get_defined_vars()));
doHeader();

/// $oTemplate is a global variable defined in controller/survey/index
$oTemplate = Template::model()->getInstance(null, $surveyid);
echo templatereplace(file_get_contents($oTemplate->viewPath."startpage.pstpl"),array(), $redata);


//some progress bar stuff

// Create progress bar which is shown while creating the results
$prb = new ProgressBar();
$prb->pedding = 2; // Bar Pedding
$prb->brd_color = "#404040 #dfdfdf #dfdfdf #404040"; // Bar Border Color
//~ $prb = new ProgressBar();
//~ $prb->pedding = 2; // Bar Pedding
//~ $prb->brd_color = "#404040 #dfdfdf #dfdfdf #404040"; // Bar Border Color

$prb->setFrame(); // set ProgressBar Frame
$prb->frame['left'] = 50; // Frame position from left
$prb->frame['top'] = 80; // Frame position from top
$prb->addLabel('text','txt1',gT("Please wait ...")); // add Text as Label 'txt1' and value 'Please wait'
$prb->addLabel('percent','pct1'); // add Percent as Label 'pct1'
$prb->addButton('btn1',gT('Go back'),'?action=statistics&sid='.$iSurveyID); // add Button as Label 'btn1' and action '?restart=1'
//~ $prb->setFrame(); // set ProgressBar Frame
//~ $prb->frame['left'] = 50; // Frame position from left
//~ $prb->frame['top'] = 80; // Frame position from top
//~ $prb->addLabel('text','txt1',gT("Please wait ...")); // add Text as Label 'txt1' and value 'Please wait'
//~ $prb->addLabel('percent','pct1'); // add Percent as Label 'pct1'
//~ $prb->addButton('btn1',gT('Go back'),'?action=statistics&sid='.$iSurveyID); // add Button as Label 'btn1' and action '?restart=1'

$prb->show(); // show the ProgressBar
//~ $prb->show(); // show the ProgressBar

// 1: Get list of questions with answers chosen
//"Getting Questions and Answer ..." is shown above the bar
$prb->setLabelValue('txt1',gT('Getting questions and answers ...'));
$prb->moveStep(5);
//~ // 1: Get list of questions with answers chosen
//~ //"Getting Questions and Answer ..." is shown above the bar
//~ $prb->setLabelValue('txt1',gT('Getting questions and answers ...'));
//~ $prb->moveStep(5);

// creates array of post variable names
$postvars = array();
Expand All @@ -303,8 +287,8 @@ public function actionAction($surveyid,$language=null)
if (isset($summary) && !empty($summary))
{
//"Generating Summaries ..." is shown above the progress bar
$prb->setLabelValue('txt1',gT('Generating summaries ...'));
$prb->moveStep($process_status);
//~ $prb->setLabelValue('txt1',gT('Generating summaries ...'));
//~ $prb->moveStep($process_status);

//let's run through the survey // Fixed bug 3053 with array_unique
$runthrough=array_unique($summary);
Expand All @@ -315,7 +299,7 @@ public function actionAction($surveyid,$language=null)

//update progress bar
if ($process_status < 100) $process_status++;
$prb->moveStep($process_status);
//~ $prb->moveStep($process_status);

} // end foreach -> loop through all questions

Expand All @@ -328,18 +312,14 @@ public function actionAction($surveyid,$language=null)
//done! set progress bar to 100%
if (isset($prb))
{
$prb->setLabelValue('txt1',gT('Completed'));
$prb->moveStep(100);
$prb->hide();
//~ $prb->setLabelValue('txt1',gT('Completed'));
//~ $prb->moveStep(100);
//~ $prb->hide();
}

$redata = compact(array_keys(get_defined_vars()));
$data['redata'] = $redata;
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . 'statistics_user.js');
$this->renderPartial('/statistics_user_view',$data);

//output footer
echo getFooter();
$this->layout="public";
$this->render('/statistics_user_view',$data);

//Delete all Session Data
Yii::app()->session['finished'] = true;
Expand Down
6 changes: 5 additions & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -71,7 +71,11 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
if ($sTemplateName=='')
{
$this->oSurvey = Survey::model()->findByPk($iSurveyId);
$this->sTemplateName = $this->oSurvey->template;
if($this->oSurvey){
$this->sTemplateName = $this->oSurvey->template;
}else{
$this->sTemplateName = Template::templateNameFilter(App()->getConfig('defaulttemplate','default'));
}
}

// We check if it's a CORE template
Expand Down
2 changes: 1 addition & 1 deletion application/views/layouts/public.php
Expand Up @@ -39,7 +39,7 @@
}
Yii::app()->clientScript->registerPackage('survey-template');
// Maybe can add language changer here
/* Add head by template + star body (if template start body here ....) */
/* Add head by template + start body (if template start body here ....) */
echo templatereplace(file_get_contents($oTemplate->viewPath."startpage.pstpl"),$this->aReplacementData,$this->aGlobalData);
if(!empty($this->bStartSurvey)){
echo templatereplace(file_get_contents($oTemplate->viewPath."survey.pstpl"),$this->aReplacementData,$this->aGlobalData);
Expand Down
9 changes: 6 additions & 3 deletions templates/lumen/config.xml
Expand Up @@ -3,12 +3,12 @@
<!-- Those metadatas will be display in the template configuration page. They are not used for now. -->
<metadatas>
<name>Basic</name>
<creationDate>14/04/2016</creationDate>
<creationDate>2016-10-31</creationDate>
<author>Denis Chenu</author>
<authorEmail>denis@sondages.pro</authorEmail>
<license>GNU General Public License version 3 or later and MIT</license>
<version>0.2</version>
<description>Basic template for LimeSurvey, based on core bootsrap, with awesome button.</description>
<version>1.0</version>
<description>Basic template for LimeSurvey, using lumen from boostswatch, with awesome button.</description>
<!--
The last_update field must be updated before each release,
to be sure that the asset manager will publish new assets and make visible CSS changes for final users (without browser cache refresh)
Expand All @@ -23,6 +23,7 @@
-->
<css>
<filename>css/jquery-ui.css</filename>
<!-- Use you own boostrap css here -->
<filename>css/bootswatch-lumen.css</filename>
<filename>css/awesome-bootstrap-checkbox.css</filename>
<filename>css/template-core.css</filename>
Expand Down Expand Up @@ -70,6 +71,8 @@
<engine>
<cssframework>bootstrap</cssframework>
<pstpldirectory>pstpl</pstpldirectory>
<!-- we can set to an invalid directory : we don't use it -->
<viewsdirectory>views</viewsdirectory>
<filesdirectory>files</filesdirectory>

<!--
Expand Down
2 changes: 2 additions & 0 deletions templates/lumen/css/template-core.css
Expand Up @@ -3,6 +3,8 @@
*/
/* Some partial reset */
.ls-answers img,.ls-answers video,.ls-answers svg{max-width: 100%;height: auto;}
.statisticstable img{max-width: 100%;height: auto;}

label,th{font-weight:400}

/**
Expand Down
7 changes: 7 additions & 0 deletions templates/lumen/js/template.js
Expand Up @@ -2,6 +2,13 @@
* @file Do your own javascript function here
*/
$(document).ready(function(){

// If list of nav-bar action is empty: remove it (else .navbar-toggle is shown on small screen) //
if(!$("#navbar li").length){
$("#navbar").remove();
$("[data-target='#navbar']").remove();
}

/* Remove the input error if finally all answers is OK */
$('.question-wrapper.mandatory.panel-warning .ls-answers').on('blur',':not(other-text-item) input:text',function(){
if($(this).closest(".ls-answers").find(":not(other-text-item) input:text[value='']").filter(function(){ return !$(this).val(); }).length==0){
Expand Down

0 comments on commit 9731f64

Please sign in to comment.