Skip to content

Commit

Permalink
Dev: #11771: Review HTML produced for save/reload : do views
Browse files Browse the repository at this point in the history
Dev: Add a display.php view for all of this message (this fix a js out of body in save/load)
Dev: Move some core replacement to "where used" replacement
  • Loading branch information
Shnoulle committed Oct 13, 2016
1 parent f2b923e commit 97703ea
Show file tree
Hide file tree
Showing 23 changed files with 391 additions and 249 deletions.
2 changes: 1 addition & 1 deletion application/controllers/SurveyController.php
Expand Up @@ -71,7 +71,7 @@ public function actions()
'uploader' => 'application.controllers.uploader',
'verification' => 'application.controllers.verification',
'captcha' => array(
'class' => 'CCaptchaAction',
'class' => 'CCaptchaAction',
'backColor'=>0xf6f6f6
)
);
Expand Down
21 changes: 15 additions & 6 deletions application/controllers/survey/index.php
Expand Up @@ -316,15 +316,18 @@ function action()
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.");
}

// if security question answer is incorrect
Expand All @@ -333,15 +336,17 @@ function action()
{
$sLoadSecurity=Yii::app()->request->getPost('loadsecurity');
$captcha = Yii::app()->getController()->createAction('captcha');
$captchaCorrect = $captcha->validate( $sLoadsecurity, false);
$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 All @@ -352,23 +357,27 @@ function action()
Yii::app()->setConfig('move','reload');
$move = "reload";// veyRunTimeHelper use $move in $arg
} else {
$errormsg .= gT("There is no matching saved survey");
$aLoadErrorMsg['matching']=gT("There is no matching saved survey.");
}
randomizationGroupsAndQuestions($surveyid);
initFieldArray($surveyid, $_SESSION['survey_' . $surveyid]['fieldmap']);
}
if ($errormsg) {
if (count($aLoadErrorMsg)) {
Yii::app()->setConfig('move',"loadall");// Show loading form
}
}

//Allow loading of saved survey
if (Yii::app()->getConfig('move')=="loadall")
{
$redata = compact(array_keys(get_defined_vars()));
$aLoadErrorMsg=empty($aLoadErrorMsg) ? null : $aLoadErrorMsg; // Set tit to null if empty
Yii::import("application.libraries.Load_answers");
$tmp = new Load_answers();
$tmp->run($redata);
$tmp->run(array(
"surveyid"=>$surveyid, // Not really needed : already in App()->getConfig('surveyID')
"aLoadErrorMsg"=>$aLoadErrorMsg,
"clienttoken"=>isset($clienttoken)? $clienttoken : null ,
));
}


Expand Down
16 changes: 7 additions & 9 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -617,20 +617,17 @@ function run($surveyid,$args)
display_first_page();
Yii::app()->end(); // So we can still see debug messages
}

