aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ajax-email-offer.php86
-rw-r--r--include/offers-view.php20
-rw-r--r--include/offers.php115
3 files changed, 143 insertions, 78 deletions
diff --git a/include/ajax-email-offer.php b/include/ajax-email-offer.php
new file mode 100644
index 0000000..3960d37
--- /dev/null
+++ b/include/ajax-email-offer.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * BusinessAdmin: administrative software for small companies
+ * Copyright (C) 2015 Camil Staps (ViviSoft)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('./login-ajax.php');
+
+$_offer = new Offer($_pdo, $_REQUEST['id']);
+$_mailer = $_offer->mailer();
+
+function format_email($address) {
+ if ($address[1] != '') {
+ return "{$address[1]} <{$address[0]}>";
+ } else {
+ return $address[0];
+ }
+}
+
+if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+?>
+ <form action='#' class='form-horizontal' method='post'>
+ <input type='hidden' name='id' value='<?=$_offer->id?>'/>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>From</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='from' value='<?=$_mailer->FromName?> <<?=$_mailer->From?>>'/></div>
+ </div>
+ <?php foreach ($_mailer->getReplyToAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Reply-To</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='replyto[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getBccAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>BCC</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='bcc[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getCcAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>CC</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='cc[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } foreach ($_mailer->getToAddresses() as $addr) { ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>To</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' readonly='readonly' name='to[]' value='<?=format_email($addr)?>'/></div>
+ </div>
+ <?php } ?>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Subject</label>
+ <div class='col-sm-10'><input class='form-control input-sm' type='text' name='subject' value='<?=$_mailer->Subject?>'/></div>
+ </div>
+ <div class='form-group'>
+ <label class='col-sm-2 control-label'>Body</label>
+ <div class='col-sm-10'><textarea class='form-control input-sm' rows='10' name='body'><?=$_mailer->Body?></textarea></div>
+ </div>
+ </form>
+<?php
+} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $_mailer->Subject = $_POST['subject'];
+ $_mailer->Body = $_POST['body'];
+ try {
+ if ($_mailer->send()) {
+ echo 'OK';
+ } else {
+ http_response_code(500);
+ echo 'Sending the email failed:<br/>' . $_mailer->ErrorInfo;
+ }
+ } catch (Exception $e) {
+ http_response_code(500);
+ echo "Sending the email failed with an exception ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+}
diff --git a/include/offers-view.php b/include/offers-view.php
index d96e9ed..ec579b6 100644
--- a/include/offers-view.php
+++ b/include/offers-view.php
@@ -107,26 +107,6 @@ $_offer = new Offer($_pdo, $_id);
</div>
</div>
</div>
-<div class="clearfix"></div>
-<div class="col-md-6">
- <div class="panel panel-default">
- <div class="panel-heading">Tools</div>
- <div class="panel-body">
- <?php
- $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'];
- ?>
- <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='?id=<?=$_offer->id?>&send_invoice=<?=$_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>
- </div>
- </div>
-</div>
<div class="col-md-6">
<div class="panel panel-default" id="panel-timeline">
<div class="panel-heading">
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');