$respText) { $respText = strtolower(trim($respText)); //find the security questions that match the submitted question (using keymap) $matchedSecQ = $_SESSION['security_keymap'][$questKey]; foreach($matchedSecQ as $qIdx) { //check each matched question in $_SESSION['security_questions'] that matched the posted question //the posted question is mapped to $_SESSION['security_questions'] through $_SESSION['security_keymap'] $checkThisResp = strtolower(trim(preg_replace('/\"(.*)\"/','$1',$_SESSION['security_responses'][$qIdx]))); if(strcmp($checkThisResp,$respText) == 0) { //A match was found! $subjectMatched = true; include_once('htmlhead_name_mesg.php'); //Present the subject with their password, set their subject ID, reinstate their old session (if exists), and allow them to proceed. print "

" . LANGUAGE_TEXT_YOUR_PASSCODE_IS . $_SESSION['security_passphrases'][$qIdx] .". "; print LANGUAGE_TEXT_PRINT_OR_WRITE_INSTRUCTION . "

"; //assign the subject_id $_SESSION['subject_id'] = $_SESSION['security_subject_ids'][$qIdx]; if(responses_exist_for_sub($_SESSION['subject_id'],$_SESSION['response_table'])) { find_old_session($_SESSION['subject_id']); } else { //if there are no pre-existing responses, update the current session ID and responses with the subject ID // add the subject id to the session information $sql_update_session = sprintf("update session set subject_id = %s, php_session_id=%s where session_id = %s ", GetSQLValueString($_SESSION['subject_id'],"text"), GetSQLValueString($_COOKIE[$QPI_SESSION_NAME],"text"), GetSQLValueString($_SESSION['session_id'],"int")); mysql_update($sql_update_session); // update any responses that have already been given in the experiment's response table $sql_update_responses = sprintf("update %s set subject_id = %s where session_id = %s ", $_SESSION['response_table'], GetSQLValueString($_SESSION['subject_id'],"text"), GetSQLValueString($_SESSION['session_id'],"int")); mysql_update($sql_update_responses); }//else //clear the security session variables unset($_SESSION['security_questions']); unset($_SESSION['security_responses']); unset($_SESSION['security_subject_ids']); unset($_SESSION['security_passphrases']); unset($_SESSION['security_keymap']); unset($_SESSION['security_first_name']); unset($_SESSION['security_last_name']); unset($_SESSION['security_dob']); //print a form to continue the session printf("
\n"); printf("\n",LANGUAGE_TEXT_QPI_NEXT_BUTTON); printf("\n
\n"); //break out of both "for" loops break 2; } //if(strcmp($checkThisResp,$respText) == 0) } //foreach $matchedSecQ (matched questions to this name/dob combination } //foreach $questResps (each response that was posted to the security questions if(!$subjectMatched) { //if subject was not matched (no security responses matched), the survey will proceed without a subject ID //make sure to follow this form with another form that provides the subject with instructions on what to do //since there is no subject ID for this session! You may also want to assign appropriate form handlers to end the //session after providing the subject with a message. include('update_session.php'); } } else { //this section displays the questions (prior to posting the form) //get all possible security questions and responses that match this subject $sql_get_security_questions = sprintf("select subject_id,security_questions,aes_decrypt(`security_responses`,'%s') as security_responses, " . " aes_decrypt(`passphrase`,'%s') as passphrase from subject where " . " lower(convert(aes_decrypt(`name_first`,'%s') using utf8)) like '%s' " . " and lower(convert(aes_decrypt(`name_last`,'%s') using utf8)) like '%s' " . " and aes_decrypt(`dob`,'%s') like '%s' ", $enc_key, $enc_key, $enc_key,strtolower($first_name_match), $enc_key,strtolower($last_name_match), $enc_key,$dob_match); $result_get_security_questions = mysql_query($sql_get_security_questions) or report_error_form(mysql_error()); $seqQuestions = array(); $seqResponses = array(); $seqSIDs = array(); $seqPassphrases = array(); while($row_get_security_questions = mysql_fetch_assoc($result_get_security_questions)) { $questsThisSub = explode(",",$row_get_security_questions['security_questions']); $respsThisSub = explode(",",$row_get_security_questions['security_responses']); $nQuests = sizeof($questsThisSub); $seqQuestions = array_merge($seqQuestions,$questsThisSub); $seqResponses = array_merge($seqResponses,$respsThisSub); $thisSubID = $row_get_security_questions['subject_id']; $thisPassphrase = $row_get_security_questions['passphrase']; $seqSIDs = array_merge($seqSIDs,array_fill(0,$nQuests,$thisSubID)); $seqPassphrases = array_merge($seqPassphrases,array_fill(0,$nQuests,$thisPassphrase)); } $uniqueQuestions = array_unique($seqQuestions); //remove null values from $uniqueQuestions $uniqueQuestions = array_filter($uniqueQuestions,strlen); //if no $uniqueQuestions, just go to the next form. This means that there are no security questions in the subject table. if((sizeof($uniqueQuestions) == 0)) { include('update_session.php'); } $_SESSION['security_questions'] = $seqQuestions; $_SESSION['security_responses'] = $seqResponses; $_SESSION['security_subject_ids'] = $seqSIDs; $_SESSION['security_passphrases'] = $seqPassphrases; include_once('htmlhead_name_mesg_formhead.php'); printf("
\n",$_SERVER['PHP_SELF']); //present the unique security questions for this name/dob match foreach ($uniqueQuestions as $questKey=>$thisQuest) { //find the mapping between unique questions and the security_questions list $_SESSION['security_keymap'][$questKey] = array_keys($_SESSION['security_questions'],$thisQuest); //remove the double quotes around the question for display $thisQuest = preg_replace('/\"(.*)\"/','$1',$thisQuest); printf("

%s
",$thisQuest); printf("

\n",$questKey,$questKey); } printf("\n"); printf("\n",LANGUAGE_TEXT_QPI_NEXT_BUTTON); printf("\n
\n"); } //else ?>