<li onclick="location.assign('index.php')"><span class="text">Home</span></li>
					<li onclick="location.assign('scoreboard.php')"><span class="text">Scoreboard</span></li>
					<li onclick="Data.SignOut()"><span class="text">Log Out</span></li>
				<?php 
}
?>
			</ul>
		</div>
		<div id="main" class="challenges">
			<?php 
if (load_user_data('team')) {
    $all = load_challenges();
    if (count($all) > 0) {
        $lst = [];
        foreach ($all as $chal) {
            $lst[] = load_full_challenge($chal);
        }
        $dsp = [];
        foreach ($lst as $item) {
            $cat = $item['category'];
            $dsp[$cat][] = ["points" => $item['points'], "id" => $item['challenge_id']];
        }
        foreach ($dsp as $cname => $category) {
            echo "<div class=\"row\">";
            echo "<div class=\"cname\">" . htmlentities($cname) . "</div>";
            foreach ($category as $questiondata) {
                $question = htmlentities($questiondata['points']);
                $id = htmlentities($questiondata['id']);
                $class = "";
                if (check_has_solved($id)) {
                    $class = "solved";
     if (!isset($_POST['id'])) {
         die("No ID provided for challenge fetch.");
     }
     echo load_challenge($_POST['id']);
     break;
 case 'fetch_full':
     if (!isset($_POST['id'])) {
         die("No ID provided for challenge fetch.");
     }
     echo json_encode(load_full_challenge($_POST['id']));
     break;
 case 'list':
     $cs = load_challenges();
     $qs = [];
     foreach ($cs as $item) {
         $fc = load_full_challenge($item);
         $qs[] = json_encode(['qtext' => $fc['qtext'], 'challenge_id' => $fc['challenge_id'], 'points' => $fc['points'], 'category' => $fc['category']]);
     }
     echo json_encode($qs);
     break;
 case 'verify':
     if (!(isset($_POST['id']) && isset($_POST['answer']))) {
         die('ID or answer not provided to verify question.');
     }
     $id = $conn->real_escape_string($_POST['id']);
     $ans = $conn->real_escape_string($_POST['answer']);
     $hassolved = check_has_solved($id);
     if ($hassolved) {
         die('You have already solved this question!');
     }
     $v = verify_challenge($id, $ans);