Skip to content

Commit

Permalink
Dev : better fix #06210
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Jun 22, 2012
1 parent 3d53869 commit 7057cfd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion application/controllers/survey/index.php
Expand Up @@ -526,7 +526,7 @@ function sendreq(surveyid)
{
// delete the response but only if not already completed
$s_lang = $_SESSION['survey_'.$surveyid]['s_lang'];
if (isset($_SESSION['survey_'.$surveyid]['srid']))
if (isset($_SESSION['survey_'.$surveyid]['srid']) && !Survey_dynamic::model($surveyid)->isCompleted($_SESSION['survey_'.$surveyid]['srid']))
{
// delete the response but only if not already completed
$result= dbExecuteAssoc('DELETE FROM {{survey_'.$surveyid.'}} WHERE id='.$_SESSION['survey_'.$surveyid]['srid']." AND submitdate IS NULL");
Expand Down
10 changes: 4 additions & 6 deletions application/helpers/replacements_helper.php
Expand Up @@ -399,14 +399,11 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$_linkreplace='';
}

if(tableExists('{{tokens_'.$thissurvey['sid'].'}}') && $thissurvey['alloweditaftercompletion'] == 'Y')
if(isset($surveyid) && !isset($saved_id) && isset($_SESSION['survey_'.$surveyid]['srid']))
{
if (usedTokens($_token,$surveyid))
{
$dontclear=true;
}
$saved_id=$_SESSION['survey_'.$surveyid]['srid'];
}
if (isset($surveyid) && !isset($dontclear))
if (isset($surveyid) && !Survey_dynamic::model($surveyid)->isCompleted(isset($saved_id) ? $saved_id : 0))
{
$_clearall = "<input type='button' name='clearallbtn' value='" . $clang->gT("Exit and Clear Survey") . "' class='clearall' "
. "onclick=\"if (confirm('" . $clang->gT("Are you sure you want to clear all your responses?", 'js') . "')) {\nwindow.open('".Yii::app()->getController()->createUrl("survey/index/sid/$surveyid?move=clearall&amp;lang=" . $s_lang);
Expand All @@ -421,6 +418,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
{
$_clearall = "";
}

if (isset(Yii::app()->session['datestamp']))
{
$_datestamp = Yii::app()->session['datestamp'];
Expand Down
26 changes: 26 additions & 0 deletions application/models/Survey_dynamic.php
Expand Up @@ -145,5 +145,31 @@ public function addTokenCriteria($condition)
return $newCriteria;
}

/**
* Return true if actual survey is completed
*
* @param $srid : actual save survey id
*
* @return boolean
*/
public function isCompleted($srid)
{
$sid = self::$sid;
$completed=false;

if(Yii::app()->db->schema->getTable($this->tableName())){
$data=Yii::app()->db->createCommand()
->select("submitdate")
->from($this->tableName())
->where('id=:id', array(':id'=>$srid))
->queryRow();
if($data && $data['submitdate'])
{
$completed=true;
}
}
return $completed;
}

}
?>

0 comments on commit 7057cfd

Please sign in to comment.