Skip to content

Commit

Permalink
Dev: Fixed issue #11846: Differenciate views and pstpl file
Browse files Browse the repository at this point in the history
Dev: TemplateConfiguration->pstplPath for pstpl
Dev: TemplateConfiguration->viewPath for view(s)
  • Loading branch information
Shnoulle committed Oct 31, 2016
1 parent 9731f64 commit 16c8d08
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 295 deletions.
3 changes: 2 additions & 1 deletion application/controllers/OptinController.php
Expand Up @@ -110,7 +110,8 @@ private function _renderHtml($html, $aSurveyInfo, $iSurveyID)
{
App()->bootstrap->register();
}
$thistpl = $oTemplate->viewPath;
App()->clientScript->registerPackage('survey-template');
$thistpl = $oTemplate->pstplPath;

echo templatereplace(file_get_contents($thistpl.'startpage.pstpl'),array(), $aSupportData);
$aData['html'] = $html;
Expand Down
8 changes: 6 additions & 2 deletions application/controllers/OptoutController.php
Expand Up @@ -182,8 +182,12 @@ private function _renderHtml($html, $aSurveyInfo, $iSurveyID)
{
App()->bootstrap->register();
}
$thistpl = $oTemplate->viewPath;
Yii::app()->clientScript->registerPackage('survey-template');
$thistpl = $oTemplate->pstplPath;
if($oTemplate->cssFramework == 'bootstrap')
{
App()->bootstrap->register();
}
App()->clientScript->registerPackage('survey-template');
ob_start(function($buffer, $phase)
{
App()->getClientScript()->render($buffer);
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/PrintanswersController.php
Expand Up @@ -104,7 +104,7 @@ function actionView($surveyid,$printableexport=FALSE)
$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);
$content=templatereplace(file_get_contents($oTemplate->pstplPath."message.pstpl"),$aReplacementData,$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$content));
App()->end();
}
Expand Down Expand Up @@ -168,7 +168,7 @@ function actionView($surveyid,$printableexport=FALSE)
$sOutput .= "</table>\n";
$this->aGlobalData['thissurvey']=$aSurveyInfo;
$sOutput=templatereplace($sOutput, array() , $sData, '', $aSurveyInfo['anonymized']=="Y",NULL, array(), true);// Do a static replacement
$content=templatereplace(file_get_contents($oTemplate->viewPath.'/printanswers.pstpl'),array('ANSWERTABLE'=>$sOutput),$this->aGlobalData);
$content=templatereplace(file_get_contents($oTemplate->pstplPath.'/printanswers.pstpl'),array('ANSWERTABLE'=>$sOutput),$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$sOutput));
App()->end();
}
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/RegisterController.php
Expand Up @@ -218,7 +218,7 @@ public function getRegisterForm($iSurveyId)
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
$aData['languagechanger'] = makeLanguageChangerSurvey(App()->language);
$oTemplate = Template::model()->getInstance(null, $iSurveyId);
return templatereplace(file_get_contents($oTemplate->viewPath . "/register.pstpl"),$aReplacement,$aData);
return templatereplace(file_get_contents($oTemplate->pstplPath . "/register.pstpl"),$aReplacement,$aData);
}

