function checkAccess() { global $db, $survey; switch ($survey->getAccessType()) { case LOGIN_ANONYMOUS: return true; break; case LOGIN_DIRECT: return true; break; case LOGIN_LOGINCODE: $logincode = loadvarSurvey('primkey'); $result = $db->selectQuery('select count(*), primkey from ' . Config::dbSurvey() . '_respondents where aes_decrypt(logincode, \'' . Config::loginCodeKey() . '\') = \'' . prepareDatabaseString($logincode) . '\''); //echo 'select count(*), primkey from ' . Config::dbSurvey() . '_respondents where aes_decrypt(logincode, "' . Config::loginCodeKey() . '") = "' . prepareDatabaseString($logincode) . '"'; $row = $db->getRow($result); if ($row[0] == 1) { $_SESSION['PRIMKEY'] = $row['primkey']; return true; } else { $logactions = new LogActions(); $logactions->addAction('', '', "loginwrong", USCIC_SURVEY); } break; } return false; }
function doBackState($lastrgid, $dkrfnacheck, $save = true) { /* we load the last state */ $this->loadLastState(); $currentprefix = $this->getPrefix(); $currentparentprefix = $this->getParentPrefix(); $currentseid = $this->getSeid(); /* delete last screenshot NOT ANYMORE, WE KEEP ALL SCREENSHOTS */ //$this->deleteLastScreenshot(); /* delete last state from db */ $this->deleteLastState(); /* determine which ones are the 'clean' variables * (i.e. still in the state somewhere as displayed or assigned) */ $cleanvariables = $this->getCleanVariables(); /* undo any assignments in the db that were the result * of the last time we went forward */ $this->undoAssignments($cleanvariables); /* get all data from the last state */ $data = $this->state->getAllData(); /* we load the last state before the last state we just deleted */ $this->loadLastState(); /* set all data from deleted state to the previous one */ $this->state->setAllData($data); // save answers: only first time, if we go back across section calls then any answers will have been stored // in the state that we had updated before if ($save) { $vars = splitString("/~/", getFromSessionParams(SESSION_PARAM_VARIABLES)); $cnt = 1; // Check if one or more current answers are DK/RF/NA. If so, then if current values are empty, we keep DK/RF/NA. // If we have a non-empty answer OR current answer is not DK/RF/NA, then we store all answers $update = false; foreach ($vars as $var) { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); if (!is_array($answer) && trim($answer) != "" || is_array($answer) && trim($answer[0]) != "") { $update = true; break; } else { $current = $this->getAnswer($var); if (!inArray($current, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) { $update = true; break; } } } /* if individual dk/rf/na, then we always update on going back (if not, then on going back we preserve dk/rf/na if empty answer) */ if ($dkrfnacheck == true) { $update = true; } // use prefix from last state, not previous, so we store answers under the right name! $newprefix = $this->getPrefix(); $newparentprefix = $this->getParentPrefix(); $newseid = $this->getSeid(); $this->setPrefix($currentprefix); $this->setParentPrefix($currentparentprefix); $this->setSeid($currentseid); /* store answers in db and previous state */ if ($update == true) { $defaultcleanvariables = getDefaultCleanVariables(); $cnt = 1; foreach ($vars as $var) { $vd = $this->getVariableDescriptive($var); if ($vd->getAnswerType() == ANSWER_TYPE_SETOFENUMERATED) { $answer = ""; if ($dkrfnacheck == true) { /* dk/rf/na */ $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna"); if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); } } else { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); } if (is_array($answer)) { $answer = implode(SEPARATOR_SETOFENUMERATED, $answer); } if (inArray($var, $cleanvariables) || inArray($var, $defaultcleanvariables)) { $dirty = DATA_CLEAN; } else { $dirty = DATA_DIRTY; } //echo $var . '----' . $answer . "<br/>"; $this->setAnswer($var, $answer, $dirty); } else { if ($vd->getAnswerType() != ANSWER_TYPE_NONE) { $answer = ""; if ($dkrfnacheck == true) { /* dk/rf/na */ $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt . "_dkrfna"); if (!inArray($answer, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); } } else { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); } $dirty = DATA_DIRTY; if (inArray($var, $cleanvariables) || inArray($var, $defaultcleanvariables)) { $dirty = DATA_CLEAN; } $this->setAnswer($var, $answer, $dirty); } } $cnt++; } } // restore to new state now that we stored the answer(s) $this->setPrefix($newprefix); $this->setParentPrefix($newparentprefix); $this->setSeid($newseid); } /* log action */ $this->logAction($lastrgid, ACTION_EXIT_BACK); /* update previous state * (for any answers given on the current screen) */ $this->saveState(false); }
function getSurveyTemplate() { /* SURVEY */ // check for new template global $survey, $template; /* global template has been set! (via setting below, so no need to repeat) */ if (isSurveyTemplate($template)) { return $template; } /* get from loadvar (IF ALLOWED) */ if (getSurveyTemplateAllowChange() != TEMPLATE_CHANGE_NOTALLOWED) { $l = loadvarSurvey(POST_PARAM_TEMPLATE); if (isSurveyTemplate($l)) { $template = $l; $_SESSION["PARAMS"][SESSION_PARAM_TEMPLATE] = $l; return $template; } $l = getFromSessionParams(SESSION_PARAM_NEWTEMPLATE); if (isSurveyTemplate($l)) { $_SESSION["PARAMS"][SESSION_PARAM_TEMPLATE] = $l; unset($_SESSION["PARAMS"][SESSION_PARAM_NEWTEMPLATE]); $template = $l; return $l; } // check in submitted answers $vars = splitString("/~/", getFromSessionParams(SESSION_PARAM_VARIABLES)); if (inArray(VARIABLE_TEMPLATE, $vars)) { $cnt = 1; foreach ($vars as $var) { if (strtoupper($var) == strtoupper(VARIABLE_TEMPLATE)) { $answer = loadvarSurvey(SESSION_PARAMS_ANSWER . $cnt); if (isSurveyTemplate($answer)) { $template = $answer; return $answer; } break; } } } } // check for old template from session $l = getFromSessionParams(SESSION_PARAM_TEMPLATE); if (isSurveyTemplate($l)) { $template = $l; return $l; } // default template from survey return $survey->getTemplate(); }
function surveyEntry() { global $engine; if ($this->checkDateTime() == false) { /* get whatever the language is (either post or default) and use it */ $l = getSurveyLanguage(); if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) { require_once 'language' . getSurveyLanguagePostFix($l) . '.php'; // language } else { require_once 'language_en.php'; // fall back on english language file } $login = new Login(session_id()); return $login->getClosedScreen(); } $logactions = new LogActions(); $nosessionactions = $logactions->getNumberOfSurveyActionsBySession($this->phpid, USCIC_SURVEY); /* no entry yet, then ask for prim_key in login screen */ if ($nosessionactions == 0 || loadvarSurvey(POST_PARAM_NEW_PRIMKEY) == '1') { //no entry yet: ask for prim_key! if (loadvarSurvey(POST_PARAM_NEW_PRIMKEY) == '1') { $logactions->deleteLoggedInSurveySession($this->phpid); } /* get whatever the language is (either post or default) and use it */ $l = getSurveyLanguage(); if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) { require_once 'language' . getSurveyLanguagePostFix($l) . '.php'; // language } else { require_once 'language_en.php'; // fall back on english language file } $logactions->addAction('', '', "loginstart", USCIC_SURVEY, 1); $login = new Login($this->phpid); return $login->getLoginScreen(); } else { //entry: is this person logged in? $loggedin = $logactions->getLoggedInSurveySession($this->phpid); // gets the last logged in action /* no prim_key assigned to this sessionid. Assign if given (and check for pwd etc??)! */ if ($loggedin["count"] == 0) { /* we don't have active session, so take the template we can get */ global $survey; require_once "display/templates/displayquestion_" . getSurveyTemplate() . ".php"; // we don't have an active session, so fall back to whatever was passed along as language in post OR is the default language $l = getSurveyLanguage(); if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) { //echo 'well done'; require_once 'language' . getSurveyLanguagePostFix($l) . '.php'; // language } else { require_once 'language_en.php'; // fall back on english language file } $primkey = loadvarSurvey(POST_PARAM_PRIMKEY); $_SESSION['PRIMKEY'] = $primkey; if ($primkey != '' && strlen($primkey) < 20) { // make sure primkey is not encrypted! //check!!!!!! $login = new Login($this->phpid); if ($login->checkAccess()) { $primkey = $_SESSION['PRIMKEY']; $logactions->addAction($primkey, '', "loggedin", USCIC_SURVEY, 1); // pass along primkey to load correct engine! $engine = loadEngine(getSurvey(), $primkey, $this->phpid, getSurveyVersion(), getSurveySection(getSurvey(), $primkey)); $engine->setFirstForm(true); return $engine->getNextQuestion(); } else { // incorrect login..start new session endSession(); session_start(); session_regenerate_id(true); $logactions->addAction('', '', "loginempty", USCIC_SURVEY, 1); $login = new Login(session_id()); global $survey; return $login->getLoginScreen($survey->getLoginError()); } } else { $logactions->addAction('', '', "loginempty", USCIC_SURVEY, 1); $login = new Login($this->phpid); global $survey; if ($survey->getAccessType() == LOGIN_ANONYMOUS) { return $login->getLoginScreen(Language::messageEnterPrimKey()); } else { if ($survey->getAccessType() == LOGIN_LOGINCODE) { return $login->getLoginScreen($survey->getLoginError()); } else { return $login->getLoginScreen(Language::messageEnterPrimKeyDirectAccess()); } } } } else { //continue interview! EXTRA CHECK!!! /* update survey info with what we know from the last session action */ setSurvey($loggedin["suid"]); /* include survey template now that we know which survey we are in */ global $survey; require_once "display/templates/displayquestion_" . getSurveyTemplate() . ".php"; /* update interview mode with what we know from the last session action * IF we are not changing the interview mode right now */ if (isset($_POST['navigation']) && $_POST['navigation'] != NAVIGATION_MODE_CHANGE && $survey->getReentryMode() == MODE_REENTRY_YES) { setSurveyMode($loggedin["mode"]); } /* update language with what we know from the last session action * IF we are not changing the language right now */ if (isset($_POST['navigation']) && $_POST['navigation'] != NAVIGATION_LANGUAGE_CHANGE && $survey->getReentryLanguage(getSurveyMode()) == LANGUAGE_REENTRY_YES) { setSurveyLanguage($loggedin["language"]); } /* update version with what we know from the last session action */ setSurveyVersion($loggedin["version"]); // include language file $l = getSurveyLanguage(); //echo 'NOW: ' . $l; if (file_exists("language/language" . getSurveyLanguagePostFix($l) . ".php")) { //echo 'well done'; require_once 'language' . getSurveyLanguagePostFix($l) . '.php'; // language } else { require_once 'language_en.php'; // fall back on english language file } // pass along primkey to load correct engine! $engine = loadEngine(getSurvey(), $loggedin["primkey"], $this->phpid, getSurveyVersion(), getSurveySection(getSurvey(), $loggedin["primkey"])); /* handle button click */ return $engine->getNextQuestion(); } } }