Skip to content

Commit

Permalink
Dev: Survey template configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jan 8, 2016
1 parent 1ca8292 commit b16ab9a
Show file tree
Hide file tree
Showing 45 changed files with 365 additions and 134 deletions.
10 changes: 8 additions & 2 deletions application/controllers/OptinController.php
Expand Up @@ -105,11 +105,17 @@ private function _renderHtml($html,$thistpl, $aSurveyInfo)
sendCacheHeaders();
doHeader();
$aSupportData=array('thissurvey'=>$aSurveyInfo);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'startpage.pstpl'),array(), $aSupportData);

// $oTemplate is a global variable defined in controller/survey/index
global $oTemplate;
$sTemplatePath = $oTemplate->path;
$thistpl = $oTemplate->viewPath;

echo templatereplace(file_get_contents($thistpl.'startpage.pstpl'),array(), $aSupportData);
$aData['html'] = $html;
$aData['thistpl'] = $thistpl;
$this->render('/opt_view',$aData);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'endpage.pstpl'),array(), $aSupportData);
echo templatereplace(file_get_contents($thistpl.'endpage.pstpl'),array(), $aSupportData);
doFooter();
}

Expand Down
11 changes: 9 additions & 2 deletions application/controllers/OptoutController.php
Expand Up @@ -190,11 +190,18 @@ private function _renderHtml($html, $thistpl, $aSurveyInfo)
sendCacheHeaders();
doHeader();
$aSupportData=array('thissurvey'=>$aSurveyInfo);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'startpage.pstpl'),array(), $aSupportData);

// $oTemplate is a global variable defined in controller/survey/index
global $oTemplate;
$sTemplatePath = $oTemplate->path;
$thistpl = $oTemplate->viewPath;


echo templatereplace(file_get_contents($thistpl.'startpage.pstpl'),array(), $aSupportData);
$aData['html'] = $html;
$aData['thistpl'] = $thistpl;
$this->render('/opt_view',$aData);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'endpage.pstpl'),array(), $aSupportData);
echo templatereplace(file_get_contents($thistpl.'endpage.pstpl'),array(), $aSupportData);
doFooter();
}

Expand Down
16 changes: 11 additions & 5 deletions application/controllers/PrintanswersController.php
Expand Up @@ -67,19 +67,25 @@ function actionView($surveyid,$printableexport=FALSE)
$aSurveyInfo = getSurveyInfo($iSurveyID,$sLanguage);
//SET THE TEMPLATE DIRECTORY
$sTemplate = $aSurveyInfo['template'];



//Survey is not finished or don't exist
if (!isset($_SESSION['survey_'.$iSurveyID]['finished']) || !isset($_SESSION['survey_'.$iSurveyID]['srid']))
//display "sorry but your session has expired"
{
sendCacheHeaders();
doHeader();
echo templatereplace(file_get_contents(getTemplatePath($sTemplate).'/startpage.pstpl'),array());

/// $oTemplate is a global variable defined in controller/survey/index
global $oTemplate;
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(getTemplatePath($sTemplate).'/endpage.pstpl'),array());
echo templatereplace(file_get_contents($oTemplate->viewPath.'/endpage.pstpl'),array());
doFooter();
exit;
}
Expand Down Expand Up @@ -152,9 +158,9 @@ function actionView($surveyid,$printableexport=FALSE)