/**
Expand Down Expand Up @@ -478,7 +478,7 @@ private function display($iSurveyId)
$this->aReplacementData['content']=self::getRegisterForm($iSurveyId);
}else{
// Must use message.pstpl
$this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->viewPath . "/message.pstpl"),
$this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->pstplPath . "/message.pstpl"),
array(
'MESSAGEID'=>'register-message',
'ERROR'=>'',
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/SurveyController.php
Expand Up @@ -128,7 +128,7 @@ function renderExitMessage($iSurveyId,$sType,$aMessages=array(),$aUrl=null,$aErr
$aReplacementData['MESSAGE']=$message;
$aReplacementData['URL']=$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);
$content=templatereplace(file_get_contents($oTemplate->pstplPath."message.pstpl"),$aReplacementData,$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$content));
App()->end();
}
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/printablesurvey.php
Expand Up @@ -81,7 +81,7 @@ function index($surveyid, $lang = null)
//Fix $templatename : control if print_survey.pstpl exist
$oTemplate = Template::model()->getTemplateConfiguration($templatename);
$sFullTemplatePath = $oTemplate->path;
if($oTemplate->viewPath . DIRECTORY_SEPARATOR . 'print_survey.pstpl')
if($oTemplate->pstplPath . DIRECTORY_SEPARATOR . 'print_survey.pstpl')
{
$templatename = $templatename;// Change nothing
}
Expand Down Expand Up @@ -1596,7 +1596,7 @@ function index($surveyid, $lang = null)
*/
private function _populate_template( $oTemplate, $template , $input , $line = '')
{
$full_path = $oTemplate->viewPath.DIRECTORY_SEPARATOR.'print_'.$template.'.pstpl';
$full_path = $oTemplate->pstplPath.DIRECTORY_SEPARATOR.'print_'.$template.'.pstpl';
$full_constant = 'TEMPLATE'.$template.'.pstpl';
if(!defined($full_constant))
{
Expand Down
228 changes: 0 additions & 228 deletions application/controllers/admin/questions.php
Expand Up @@ -1865,234 +1865,6 @@ public function ajaxchecklabel()
}
}


/**
* Load preview of a question screen.
*
* @access public
* @param int $surveyid
* @param int $qid
* @param string $lang
* @return void
* @deprecated THIS IS OBSOLETE AS QUESTION PREVIEW IS NOW HANDLED BY controllers/survey/index.php
*/
public function preview($surveyid, $qid, $lang = null)
{
$surveyid = sanitize_int($surveyid);
$qid = sanitize_int($qid);
$LEMdebugLevel=0;

Yii::app()->loadHelper("qanda");
Yii::app()->loadHelper("surveytranslator");

if (empty($surveyid))
$this->getController()->error('No Survey ID provided');
if (empty($qid))
$this->getController()->error('No Question ID provided');

if (empty($lang))
$language = Survey::model()->findByPk($surveyid)->language;
else
$language = $lang;

if (!isset(Yii::app()->session['step'])) { Yii::app()->session['step'] = 0; }
if (!isset(Yii::app()->session['prevstep'])) { Yii::app()->session['prevstep'] = 0; }
if (!isset(Yii::app()->session['maxstep'])) { Yii::app()->session['maxstep'] = 0; }

// Use $_SESSION instead of $this->session for frontend features.
$_SESSION['survey_'.$surveyid]['s_lang'] = $language;
$_SESSION['survey_'.$surveyid]['fieldmap'] = createFieldMap($surveyid, 'full', true, $qid, $language);


// Prefill question/answer from defaultvalues
foreach ($_SESSION['survey_'.$surveyid]['fieldmap'] as $field)
if (isset($field['defaultvalue']))
$_SESSION['survey_'.$surveyid][$field['fieldname']] = $field['defaultvalue'];

App()->setLanguage($language);

$thissurvey = getSurveyInfo($surveyid);

setNoAnswerMode($thissurvey);

$qrows = Question::model()->findByAttributes(array('sid' => $surveyid, 'qid' => $qid, 'language' => $language))->getAttributes();

$ia = array(
0 => $qid,
1 => $surveyid . 'X' . $qrows['gid'] . 'X' . $qid,
2 => $qrows['title'],
3 => $qrows['question'],
4 => $qrows['type'],
5 => $qrows['gid'],
6 => $qrows['mandatory'],
7 => 'N',
8 => 'N'
);

$radix=getRadixPointData($thissurvey['surveyls_numberformat']);
$radix = $radix['separator'];
$surveyOptions = array(
'radix'=>$radix,
'tempdir'=>Yii::app()->getConfig('tempdir')
);
LimeExpressionManager::StartSurvey($surveyid, 'question', $surveyOptions, false, $LEMdebugLevel);
$qseq = LimeExpressionManager::GetQuestionSeq($qid);
$moveResult = LimeExpressionManager::JumpTo($qseq + 1, true, false, true);

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

$oTemplate = Template::model()->getInstance(null, $surveyid);
$sTemplatePath = $oTemplate->path;
$thistpl = $oTemplate->viewPath;

doHeader();

$showQuestion = "$('#question$qid').show();";
$dummy_js = <<< EOD
<script type='text/javascript'>
<!--
LEMradix='$radix';
var numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');
var intRegex = new RegExp('[^-0-9]','g');
function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
newval = new String(value);
if (typeof intonly !=='undefined' && intonly==1) {
newval = newval.replace(intRegex,'');
}
else {
newval = newval.replace(numRegex,'');
}
if (LEMradix === ',') {
newval = newval.split(',').join('.');
}
if (newval != '-' && newval != '.' && newval != '-.' && newval != parseFloat(newval)) {
newval = '';
}
displayVal = newval;
if (LEMradix === ',') {
displayVal = displayVal.split('.').join(',');
}
if (name.match(/other$/)) {
$('#answer'+name+'text').val(displayVal);
}
$('#answer'+name).val(displayVal);
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
}
checkconditions(newval, name, type, evt_type);
}
function checkconditions(value, name, type, evt_type)
{
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
}
if (type == 'radio' || type == 'select-one')
{
var hiddenformname='java'+name;
document.getElementById(hiddenformname).value=value;
}
else if (type == 'checkbox')
{
if (document.getElementById('answer'+name).checked)
{
$('#java'+name).val('Y');
} else
{
$('#java'+name).val('');
}
}
else if (type == 'text' && name.match(/other$/) && typeof document.getElementById('java'+name) !== 'undefined' && document.getElementById('java'+name) != null)
{
$('#java'+name).val(value);
}
ExprMgr_process_relevance_and_tailoring(evt_type,name,type);
$showQuestion
}
$(document).ready(function() {
$showQuestion
});
$(document).change(function() {
$showQuestion
});
$(document).bind('keydown',function(e) {
if (e.keyCode == 9) {
$showQuestion
return true;
}
return true;
});
// -->
</script>
EOD;


