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"; } echo <<<HTML <div class="question {$class}" onclick="load_question({$id})"> \t{$question} </div> HTML; } echo "</div>"; } } } else { echo "<h1>You must be on a team to compete!</h1>"; } ?>
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); if ($v) { set_has_solved($id); echo 'OK'; } else { echo 'Incorrect.'; } break; case 'modify': if (!(isset($_POST['id']) && isset($_POST['q']) && isset($_POST['a']) && isset($_POST['cat']) && isset($_POST['points']))) { die("Insufficient data to update challenge."); }