// TODO FIXME
if ($thissurvey['active'] == "Y") {
Yii::import("application.libraries.Save");
$cSave = new Save();
}
if ($thissurvey['active'] == "Y" && Yii::app()->request->getPost('saveall')) // Don't test if save is allowed
{
$bTokenAnswerPersitance = $thissurvey['tokenanswerspersistence'] == 'Y' && isset($surveyid) && tableExists('tokens_'.$surveyid);
// must do this here to process the POSTed values
$moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false); // by jumping to current step, saves data so far
if (!isset($_SESSION[$LEMsessid]['scid']) && !$bTokenAnswerPersitance )
{
$cSave->showsaveform(); // generates a form and exits, awaiting input
Yii::import("application.libraries.Save");
$cSave = new Save();
$cSave->showsaveform($thissurvey['sid']); // generates a form and exits, awaiting input
}
else
{
Expand All @@ -648,11 +645,12 @@ function run($surveyid,$args)
{
// The response from the save form
// CREATE SAVED CONTROL RECORD USING SAVE FORM INFORMATION
Yii::import("application.libraries.Save");
$cSave = new Save();
$popup = $cSave->savedcontrol();

if (isset($errormsg) && $errormsg != "")
if (!empty($cSave->aSaveErrors))
{
$cSave->showsaveform(); // reshow the form if there is an error
$cSave->showsaveform($thissurvey['sid']); // reshow the form if there is an error
}

$moveResult = LimeExpressionManager::GetLastMoveResult(true);
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/common_helper.php
Expand Up @@ -5613,9 +5613,9 @@ function getHeader($meta = false)
}
$header.= " class=\"{$class}\">\n";
$header.= "\t<head>\n";
$header.= "<script type='text/javascript'>/*<![CDATA[*/(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement);/*]]>*/</script>";
if ($meta)
$header .= $meta;
App()->clientScript->registerScript("nojsReplace","(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement);",CClientScript::POS_HEAD);


if ( !$embedded )
Expand Down
13 changes: 5 additions & 8 deletions application/helpers/frontend_helper.php
Expand Up @@ -176,9 +176,10 @@ function makegraph($currentstep, $total)
/**
* This function creates the language selector for a particular survey
*
* @param mixed $sSelectedLanguage The language in which all information is shown
* @param string $sSelectedLanguage : lang to be selected (forced)
* @param boolean $withForm : add a form (method="get") around the select
*/
function makeLanguageChangerSurvey($sSelectedLanguage)
function makeLanguageChangerSurvey($sSelectedLanguage="",$withForm=false)
{
$surveyid = Yii::app()->getConfig('surveyID');
Yii::app()->loadHelper("surveytranslator");
Expand Down Expand Up @@ -216,24 +217,20 @@ function makeLanguageChangerSurvey($sSelectedLanguage)
$sTargetURL=null;
}

/* @todo : find when we need a form , and how to set here */
$form=false;


$aListLang = array();
foreach ($aSurveyLangs as $sLangCode => $aSurveyLang)
{
$aListLang[$sLangCode]=html_entity_decode($aSurveyLang['nativedescription'], ENT_COMPAT,'UTF-8');
}
$sSelected=App()->language;
$sSelected=($sSelectedLanguage) ? $sSelectedLanguage : App()->language;

$languageChangerDatas = array(
'sSelected' => $sSelected ,
'aListLang' => $aListLang ,
'sClass' => $sClass ,
'targetUrl' => $sTargetURL,
);
if($form){
if($withForm){
$sHTMLCode = App()->getController()->renderPartial('/survey/system/LanguageChanger/LanguageChangerForm', $languageChangerDatas, true);
}else{
$sHTMLCode = App()->getController()->renderPartial('/survey/system/LanguageChanger/LanguageChanger', $languageChangerDatas, true);
Expand Down
142 changes: 16 additions & 126 deletions application/helpers/replacements_helper.php
Expand Up @@ -18,11 +18,15 @@
* NOTE - Don't do any embedded replacements in this function. Create the array of replacement values and
* they will be done in batch at the end
*
* @param mixed $line Text to search in
* @param mixed $replacements Array of replacements: Array( <stringtosearch>=><stringtoreplacewith>
* @param string $line Text to search in
* @param string[] $replacements Array of replacements: Array( <stringtosearch>=><stringtoreplacewith>
* @param array $redata : array of global var used in the function
* @param string $debugSrc deprecated
* @param boolean $anonymized Determines if token data is being used or just replaced with blanks
* @param questionNum - needed to support dynamic JavaScript-based tailoring within questions
* @param bStaticReplacement - Default off, forces non-dynamic replacements without <SPAN> tags (e.g. for the Completed page)
* @param integer|null $questionNum - needed to support dynamic JavaScript-based tailoring within questions
* @param null $registerdata - deprecated
* @param boolean bStaticReplacement - Default off, forces non-dynamic replacements without <SPAN> tags (e.g. for the Completed page)
* @param object|string - the template object to be used
* @return string Text with replaced strings
*/
function templatereplace($line, $replacements = array(), &$redata = array(), $debugSrc = 'Unspecified', $anonymized = false, $questionNum = NULL, $registerdata = array(), $bStaticReplacement = false, $oTemplate='')
Expand All @@ -45,7 +49,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
'percentcomplete',
'privacy',
's_lang',
'saved_id',
'showgroupinfo',
'showqnumcode',
'showxquestions',
Expand Down Expand Up @@ -82,7 +85,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$thissurvey=getSurveyInfo($_surveyid,$s_lang);
}
if (!isset($captchapath)) { $captchapath = ''; }
if (!isset($saved_id) && isset(Yii::app()->session['survey_'.$_surveyid]['srid'])) { $saved_id=Yii::app()->session['survey_'.$_surveyid]['srid'];}


Yii::app()->loadHelper('surveytranslator');
Expand Down Expand Up @@ -414,15 +416,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$_restart = "";
}

if (isset($thissurvey['anonymized']) && $thissurvey['anonymized'] == 'Y')
{
$_savealert = gT("To remain anonymous please use a pseudonym as your username, also an email address is not required.");
}
else
{
$_savealert = "";
}

if (isset($surveyid))
{
if($_token)
Expand All @@ -433,113 +426,17 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
{
$returnlink=Yii::app()->getController()->createUrl("survey/index/sid/{$surveyid}");
}
$_return_to_survey = "<a href='{$returnlink}'>".gT("Return to survey")."</a>";
if(isset(Yii::app()->session['survey_'.$_surveyid]['step'])){
$_return_to_survey = "<a href='{$returnlink}'>".gT("Return to survey")."</a>";
}else{
$_return_to_survey = "<a href='{$returnlink}'>".gT("Go to survey")."</a>";
}
}
else
{
$_return_to_survey = "";
}

// Save Form
$_saveform = "
<div class='save-survey-form form-horizontal'>
<div class='form-group save-survey-row save-survey-name'>
<label class='control-label col-sm-3 save-survey-label label-cell' for='savename'>" . gT("Name:") . "</label>
<div class='col-sm-7 save-survey-input input-cell'>
<input class='form-control' type='text' name='savename' id='savename' value='" . (isset($_POST['savename']) ? HTMLEscape(autoUnescape($_POST['savename'])) : '') . "' />
</div>
</div>
<div class='form-group save-survey-row save-survey-password-1'>
<label class='control-label col-sm-3 save-survey-label label-cell' for='savepass'>" . gT("Password:") . "</label>
<div class='col-sm-7 save-survey-input input-cell'>
<input class='form-control' type='password' id='savepass' name='savepass' value='" . (isset($_POST['savepass']) ? HTMLEscape(autoUnescape($_POST['savepass'])) : '')
. "' /></div></div>\n"

. " <div class='form-group save-survey-row save-survey-password-2'>
<label class='control-label col-sm-3 save-survey-label label-cell' for='savepass2'>" . gT("Repeat password:") . "</label>
<div class='col-sm-7 save-survey-input input-cell'>
<input class='form-control' type='password' id='savepass2' name='savepass2' value='" . (isset($_POST['savepass2']) ? HTMLEscape(autoUnescape($_POST['savepass2'])) : '')

. "' /></div></div>\n"

. " <div class='form-group save-survey-row save-survey-email'>
<label class='col-sm-3 control-label save-survey-label label-cell' for='saveemail'>" . gT("Your email address:") . "</label>
<div class='col-sm-7 save-survey-input input-cell'>
<input class='form-control' type='text' id='saveemail' name='saveemail' value='" . (isset($_POST['saveemail']) ? HTMLEscape(autoUnescape($_POST['saveemail'])) : '')

. "' /></div></div>\n";

if ( isset($thissurvey['usecaptcha']) && function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha']))
{
$_saveform .="
<div class='form-group save-survey-row save-survey-captcha'>
<label class='control-label col-sm-3 save-survey-label label-cell' for='loadsecurity'>" . gT("Security question:") . "</label>
<div class='col-sm-7 save-survey-input input-cell'>
<div class='input-group'>
<div class='input-group-addon captcha-image'>
<img alt='' src='".Yii::app()->getController()->createUrl('/verification/image/sid/'.((isset($surveyid)) ? $surveyid : ''))."' />
</div>
<input class='form-control' type='text' size='5' maxlength='3' id='loadsecurity' name='loadsecurity' value='' />
</div>
</div>
</div>\n";
}
$_saveform .= "
<div class='form-group save-survey-row save-survey-submit'>
<div class='form-group save-survey-input input-cell'>
<div class='col-sm-7 col-md-offset-3'>
<input class='btn btn-default' type='submit' id='savebutton' name='savesubmit' value='" . gT("Save Now") . "' />
</div>
</div>
</div>\n"
. "</div>
";
// End save form


// Load Form
$_loadform = "
<div class='load-survey-form form-horizontal'>
<div class='form-group load-survey-row load-survey-name'>
<label class='control-label col-sm-3 load-survey-label label-cell' for='loadname'>" . gT("Saved name:") . "</label>
<div class='col-sm-7 load-survey-input input-cell'>
<input class='form-control' type='text' id='loadname' name='loadname' value='' />
</div>
</div>
<div class='form-group load-survey-row load-survey-password'>
<label class='control-label col-sm-3 load-survey-label label-cell' for='loadpass'>" . gT("Password:") . "</label>
<div class='col-sm-7 load-survey-input input-cell'>
<input class='form-control' type='password' id='loadpass' name='loadpass' value='' />
</div>
</div>
";

if (isset($thissurvey['usecaptcha']) && function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha']))
{
$_loadform .="
<div class='form-group load-survey-row load-survey-captcha'>
<label class='control-label col-sm-3 load-survey-label label-cell' for='loadsecurity'>" . gT("Security question:") . "</label>
<div class='col-sm-7 load-survey-input input-cell'>
<div class='input-group'>
<div class='input-group-addon captcha-image' >
<img src='".Yii::app()->getController()->createUrl('/verification/image/sid/'.((isset($surveyid)) ? $surveyid : ''))."' alt='' />
</div>
<input class='form-control' type='text' size='5' maxlength='3' id='loadsecurity' name='loadsecurity' value='' alt=''/>
</div>
</div>
</div>
";
}

$_loadform .="
<div class='form-group load-survey-row load-survey-submit'>
<div class='col-sm-7 col-md-offset-3 load-survey-input input-cell'>
<input type='submit' id='loadbutton' class='btn btn-default' value='" . gT("Load now") . "' />
</div>
</div>
</div>
";

// Assessments
$assessmenthtml="";
if (isset($surveyid) && !is_null($surveyid) && function_exists('doAssessment'))
Expand Down Expand Up @@ -670,10 +567,8 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$coreReplacements['LANG'] = App()->language;
$coreReplacements['LANGUAGECHANGER'] = isset($languagechanger) ? $languagechanger : ''; // global
$coreReplacements['FLASHMESSAGE'] = makeFlashMessage(); // TODO: Really generate this each time function is called? Only relevant for startpage.tstpl
$coreReplacements['LOADERROR'] = isset($errormsg) ? $errormsg : ''; // global
$coreReplacements['LOADFORM'] = $_loadform;
$coreReplacements['LOADHEADING'] = gT("Load a previously saved survey");
$coreReplacements['LOADMESSAGE'] = gT("You can load a survey that you have previously saved from this screen.")."<br />".gT("Type in the 'name' you used to save the survey, and the password.")."<br />";


$coreReplacements['NAVIGATOR'] = isset($navigator) ? $navigator : ''; // global
$coreReplacements['MOVEPREVBUTTON'] = isset($moveprevbutton) ? $moveprevbutton : ''; // global
$coreReplacements['MOVENEXTBUTTON'] = isset($movenextbutton) ? $movenextbutton : ''; // global
Expand All @@ -688,12 +583,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$coreReplacements['RETURNTOSURVEY'] = $_return_to_survey;
$coreReplacements['SAVE_LINKS'] = $_savelinks;
$coreReplacements['SAVE'] = $_saveall;
$coreReplacements['SAVEALERT'] = $_savealert;
$coreReplacements['SAVEDID'] = isset($saved_id) ? $saved_id : ''; // global
$coreReplacements['SAVEERROR'] = isset($errormsg) ? $errormsg : ''; // global - same as LOADERROR
$coreReplacements['SAVEFORM'] = $_saveform;
$coreReplacements['SAVEHEADING'] = gT("Save your unfinished survey");
$coreReplacements['SAVEMESSAGE'] = gT("Enter a name and password for this survey and click save below.")."<br />\n".gT("Your survey will be saved using that name and password, and can be completed later by logging in with the same name and password.")."<br /><br />\n<span class='emailoptional'>".gT("If you give an email address, an email containing the details will be sent to you.")."</span><br /><br />\n".gT("After having clicked the save button you can either close this browser window or continue filling out the survey.");
$coreReplacements['SAVEDID'] = isset(Yii::app()->session['survey_'.$_surveyid]['srid']) ? Yii::app()->session['survey_'.$_surveyid]['srid']: '';
$coreReplacements['SID'] = Yii::app()->getConfig('surveyID','');// Allways use surveyID from config
$coreReplacements['SITENAME'] = Yii::app()->getConfig('sitename');
$coreReplacements['SITELOGO'] = $sitelogo;
Expand Down

0 comments on commit 97703ea

Please sign in to comment.