Update ticket scheduled post actions.

This commit is contained in:
o-psi
2024-02-09 17:10:59 +00:00
parent 672e51b21a
commit c72a4a2413
+21 -6
View File
@@ -1510,8 +1510,19 @@ if (isset($_POST['edit_ticket_schedule'])) {
WHERE ticket_id = $ticket_id"
);
// Check for other conflicting scheduled items based on 2 hr window
$start = date('Y-m-d H:i:s', strtotime($schedule) - 7200);
$end = date('Y-m-d H:i:s', strtotime($schedule) + 7200);
$sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_schedule BETWEEN '$start' AND '$end' AND ticket_id != $ticket_id AND ticket_status = 'Scheduled'");
if (mysqli_num_rows($sql) > 0) {
$conflicting_tickets = [];
while ($row = mysqli_fetch_array($sql)) {
$conflicting_tickets[] = $row['ticket_id'] . " - " . $row['ticket_subject'] . " @ " . $row['ticket_schedule'];
}
$_SESSION['alert_message'] = "Ticket scheduled, but there are other tickets scheduled within 2 hours of this time. Please check the schedule for tickets: " . implode(", ", $conflicting_tickets);
header("Location: " . $_SERVER["HTTP_REFERER"]);
}else {
//Send email to client and assigned user
$sql = mysqli_query($mysqli,"SELECT * FROM tickets
@@ -1525,14 +1536,18 @@ if (isset($_POST['edit_ticket_schedule'])) {
$client_id = intval($row['ticket_client_id']);
$client_name = sanitizeInput($row['client_name']);
$ticket_details = sanitizeInput($row['ticket_details']);
$contact_name = sanitizeInput($row['contact_name']);
$contact_email = sanitizeInput($row['contact_email']);
$ticket_prefix = sanitizeInput($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_subject = sanitizeInput($row['ticket_subject']);
$cal_str = createCalendarEvent($schedule, $ticket_subject, $ticket_link, $config_base_url);
$cal_subject = $ticket_number . ": " .$client_name . " - " . $ticket_subject;
$cal_description = $ticket_details . " - " . $full_ticket_url;
$cal_str = createCalendarEvent($schedule, $cal_subject, $cal_description, $cal_location);
$data = [
[
@@ -1554,9 +1569,7 @@ if (isset($_POST['edit_ticket_schedule'])) {
'cal_str' => $cal_str
]
];
//Send all watchers an email
$sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id");
while ($row = mysqli_fetch_array($sql_watchers)) {
@@ -1571,15 +1584,15 @@ if (isset($_POST['edit_ticket_schedule'])) {
'cal_str' => $cal_str
];
}
$response = addToMailQueue($mysqli, $data);
// if response is not empty, then there was an error
if (!empty($response)) {
$_SESSION['alert_message'] = "Error sending email: " . $response;
} else {
$_SESSION['alert_message'] = "Ticket scheduled";
}
// Update ticket reply
mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Ticket scheduled for $schedule', ticket_reply_type = 'Internal', ticket_reply_time_worked = '00:05:00', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id");
//Logging
mysqli_query(
@@ -1598,4 +1611,6 @@ if (isset($_POST['edit_ticket_schedule'])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
}