* Initialization code: * This code is run at the load of classes.php, which is why the code is standalone, as opposed to wrapped in a funcion. */ // Forces the user to be authorized by CAS before displaying the page. forceAuth(); // Connect to the database $conn = new PDO('mysql:host=localhost;dbname=slatecrate', $config['DB_USERNAME'], $config['DB_PASSWORD']); // Determine if the user has admin status $isAdmin = determineAdminStatus($conn, phpCAS::getUser()); /** * Submitted actions: these are called when classes.php is loaded as an action of HTML forms from classes.php, * addclasses.php, and editclasses.php. */ if (isset($_POST["edit"])) { // Update an edited class with new details $alertArray = executeEdit($conn, $_POST["className"], $_POST["inputCategory"], $_POST["edit"]); } else { if (isset($_POST["user"])) { // Create a newly added class with the new details $alertArray = executeAdd($conn, $_POST["className"], $_POST["inputCategory"], $_POST["user"]); } else { if (isset($_POST["delete"])) { // Complete the deletion of a class $alertArray = executeDelete($conn, $_POST["delete"]); } } } /** * Uses the responses of executeEdit, executeAdd, and executeDelete to generate appropriate alerts as necessary. */ if (isset($alertArray)) {
//up or downvote if (isset($_POST["upvote"])) { executeVote($conn, $_POST["upvote"], 1); } else { if (isset($_POST["downvote"])) { executeVote($conn, $_POST["downvote"], -1); } else { if (isset($_POST["user"])) { // add class if we need to $alertArray = executeAdd($conn, $_POST["URL"], $_POST["classForAdd"], $_POST["linkName"]); } else { if (isset($_POST["delete"])) { $alertArray = executeDelete($conn, $_POST["delete"]); } else { if (isset($_POST["edit"])) { $alertArray = executeEdit($conn, $_POST["URL"], $_POST["classForAdd"], $_POST["linkName"], $_POST["edit"]); } } } } } if (isset($alertArray)) { $alertType = $alertArray[0]; $alertMessage = $alertArray[1]; } else { $alertMessage = ""; $alertType = ""; } //sort $sort = isset($_POST["sort"]) ? $_POST["sort"] : "`score` DESC"; try {