Skip to content

Commit

Permalink
Fixed #6961: CDbException unbuffered queries active when accessing su…
Browse files Browse the repository at this point in the history
…rvey or db analysis
  • Loading branch information
mennodekker committed Nov 26, 2012
1 parent 6f988c0 commit 8acdca1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 11 additions & 7 deletions application/controllers/survey/index.php
Expand Up @@ -312,7 +312,7 @@ function sendreq(surveyid)
$thissurvey=getSurveyInfo($surveyid, $_SESSION['survey_'.$surveyid]['s_lang']);

//SEE IF SURVEY USES TOKENS
if ($surveyExists == 1 && tableExists('{{tokens_'.$thissurvey['sid'].'}}'))
if ($surveyExists == 1 && Survey::model()->hasTokens($surveyid))
{
$tokensexist = 1;
}
Expand Down Expand Up @@ -445,7 +445,7 @@ function sendreq(surveyid)
// this check is done in buildsurveysession and error message
// could be more interresting there (takes into accound captcha if used)
if ($tokensexist == 1 && isset($token) && $token &&
isset($_SESSION['survey_'.$surveyid]['step']) && $_SESSION['survey_'.$surveyid]['step']>0 && tableExists("tokens_{$surveyid}}}"))
isset($_SESSION['survey_'.$surveyid]['step']) && $_SESSION['survey_'.$surveyid]['step']>0)
{
//check if tokens actually haven't been already used
$areTokensUsed = usedTokens(trim(strip_tags(returnGlobal('token'))),$surveyid);
Expand Down Expand Up @@ -477,16 +477,20 @@ function sendreq(surveyid)
$this->_niceExit($redata, __LINE__, $thistpl, $aMessage, true);
}
}
if ($tokensexist == 1 && isset($token) && $token && tableExists("{{tokens_".$surveyid."}}")) //check if token is in a valid time frame
if ($tokensexist == 1 && isset($token) && $token) //check if token is in a valid time frame
{
// check also if it is allowed to change survey after completion
if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
$tkquery = "SELECT * FROM {{tokens_".$surveyid."}} WHERE token='".$token."'";
$condition = '';
} else {
$tkquery = "SELECT * FROM {{tokens_".$surveyid."}} WHERE token='".$token."' AND (completed = 'N' or completed='')";
$condition = "(completed = 'N' or completed='')";
}
$tkresult = Tokens_dynamic::model($surveyid)->findAllByAttributes(array('token'=>$token), $condition);
if (count($tkresult)>0) {
$tokendata = array_shift($tkresult);
} else {
$tokendata = array();
}
$tkresult = dbExecuteAssoc($tkquery); //Checked
$tokendata = $tkresult->read();
if (isset($tokendata['validfrom']) && (trim($tokendata['validfrom'])!='' && $tokendata['validfrom']>dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)) ||
isset($tokendata['validuntil']) && (trim($tokendata['validuntil'])!='' && $tokendata['validuntil']<dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)))
{
Expand Down
9 changes: 9 additions & 0 deletions application/helpers/database_helper.php
Expand Up @@ -13,6 +13,15 @@
*
* $Id$
*/


/**
*
* @param type $sql
* @param type $inputarr
* @param type $silent
* @return CDbDataReader
*/
function dbExecuteAssoc($sql,$inputarr=false,$silent=true)
{
$error = '';
Expand Down

0 comments on commit 8acdca1

Please sign in to comment.