From c50a323c25a0787ba2051b19721983776a229615 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 5 Feb 2015 00:40:47 +0100 Subject: Initial commit --- include/assignments.php | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 include/assignments.php (limited to 'include/assignments.php') diff --git a/include/assignments.php b/include/assignments.php new file mode 100644 index 0000000..5ba21c6 --- /dev/null +++ b/include/assignments.php @@ -0,0 +1,98 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the assignment with id + // ?delete= Delete the assignment with id + //------------------------------------------------------------------------------ + + // The header of the page + $header = 'Assignments'; + // Whether or not to show an individual assignment in the end (false if not, or the id if yes) + $show_individual = false; + + // View assignment + if (isset($_GET['id'])) { + $id = (int) $_GET['id']; + try { + $assignment = new assignment($_pdo, $id); + $header = "Assignments / {$assignment->getTitle()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The assignment with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The assignment with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Delete assignment + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $assignment = new assignment($_pdo, $id); + if ($assignment->delete()) { + echo "
The assignment with title {$assignment->getTitle()} has been removed.
"; + } else { + echo "
The assignment with title {$assignment->getTitle()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The assignment could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The assignment with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('assignments-view.php'); + } else { + require('assignments-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file -- cgit v1.2.3