Adding ldap Authentication to the limesurvey when survey is accesed by the user,

More
2 years 11 months ago #124546 by Prabhu2479
Prabhu2479 created the topic: Adding ldap Authentication to the limesurvey when survey is accesed by the user,
i want to add the LDAP authentication to the users who is accessing the survey for that i added the LDAP_bind code to the index.php which is in '\application\controllers\survey' it is not working , but the code is working the outside lime survey envirornment.
Original index page:-
class index extends CAction {

public function run()
{
/*
* Instead of manually rendering scripts after this function returns we
* use the callback. This ensures that scripts are always rendered, even
* if we call exit at some point in the code. (Which we shouldn't, but
* it happens.)
*/
// Ensure to set some var, but script are replaced in SurveyRuntimeHelper

$aLSJavascriptVar=array();
$aLSJavascriptVar=(int)(bool)Yii::app()->getConfig('bFixNumAuto',1);
$aLSJavascriptVar=(int)(bool)Yii::app()->getConfig('bNumRealValue',0);
$aLangData=getLanguageData();
$aRadix=getRadixPointData($aLangData[ Yii::app()->getConfig('defaultlang')]);
$aLSJavascriptVar=$aRadix;
$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar) . ';';
App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
App()->clientScript->registerScript('setJsVar',"setJsVar();",CClientScript::POS_BEGIN);// Ensure all js var is set before rendering the page (User can click before $.ready)

App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
useFirebug();

ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);
$this->action();
ob_flush();
}

