Skip to content

Commit 28a0343

Browse files
author
wrongecho
committed
Quote notifications
- Send an internal email when quotes are accepted/declined - Clients are prompted to confirm accept/decline with confirm-link - Tidy
1 parent e4f618c commit 28a0343

File tree

9 files changed

+101
-11
lines changed

9 files changed

+101
-11
lines changed

admin_settings_quote.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
<textarea class="form-control" rows="4" name="config_quote_footer"><?php echo nullable_htmlentities($config_quote_footer); ?></textarea>
3636
</div>
3737

38+
<div class="form-group">
39+
<label>Email address to notify when quotes are accepted/declined <small class="text-secondary">(Ideally a distribution list/shared mailbox)</small></label>
40+
<div class="input-group">
41+
<div class="input-group-prepend">
42+
<span class="input-group-text"><i class="fa fa-fw fa-bell"></i></span>
43+
</div>
44+
<input type="email" class="form-control" name="config_quote_notification_email" placeholder="Address to notify for quote accept/declines, leave bank for none" value="<?php echo nullable_htmlentities($config_quote_notification_email); ?>">
45+
</div>
46+
</div>
47+
3848
<hr>
3949

4050
<button type="submit" name="edit_quote_settings" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>

database_updates.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,10 +2232,16 @@ function processFile($file_path, $file_name, $mysqli) {
22322232
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.5'");
22332233
}
22342234

