<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../include/magicquotes.inc.php';

include_once $_SERVER['DOCUMENT_ROOT'] . '/../include/helpers.inc.php';

require_once $_SERVER['DOCUMENT_ROOT'] . '/../include/access.inc.php';

if (!userIsLoggedIn()) {
	include '../login.html.php';
	exit();
}

// Display listing of this user's critiques
include $_SERVER['DOCUMENT_ROOT'] . '/../include/db.inc.php';
// $result = mysqli_query($link, "SELECT posted, type, content FROM critique WHERE recipient='{$_SESSION[username]}' ORDER BY posted DESC");
$rec = $_SESSION['username'];
$result = mysqli_query($link, "SELECT posted, type, content, admin FROM critique 
                                 INNER JOIN user
								 ON critic = username
								 WHERE recipient='{$rec}' ORDER BY posted DESC");
if (!$result) {
	$err = 'Error fetching user&rsquo;s critiques from database!';
	include $_SERVER['DOCUMENT_ROOT'] . '/../include/errmsg.html.php';
	exit();
}

$prescritiques = array();
$tutcritiques = array();
while ($row = mysqli_fetch_assoc($result)) {
	if ($row['type'] == 'Presentation') {
		// $prescritiques[] = $row['content'];
		$prescritiques[] = array(html($row['content']), $row['admin']);
	} else {
		// $tutcritiques[] = $row['content'];
		$tutcritiques[] = array(html($row['content']), $row['admin']);
	}
}

include 'viewcritiques.html.php';
?>
