Skip to content

Commit

Permalink
Fixed issue: only load answer with token if tokenanswerspersistence i…
Browse files Browse the repository at this point in the history
…s Yes

Dev: use model to get attributes
Dev: need some fix in token to be really tested (do a quick fix for testing purpose, but do not pull)
  • Loading branch information
Shnoulle committed Sep 20, 2013
1 parent 71a9cf0 commit 81a30cf
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions application/controllers/survey/index.php
Expand Up @@ -490,10 +490,9 @@ function sendreq(surveyid)
{
// check also if it is allowed to change survey after completion
if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
$tokenInstance = Token::model($surveyid)->usable()->findByAttributes(array('token' => $token));
$tokenInstance = Token::model($surveyid)->usable()->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))
{
Expand Down Expand Up @@ -609,17 +608,17 @@ function sendreq(surveyid)
if (!isset($_SESSION['survey_'.$surveyid]['srid']) && $thissurvey['anonymized'] == "N" && $thissurvey['active'] == "Y" && isset($token) && $token !='')
{
// load previous answers if any (dataentry with nosubmit)
$sQuery="SELECT id,submitdate,lastpage FROM {$thissurvey['tablename']} WHERE {$thissurvey['tablename']}.token='{$token}' order by id desc";
$aRow = Yii::app()->db->createCommand($sQuery)->queryRow();
if ( $aRow )
//$oSurveyTokenInstance=SurveyDynamic::model($surveyid)->find(array('select'=>'id,submitdate,lastpage', 'condition'=>'token=:token', 'order'=>'id DESC','params'=>array('token' => $token)));
$oSurveyTokenInstance=SurveyDynamic::model($surveyid)->find(array('condition'=>'token=:token', 'order'=>'id DESC','params'=>array('token' => $token)));
if ( $oSurveyTokenInstance )
{
if(($aRow['submitdate']=='' && $thissurvey['tokenanswerspersistence'] == 'Y' )|| ($aRow['submitdate']!='' && $thissurvey['alloweditaftercompletion'] == 'Y'))
if((empty($oSurveyTokenInstance->submitdate) || $thissurvey['alloweditaftercompletion'] == 'Y' ) && $thissurvey['tokenanswerspersistence'] == 'Y')
{
$_SESSION['survey_'.$surveyid]['srid'] = $aRow['id'];
if (!is_null($aRow['lastpage']) && $aRow['submitdate']=='')
$_SESSION['survey_'.$surveyid]['srid'] = $oSurveyTokenInstance->id;
if (!empty($oSurveyTokenInstance->lastpage) && empty($oSurveyTokenInstance->submitdate))
{
$_SESSION['survey_'.$surveyid]['LEMtokenResume'] = true;
$_SESSION['survey_'.$surveyid]['step'] = $aRow['lastpage'];
$_SESSION['survey_'.$surveyid]['step'] = $oSurveyTokenInstance->lastpage;
}
}
buildsurveysession($surveyid);
Expand Down

0 comments on commit 81a30cf

Please sign in to comment.