2235-
// if (CURRENT_DATABASE_VERSION == '1.6.5') {
2236-
// // Insert queries here required to update to DB version 1.6.6
2235+
if (CURRENT_DATABASE_VERSION == '1.6.5') {
2236+
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_quote_notification_email` VARCHAR(200) DEFAULT NULL AFTER `config_quote_from_email`");
2237+
2238+
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.6'");
2239+
}
2240+
2241+
// if (CURRENT_DATABASE_VERSION == '1.6.6') {
2242+
// // Insert queries here required to update to DB version 1.6.7
22372243
// // Then, update the database to the next sequential version
2238-
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.6'");
2244+
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.7'");
22392245
// }
22402246

22412247
} else {

database_version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* It is used in conjunction with database_updates.php
66
*/
77

8-
DEFINE("LATEST_DATABASE_VERSION", "1.6.5");
8+
DEFINE("LATEST_DATABASE_VERSION", "1.6.6");

db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ CREATE TABLE `settings` (
15171517
`config_quote_footer` text DEFAULT NULL,
15181518
`config_quote_from_name` varchar(200) DEFAULT NULL,
15191519
`config_quote_from_email` varchar(200) DEFAULT NULL,
1520+
`config_quote_notification_email` varchar(200) DEFAULT NULL,
15201521
`config_ticket_prefix` varchar(200) DEFAULT NULL,
15211522
`config_ticket_next_number` int(11) DEFAULT NULL,
15221523
`config_ticket_from_name` varchar(200) DEFAULT NULL,

get_settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
$config_quote_footer = $row['config_quote_footer'];
5959
$config_quote_from_name = $row['config_quote_from_name'];
6060
$config_quote_from_email = $row['config_quote_from_email'];
61+
$config_quote_notification_email = $row['config_quote_notification_email'];
6162

6263
// Projects
6364
$config_project_prefix = $row['config_project_prefix'];

guest_footer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<!-- ./wrapper -->
88

99
<!-- REQUIRED SCRIPTS -->
10+
<?php require_once "inc_confirm_modal.php"; ?>
1011

1112
<!-- jQuery -->
1213
<script src="plugins/jquery/jquery.min.js"></script>
@@ -23,5 +24,7 @@
2324

2425
<script src="js/app.js"></script>
2526

27+
<script src="js/confirm_modal.js"></script>
28+
2629
</body>
2730
</html>

guest_post.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,44 @@
2323

2424
mysqli_query($mysqli, "UPDATE quotes SET quote_status = 'Accepted' WHERE quote_id = $quote_id");
2525
mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Accepted', history_description = 'Client accepted Quote!', history_quote_id = $quote_id");
26+
2627
// Notification
2728
appNotify("Quote Accepted", "Quote $quote_prefix$quote_number has been accepted by $client_name", "quote.php?quote_id=$quote_id", $client_id);
29+
customAction('quote_accept', $quote_id);
2830

31+
// Internal email notification
32+
33+
$sql_company = mysqli_query($mysqli, "SELECT company_name FROM companies WHERE company_id = 1");
34+
$row = mysqli_fetch_array($sql_company);
35+
$company_name = sanitizeInput($row['company_name']);
36+
37+
$sql_settings = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1");
38+
$row = mysqli_fetch_array($sql_settings);
39+
$config_smtp_host = $row['config_smtp_host'];
40+
$config_smtp_port = intval($row['config_smtp_port']);
41+
$config_smtp_encryption = $row['config_smtp_encryption'];
42+
$config_smtp_username = $row['config_smtp_username'];
43+
$config_smtp_password = $row['config_smtp_password'];
44+
$config_quote_from_name = sanitizeInput($row['config_quote_from_name']);
45+
$config_quote_from_email = sanitizeInput($row['config_quote_from_email']);
46+
$config_quote_notification_email = sanitizeInput($row['config_quote_notification_email']);
47+
$config_base_url = sanitizeInput($config_base_url);
48+
49+
if (!empty($config_smtp_host) && !empty($config_quote_notification_email)) {
50+
$subject = "Quote Accepted - $client_name - Quote $quote_prefix$quote_number";
51+
$body = "Hello, <br><br>This is a notification that a quote has been accepted in ITFlow. <br><br>Client: $client_name<br>Quote: <a href=\'https://$config_base_url/quote.php?quote_id=$quote_id\'>$quote_prefix$quote_number</a><br><br>~<br>$company_name - Billing<br>$config_quote_from_email";
52+
53+
$data[] = [
54+
'from' => $config_quote_from_email,
55+
'from_name' => $config_quote_from_name,
56+
'recipient' => $config_quote_notification_email,
57+
'subject' => $subject,
58+
'body' => $body,
59+
];
60+
61+
$mail = addToMailQueue($mysqli, $data);
62+
}
2963

30-
customAction('quote_accept', $quote_id);
3164
$_SESSION['alert_message'] = "Quote Accepted";
3265
header("Location: " . $_SERVER["HTTP_REFERER"]);
3366
} else {
@@ -51,10 +84,44 @@
5184

5285
mysqli_query($mysqli, "UPDATE quotes SET quote_status = 'Declined' WHERE quote_id = $quote_id");
5386
mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Declined', history_description = 'Client declined Quote!', history_quote_id = $quote_id");
87+
5488
// Notification
5589
appNotify("Quote Declined", "Quote $quote_prefix$quote_number has been declined by $client_name", "quote.php?quote_id=$quote_id", $client_id);
56-
5790
customAction('quote_decline', $quote_id);
91+
92+
// Internal email notification
93+
94+
$sql_company = mysqli_query($mysqli, "SELECT company_name FROM companies WHERE company_id = 1");
95+
$row = mysqli_fetch_array($sql_company);
96+
$company_name = sanitizeInput($row['company_name']);
97+
98+
$sql_settings = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1");
99+
$row = mysqli_fetch_array($sql_settings);
100+
$config_smtp_host = $row['config_smtp_host'];
101+
$config_smtp_port = intval($row['config_smtp_port']);
102+
$config_smtp_encryption = $row['config_smtp_encryption'];
103+
$config_smtp_username = $row['config_smtp_username'];
104+
$config_smtp_password = $row['config_smtp_password'];
105+
$config_quote_from_name = sanitizeInput($row['config_quote_from_name']);
106+
$config_quote_from_email = sanitizeInput($row['config_quote_from_email']);
107+
$config_quote_notification_email = sanitizeInput($row['config_quote_notification_email']);
108+
$config_base_url = sanitizeInput($config_base_url);
109+
110+
if (!empty($config_smtp_host) && !empty($config_quote_notification_email)) {
111+
$subject = "Quote Declined - $client_name - Quote $quote_prefix$quote_number";
112+
$body = "Hello, <br><br>This is a notification that a quote has been declined in ITFlow. <br><br>Client: $client_name<br>Quote: <a href=\'https://$config_base_url/quote.php?quote_id=$quote_id\'>$quote_prefix$quote_number</a><br><br>~<br>$company_name - Billing<br>$config_quote_from_email";
113+
114+
$data[] = [
115+
'from' => $config_quote_from_email,
116+
'from_name' => $config_quote_from_name,
117+
'recipient' => $config_quote_notification_email,
118+
'subject' => $subject,
119+
'body' => $body,
120+
];
121+
122+
$mail = addToMailQueue($mysqli, $data);
123+
}
124+
58125
$_SESSION['alert_type'] = "danger";
59126
$_SESSION['alert_message'] = "Quote Declined";
60127
header("Location: " . $_SERVER["HTTP_REFERER"]);

guest_view_quote.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
$quote_amount = floatval($row['quote_amount']);
4545
$quote_currency_code = nullable_htmlentities($row['quote_currency_code']);
4646
$quote_note = nullable_htmlentities($row['quote_note']);
47-
$category_id = intval($row['category_id']);
4847
$client_id = intval($row['client_id']);
4948
$client_name = nullable_htmlentities($row['client_name']);
5049
$client_name_escaped = sanitizeInput($row['client_name']);
@@ -273,10 +272,10 @@
273272
<?php
274273
if ($quote_status == "Sent" || $quote_status == "Viewed" && strtotime($quote_expire) > strtotime("now")) {
275274
?>
276-
<a class="btn btn-success" href="guest_post.php?accept_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
275+
<a class="btn btn-success confirm-link" href="guest_post.php?accept_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
277276
<i class="fas fa-fw fa-thumbs-up mr-2"></i>Accept
278277
</a>
279-
<a class="btn btn-danger" href="guest_post.php?decline_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
278+
<a class="btn btn-danger confirm-link" href="guest_post.php?decline_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
280279
<i class="fas fa-fw fa-thumbs-down mr-2"></i>Decline
281280
</a>
282281
<?php } ?>
@@ -712,7 +711,6 @@
712711
}
713712
</script>
714713

715-
716714
<?php
717715
require_once "guest_footer.php";
718716

post/admin/admin_settings_quote.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
$config_quote_prefix = sanitizeInput($_POST['config_quote_prefix']);
88
$config_quote_next_number = intval($_POST['config_quote_next_number']);
99
$config_quote_footer = sanitizeInput($_POST['config_quote_footer']);
10+
$config_quote_notification_email = '';
11+
if (filter_var($_POST['config_quote_notification_email'], FILTER_VALIDATE_EMAIL)) {
12+
$config_quote_notification_email = sanitizeInput($_POST['config_quote_notification_email']);
13+
}
1014

11-
mysqli_query($mysqli,"UPDATE settings SET config_quote_prefix = '$config_quote_prefix', config_quote_next_number = $config_quote_next_number, config_quote_footer = '$config_quote_footer' WHERE company_id = 1");
15+
mysqli_query($mysqli,"UPDATE settings SET config_quote_prefix = '$config_quote_prefix', config_quote_next_number = $config_quote_next_number, config_quote_footer = '$config_quote_footer', config_quote_notification_email = '$config_quote_notification_email' WHERE company_id = 1");
1216

1317
//Logging
1418
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name modified quote settings', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");

0 commit comments

Comments
 (0)