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/offers.php | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 include/offers.php (limited to 'include/offers.php') diff --git a/include/offers.php b/include/offers.php new file mode 100644 index 0000000..872773d --- /dev/null +++ b/include/offers.php @@ -0,0 +1,157 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the offer with id + // ?toggle_accept= Toggle the accepted status of the offer with id + // ?generate_invoice= Generate an invoice for the offer with id + // ?trash_invoice= Trash the invoice file + // ?delete= Delete the offer with id + //------------------------------------------------------------------------------ + + // The header of the page + $header = 'Offers'; + // Whether or not to show an individual offer in the end (false if not, or the id if yes) + $show_individual = false; + + // View offer + if (isset($_GET['id'])) { + $id = (int) $_GET['id']; + try { + $offer = new offer($_pdo, $id); + $header = "Offers / #{$offer->getId()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The offer with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The offer with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Accept offer + if (isset($_GET['toggle_accept'])) { + echo "
"; + $id = (int) $_GET['toggle_accept']; + try { + $offer = new offer($_pdo, $id); + if ($offer->toggleAccepted()) { + echo "
The status offer #{$offer->getId()} has been set to ".($offer->isAccepted() ? "accepted" : "unaccepted").".
"; + } else { + echo "
The status of the offer #{$offer->getId()} could not be changed.
"; + } + } catch (PDOException $e) { + echo "
The status of the offer could not be changed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The offer with id {$id} could not be found.
"; + } + + echo "
"; + } + + // Generate invoice + if (isset($_GET['generate_invoice'])) { + echo "
"; + $id = (int) $_GET['generate_invoice']; + try { + $offer = new offer($_pdo, $id); + $file = $offer->generateInvoice(); + echo "
The invoice for offer #{$offer->getId()} is generated: {$file->getFilename()}
"; + } catch (PDOException $e) { + echo "
The invoice for offer #{$offer->getId()} could not be generated due to a PDO error.
"; + } catch (Exception $e) { + echo "
The invoice for offer #{$id} could not be generated.
"; + } + echo "
"; + } + + // Trash invoice + if (isset($_GET['trash_invoice'])) { + echo "
"; + $id = (int) $_GET['trash_invoice']; + try { + $offer = new offer($_pdo, $id); + $file = $offer->getInvoiceFile(); + if ($file instanceof file && $file->delete()) { + echo "
The invoice for offer #{$offer->getId()} is trashed.
"; + } else { + echo "
The invoice for offer #{$id} could not be trashed.
"; + } + } catch (PDOException $e) { + echo "
The invoice for offer #{$offer->getId()} could not be trashed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The invoice for offer #{$id} could not be trashed.
"; + } + echo "
"; + } + + // Delete offer + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $offer = new offer($_pdo, $id); + if ($offer->delete()) { + echo "
The offer #{$offer->getId()} has been removed.
"; + } else { + echo "
The offer #{$offer->getId()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The offer could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The offer with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('offers-view.php'); + } else { + require('offers-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file -- cgit v1.2.3