From 0b60b0ccc66cbcc26619ac762b8881f52fa85bf7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 20 Jul 2016 10:54:07 +0200 Subject: Discounts --- include/discounts.php | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 include/discounts.php (limited to 'include/discounts.php') diff --git a/include/discounts.php b/include/discounts.php new file mode 100644 index 0000000..83cb1b8 --- /dev/null +++ b/include/discounts.php @@ -0,0 +1,98 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ 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->getTitle()}"; + $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->getTitle()} has been removed.
"; + } else { + echo "
The discount with title {$discount->getTitle()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The discount could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The discount with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('discounts-view.php'); + } else { + require('discounts-overview.php'); + } + ?> +
+ +
+ + +
+ + + -- cgit v1.2.3