Skip to content

Commit

Permalink
New feature #11797: Allow template to use some class in default core …
Browse files Browse the repository at this point in the history
…message: message.pstpl

Dev: move some message to this new pstpl file
Dev: surely some more todo
  • Loading branch information
Shnoulle committed Oct 15, 2016
1 parent a027f11 commit 9cad06b
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 98 deletions.
44 changes: 44 additions & 0 deletions application/controllers/SurveyController.php
Expand Up @@ -87,4 +87,48 @@ public function actions()
);
}

//~ /**
//~ * Reset the session
//~ **/
//~ function resetSession($iSurveyId)
//~ {

//~ }
/**
* Show a message and exit
* @param string $sType : type of message
* @param string[] $aMessage : string for the messageconstructed via array of string
* @param array[null : $aUrl : if url can/must be set
* @return void
**/
function renderExitMessage($iSurveyId,$sType,$aMessages=array(),$aUrl=null,$aErrors=null)
{
$this->layout='survey';
$oTemplate = Template::model()->getInstance('', $iSurveyId);
$this->sTemplate=$oTemplate->sTemplateName;
$message=$this->renderPartial("/survey/system/message",array(
'aMessage'=>$aMessages
),true);
if(!empty($aUrl)){
$url=$this->renderPartial("/survey/system/url",$aUrl,true);
}else{
$url="";
}
if(!empty($aErrors)){
$error=$this->renderPartial("/survey/system/error",array(
'aErrors'=>$aErrors
),true);
}else{
$error="";
}
/* Set the data for templatereplace */
$this->aGlobalData['thissurvey']=getSurveyInfo($iSurveyId); /* Did we need it, or did we just use Yii::app()->getConfig('surveyID'); ? */
$aReplacementData['MESSAGEID']=$sType;
$aReplacementData['MESSAGE']=$message;
$aReplacementData['URL']=$url;
$aReplacementData['ERROR']=$error;
$content=templatereplace(file_get_contents($oTemplate->viewPath."message.pstpl"),$aReplacementData,$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$content));
App()->end();
}
}
204 changes: 127 additions & 77 deletions application/controllers/survey/index.php
Expand Up @@ -143,37 +143,65 @@ function action()
if ( $this->_isClientTokenDifferentFromSessionToken($clienttoken,$surveyid) )
{
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",array('token'=>$clienttoken,'lang'=>App()->language,'newtest'=>'Y'));
$asMessage = array(
gT('Token mismatch'),
gT('The token you provided doesn\'t match the one in your session.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".gT("Click here to start the survey.")."</a>"
$aErrors=array(gT('Token mismatch'));
$asMessage = array(gT('The token you provided doesn\'t match the one in your session.'));
$aUrl=array(
'url'=>$sReloadUrl,
'type'=>'restartsurvey',
'description'=>gT("Click here to start the survey.")
);
killSurveySession($surveyid);
App()->getController()->renderExitMessage(
$surveyid,
'restart-survey',
$aMessage,
$aUrl,
$aErrors
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

if ( $this->_isSurveyFinished($surveyid) && ($thissurvey['alloweditaftercompletion'] != 'Y' || $thissurvey['tokenanswerspersistence'] != 'Y')) // No test for response update
{
$aReloadUrlParam=array('lang'=>App()->language,'newtest'=>'Y');
if($clienttoken){$aReloadUrlParam['token']=$clienttoken;}
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",$aReloadUrlParam);
$asMessage = array(
gT('Previous session is set to be finished.'),
gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".gT("Click here to start the survey.")."</a>"
if($clienttoken){
$aReloadUrlParam['token']=$clienttoken;
}
$aErrors=array(gT('Previous session is set to be finished.'));
$aMessage = array(
gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'),
);
$aUrl=array(
'url'=>$this->getController()->createUrl("/survey/index/sid/{$surveyid}",$aReloadUrlParam),
'type'=>'restartsurvey',
'description'=>gT("Click here to start the survey.")
);
killSurveySession($surveyid);
App()->getController()->renderExitMessage(
$surveyid,
'restart-survey',
$aMessage,
$aUrl,
$aErrors
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

$previewmode=false;
if (isset($param['action']) && (in_array($param['action'],array('previewgroup','previewquestion'))))
{
if(!$this->_canUserPreviewSurvey($surveyid))
{
$asMessage = array(
gT('Error'),
gT("We are sorry but you don't have permissions to do this.")
// @todo : throw a 401
$aErrors=array(gT('Error'));
$aMessage = array(
gT("We are sorry but you don't have permissions to do this."),
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'norights-410',
$aMessage,
null,
$aErrors
);
}
else
{
Expand All @@ -188,12 +216,18 @@ function action()

if ($bPreviewRight === false)
{
$asMessage = array(
gT("Error"),
gT("We are sorry but you don't have permissions to do this."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])
// @todo : throw a 401
$aErrors=array(gT('Error'));
$aMessage = array(
gT("We are sorry but you don't have permissions to do this."),
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'norights-410',
$aMessage,
null,
$aErrors
);
}
}

Expand All @@ -209,14 +243,17 @@ function action()

if ( $this->_didSessionTimeOut($surveyid) )
{
// @TODO is this still required ?
$asMessage = array(
gT("Error"),
gT("We are sorry but your session has expired."),
$aErrors=array(gT('We are sorry but your session has expired.'));
$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."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'session-timeout',
$aMessage,
null,
$aErrors
);
};


Expand Down Expand Up @@ -275,58 +312,65 @@ function action()
//MAKE SURE SURVEY HASN'T EXPIRED
if ($thissurvey['expiry']!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)>$thissurvey['expiry'] && $thissurvey['active']!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
gT("Error"),
gT("We are sorry but the survey is expired and no longer available."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])
$aErrors=array(gT('Error'));
$aMessage = array(
gT("We are sorry but the survey is expired and no longer available."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail']) /* Maybe better to move this to a global replacement 'surveycontact' */
);

$this->_niceExit($redata, __LINE__, $thissurvey['templatedir'], $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'survey-expiry',
$aMessage,
$aErrors
);
}

//MAKE SURE SURVEY IS ALREADY VALID
if ($thissurvey['startdate']!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)<$thissurvey['startdate'] && $thissurvey['active']!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
gT("Error"),
gT("This survey is not yet started."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])
$aErrors=array(gT('Error'));
$aMessage = array(
gT("This survey is not yet started."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])/* Maybe better to move this to a global replacement 'surveycontact' */
);
$this->_niceExit($redata, __LINE__, $thissurvey['templatedir'], $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
$aErrors
);
}

//CHECK FOR PREVIOUSLY COMPLETED COOKIE
//If cookies are being used, and this survey has been completed, a cookie called "PHPSID[sid]STATUS" will exist (ie: SID6STATUS) and will have a value of "COMPLETE"
$sCookieName="LS_".$surveyid."_STATUS";
if (isset($_COOKIE[$sCookieName]) && $_COOKIE[$sCookieName] == "COMPLETE" && $thissurvey['usecookie'] == "Y" && $tokensexist != 1 && (!isset($param['newtest']) || $param['newtest'] != "Y"))
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
gT("Error"),
gT("You have already completed this survey."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])
$aErrors=array(gT('Error'));
$aMessage = array(
gT("You have already completed this survey."),
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])/* Maybe better to move this to a global replacement 'surveycontact' */
);

$this->_niceExit($redata, __LINE__, $thissurvey['templatedir'], $asMessage);
App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
$aErrors
);
}

