View information of the discount with id
// ?delete= Delete the discount with id
//------------------------------------------------------------------------------
// The header of the page
$header = 'Discounts';
// Whether or not to show an individual discount in the end (false if not, or the id if yes)
$show_individual = false;
// View discount
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
try {
$discount = new Discount($_pdo, $id);
$header = "Discounts / {$discount->title}";
$show_individual = $id;
} catch (PDOException $e) {
$alert = "
The discount with id $id could not be found.
";
} catch (Exception $e) {
$alert = "
The discount with id $id could not be found.
";
}
}
// Show the header
echo "
$header
";
if (isset($alert)) echo "
$alert
";
// Delete discount
if (isset($_GET['delete'])) {
echo "
";
$id = (int) $_GET['delete'];
try {
$discount = new Discount($_pdo, $id);
if ($discount->delete()) {
echo "
The discount with title {$discount->title} has been removed.
";
} else {
echo "
The discount with title {$discount->title} could not be removed. Perhaps it's already removed?
";
}
} catch (PDOException $e) {
echo "
The discount could not be removed due to a PDO error.