aboutsummaryrefslogtreecommitdiff
path: root/include/offers.php
diff options
context:
space:
mode:
authorCamil Staps2016-07-31 23:39:22 +0200
committerCamil Staps2016-07-31 23:39:22 +0200
commit87b38e1cb5d5d5ebddfa4601a9088c3eadaf7ef0 (patch)
treed3bae56b43ab75e0939040c8af271abc7631387e /include/offers.php
parentMail: add SMTP_AUTH_TYPE (diff)
Easier emails
Diffstat (limited to 'include/offers.php')
-rw-r--r--include/offers.php115
1 files changed, 57 insertions, 58 deletions
diff --git a/include/offers.php b/include/offers.php
index dbe5df0..e06a4eb 100644
--- a/include/offers.php
+++ b/include/offers.php
@@ -41,49 +41,22 @@ require('./header.php');
// ?delete=<id> Delete the offer with id <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 = "<a href='".Constants::url_external."offers'>Offers</a> / #{$offer->id}";
- $show_individual = $id;
- } catch (PDOException $e) {
- $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id $id</i> could not be found.</div>";
- } catch (Exception $e) {
- $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id $id</i> could not be found.</div>";
- }
- }
-
- // Show the header
- echo "<div class='col-lg-12'><h1 class='page-header'>$header</h1></div>";
- if (isset($alert)) echo "<div class='col-lg-12'>$alert</div>";
-
// Accept offer
if (isset($_GET['toggle_accept'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['toggle_accept'];
try {
$offer = new Offer($_pdo, $id);
$offer->accepted = !$offer->accepted;
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of offer #{$offer->id} has been set to <i>".($offer->accepted ? "accepted" : "unaccepted")."</i>.</div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of offer #{$offer->id} has been set to <i>".($offer->accepted ? "accepted" : "unaccepted")."</i>.</div>";
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of the offer could not be changed due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of the offer could not be changed due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
}
-
- echo "</div>";
}
// Toggle offer payment eligibility
if (isset($_GET['toggle_payment_eligibility'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['toggle_payment_eligibility'];
try {
$offer = new Offer($_pdo, $id);
@@ -92,91 +65,117 @@ require('./header.php');
} else {
$offer->payment_key = Offer::getRandomPaymentKey();
}
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} is now <i>".($offer->getPaymentEligibility() ? "eligible" : "ineligible")."</i> for online payment.</div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} is now <i>".($offer->getPaymentEligibility() ? "eligible" : "ineligible")."</i> for online payment.</div>";
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The online payment eligibility could not be changed due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The online payment eligibility could not be changed due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
}
-
- echo "</div>";
}
// Generate invoice
if (isset($_GET['generate_invoice'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['generate_invoice'];
try {
$offer = new Offer($_pdo, $id);
$file = $offer->generateInvoice();
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is generated: <a class='alert-link' href='{$file->getFilenameURI()}' target='_blank'>{$file->filename}</a></div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is generated: <a class='alert-link' href='{$file->getFilenameURI()}' target='_blank'>{$file->filename}</a></div>";
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be generated due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be generated due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be generated.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be generated.</div>";
}
- echo "</div>";
}
// Trash invoice
if (isset($_GET['trash_invoice'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['trash_invoice'];
try {
$offer = new Offer($_pdo, $id);
$file = $offer->getInvoiceFile();
if ($file instanceof file && $file->delete()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is trashed.</div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is trashed.</div>";
} else {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
}
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be trashed due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be trashed due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
}
- echo "</div>";
}
// Send invoice
if (isset($_GET['send_invoice'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['send_invoice'];
try {
$offer = new Offer($_pdo, $id);
if ($offer->send()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer {$id} has been sent to {$offer->getContact()->email}.</div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer {$id} has been sent to {$offer->getContact()->email}.</div>";
} else {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to an unknown error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to an unknown error.</div>";
}
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
}
- echo "</div>";
}
// Delete offer
if (isset($_GET['delete'])) {
- echo "<div class='col-lg-12'>";
$id = (int) $_GET['delete'];
try {
$offer = new Offer($_pdo, $id);
if ($offer->delete()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} has been removed.</div>";
+ $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} has been removed.</div>";
} else {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} could not be removed. Perhaps it's already removed?</div>";
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} could not be removed. Perhaps it's already removed?</div>";
}
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer could not be removed due to a PDO error.</div>";
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer could not be removed due to a PDO error.</div>";
} catch (Exception $e) {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>";
}
+ }
+
+ //------------------------------------------------------------------------------
+ // 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;
- echo "</div>";
+ // View offer
+ if (isset($_GET['id'])) {
+ $id = (int) $_GET['id'];
+ try {
+ $offer = new Offer($_pdo, $id);
+ $header = "<a href='".Constants::url_external."offers'>Offers</a> / #{$offer->id}";
+ $show_individual = $id;
+ $accepted = $offer->accepted ?
+ ['Accepted', 'btn-success'] :
+ ['Not accepted', 'btn-default'];
+ $eligible = $offer->getPaymentEligibility() ?
+ ['Eligible for online payment', 'btn-success'] :
+ ['Not eligible for online payment', 'btn-default'];
+ $header .= "<span class='pull-right'>
+ <a title='{$accepted[0]}' href='?id={$offer->id}&toggle_accept={$offer->id}' class='btn {$accepted[1]}'><i class='fa fa-fw fa-check'></i> {$accepted[0]}</a>
+ <a title='{$eligible[0]}' href='?id={$offer->id}&toggle_payment_eligibility={$offer->id}' class='btn {$eligible[1]}'><i class='fa fa-fw fa-credit-card'></i> {$eligible[0]}</a>
+ <a title='Send invoice' href='#' onclick='offerEmail({$offer->id})' class='btn btn-info'><i class='fa fa-fw fa-envelope'></i> Send invoice to contact</a>
+ <a title='Delete' href='?delete={$offer->id}' class='btn btn-danger'><i class='fa fa-fw fa-times'></i> Delete</a>
+ </span>";
+ } catch (PDOException $e) {
+ $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id $id</i> could not be found.</div>";
+ } catch (Exception $e) {
+ $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id $id</i> could not be found.</div>";
+ }
}
+ // Show the header
+ echo "<div class='col-lg-12'><h1 class='page-header'>$header</h1></div>";
+ if (isset($alert)) echo "<div class='col-lg-12'>$alert</div>";
+
if ($show_individual !== false) {
$_id = $show_individual;
require('offers-view.php');