<commit_before><?php

	// Start a session on the server.
	ob_start();
	include_once("prisoner.classes.php");
	session_start();

	// Include any required components.
	include_once("prisoner.authentication.php");
	include_once("prisoner.classes.php");
	include_once("prisoner.constants.php");
	include_once("prisoner.core.php");
	include_once("prisoner.database.php");
	include_once("prisoner.mail.php");
	include_once("prisoner.questionnaire.php");
	
	// Session / cache control.
	header("Cache-Control: no-cache");
	
	// Should the participant be here?
	$can_view = assert_can_view(STAGE_GIVEN_CONSENT);
	
	// No. Take them back to the index / landing page.
	if (!$can_view) {
		log_msg("Caught bad participant. Redirecting to landing page.");
		header("Location: index.php");
	}
		
	// Retrieve info from session.
	$participant_id = $_SESSION["participant_id"];
	$prisoner_participant_id = $_SESSION["prisoner_participant_id"];
	$participant_group = $_SESSION["group"];
	$study_title = $_SESSION["study_title"];
	$prisoner_session_id = $_SESSION["prisoner_session_id"];
	
	// Grab data from database.
	$query = "SELECT * FROM participant WHERE id = '$participant_id'";
	$result = mysqli_query($db, $query);
	$row = mysqli_fetch_array($result);
	$email_address_msg = NULL;
	
	// This should NOT happen, but just in case.
	if (!$result) {
		log_msg("Error - Failed to retrieve participant email address: " . mysqli_error($db));
		$email_address_msg = get_notice("To get your Amazon voucher code, please email <a href='mailto:<EMAIL>'><EMAIL></a> " .
		"and quote the reference <strong>" . $participant_id . "</strong>.", false);
	}
	
	// Tell the participant where their voucher code will be sent.
	else {
		log_msg("Retrieved participant email address.");
		log_msg("Address (" . $email_address . ") matches PRISONER participant ID " . $prisoner_participant_id . ".");
		$email_address = decrypt($row["email_address"]);
		$email_address_msg = get_notice("Your Amazon voucher code will be sent to the email address <strong>" . $email_address ."</strong> within " .
		"a few days.", false);
	}
	
	// Flush output buffers.
	ob_end_flush();
	
?>

<!DOCTYPE HTML>
<html>
	<head>
		<?php include_once("prisoner.include.head.php"); ?>
		<title>Ethics In Online Social Network Research - University Of St Andrews</title>
	</head>
	
	<body>
		<div class="wrapper">
			<div class="content-container">
				<div class="content">
					<div class="info">
						<h1>Debriefing</h1>
						
						<?php echo $email_address_msg; ?>
						
						<h2>1. Your results</h2>
						<ul><commit_msg>Moved call to log_msg() so we have the encrypted email address by the time it is called.<commit_after><?php

	// Start a session on the server.
	ob_start();
	include_once("prisoner.classes.php");
	session_start();

	// Include any required components.
	include_once("prisoner.authentication.php");
	include_once("prisoner.classes.php");
	include_once("prisoner.constants.php");
	include_once("prisoner.core.php");
	include_once("prisoner.database.php");
	include_once("prisoner.mail.php");
	include_once("prisoner.questionnaire.php");
	
	// Session / cache control.
	header("Cache-Control: no-cache");
	
	// Should the participant be here?
	$can_view = assert_can_view(STAGE_GIVEN_CONSENT);
	
	// No. Take them back to the index / landing page.
	if (!$can_view) {
		log_msg("Caught bad participant. Redirecting to landing page.");
		header("Location: index.php");
	}
		
	// Retrieve info from session.
	$participant_id = $_SESSION["participant_id"];
	$prisoner_participant_id = $_SESSION["prisoner_participant_id"];
	$participant_group = $_SESSION["group"];
	$study_title = $_SESSION["study_title"];
	$prisoner_session_id = $_SESSION["prisoner_session_id"];
	
	// Grab data from database.
	$query = "SELECT * FROM participant WHERE id = '$participant_id'";
	$result = mysqli_query($db, $query);
	$row = mysqli_fetch_array($result);
	$email_address_msg = NULL;
	
	// This should NOT happen, but just in case.
	if (!$result) {
		log_msg("Error - Failed to retrieve participant email address: " . mysqli_error($db));
		$email_address_msg = get_notice("To get your Amazon voucher code, please email <a href='mailto:<EMAIL>'><EMAIL></a> " .
		"and quote the reference <strong>" . $participant_id . "</strong>.", false);
	}
	
	// Tell the participant where their voucher code will be sent.
	else {
		log_msg("Retrieved participant email address.");
		$email_address = decrypt($row["email_address"]);
		$email_address_msg = get_notice("Your Amazon voucher code will be sent to the email address <strong>" . $email_address ."</strong> within " .
		"a few days.", false);
		log_msg("Address (" . $email_address . ") matches PRISONER participant ID " . $prisoner_participant_id . ".");
	}
	
	// Flush output buffers.
	ob_end_flush();
	
?>

<!DOCTYPE HTML>
<html>
	<head>
		<?php include_once("prisoner.include.head.php"); ?>
		<title>Ethics In Online Social Network Research - University Of St Andrews</title>
	</head>
	
	<body>
		<div class="wrapper">
			<div class="content-container">
				<div class="content">
					<div class="info">
						<h1>Debriefing</h1>
						
						<?php echo $email_address_msg; ?>
						
						<h2>1. Your results</h2>
						<ul>
{'fraction_non_alphanumeric': 0.14876507754164273, 'fraction_numerical': 0.0019146084625694046, 'mean_word_length': 4.330612244897959, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4643034', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1675, 'n_words': 423}