$answer = $answers[0][1];
// $help = $answers[0][2];

$qinfo = LimeExpressionManager::GetQuestionStatus($qid);
$help = $qinfo['info']['help'];


$question = $answers[0][0];
$question['code'] = $answers[0][5];
$question['class'] = getQuestionClass($qrows['type']);
$question['essentials'] = 'id="question' . $qrows['qid'] . '"';
$question['sgq'] = $ia[1];
$question['aid']='unknown';
$question['sqid']='unknown';

if ($qrows['mandatory'] == 'Y')
$question['man_class'] = ' mandatory';
else
$question['man_class'] = '';

$redata = compact(array_keys(get_defined_vars()));
$content = templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata);
$content .= CHtml::form('index.php', 'post', array('id'=>"limesurvey",'name'=>"limesurvey",'autocomplete'=>'off', 'class'=>'survey-form-container Questions'));
$content .= templatereplace(file_get_contents("$thistpl/startgroup.pstpl"), array(), $redata);

$question_template = file_get_contents("$thistpl/question.pstpl");
// the following has been added for backwards compatiblity.
if (substr_count($question_template, '{QUESTION_ESSENTIALS}') > 0)
{
// LS 1.87 and newer templates
$content .= "\n" . templatereplace($question_template, array(), $redata, 'Unspecified', false, $qid) . "\n";
}
else
{
// LS 1.86 and older templates
$content .= '<div ' . $question['essentials'] . ' class="' . $question['class'] . $question['man_class'] . '">';
$content .= "\n" . templatereplace($question_template, array(), $redata, 'Unspecified', false, $qid) . "\n";
$content .= "\n\t</div>\n";
};

$content .= templatereplace(file_get_contents("$thistpl/endgroup.pstpl"), array(), $redata) . $dummy_js;
LimeExpressionManager::FinishProcessingGroup();
$content .= LimeExpressionManager::GetRelevanceAndTailoringJavaScript();
$content .= '<p>&nbsp;</form>';
$content .= templatereplace(file_get_contents("$thistpl/endpage.pstpl"), array(), $redata);

LimeExpressionManager::FinishProcessingPage();

echo $content;

if ($LEMdebugLevel >= 1) {
echo LimeExpressionManager::GetDebugTimingMessage();
}
if ($LEMdebugLevel >= 2) {
echo "<table><tr><td align='left'><b>Group/Question Validation Results:</b>".$moveResult['message']."</td></tr></table>\n";
}

echo "</html>\n";

exit;
}

/**
* function ajaxValidate
*/
Expand Down

0 comments on commit 16c8d08

Please sign in to comment.