//LOAD SAVED SURVEY
if (Yii::app()->request->getParam('loadall') == "reload")
{
$errormsg="";
$aLoadErrorMsg=array();
$sLoadName=Yii::app()->request->getParam('loadname');
$sLoadPass=Yii::app()->request->getParam('loadpass');
if ( isset($sLoadName) && !$sLoadName)
{
$errormsg .= gT("You did not provide a name")."<br />\n";
$aLoadErrorMsg['name']=gT("You did not provide a name.");
}
if ( isset($sLoadPass) && !$sLoadPass)
{
$errormsg .= gT("You did not provide a password")."<br />\n";
$aLoadErrorMsg['password']=gT("You did not provide a password.");
}

Expand All @@ -337,15 +381,12 @@ function action()
$sLoadSecurity=Yii::app()->request->getPost('loadsecurity');
$captcha = Yii::app()->getController()->createAction('captcha');
$captchaCorrect = $captcha->validate( $sLoadSecurity, false);

if(empty($sLoadSecurity))
{
$errormsg .= gT("You did not answer to the security question.")."<br />\n";
$aLoadErrorMsg['captchaempty']=gT("You did not answer to the security question.");
}
elseif ( !$captchaCorrect )
{
$errormsg .= gT("The answer to the security question is incorrect.")."<br />\n";
$aLoadErrorMsg['captcha']=gT("The answer to the security question is incorrect.");
}
}
Expand Down Expand Up @@ -439,12 +480,17 @@ function action()
{
$sError = gT("This is a controlled survey. You need a valid token to participate.");
}
$asMessage = array(
$sError,
$aMessage = array(
gT("We are sorry but you are not allowed to enter this survey."),
sprintf(gT("For further information please contact %s"), $thissurvey['adminname']." (<a href='mailto:{$thissurvey['adminemail']}'>"."{$thissurvey['adminemail']}</a>)")
sprintf(gT("Please contact %s ( %s ) for further assistance."),$thissurvey['adminname'],$thissurvey['adminemail'])/* Maybe better to move this to a global replacement 'surveycontact' */
);

App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
null,
array($sError)
);
$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
else
Expand Down Expand Up @@ -508,26 +554,30 @@ function action()
dbExecuteAssoc('DELETE FROM {{saved_control}} WHERE srid='.$_SESSION['survey_'.$surveyid]['srid'].' AND sid='.$surveyid);
}
killSurveySession($surveyid);
sendCacheHeaders();
doHeader();

$redata = compact(array_keys(get_defined_vars()));
$this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__);
echo "\n\n<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->\n"
."\t<script type='text/javascript'>\n"
."\t<!--\n"
."function checkconditions(value, name, type, evt_type)\n"
."\t{\n"
."\t}\n"
."\t//-->\n"
."\t</script>\n\n";

//Present the clear all page using clearall.pstpl template
$this->_printTemplateContent($thistpl.'/clearall.pstpl', $redata, __LINE__);

$this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__);
doFooter();
exit;
$content=templatereplace(file_get_contents($oTemplate->viewPath."clearall.pstpl"),array());
$this->getController()->layout='survey';
$this->getController()->render("/survey/system/display",array('content'=>$content));
App()->end();
//~ sendCacheHeaders();
//~ doHeader();

//~ $redata = compact(array_keys(get_defined_vars()));
//~ $this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__);
//~ echo "\n\n<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->\n"
//~ ."\t<script type='text/javascript'>\n"
//~ ."\t<!--\n"
//~ ."function checkconditions(value, name, type, evt_type)\n"
//~ ."\t{\n"
//~ ."\t}\n"
//~ ."\t//-->\n"
//~ ."\t</script>\n\n";

//~ //Present the clear all page using clearall.pstpl template
//~ $this->_printTemplateContent($thistpl.'/clearall.pstpl', $redata, __LINE__);

//~ $this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__);
//~ doFooter();
//~ exit;
}


Expand Down

0 comments on commit 9cad06b

Please sign in to comment.