sendCacheHeaders();
doHeader();
echo templatereplace(file_get_contents(getTemplatePath($sTemplate).'/startpage.pstpl'),array(),$sData);
echo templatereplace(file_get_contents(getTemplatePath($sTemplate).'/printanswers.pstpl'),array('ANSWERTABLE'=>$sOutput),$sData);
echo templatereplace(file_get_contents(getTemplatePath($sTemplate).'/endpage.pstpl'),array(),$sData);
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();
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/RegisterController.php
Expand Up @@ -197,7 +197,10 @@ public function getRegisterForm($iSurveyId){
$aData['thissurvey'] = $aSurveyInfo;
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
$aData['languagechanger'] = makeLanguageChangerSurvey(App()->language);
return templatereplace(file_get_contents("$sTemplate/register.pstpl"),$aReplacement,$aData);

/// $oTemplate is a global variable defined in controller/survey/index
global $oTemplate;
return templatereplace(file_get_contents("$oTemplate->viewPath/register.pstpl"),$aReplacement,$aData);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions application/controllers/Statistics_userController.php
Expand Up @@ -345,13 +345,16 @@ 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.
$data['sTemplatePath'] = $surveyinfo['template'];// surveyinfo=getSurveyInfo and if survey don't exist : stop before.


//---------- CREATE STATISTICS ----------
$redata = compact(array_keys(get_defined_vars()));
doHeader();
echo templatereplace(file_get_contents(getTemplatePath($data['sTemplatePath']).DIRECTORY_SEPARATOR."startpage.pstpl"),array(), $redata);

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


//some progress bar stuff
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/admin/questions.php
Expand Up @@ -1445,7 +1445,12 @@ public function preview($surveyid, $qid, $lang = null)

$answers = retrieveAnswers($ia,$surveyid);

$thistpl = getTemplatePath($thissurvey['template']);
//$thistpl = getTemplatePath($thissurvey['template']);
// $oTemplate is a global variable defined in controller/survey/index
global $oTemplate;
$sTemplatePath = $oTemplate->path;
$thistpl = $oTemplate->viewPath;


doHeader();

Expand Down
52 changes: 35 additions & 17 deletions application/controllers/survey/index.php
Expand Up @@ -13,14 +13,16 @@

class index extends CAction {

public $oTemplate;

public function run()
{
/*
* Instead of manually rendering scripts after this function returns we
* use the callback. This ensures that scripts are always rendered, even
* if we call exit at some point in the code. (Which we shouldn't, but
* it happens.)
*/
/*
* Instead of manually rendering scripts after this function returns we
* use the callback. This ensures that scripts are always rendered, even
* if we call exit at some point in the code. (Which we shouldn't, but
* it happens.)
*/
// Ensure to set some var, but script are replaced in SurveyRuntimeHelper
$aLSJavascriptVar=array();
$aLSJavascriptVar['bFixNumAuto']=(int)(bool)Yii::app()->getConfig('bFixNumAuto',1);
Expand All @@ -29,13 +31,26 @@ public function run()
$aRadix=getRadixPointData($aLangData[ Yii::app()->getConfig('defaultlang')]['radixpoint']);
$aLSJavascriptVar['sLEMradix']=$aRadix['separator'];
$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar) . ';';

// Template configuration
global $oTemplate;
$oTemplate = Template::model()->getTemplateConfiguration(Yii::app()->getConfig("defaulttemplate"));
$this->oTemplate = $oTemplate;

App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
App()->clientScript->registerScript('setJsVar',"setJsVar();",CClientScript::POS_BEGIN);// Ensure all js var is set before rendering the page (User can click before $.ready)

App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
foreach($oTemplate->packages as $package)
{
App()->getClientScript()->registerPackage($package);
}

App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
App()->bootstrap->register();

if($oTemplate->cssFramework == 'bootstrap')
{
App()->bootstrap->register();
}

useFirebug();

Expand Down Expand Up @@ -347,17 +362,17 @@ function action()
// bypass only this check at first page (Step=0) because
// this check is done in buildsurveysession and error message
// could be more interresting there (takes into accound captcha if used)
if ($tokensexist == 1 && isset($token) && $token!="" &&
if ($tokensexist == 1 && isset($token) && $token!="" &&
isset($_SESSION['survey_'.$surveyid]['step']) && $_SESSION['survey_'.$surveyid]['step']>0 && tableExists("tokens_{$surveyid}}}"))
{
// check also if it is allowed to change survey after completion
if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
$tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));
if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
$tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}

if (!isset($tokenInstance) && !$previewmode)
if (!isset($tokenInstance) && !$previewmode)
{
//TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
$asMessage = array(
Expand Down Expand Up @@ -680,12 +695,15 @@ function _niceExit(&$redata, $iDebugLine, $sTemplateDir = null, $asMessage = arr
sendCacheHeaders();

doHeader();
$this->_printTemplateContent($sTemplateDir.'/startpage.pstpl', $redata, $iDebugLine);

$oTemplate = $this->oTemplate; //$oTemplate->viewPath;

$this->_printTemplateContent($oTemplate->viewPath.'/startpage.pstpl', $redata, $iDebugLine);
$this->_printMessage($asMessage);
$this->_printTemplateContent($sTemplateDir.'/endpage.pstpl', $redata, $iDebugLine);
$this->_printTemplateContent($oTemplate->viewPath.'/endpage.pstpl', $redata, $iDebugLine);

doFooter();
exit;
exit;
}

function _createNewUserSessionAndRedirect($surveyid, &$redata, $iDebugLine, $asMessage = array())
Expand Down

0 comments on commit b16ab9a

Please sign in to comment.