diff --git a/application/controllers/RegisterController.php b/application/controllers/RegisterController.php
index bb9fe70d4fe..8c7dd07d9c7 100644
--- a/application/controllers/RegisterController.php
+++ b/application/controllers/RegisterController.php
@@ -21,7 +21,16 @@
*/
class RegisterController extends LSYii_Controller {
- public $layout = 'bare';
+ /* @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= true;
/**
* The array of errors to be displayed
@@ -179,9 +188,9 @@ public function getRegisterForm($iSurveyId)
App()->getPluginManager()->dispatchEvent($event);
// Allow adding error or replace error with plugin ?
$this->aRegisterErrors=$event->get('aRegistersErrors');
- if(!is_null($event->get('registerForm')))
+ if(!is_null($event->get('registerForm'))){
return $event->get('registerForm');
-
+ }
$aFieldValue=$this->getFieldValue($iSurveyId);
$aRegisterAttributes=$this->getExtraAttributeInfo($iSurveyId);
$aData['iSurveyId'] = $iSurveyId;
@@ -191,27 +200,20 @@ public function getRegisterForm($iSurveyId)
$aData['sEmail'] = $aFieldValue['sEmail'];
$aData['aAttribute'] = $aFieldValue['aAttribute'];
$aData['aExtraAttributes']=$aRegisterAttributes;
- $aData['urlAction']=App()->createUrl('register/index',array('sid'=>$iSurveyId));
$aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha']);
- $aReplacement['REGISTERFORM']=$this->renderPartial('registerForm',$aData,true);
+ $aReplacement['REGISTERFORM'] = CHtml::form(App()->createUrl('register/index',array('sid'=>$iSurveyId)),'post',array('id'=>'limesurvey', 'role' => 'form', 'class' => 'ls-form'));
+ $aReplacement['REGISTERFORM'].= $this->renderPartial('/survey/frontpage/registerForm/form',$aData,true);
+ $aReplacement['REGISTERFORM'].= CHtml::endForm();
if(is_array($this->aRegisterErrors))
{
- $sRegisterError="
"
- .implode(' ',$this->aRegisterErrors)
- ."
";
+ $aReplacement['REGISTERERROR']=$this->renderPartial("/survey/frontpage/registerForm/error",array('aErrors'=>$this->aRegisterErrors),true);
}
else
{
- $sRegisterError='';
+ $aReplacement['REGISTERERROR']='';
}
-
- $aReplacement['REGISTERERROR'] = $sRegisterError;
- $aReplacement['REGISTERMESSAGE1'] = gT("You must be registered to complete this survey");
- if($sStartDate=$this->getStartDate($iSurveyId))
- $aReplacement['REGISTERMESSAGE2'] = sprintf(gT("You may register for this survey but you have to wait for the %s before starting the survey."),$sStartDate)." \n".gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately.");
- else
- $aReplacement['REGISTERMESSAGE2'] = gT("You may register for this survey if you wish to take part.")." \n".gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately.");
-
+ $aReplacement['REGISTERMESSAGE1']=$this->renderPartial("/survey/frontpage/registerForm/heading",array(),true);
+ $aReplacement['REGISTERMESSAGE2']=$this->renderPartial("/survey/frontpage/registerForm/message",array('sStartDate'=>$this->getStartDate($iSurveyId)),true);
$aData['thissurvey'] = $aSurveyInfo;
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
$aData['languagechanger'] = makeLanguageChangerSurvey(App()->language);
@@ -318,19 +320,18 @@ public function sendRegistrationEmail($iSurveyId,$iTokenId){
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent=$today;
$oToken->save();
- $this->sMessage=""
- . "
".gT("Thank you for registering to participate in this survey.")."
\n"
- . "
{$this->sMailMessage}
\n"
- . "
".sprintf(gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail'])."
"
- . "
\n";
+ $aMessage=array();
+ $aMessage['mail-thanks']=gT("Thank you for registering to participate in this survey.");
+ $aMessage['mail-message']=$this->sMailMessage;
+ $aMessage['mail-contact']=sprintf(gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail']);
+ $this->sMessage=$this->renderPartial('/survey/system/message',array('aMessage'=>$aMessage),true);
}
else
{
- $this->sMessage=""
- . "
".gT("Thank you for registering to participate in this survey.")."
\n"
- . "
".gT("You are registered but an error happened when trying to send the email - please contact the survey administrator.")."
\n"
- . "
".sprintf(gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail'])."
"
- . "
\n";
+ $aMessage['mail-thanks']=gT("Thank you for registering to participate in this survey.");
+ $aMessage['mail-message-error']=gT("You are registered but an error happened when trying to send the email - please contact the survey administrator.");
+ $aMessage['mail-contact']=sprintf(gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail']);
+ $this->sMessage=$this->renderPartial('/survey/system/message',array('aMessage'=>$aMessage),true);
}
// Allways return true : if we come here, we allways trye to send an email
return true;
@@ -461,39 +462,46 @@ public function getStartDate($iSurveyId){
private function display($iSurveyId)
{
$sLanguage=Yii::app()->language;
- $aData['surveyid']=$surveyid=$iSurveyId;
- $aData['thissurvey']=getSurveyInfo($iSurveyId,$sLanguage);
- $sTemplate=getTemplatePath($aData['thissurvey']['template']);
+ $this->aGlobalData['surveyid']=$surveyid=$iSurveyId;
+ $this->aGlobalData['thissurvey']=getSurveyInfo($iSurveyId,$sLanguage);
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
- $aData['sitename']=Yii::app()->getConfig('sitename');
- $aData['aRegisterErrors']=$this->aRegisterErrors;
- $aData['sMessage']=$this->sMessage;
+ $this->aReplacementData['sitename']=Yii::app()->getConfig('sitename');
+ $this->aReplacementData['aRegisterErrors']=$this->aRegisterErrors;
+ $this->aReplacementData['sMessage']=$this->sMessage;
- $oTemplate = Template::model()->getInstance('', $iSurveyId);
- Yii::app()->clientScript->registerPackage( 'survey-template' );
- sendCacheHeaders();
- doHeader();
- $aViewData['sTemplate']=$sTemplate;
+ $oTemplate = Template::model()->getInstance('', $iSurveyId);
+ Yii::app()->clientScript->registerPackage( 'survey-template' );
+
+ $this->sTemplate=$oTemplate->name;
if(!$this->sMessage){
- $aData['languagechanger']=makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission
- $aViewData['content']=self::getRegisterForm($iSurveyId);
+ $this->aGlobalData['languagechanger']=makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission
+ $this->aReplacementData['content']=self::getRegisterForm($iSurveyId);
}else{
- $aViewData['content']=templatereplace($this->sMessage);
+ // Must use message.pstpl
+ $this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->viewPath . "/message.pstpl"),
+ array(
+ 'MESSAGEID'=>'register-message',
+ 'ERROR'=>'',
+ 'MESSAGE'=>$this->sMessage,
+ )
+ ,$this->aGlobalData
+ );
+
}
- $aViewData['aData']=$aData;
// Test if we come from index or from register
if(empty(App()->clientScript->scripts)){
+ /* This surely can be moved to layout , but remove iot from surveyController before */
$oTemplate = Template::model()->getInstance('', $iSurveyId);
Yii::app()->clientScript->registerPackage( 'survey-template' );
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
useFirebug();
- $this->render('/register/display',$aViewData);
+ $this->layout='survey';
+ $this->render('/survey/system/display',$this->aReplacementData);
}else{
// Survey/index need renderPartial
- echo $this->renderPartial('/register/display',$aViewData, true, true);
+ echo $this->render('/survey/system/display',$this->aReplacementData, true, true);
}
- doFooter();
}
}
diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php
index 92bfc93d746..e99a997d2cb 100644
--- a/application/helpers/frontend_helper.php
+++ b/application/helpers/frontend_helper.php
@@ -265,17 +265,6 @@ function makeLanguageChanger($sSelectedLanguage)
'sClass' => $sClass ,
);
$sHTMLCode = Yii::app()->getController()->renderPartial('/surveys/LanguageChangerForm', $languageChangerDatas, true);
-
- //~ $sHTMLCode= CHtml::beginForm(App()->createUrl('surveys/publiclist'),'get', array('class' => 'form-horizontal'));
- //~ $sHTMLCode = Yii::app()->getController()->renderPartial('/survey/system/LanguageChanger/LanguageChanger', $languageChangerDatas, true);
- //~ $sHTMLCode.=CHtml::label(gT("Language:"), 'lang',array('class'=>'control-label col-xs-4 col-sm-8'));
- //~ $sHTMLCode .= "";
- //~ $sHTMLCode.= CHtml::dropDownList('lang', $sSelected,$aListLang,array('class'=>$sClass));
- //~ $sHTMLCode .= "
";
- //~ $sHTMLCode .= "";
- //~ $sHTMLCode.="".gT("Change the language")." ";
- //~ $sHTMLCode .= "
";
- //~ $sHTMLCode.= CHtml::endForm();
return $sHTMLCode;
}
else
@@ -905,6 +894,7 @@ function buildsurveysession($surveyid,$preview=false)
$sTemplatePath = $_SESSION['survey_'.$surveyid]['templatepath'];
$oTemplate = Template::model()->getInstance('', $surveyid);
+ App()->getController()->sTemplate=$oTemplate->name;
$sTemplatePath = $oTemplate->path;
$sTemplateViewPath = $oTemplate->viewPath;
@@ -940,7 +930,6 @@ function buildsurveysession($surveyid,$preview=false)
} else {
$oTokenEntry = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $clienttoken));
}
-
$subscenarios['tokenValid'] = ((!empty($oTokenEntry) && ($clienttoken != "")));
}
else
@@ -952,9 +941,8 @@ function buildsurveysession($surveyid,$preview=false)
if($scenarios['captchaRequired'])
{
//Check if the Captcha was correct
- $loadsecurity = returnGlobal('loadsecurity',true);
$captcha = Yii::app()->getController()->createAction('captcha');
- $subscenarios['captchaCorrect'] = $captcha->validate($loadsecurity, false);
+ $subscenarios['captchaCorrect'] = $captcha->validate(App()->getRequest()->getPost('loadsecurity'), false);
}
else
{
@@ -962,11 +950,14 @@ function buildsurveysession($surveyid,$preview=false)
$loadsecurity = false;
}
+
//RenderWay defines which html gets rendered to the user_error
// Possibilities are main,register,correct
$renderCaptcha = "";
$renderToken = "";
-
+ /**
+ * @todo : create 2 new function to create and call form
+ */
//Define array to render the partials
$aEnterTokenData = array();
$aEnterTokenData['bNewTest'] = false;
@@ -985,19 +976,28 @@ function buildsurveysession($surveyid,$preview=false)
$aEnterTokenData['sLoadpass'] = htmlspecialchars($loadpass);
}
- $FlashError = "";
+ $aEnterErrors=array();
+ // Scenario => Token required
+ if ($scenarios['tokenRequired'] && !$preview){
+ //Test if token is valid
+ list($renderToken, $FlashError) = testIfTokenIsValid($subscenarios, $thissurvey, $aEnterTokenData, $clienttoken);
+ if(!empty($FlashError)){
+ $aEnterErrors['token']=$FlashError;
+ }
+ }
// Scenario => Captcha required
if($scenarios['captchaRequired'] && !$preview) {
$FlashError = '';
- //Apply the captchaEnabled flag to the partial
+ //Apply the captcYii::app()->getRequest()->getPost($id);haEnabled flag to the partial
$aEnterTokenData['bCaptchaEnabled'] = true;
// IF CAPTCHA ANSWER IS NOT CORRECT OR NOT SET
if (!$subscenarios['captchaCorrect']) {
- if ($loadsecurity) {
- // was a bad answer
- $FlashError.=gT("Your answer to the security question was not correct - please try again.")." \n";
+ if(App()->getRequest()->getPost('loadsecurity')){
+ $aEnterErrors['captcha']=gT("Your answer to the security question was not correct - please try again.");
+ }elseif(null!==App()->getRequest()->getPost('loadsecurity')){
+ $aEnterErrors['captcha']=gT("Your must answer to the security question - please try again.");
}
$renderCaptcha='main';
}
@@ -1007,19 +1007,14 @@ function buildsurveysession($surveyid,$preview=false)
}
}
- // Scenario => Token required
- if ($scenarios['tokenRequired'] && !$preview){
- //Test if token is valid
- list($renderToken, $FlashError) = testIfTokenIsValid($subscenarios, $thissurvey, $aEnterTokenData, $clienttoken);
- }
-
//If there were errors, display through yii->FlashMessage
if($FlashError !== ""){
$aEnterTokenData['errorMessage'] = $FlashError;
}
-
+ $aEnterTokenData['aEnterErrors']=$aEnterErrors;
$renderWay = getRenderWay($renderToken, $renderCaptcha);
$redata = compact(array_keys(get_defined_vars()));
+ /* This funtion end if an form need to be shown */
renderRenderWayForm($renderWay, $redata, $scenarios, $sTemplateViewPath, $aEnterTokenData, $surveyid);
// Reset all the session variables and start again
@@ -1564,12 +1559,7 @@ function testIfTokenIsValid(array $subscenarios, array $thissurvey, array $aEnte
}
else
{ //token was wrong
- $errorMsg= ""
- . gT("The token you have provided is either not valid, or has already been used.")." \n"
- . sprintf( gT("For further information please contact %s"), $thissurvey['adminname'])
- . "("
- . $thissurvey['adminemail']." )";
-
+ $errorMsg= gT("The token you have provided is either not valid, or has already been used.");
$FlashError .= $errorMsg;
$renderToken='main';
@@ -1633,26 +1623,35 @@ function renderRenderWayForm($renderWay, array $redata, array $scenarios, $sTemp
{
switch($renderWay){
case "main": //Token required, maybe Captcha required
- sendCacheHeaders();
- doHeader();
- echo templatereplace(file_get_contents($sTemplateViewPath."startpage.pstpl"),array(),$redata,'frontend_helper[875]');
- echo templatereplace(file_get_contents($sTemplateViewPath."survey.pstpl"),array(),$redata,'frontend_helper[877]');
-
+ App()->getController()->layout="survey";
+ App()->getController()->aReplacementData=$aEnterTokenData;
+ App()->getController()->bStartSurvey=true;
// render token form
+
if($scenarios['tokenRequired']){
- App()->getController()->renderPartial('/survey/frontpage/enterToken', $aEnterTokenData);
+ $aReplacements['FORMID'] = 'token';
} else {
- App()->getController()->renderPartial('/survey/frontpage/enterCaptcha', $aEnterTokenData);
+ $aReplacements['FORMID'] = 'captcha';
}
-
- echo templatereplace(file_get_contents($sTemplateViewPath."endpage.pstpl"),array(),$redata,'frontend_helper[1645]');
- doFooter();
+ $aReplacements['FORMHEADING'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/heading",$aEnterTokenData,true);
+ $aReplacements['FORMMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/message",$aEnterTokenData,true);
+ $aReplacements['FORMERROR'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/error",$aEnterTokenData,true);
+
+ $aReplacements['FORM'] = CHtml::beginForm(array("/survey/index","sid"=>$surveyid), 'post',array('id'=>'form-'.$aReplacements['FORMID'],'class'=>'ls-form'));
+ $aReplacements['FORM'].= App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/form",$aEnterTokenData,true);
+ /* @ todo : some hidden field must be moved here : in controller */
+ $aReplacements['FORM'].= CHtml::endForm();
+ $content = templatereplace(file_get_contents($sTemplateViewPath."form.pstpl"),$aReplacements,$aData);
+ App()->getController()->render("/survey/system/display",array(
+ 'content'=>$content,
+ ));
Yii::app()->end();
break;
case "register": //Register new user
// Add the event and test if done
Yii::app()->runController("register/index/sid/{$surveyid}");
Yii::app()->end();
+ /* We never get here */
echo templatereplace(file_get_contents($sTemplateViewPath."register.pstpl"),array(),$redata,'frontend_helper[1751]');
break;
case "correct": //Nothing to hold back, render survey
diff --git a/application/libraries/Load_answers.php b/application/libraries/Load_answers.php
index cd66d776bb9..121b004f221 100644
--- a/application/libraries/Load_answers.php
+++ b/application/libraries/Load_answers.php
@@ -27,10 +27,10 @@ function run($args) {
$sTemplate=Survey::model()->findByPk($surveyid)->template;
$oTemplate = Template::model()->getInstance($sTemplate);
/* Construction of data for templatereplace */
- $aReplacements['LOADHEADING'] = App()->getController()->renderPartial("/survey/system/loadForm/heading",array(),true);
- $aReplacements['LOADMESSAGE'] = App()->getController()->renderPartial("/survey/system/loadForm/message",array(),true);
+ $aReplacements['LOADHEADING'] = App()->getController()->renderPartial("/survey/frontpage/loadForm/heading",array(),true);
+ $aReplacements['LOADMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/loadForm/message",array(),true);
if(!empty($aLoadErrorMsg)){
- $aReplacements['LOADERROR'] = App()->getController()->renderPartial("/survey/system/loadForm/error",array('aLoadErrorMsg'=>$aLoadErrorMsg),true);
+ $aReplacements['LOADERROR'] = App()->getController()->renderPartial("/survey/frontpage/loadForm/error",array('aLoadErrorMsg'=>$aLoadErrorMsg),true);
}else{
$aReplacements['LOADERROR'] = "";
}
@@ -40,7 +40,7 @@ function run($args) {
$captcha=null;
}
$loadForm = CHtml::beginForm(array("/survey/index","sid"=>$surveyid), 'post',array('id'=>'form-load'));
- $loadForm .= App()->getController()->renderPartial("/survey/system/loadForm/form",array('captcha'=>$captcha),true);
+ $loadForm .= App()->getController()->renderPartial("/survey/frontpage/loadForm/form",array('captcha'=>$captcha),true);
if ($clienttoken)
{
$loadForm .= CHtml::hiddenField('token',$clienttoken);
diff --git a/application/libraries/Save.php b/application/libraries/Save.php
index 13371d4141c..e29db01275a 100644
--- a/application/libraries/Save.php
+++ b/application/libraries/Save.php
@@ -80,13 +80,13 @@ function showsaveform($iSurveyId)
$sTemplate=$oSurvey->template;
$oTemplate = Template::model()->getInstance($sTemplate);
- $aReplacements['SAVEHEADING'] = App()->getController()->renderPartial("/survey/system/saveForm/heading",array(),true);
- $aReplacements['SAVEMESSAGE'] = App()->getController()->renderPartial("/survey/system/saveForm/message",array(),true);
+ $aReplacements['SAVEHEADING'] = App()->getController()->renderPartial("/survey/frontpage/saveForm/heading",array(),true);
+ $aReplacements['SAVEMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/saveForm/message",array(),true);
if($oSurvey->anonymized=="Y"){
- $aReplacements['SAVEALERT'] = App()->getController()->renderPartial("/survey/system/saveForm/anonymized",array(),true);
+ $aReplacements['SAVEALERT'] = App()->getController()->renderPartial("/survey/frontpage/saveForm/anonymized",array(),true);
}
if(!empty($this->aSaveErrors)){
- $aReplacements['SAVEERROR'] = App()->getController()->renderPartial("/survey/system/saveForm/error",array('aSaveErrors'=>$this->aSaveErrors),true);
+ $aReplacements['SAVEERROR'] = App()->getController()->renderPartial("/survey/frontpage/saveForm/error",array('aSaveErrors'=>$this->aSaveErrors),true);
}else{
$aReplacements['SAVEERROR'] = "";
}
@@ -96,8 +96,9 @@ function showsaveform($iSurveyId)
}else{
$captcha=null;
}
- $saveForm = CHtml::beginForm(array("/survey/index","sid"=>$iSurveyId), 'post',array('id'=>'form-save'));
- $saveForm .= App()->getController()->renderPartial("/survey/system/saveForm/form",array('captcha'=>$captcha),true);
+ $saveForm = CHtml::beginForm(array("/survey/index","sid"=>$iSurveyId), 'post',array('id'=>'form-save','class'=>'ls-form'));
+ $saveForm .= CHtml::hiddenField('savesubmit','save');
+ $saveForm .= App()->getController()->renderPartial("/survey/frontpage/saveForm/form",array('captcha'=>$captcha),true);
if ($clienttoken)
{
$saveForm .= CHtml::hiddenField('token',$clienttoken);
diff --git a/application/views/layouts/survey.php b/application/views/layouts/survey.php
index d577701eeaa..5e52b169581 100644
--- a/application/views/layouts/survey.php
+++ b/application/views/layouts/survey.php
@@ -30,15 +30,15 @@
getInstance($this->sTemplate);
+ App()->getClientScript()->registerPackage('fontawesome');
// 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->aReplacementData);
-
+ 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->aReplacementData);
+ echo templatereplace(file_get_contents($oTemplate->viewPath."survey.pstpl"),$this->aReplacementData,$this->aGlobalData);
}
echo $content;
- echo templatereplace(file_get_contents($oTemplate->viewPath."endpage.pstpl"),$this->aReplacementData,$this->aReplacementData);
+ echo templatereplace(file_get_contents($oTemplate->viewPath."endpage.pstpl"),$this->aReplacementData,$this->aGlobalData);
?>