function action()
{

global $surveyid;
global $thissurvey, $thisstep;
global $clienttoken, $tokensexist, $token;
global $clang;
$clang = Yii::app()->lang;
// only attempt to change session lifetime if using a DB backend
// with file based sessions, it's up to the admin to configure maxlifetime
if(isset(Yii::app()->session->connectionID)) {
@ini_set('session.gc_maxlifetime', Yii::app()->getConfig('iSessionExpirationTime'));
}

$this->_loadRequiredHelpersAndLibraries();

$param = $this->_getParameters(func_get_args(), $_POST);

$surveyid = $param;
Yii::app()->setConfig('surveyID',$surveyid);
$thisstep = $param;
$move=getMove();
Yii::app()->setConfig('move',$move);
$clienttoken = trim($param);
$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
if (is_null($thissurvey) && !is_null($surveyid)) $thissurvey = getSurveyInfo($surveyid);

// unused vars in this method (used in methods using compacted method vars)
@$loadname = $param;
@$loadpass = $param;
$sitename = Yii::app()->getConfig('sitename');

if (isset($param) && $param == "Y")
{
killSurveySession($surveyid);
}

$surveyExists=($surveyid && Survey::model()->findByPk($surveyid));
$isSurveyActive=($surveyExists && Survey::model()->findByPk($surveyid)->active=="Y");

// collect all data in this method to pass on later
$redata = compact(array_keys(get_defined_vars()));

$clang = $this->_loadLimesurveyLang($surveyid);

if ( $this->_isClientTokenDifferentFromSessionToken($clienttoken,$surveyid) )
{
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",array('token'=>$clienttoken,'lang'=>$clang->langcode,'newtest'=>'Y'));
$asMessage = array(
$clang->gT('Token mismatch'),
$clang->gT('The token you provided doesn\'t match the one in your session.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".$clang->gT("Click here to start the survey.")."</a>"
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

if ( $this->_isSurveyFinished($surveyid) && ($thissurvey != 'Y' || $thissurvey != 'Y')) // No test for response update
{
$aReloadUrlParam=array('lang'=>$clang->langcode,'newtest'=>'Y');
if($clienttoken){$aReloadUrlParam=$clienttoken;}
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",$aReloadUrlParam);
$asMessage = array(
$clang->gT('Previous session is set to be finished.'),
$clang->gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".$clang->gT("Click here to start the survey.")."</a>"
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

$previewmode=false;
if (isset($param) && (in_array($param,array('previewgroup','previewquestion'))))
{
if(!$this->_canUserPreviewSurvey($surveyid))
{
$asMessage = array(
$clang->gT('Error'),
$clang->gT("We are sorry but you don't have permissions to do this.")
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
}
else
{
if((intval($param) && $param=='previewquestion')) $previewmode='question';
if((intval($param) && $param=='previewgroup')) $previewmode='group';
}
}
Yii::app()->setConfig('previewmode',$previewmode);
if ( $this->_surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $isSurveyActive, $surveyExists) )
{
$bPreviewRight = $this->_userHasPreviewAccessSession($surveyid);

if ($bPreviewRight === false)
{
$asMessage = array(
$clang->gT("Error"),
$clang->gT("We are sorry but you don't have permissions to do this."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
}
}


// TODO can this be moved to the top?
// (Used to be global, used in ExpressionManager, merged into amVars. If not filled in === '')
// can this be added in the first computation of $redata?
if (isset($_SESSION))
{
$saved_id = $_SESSION;
//echo('Authorization success');
}
// recompute $redata since $saved_id used to be a global
$redata = compact(array_keys(get_defined_vars()));


if ( $this->_didSessionTimeOut($surveyid) )
{
// @TODO is this still required ?
$asMessage = array(
$clang->gT("Error"),
$clang->gT("We are sorry but your session has expired."),
$clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
};

// Set the language of the survey, either from POST, GET parameter of session var
// Keep the old value, because SetSurveyLanguage update $_SESSION
$sOldLang=isset($_SESSION)?$_SESSION:"";// Keep the old value, because SetSurveyLanguage update $_SESSION
if (!empty($param))
{
$sDisplayLanguage = $param;// $param take lang from returnGlobal and returnGlobal sanitize langagecode
}
elseif (isset($_SESSION))
{
$sDisplayLanguage = $_SESSION;
}
else
{
$sDisplayLanguage=Yii::app()->getConfig('defaultlang');
}

//CHECK FOR REQUIRED INFORMATION (sid)
if ($surveyid && $surveyExists)
{
LimeExpressionManager::SetSurveyId($surveyid); // must be called early - it clears internal cache if a new survey is being used
$clang = SetSurveyLanguage( $surveyid, $sDisplayLanguage);
if($previewmode) LimeExpressionManager::SetPreviewMode($previewmode);
if ($clang->langcode != $sOldLang) // Update the Session var only if needed
{
UpdateGroupList($surveyid, $clang->langcode); // to refresh the language strings in the group list session variable
UpdateFieldArray(); // to refresh question titles and question text
}
}
else
{
throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
}

// Get token
if (!isset($token))
{
$token=$clienttoken;
}

//GET BASIC INFORMATION ABOUT THIS SURVEY
$thissurvey=getSurveyInfo($surveyid, $_SESSION);

$event = new PluginEvent('beforeSurveyPage');
$event->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($event);
if (!is_null($event->get('template')))
{
$thissurvey = $event->get('template');
}

//SEE IF SURVEY USES TOKENS
if ($surveyExists == 1 && tableExists('{{tokens_'.$thissurvey.'}}'))
{
$tokensexist = 1;
}
else
{
$tokensexist = 0;
unset($_POST);
unset($param);
unset($token);
unset($clienttoken);
}

//SET THE TEMPLATE DIRECTORY

$thistpl = getTemplatePath($thissurvey);


$timeadjust = Yii::app()->getConfig("timeadjust");
//MAKE SURE SURVEY HASN'T EXPIRED
if ($thissurvey!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)>$thissurvey && $thissurvey!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("This survey is no longer available."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//MAKE SURE SURVEY IS ALREADY VALID
if ($thissurvey!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)<$thissurvey && $thissurvey!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("This survey is not yet started."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//CHECK FOR PREVIOUSLY COMPLETED COOKIE
//If cookies are being used, and this survey has been completed, a cookie called "PHPSID[sid]STATUS" will exist (ie: SID6STATUS) and will have a value of "COMPLETE"
$sCookieName="LS_".$surveyid."_STATUS";
if (isset($_COOKIE[$sCookieName]) && $_COOKIE[$sCookieName] == "COMPLETE" && $thissurvey == "Y" && $tokensexist != 1 && (!isset($param) || $param != "Y"))
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("You have already completed this survey."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//LOAD SAVED SURVEY
if (Yii::app()->request->getParam('loadall') == "reload")
{
$errormsg="";
$sLoadName=Yii::app()->request->getParam('loadname');
$sLoadPass=Yii::app()->request->getParam('loadpass');
if ( isset($sLoadName) && !$sLoadName)
{
$errormsg .= $clang->gT("You did not provide a name")."<br />\n";
}
if ( isset($sLoadPass) && !$sLoadPass)
{
$errormsg .= $clang->gT("You did not provide a password")."<br />\n";
}

// if security question answer is incorrect
// Not called if scid is set in GET params (when using email save/reload reminder URL)
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen',$thissurvey) && is_null(Yii::app()->request->getQuery('scid')))
{
$sLoadSecurity=Yii::app()->request->getPost('loadsecurity');
if(empty($sLoadSecurity))
{
$errormsg .= $clang->gT("You did not answer to the security question.")."<br />\n";
}
elseif ( (!isset($_SESSION) || $sLoadSecurity != $_SESSION) )
{
$errormsg .= $clang->gT("The answer to the security question is incorrect.")."<br />\n";
}
}

if ($errormsg == "") {
LimeExpressionManager::SetDirtyFlag();
buildsurveysession($surveyid);
if (loadanswers()){
Yii::app()->setConfig('move','movenext');
$move = "movenext";// 140113 : deprecated ?
} else {
$errormsg .= $clang->gT("There is no matching saved survey");
}
}
if ($errormsg) {
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()));
Yii::import("application.libraries.Load_answers");
$tmp = new Load_answers();
$tmp->run($redata);
}


//Check if TOKEN is used for EVERY PAGE
//This function fixes a bug where users able to submit two surveys/votes
//by checking that the token has not been used at each page displayed.
// bypass only this check at first page (Step=0) because
// 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) && $_SESSION>0 && tableExists("tokens_{$surveyid}}}"))
{
// check also if it is allowed to change survey after completion
if ($thissurvey == 'Y' ) {
$tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}

if (!isset($tokenInstance) && !$previewmode)
{
//TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
$asMessage = array(
null,
$clang->gT("This is a controlled survey. You need a valid token to participate."),
sprintf($clang->gT("For further information please contact %s"), $thissurvey." (<a href='mailto:{$thissurvey}'>"."{$thissurvey}</a>)")
);

$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
}
if ($tokensexist == 1 && isset($token) && $token!="" && tableExists("{{tokens_".$surveyid."}}") && !$previewmode) //check if token is in a valid time frame
{
// check also if it is allowed to change survey after completion
if ($thissurvey == 'Y' ) {
$tokenInstance = Token::model($surveyid)->editable()->findByAttributes(array('token' => $token));
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}
if (!isset($tokenInstance))
{
$oToken = Token::model($surveyid)->findByAttributes(array('token' => $token));
if($oToken)
{
$now = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig("timeadjust"));
if($oToken->completed != 'N' && !empty($oToken->completed))
{
$sError = $clang->gT("This invitation has already been used.");
}
elseif(strtotime($now) < strtotime($oToken->validfrom))
{
$sError = $clang->gT("This invitation is not valid yet.");
}
elseif(strtotime($now) > strtotime($oToken->validuntil))
{
$sError = $clang->gT("This invitation is not valid anymore.");
}
else // This can not happen
{
$sError = $clang->gT("This is a controlled survey. You need a valid token to participate.");
}
}
else
{
$sError = $clang->gT("This is a controlled survey. You need a valid token to participate.");
}
$asMessage = array(
null,
$clang->gT("We are sorry but you are not allowed to enter this survey."),
$sError,
sprintf($clang->gT("For further information please contact %s"), $thissurvey." (<a href='mailto:{$thissurvey}'>"."{$thissurvey}</a>)")
);

$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
}


//Clear session and remove the incomplete response if requested.
if (isset($move) && $move == "clearall")
{
// delete the response but only if not already completed
$s_lang = $_SESSION;
if (isset($_SESSION) && !SurveyDynamic::model($surveyid)->isCompleted($_SESSION))
{
// delete the response but only if not already completed
$result= dbExecuteAssoc('DELETE FROM {{survey_'.$surveyid.'}} WHERE id='.$_SESSION." AND submitdate IS NULL");
if($result->count()>0){ // Using count() here *should* be okay for MSSQL because it is a delete statement
// find out if there are any fuqt questions - checked
$fieldmap = createFieldMap($surveyid,'short',false,false,$s_lang);
foreach ($fieldmap as $field)
{
if ($field == "|" && !strpos($field, "_filecount"))
{
if (!isset($qid)) { $qid = array(); }
$qid[] = $field;
}
}

// if yes, extract the response json to those questions
if (isset($qid))
{
$query = "SELECT * FROM {{survey_".$surveyid."}} WHERE id=".$_SESSION;
$result = dbExecuteAssoc($query);
foreach($result->readAll() as $row)
{
foreach ($qid as $question)
{
$json = $row[$question];
if ($json == "" || $json == NULL)
continue;

// decode them
$phparray = json_decode($json);

foreach ($phparray as $metadata)
{
$target = Yii::app()->getConfig("uploaddir")."/surveys/".$surveyid."/files/";
// delete those files
unlink($target.$metadata->filename);
}
}
}
}
// done deleting uploaded files
}

// also delete a record from saved_control when there is one
dbExecuteAssoc('DELETE FROM {{saved_control}} WHERE srid='.$_SESSION.' AND sid='.$surveyid);
}
killSurveySession($surveyid);
sendCacheHeaders();
doHeader();

$redata = compact(array_keys(get_defined_vars()));
$this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__);
echo "\n\n<!--JavaScript FOR CONDITIONAL QUESTIONS -->\n"
."\t<script type='text/javascript'>\n"
."\t<!--\n"
."function checkconditions(value, name, type, evt_type)\n"
."\t{\n"
."\t}\n"
."\t//-->\n"
."\t</script>\n\n";

//Present the clear all page using clearall.pstpl template
$this->_printTemplateContent($thistpl.'/clearall.pstpl', $redata, __LINE__);

$this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__);
doFooter();
exit;
}


//Check to see if a refering URL has been captured.
if (!isset($_SESSION))
{
$_SESSION=GetReferringUrl(); // do not overwrite refurl
}

// Let's do this only if
// - a saved answer record hasn't been loaded through the saved feature
// - the survey is not anonymous
// - the survey is active
// - a token information has been provided
// - the survey is setup to allow token-response-persistence

if (!isset($_SESSION) && $thissurvey == "N" && $thissurvey == "Y" && isset($token) && $token !='')
{
// load previous answers if any (dataentry with nosubmit)
$oResponses = Response::model($surveyid)->findAllByAttributes(array(
'token' => $token
), array('order' => 'id DESC'));
if (!empty($oResponses))
{
/**
* We fire the response selection event when at least 1 response was found.
* If there is just 1 response the plugin still has to option to choose
* NOT to use it.
*/
$event = new PluginEvent('beforeLoadResponse');
$event->set('responses', $oResponses);
$event->set('surveyId', $surveyid);
App()->pluginManager->dispatchEvent($event);

$oResponse = $event->get('response');
// If $oResponse is false we act as if no response was found.
// This allows a plugin to deny continuing a response.
if ($oResponse !== false)
{
// If plugin does not set a response we use the first one found, (this replicates pre-plugin behavior)
if (!isset($oResponse) && (!isset($oResponses[0]->submitdate) || $thissurvey == 'Y') && $thissurvey == 'Y')
{
$oResponse = $oResponses[0];
}

if (isset($oResponse))
{
$_SESSION = $oResponse->id;
if (!empty($oResponse->lastpage))
{
$_SESSION = true;
// If the response was completed and user is allowed to edit after completion start at the beginning and not at the last page - just makes more sense
if (!($oResponse->submitdate && $thissurvey == 'Y'))
{
$_SESSION = $oResponse->lastpage;
}
}
buildsurveysession($surveyid);
if(!empty($oResponse->submitdate)) // alloweditaftercompletion
{
$_SESSION = $_SESSION;
}
loadanswers();
}
}
}
}
// Preview action : Preview right already tested before
if ($previewmode)
{
// Unset all SESSION: be sure to have the last version
unset($_SESSION);// Needed by createFieldMap: else fieldmap can be outdated
unset($_SESSION);
if ($param == 'previewgroup')
{
$thissurvey = 'G';
}
elseif ($param == 'previewquestion')
{
$thissurvey = 'S';
}
buildsurveysession($surveyid,true);
}

sendCacheHeaders();

//Send local variables to the appropriate survey type
unset($redata);
$redata = compact(array_keys(get_defined_vars()));
Yii::import('application.helpers.SurveyRuntimeHelper');
$tmp = new SurveyRuntimeHelper();
$tmp->run($surveyid,$redata);

if (isset($_POST) || isset($flashmessage))
{
echo "<script type='text/javascript'> $(document).ready( function() { alert('".$clang->gT("Your responses were successfully saved.","js")."');}) </script>";
}
}

function _getParameters($args = array(), $post = array())
{
$param = array();
if(@$args[0]==__CLASS__) array_shift($args);
if(count($args)%2 == 0) {
for ($i = 0; $i < count($args); $i+=2) {
//Sanitize input from URL with returnGlobal
$param[$args[$i]] = returnGlobal($args[$i], true);
}
}

// Need some $param (else PHP notice)
foreach(array('lang','action','newtest','qid','gid','sid','loadname','loadpass','scid','thisstep','move','token') as $sNeededParam)
{
$param[$sNeededParam]=returnGlobal($sNeededParam,true);
}

return $param;
}

function _loadRequiredHelpersAndLibraries()
{
//Load helpers, libraries and config vars
Yii::app()->loadHelper("database");
Yii::app()->loadHelper("frontend");
Yii::app()->loadHelper("surveytranslator");
}

function _loadLimesurveyLang($mvSurveyIdOrBaseLang)
{
if ( is_numeric($mvSurveyIdOrBaseLang) && Survey::model()->findByPk($mvSurveyIdOrBaseLang))
{
$baselang = Survey::model()->findByPk($mvSurveyIdOrBaseLang)->language;
}
elseif (!empty($mvSurveyIdOrBaseLang))
{
$baselang = $mvSurveyIdOrBaseLang;
}
else
{
$baselang = Yii::app()->getConfig('defaultlang');
}
Yii::import("application.libraries.Limesurvey_lang");
return new Limesurvey_lang($baselang);
}

function _isClientTokenDifferentFromSessionToken($clientToken, $surveyid)
{
return $clientToken != '' && isset($_SESSION) && $clientToken != $_SESSION;
}

function _isSurveyFinished($surveyid)
{
return isset($_SESSION) && $_SESSION === true;
}

function _surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $bIsSurveyActive, $bSurveyExists)
{
$bSurveyPreviewRequireAuth = Yii::app()->getConfig('surveyPreview_require_Auth');
return $surveyid && $bIsSurveyActive === false && $bSurveyExists && isset($bSurveyPreviewRequireAuth) && $bSurveyPreviewRequireAuth == true && !$this->_canUserPreviewSurvey($surveyid);
}

function _didSessionTimeout($surveyid)
{
return !isset($_SESSION) && isset($_POST);
}

function _canUserPreviewSurvey($iSurveyID)
{
if ( !isset($_SESSION) ) // This is not needed because Permission::model()->hasSurveyPermission control connexion
return false;

return Permission::model()->hasSurveyPermission($iSurveyID,'surveycontent','read');
}

function _userHasPreviewAccessSession($iSurveyID){
return (isset($_SESSION) && ($_SESSION == $iSurveyID));
}

function _niceExit(&$redata, $iDebugLine, $sTemplateDir = null, $asMessage = array())
{

if(isset($redata) && $redata && !isset($thisurvey))
{
$thissurvey=getSurveyInfo($redata);
$sTemplateDir= getTemplatePath($thissurvey);
}
else
{
$sTemplateDir= getTemplatePath($sTemplateDir);
}
sendCacheHeaders();

doHeader();
$this->_printTemplateContent($sTemplateDir.'/startpage.pstpl', $redata, $iDebugLine);
$this->_printMessage($asMessage);
$this->_printTemplateContent($sTemplateDir.'/endpage.pstpl', $redata, $iDebugLine);

doFooter();
exit;
}

function _createNewUserSessionAndRedirect($surveyid, &$redata, $iDebugLine, $asMessage = array())
{
$clang = Yii::app()->lang;
killSurveySession($surveyid);
$thissurvey=getSurveyInfo($surveyid);
if($thissurvey)
{
$templatename=$thissurvey;
}
else
{
$templatename=Yii::app()->getConfig('defaulttemplate');;
}
// Let's redirect the client to the same URL after having reset the session
$this->_niceExit($redata, $iDebugLine, $templatename, $asMessage);
}



function _printMessage($asLines)
{
if ( func_num_args() > 1 )
$asLines = func_get_args();

if ( count($asLines) == 0 )
return;

$sError = array_shift($asLines);

echo "\t<div id='wrapper'>\n";
echo "\t<p id='tokenmessage'>\n";
if ( $sError != null )
{
echo "\t<span class='error'>".$sError."</span><br /><br />\n";
}
echo "\t".implode ("<br /><br />\n\t", $asLines)."<br /><br />\n";
echo "\t</p>\n";
echo "\t</div>\n";
}

function _printTemplateContent($sTemplateFile, &$redata, $iDebugLine = -1)
{
echo templatereplace(file_get_contents($sTemplateFile),array(),$redata,'survey');
}


}
Code after modifcation:-
$ldapconfig = 'LDAP://10.64.130.20';
$ldapconfig = '389';
$ldapconfig = 'dc=@SerWizSol,dc=com';
$ldapconfig = 'My Realm';
function LDAP_authenticate() {
global $ldapconfig;
$_SERVER;
$_SERVER;
if ($_SERVER != "" && $_SERVER != "") {
$ds = LDAP_connect($ldapconfig,$ldapconfig);
if (LDAP_bind( $ds,"This email address is being protected from spambots. You need JavaScript enabled to view it.", "ind@8888")) {
return 1;
}else{
echo "LDAP-Errno: " . LDAP_errno(LDAP_bind( $ds,$_SERVER."@SerWizSol.com", $_SERVER));
return 0;
}
}
header('WWW-Authenticate: Basic realm="'.$ldapconfig.'"');
header('HTTP/1.0 401 Unauthorized');
return NULL;

}
if (!$result = LDAP_authenticate()) {
echo('Authorization Failed');
exit(0);
}
echo "Welcome:-".$_SERVER;

class index extends CAction {

public function run()
{
/*
* Instead of manually rendering scripts after this function returns we
* use the callback. This ensures that scripts are always rendered, even
* if we call exit at some point in the code. (Which we shouldn't, but
* it happens.)
*/
// Ensure to set some var, but script are replaced in SurveyRuntimeHelper

$aLSJavascriptVar=array();
$aLSJavascriptVar=(int)(bool)Yii::app()->getConfig('bFixNumAuto',1);
$aLSJavascriptVar=(int)(bool)Yii::app()->getConfig('bNumRealValue',0);
$aLangData=getLanguageData();
$aRadix=getRadixPointData($aLangData[ Yii::app()->getConfig('defaultlang')]);
$aLSJavascriptVar=$aRadix;
$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar) . ';';
App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
App()->clientScript->registerScript('setJsVar',"setJsVar();",CClientScript::POS_BEGIN);// Ensure all js var is set before rendering the page (User can click before $.ready)

App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
useFirebug();

ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);
$this->action();
ob_flush();
}

function action()
{

global $surveyid;
global $thissurvey, $thisstep;
global $clienttoken, $tokensexist, $token;
global $clang;
$clang = Yii::app()->lang;
// only attempt to change session lifetime if using a DB backend
// with file based sessions, it's up to the admin to configure maxlifetime
if(isset(Yii::app()->session->connectionID)) {
@ini_set('session.gc_maxlifetime', Yii::app()->getConfig('iSessionExpirationTime'));
}

$this->_loadRequiredHelpersAndLibraries();

$param = $this->_getParameters(func_get_args(), $_POST);

$surveyid = $param;
Yii::app()->setConfig('surveyID',$surveyid);
$thisstep = $param;
$move=getMove();
Yii::app()->setConfig('move',$move);
$clienttoken = trim($param);
$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
if (is_null($thissurvey) && !is_null($surveyid)) $thissurvey = getSurveyInfo($surveyid);

// unused vars in this method (used in methods using compacted method vars)
@$loadname = $param;
@$loadpass = $param;
$sitename = Yii::app()->getConfig('sitename');

if (isset($param) && $param == "Y")
{
killSurveySession($surveyid);
}

$surveyExists=($surveyid && Survey::model()->findByPk($surveyid));
$isSurveyActive=($surveyExists && Survey::model()->findByPk($surveyid)->active=="Y");

// collect all data in this method to pass on later
$redata = compact(array_keys(get_defined_vars()));

$clang = $this->_loadLimesurveyLang($surveyid);

if ( $this->_isClientTokenDifferentFromSessionToken($clienttoken,$surveyid) )
{
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",array('token'=>$clienttoken,'lang'=>$clang->langcode,'newtest'=>'Y'));
$asMessage = array(
$clang->gT('Token mismatch'),
$clang->gT('The token you provided doesn\'t match the one in your session.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".$clang->gT("Click here to start the survey.")."</a>"
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

if ( $this->_isSurveyFinished($surveyid) && ($thissurvey != 'Y' || $thissurvey != 'Y')) // No test for response update
{
$aReloadUrlParam=array('lang'=>$clang->langcode,'newtest'=>'Y');
if($clienttoken){$aReloadUrlParam=$clienttoken;}
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",$aReloadUrlParam);
$asMessage = array(
$clang->gT('Previous session is set to be finished.'),
$clang->gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'),
"<a class='reloadlink newsurvey' href={$sReloadUrl}>".$clang->gT("Click here to start the survey.")."</a>"
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
}

$previewmode=false;
if (isset($param) && (in_array($param,array('previewgroup','previewquestion'))))
{
if(!$this->_canUserPreviewSurvey($surveyid))
{
$asMessage = array(
$clang->gT('Error'),
$clang->gT("We are sorry but you don't have permissions to do this.")
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
}
else
{
if((intval($param) && $param=='previewquestion')) $previewmode='question';
if((intval($param) && $param=='previewgroup')) $previewmode='group';
}
}
Yii::app()->setConfig('previewmode',$previewmode);
if ( $this->_surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $isSurveyActive, $surveyExists) )
{
$bPreviewRight = $this->_userHasPreviewAccessSession($surveyid);

if ($bPreviewRight === false)
{
$asMessage = array(
$clang->gT("Error"),
$clang->gT("We are sorry but you don't have permissions to do this."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
}
}


// TODO can this be moved to the top?
// (Used to be global, used in ExpressionManager, merged into amVars. If not filled in === '')
// can this be added in the first computation of $redata?
if (isset($_SESSION))
{
$saved_id = $_SESSION;
//echo('Authorization success');
}
// recompute $redata since $saved_id used to be a global
$redata = compact(array_keys(get_defined_vars()));


if ( $this->_didSessionTimeOut($surveyid) )
{
// @TODO is this still required ?
$asMessage = array(
$clang->gT("Error"),
$clang->gT("We are sorry but your session has expired."),
$clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);
$this->_niceExit($redata, __LINE__, null, $asMessage);
};

// Set the language of the survey, either from POST, GET parameter of session var
// Keep the old value, because SetSurveyLanguage update $_SESSION
$sOldLang=isset($_SESSION)?$_SESSION:"";// Keep the old value, because SetSurveyLanguage update $_SESSION
if (!empty($param))
{
$sDisplayLanguage = $param;// $param take lang from returnGlobal and returnGlobal sanitize langagecode
}
elseif (isset($_SESSION))
{
$sDisplayLanguage = $_SESSION;
}
else
{
$sDisplayLanguage=Yii::app()->getConfig('defaultlang');
}

//CHECK FOR REQUIRED INFORMATION (sid)
if ($surveyid && $surveyExists)
{
LimeExpressionManager::SetSurveyId($surveyid); // must be called early - it clears internal cache if a new survey is being used
$clang = SetSurveyLanguage( $surveyid, $sDisplayLanguage);
if($previewmode) LimeExpressionManager::SetPreviewMode($previewmode);
if ($clang->langcode != $sOldLang) // Update the Session var only if needed
{
UpdateGroupList($surveyid, $clang->langcode); // to refresh the language strings in the group list session variable
UpdateFieldArray(); // to refresh question titles and question text
}
}
else
{
throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
}

// Get token
if (!isset($token))
{
$token=$clienttoken;
}

//GET BASIC INFORMATION ABOUT THIS SURVEY
$thissurvey=getSurveyInfo($surveyid, $_SESSION);

$event = new PluginEvent('beforeSurveyPage');
$event->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($event);
if (!is_null($event->get('template')))
{
$thissurvey = $event->get('template');
}

//SEE IF SURVEY USES TOKENS
if ($surveyExists == 1 && tableExists('{{tokens_'.$thissurvey.'}}'))
{
$tokensexist = 1;
}
else
{
$tokensexist = 0;
unset($_POST);
unset($param);
unset($token);
unset($clienttoken);
}

//SET THE TEMPLATE DIRECTORY

$thistpl = getTemplatePath($thissurvey);


$timeadjust = Yii::app()->getConfig("timeadjust");
//MAKE SURE SURVEY HASN'T EXPIRED
if ($thissurvey!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)>$thissurvey && $thissurvey!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("This survey is no longer available."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//MAKE SURE SURVEY IS ALREADY VALID
if ($thissurvey!='' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)<$thissurvey && $thissurvey!='N' && !$previewmode)
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("This survey is not yet started."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//CHECK FOR PREVIOUSLY COMPLETED COOKIE
//If cookies are being used, and this survey has been completed, a cookie called "PHPSID[sid]STATUS" will exist (ie: SID6STATUS) and will have a value of "COMPLETE"
$sCookieName="LS_".$surveyid."_STATUS";
if (isset($_COOKIE[$sCookieName]) && $_COOKIE[$sCookieName] == "COMPLETE" && $thissurvey == "Y" && $tokensexist != 1 && (!isset($param) || $param != "Y"))
{
$redata = compact(array_keys(get_defined_vars()));
$asMessage = array(
$clang->gT("Error"),
$clang->gT("You have already completed this survey."),
sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$thissurvey,$thissurvey)
);

$this->_niceExit($redata, __LINE__, $thissurvey, $asMessage);
}

//LOAD SAVED SURVEY
if (Yii::app()->request->getParam('loadall') == "reload")
{
$errormsg="";
$sLoadName=Yii::app()->request->getParam('loadname');
$sLoadPass=Yii::app()->request->getParam('loadpass');
if ( isset($sLoadName) && !$sLoadName)
{
$errormsg .= $clang->gT("You did not provide a name")."<br />\n";
}
if ( isset($sLoadPass) && !$sLoadPass)
{
$errormsg .= $clang->gT("You did not provide a password")."<br />\n";
}

// if security question answer is incorrect
// Not called if scid is set in GET params (when using email save/reload reminder URL)
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen',$thissurvey) && is_null(Yii::app()->request->getQuery('scid')))
{
$sLoadSecurity=Yii::app()->request->getPost('loadsecurity');
if(empty($sLoadSecurity))
{
$errormsg .= $clang->gT("You did not answer to the security question.")."<br />\n";
}
elseif ( (!isset($_SESSION) || $sLoadSecurity != $_SESSION) )
{
$errormsg .= $clang->gT("The answer to the security question is incorrect.")."<br />\n";
}
}

if ($errormsg == "") {
LimeExpressionManager::SetDirtyFlag();
buildsurveysession($surveyid);
if (loadanswers()){
Yii::app()->setConfig('move','movenext');
$move = "movenext";// 140113 : deprecated ?
} else {
$errormsg .= $clang->gT("There is no matching saved survey");
}
}
if ($errormsg) {
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()));
Yii::import("application.libraries.Load_answers");
$tmp = new Load_answers();
$tmp->run($redata);
}


//Check if TOKEN is used for EVERY PAGE
//This function fixes a bug where users able to submit two surveys/votes
//by checking that the token has not been used at each page displayed.
// bypass only this check at first page (Step=0) because
// 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) && $_SESSION>0 && tableExists("tokens_{$surveyid}}}"))
{
// check also if it is allowed to change survey after completion
if ($thissurvey == 'Y' ) {
$tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}

if (!isset($tokenInstance) && !$previewmode)
{
//TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
$asMessage = array(
null,
$clang->gT("This is a controlled survey. You need a valid token to participate."),
sprintf($clang->gT("For further information please contact %s"), $thissurvey." (<a href='mailto:{$thissurvey}'>"."{$thissurvey}</a>)")
);

$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
}
if ($tokensexist == 1 && isset($token) && $token!="" && tableExists("{{tokens_".$surveyid."}}") && !$previewmode) //check if token is in a valid time frame
{
// check also if it is allowed to change survey after completion
if ($thissurvey == 'Y' ) {
$tokenInstance = Token::model($surveyid)->editable()->findByAttributes(array('token' => $token));
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}
if (!isset($tokenInstance))
{
$oToken = Token::model($surveyid)->findByAttributes(array('token' => $token));
if($oToken)
{
$now = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig("timeadjust"));
if($oToken->completed != 'N' && !empty($oToken->completed))
{
$sError = $clang->gT("This invitation has already been used.");
}
elseif(strtotime($now) < strtotime($oToken->validfrom))
{
$sError = $clang->gT("This invitation is not valid yet.");
}
elseif(strtotime($now) > strtotime($oToken->validuntil))
{
$sError = $clang->gT("This invitation is not valid anymore.");
}
else // This can not happen
{
$sError = $clang->gT("This is a controlled survey. You need a valid token to participate.");
}
}
else
{
$sError = $clang->gT("This is a controlled survey. You need a valid token to participate.");
}
$asMessage = array(
null,
$clang->gT("We are sorry but you are not allowed to enter this survey."),
$sError,
sprintf($clang->gT("For further information please contact %s"), $thissurvey." (<a href='mailto:{$thissurvey}'>"."{$thissurvey}</a>)")
);

$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
}


//Clear session and remove the incomplete response if requested.
if (isset($move) && $move == "clearall")
{
// delete the response but only if not already completed
$s_lang = $_SESSION;
if (isset($_SESSION) && !SurveyDynamic::model($surveyid)->isCompleted($_SESSION))
{
// delete the response but only if not already completed
$result= dbExecuteAssoc('DELETE FROM {{survey_'.$surveyid.'}} WHERE id='.$_SESSION." AND submitdate IS NULL");
if($result->count()>0){ // Using count() here *should* be okay for MSSQL because it is a delete statement
// find out if there are any fuqt questions - checked
$fieldmap = createFieldMap($surveyid,'short',false,false,$s_lang);
foreach ($fieldmap as $field)
{
if ($field == "|" && !strpos($field, "_filecount"))
{
if (!isset($qid)) { $qid = array(); }
$qid[] = $field;
}
}

// if yes, extract the response json to those questions
if (isset($qid))
{
$query = "SELECT * FROM {{survey_".$surveyid."}} WHERE id=".$_SESSION;
$result = dbExecuteAssoc($query);
foreach($result->readAll() as $row)
{
foreach ($qid as $question)
{
$json = $row[$question];
if ($json == "" || $json == NULL)
continue;

// decode them
$phparray = json_decode($json);

foreach ($phparray as $metadata)
{
$target = Yii::app()->getConfig("uploaddir")."/surveys/".$surveyid."/files/";
// delete those files
unlink($target.$metadata->filename);
}
}
}
}
// done deleting uploaded files
}

// also delete a record from saved_control when there is one
dbExecuteAssoc('DELETE FROM {{saved_control}} WHERE srid='.$_SESSION.' AND sid='.$surveyid);
}
killSurveySession($surveyid);
sendCacheHeaders();
doHeader();

$redata = compact(array_keys(get_defined_vars()));
$this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__);
echo "\n\n<!--JavaScript FOR CONDITIONAL QUESTIONS -->\n"
."\t<script type='text/javascript'>\n"
."\t<!--\n"
."function checkconditions(value, name, type, evt_type)\n"
."\t{\n"
."\t}\n"
."\t//-->\n"
."\t</script>\n\n";

//Present the clear all page using clearall.pstpl template
$this->_printTemplateContent($thistpl.'/clearall.pstpl', $redata, __LINE__);

$this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__);
doFooter();
exit;
}


//Check to see if a refering URL has been captured.
if (!isset($_SESSION))
{
$_SESSION=GetReferringUrl(); // do not overwrite refurl
}

// Let's do this only if
// - a saved answer record hasn't been loaded through the saved feature
// - the survey is not anonymous
// - the survey is active
// - a token information has been provided
// - the survey is setup to allow token-response-persistence

if (!isset($_SESSION) && $thissurvey == "N" && $thissurvey == "Y" && isset($token) && $token !='')
{
// load previous answers if any (dataentry with nosubmit)
$oResponses = Response::model($surveyid)->findAllByAttributes(array(
'token' => $token
), array('order' => 'id DESC'));
if (!empty($oResponses))
{
/**
* We fire the response selection event when at least 1 response was found.
* If there is just 1 response the plugin still has to option to choose
* NOT to use it.
*/
$event = new PluginEvent('beforeLoadResponse');
$event->set('responses', $oResponses);
$event->set('surveyId', $surveyid);
App()->pluginManager->dispatchEvent($event);

$oResponse = $event->get('response');
// If $oResponse is false we act as if no response was found.
// This allows a plugin to deny continuing a response.
if ($oResponse !== false)
{
// If plugin does not set a response we use the first one found, (this replicates pre-plugin behavior)
if (!isset($oResponse) && (!isset($oResponses[0]->submitdate) || $thissurvey == 'Y') && $thissurvey == 'Y')
{
$oResponse = $oResponses[0];
}

if (isset($oResponse))
{
$_SESSION = $oResponse->id;
if (!empty($oResponse->lastpage))
{
$_SESSION = true;
// If the response was completed and user is allowed to edit after completion start at the beginning and not at the last page - just makes more sense
if (!($oResponse->submitdate && $thissurvey == 'Y'))
{
$_SESSION = $oResponse->lastpage;
}
}
buildsurveysession($surveyid);
if(!empty($oResponse->submitdate)) // alloweditaftercompletion
{
$_SESSION = $_SESSION;
}
loadanswers();
}
}
}
}
// Preview action : Preview right already tested before
if ($previewmode)
{
// Unset all SESSION: be sure to have the last version
unset($_SESSION);// Needed by createFieldMap: else fieldmap can be outdated
unset($_SESSION);
if ($param == 'previewgroup')
{
$thissurvey = 'G';
}
elseif ($param == 'previewquestion')
{
$thissurvey = 'S';
}
buildsurveysession($surveyid,true);
}

sendCacheHeaders();

//Send local variables to the appropriate survey type
unset($redata);
$redata = compact(array_keys(get_defined_vars()));
Yii::import('application.helpers.SurveyRuntimeHelper');
$tmp = new SurveyRuntimeHelper();
$tmp->run($surveyid,$redata);

if (isset($_POST) || isset($flashmessage))
{
echo "<script type='text/javascript'> $(document).ready( function() { alert('".$clang->gT("Your responses were successfully saved.","js")."');}) </script>";
}
}

function _getParameters($args = array(), $post = array())
{
$param = array();
if(@$args[0]==__CLASS__) array_shift($args);
if(count($args)%2 == 0) {
for ($i = 0; $i < count($args); $i+=2) {
//Sanitize input from URL with returnGlobal
$param[$args[$i]] = returnGlobal($args[$i], true);
}
}

// Need some $param (else PHP notice)
foreach(array('lang','action','newtest','qid','gid','sid','loadname','loadpass','scid','thisstep','move','token') as $sNeededParam)
{
$param[$sNeededParam]=returnGlobal($sNeededParam,true);
}

return $param;
}

function _loadRequiredHelpersAndLibraries()
{
//Load helpers, libraries and config vars
Yii::app()->loadHelper("database");
Yii::app()->loadHelper("frontend");
Yii::app()->loadHelper("surveytranslator");
}

function _loadLimesurveyLang($mvSurveyIdOrBaseLang)
{
if ( is_numeric($mvSurveyIdOrBaseLang) && Survey::model()->findByPk($mvSurveyIdOrBaseLang))
{
$baselang = Survey::model()->findByPk($mvSurveyIdOrBaseLang)->language;
}
elseif (!empty($mvSurveyIdOrBaseLang))
{
$baselang = $mvSurveyIdOrBaseLang;
}
else
{
$baselang = Yii::app()->getConfig('defaultlang');
}
Yii::import("application.libraries.Limesurvey_lang");
return new Limesurvey_lang($baselang);
}

function _isClientTokenDifferentFromSessionToken($clientToken, $surveyid)
{
return $clientToken != '' && isset($_SESSION) && $clientToken != $_SESSION;
}

function _isSurveyFinished($surveyid)
{
return isset($_SESSION) && $_SESSION === true;
}

function _surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $bIsSurveyActive, $bSurveyExists)
{
$bSurveyPreviewRequireAuth = Yii::app()->getConfig('surveyPreview_require_Auth');
return $surveyid && $bIsSurveyActive === false && $bSurveyExists && isset($bSurveyPreviewRequireAuth) && $bSurveyPreviewRequireAuth == true && !$this->_canUserPreviewSurvey($surveyid);
}

function _didSessionTimeout($surveyid)
{
return !isset($_SESSION) && isset($_POST);
}

function _canUserPreviewSurvey($iSurveyID)
{
if ( !isset($_SESSION) ) // This is not needed because Permi

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!