Skip to content

Commit

Permalink
Mail queue & tickets
Browse files Browse the repository at this point in the history
- Allow cancelling emails
- Adjust wording of ticket scheduling emails
  • Loading branch information
wrongecho committed Feb 24, 2024
1 parent da54b12 commit 1e8fbdd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
11 changes: 8 additions & 3 deletions admin_mail_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@
<td>
<button class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#viewEmailModal<?php echo $email_id; ?>"><i class="fas fa-fw fa-eye"></i></button>

<?php if($email_attempts > 3 && $email_status == 2) { ?>

<a class="btn btn-sm btn-success" href="post.php?send_failed_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-paper-plane"></i></a>
<!-- Show force resend if all retries have failed -->
<?php if ($email_status == 2 && $email_attempts > 3) { ?>
<a class="btn btn-sm btn-success" href="post.php?send_failed_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-paper-plane"></i></a>
<?php } ?>

<!-- Allow cancelling a message if it hasn't yet been picked up (e.g. stuck/bugged) -->
<?php if ($email_status == 0) { ?>
<a class="btn btn-sm btn-danger confirm-link" href="post.php?cancel_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-trash"></i></a>
<?php } ?>

</td>
</tr>

Expand Down
8 changes: 4 additions & 4 deletions cron_mail_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

// Process Mail Queue

// Email Status:
// Email Status:
// 0 Queued
// 1 Sending
// 2 Failed
Expand Down Expand Up @@ -102,20 +102,20 @@
);

if ($mail !== true) {
// Update Message
// Update Message - Failure
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = 1 WHERE email_id = $email_id");

mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email_recipient_logging'");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $email_recipient_logging regarding $email_subject_logging. $mail'");
} else {
// Update Message
// Update Message - Success
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 3, email_sent_at = NOW(), email_attempts = 1 WHERE email_id = $email_id");
}
}
}
}

//
//

// Get Mail that failed to send and attempt to send Failed Mail up to 4 times every 30 mins
$sql_failed_queue = mysqli_query($mysqli, "SELECT * FROM email_queue WHERE email_status = 2 AND email_attempts < 4 AND email_failed_at < NOW() + INTERVAL 30 MINUTE");
Expand Down
27 changes: 22 additions & 5 deletions post/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

validateCSRFToken($_POST['csrf_token']);
validateAdminRole();

$test_email = intval($_POST['test_email']);
if($test_email == 1) {
$email_from = sanitizeInput($config_mail_from_email);
Expand Down Expand Up @@ -328,7 +328,7 @@
if (isset($_POST['edit_favicon_settings'])) {

validateCSRFToken($_POST['csrf_token']);

validateAdminRole();

// Check to see if a file is attached
Expand Down Expand Up @@ -451,7 +451,7 @@
if (isset($_POST['edit_ai_settings'])) {

validateCSRFToken($_POST['csrf_token']);

validateAdminRole();

$provider = sanitizeInput($_POST['provider']);
Expand Down Expand Up @@ -538,17 +538,34 @@

$email_id = intval($_GET['send_failed_mail']);

mysqli_query($mysqli,"UPDATE email_queue SET email_attempts = 3 WHERE email_id = $email_id");
mysqli_query($mysqli,"UPDATE email_queue SET email_status = 0, email_attempts = 3 WHERE email_id = $email_id");

// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Send', log_description = '$session_name attempted to force send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Send', log_description = '$session_name attempted to force send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $email_id");

$_SESSION['alert_message'] = "Email Force Sent, give it a minute to resend";

header("Location: " . $_SERVER["HTTP_REFERER"]);

}

if (isset($_GET['cancel_mail'])) {

validateTechRole();

$email_id = intval($_GET['cancel_mail']);

mysqli_query($mysqli,"UPDATE email_queue SET email_status = 2, email_attempts = 99, email_failed_at = NOW() WHERE email_id = $email_id");

// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Cancel', log_description = '$session_name canceled send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $email_id");

$_SESSION['alert_message'] = "Email cancelled and marked as failed.";

header("Location: " . $_SERVER["HTTP_REFERER"]);

}

if (isset($_GET['download_database'])) {

validateCSRFToken($_GET['csrf_token']);
Expand Down
22 changes: 10 additions & 12 deletions post/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1473,10 +1473,10 @@
mysqli_query(
$mysqli,
"UPDATE tickets SET
ticket_schedule = '$schedule',
ticket_onsite = '$onsite',
ticket_status = 'Scheduled'
WHERE ticket_id = $ticket_id"
ticket_schedule = '$schedule',
ticket_onsite = '$onsite',
ticket_status = 'Scheduled'
WHERE ticket_id = $ticket_id"
);


Expand All @@ -1499,7 +1499,6 @@
WHERE ticket_id = $ticket_id
");


$row = mysqli_fetch_array($sql);

$client_id = intval($row['ticket_client_id']);
Expand Down Expand Up @@ -1577,15 +1576,15 @@
'body' => mysqli_escape_string($mysqli, nullable_htmlentities("<div class='header'>
Hello,
</div>
Your ticket regarding $ticket_subject has been scheduled for $email_datetime.
The ticket regarding $ticket_subject has been scheduled for $email_datetime.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>$ticket_link</a>
<br><br>
Please do not reply to this email.
<br><br>
<strong>Ticket:</strong> $ticket_prefix$ticket_number<br>
<strong>Subject:</strong> $ticket_subject<br>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access your ticket here</a>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access the ticket here</a>
<br><br>
<div class='footer'>
~<br>
Expand Down Expand Up @@ -1630,7 +1629,6 @@
header("Location: calendar_events.php");
}

exit;
}

if (isset($_GET['cancel_ticket_schedule'])) {
Expand Down Expand Up @@ -1686,7 +1684,7 @@
'body' => mysqli_escape_string($mysqli, "<div class='header'>
Hello, $contact_name
</div>
Your ticket regarding $ticket_subject has been cancelled.
Scheduled work for your ticket regarding $ticket_subject has been cancelled.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>Access your ticket here</a>
<br><br>
Expand All @@ -1713,7 +1711,7 @@
'recipient' => $user_email,
'recipient_name' => $user_name,
'subject' => "Ticket Schedule Cancelled - [$ticket_prefix$ticket_number] - $ticket_subject",
'body' => "Hello, " . $user_name . "<br><br>The ticket regarding $ticket_subject has been cancelled.<br><br>--------------------------------<br><a href=\"https://$config_base_url/ticket.php?id=$ticket_id\">$ticket_link</a><br>--------------------------------<br><br>Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email",
'body' => "Hello, " . $user_name . "<br><br>Scheduled work for the ticket regarding $ticket_subject has been cancelled.<br><br>--------------------------------<br><a href=\"https://$config_base_url/ticket.php?id=$ticket_id\">$ticket_link</a><br>--------------------------------<br><br>Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email",
'cal_str' => $cal_str
]
];
Expand All @@ -1731,15 +1729,15 @@
'body' => mysqli_escape_string($mysqli, nullable_htmlentities("<div class='header'>
Hello,
</div>
Your ticket regarding $ticket_subject has been cancelled.
Scheduled work for the ticket regarding $ticket_subject has been cancelled.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>$ticket_link</a>
<br><br>
Please do not reply to this email.
<br><br>
<strong>Ticket:</strong> $ticket_prefix$ticket_number<br>
<strong>Subject:</strong> $ticket_subject<br>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access your ticket here</a>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access the ticket here</a>
<br><br>
<div class='footer'>
~<br>
Expand Down

0 comments on commit 1e8fbdd

Please sign in to comment.