} } } } } } else { if ($wants == "films") { $filmnight_id = getCurrentFilmNight(); $selections = []; if (loginCheck($session)) { $selections = getSelectedFilmsInUserOrder($filmnight_id, $_SESSION['ID']); } echo json_encode(["status" => "success", "filmList" => $selections, "hasVoted" => $selections[1]["voted"] == "1"]); } else { if ($wants == "votes") { $results = []; if (loginCheck($session) == "admin" && status() == "voting" && !isset($_GET["night"])) { $results = getResults(getCurrentFilmNight()); } else { $results = getResults(getCurrentResultsFilmNight()); } echo json_encode(["status" => "success", "votes" => $results]); } else { echo '{"status": "error", "error": "Don\'t know how to get ' . $wants . '"}'; } } } } } else { echo '{"status": "error", "error": "Nothing Received"}'; }
function selectFilms() { $numFilms = 5; $filmnight_id = getCurrentFilmNight(5); echo $filmnight_id; // Sometimes selection happens multiple times per film night. This is usually before anyone has voted, // but we'll remove any votes just in case. query("DELETE votes FROM votes INNER JOIN selections ON selection_id = selections.id WHERE filmnight_id={$filmnight_id}"); // Now the votes have gone, we can delete existing films in selections query("DELETE FROM selections WHERE filmnight_id={$filmnight_id}"); // Finally, select 5 new films and add them into selections. query("INSERT INTO selections\n SELECT NULL, films.id, {$filmnight_id}\n FROM proposals\n INNER JOIN users ON users.id = proposals.user_id\n RIGHT JOIN films ON films.id = proposals.film_id\n WHERE enabled\n GROUP BY films.id\n HAVING IFNULL(NOT SUM(is_veto AND NOT attending), TRUE)\n ORDER BY RAND()\n LIMIT 5;"); }
ob_end_clean(); // supresses output. if (!loginCheck($session)) { echo "Error: User not logged in"; $_SESSION['ERROR'] = "votinghandler.php failed to confirm that you were logged in"; } else { if (isset($_POST['votes'])) { if ($_POST['votes'] == "WITHDRAW") { withdrawVotes(getCurrentFilmNight(), $_SESSION['ID']); } else { $vote = $_POST['votes']; echo "Vote: " . $_POST['votes']; // Sanitise votes $continue = TRUE; $jsonVote = json_decode($vote, TRUE); $filmnight_id = getCurrentFilmNight(); $sql = "SELECT id, film_id FROM selections WHERE filmnight_id = {$filmnight_id}"; $result = query($sql); $selectedFilms = []; $num_rows = $result->num_rows; if ($num_rows > 0) { while ($row = $result->fetch_assoc()) { $selectedFilms[$row['film_id']] = $row['id']; } } error_log(print_r($selectedFilms, TRUE)); error_log(print_r($jsonVote, TRUE)); $idVote = []; if (sort(array_keys($jsonVote)) != sort(array_keys($selectedFilms))) { $continue = FALSE; $_SESSION['ERROR'] = "Error: Failed to validate your vote.<br>Your list of films doesn't match our list of films<br>{$vote}";