Update Calendar to show past scheduled tickets as different colors based on status.

This commit is contained in:
o-psi
2024-02-09 22:06:34 +00:00
parent c72a4a2413
commit 6e14406364
5 changed files with 334 additions and 240 deletions
+19 -3
View File
@@ -125,13 +125,29 @@ while ($row = mysqli_fetch_array($sql)) {
} }
//Tickets Scheduled //Tickets Scheduled
$sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN tickets ON client_id = ticket_client_id WHERE ticket_schedule IS NOT NULL"); $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN tickets ON client_id = ticket_client_id LEFT JOIN users ON ticket_assigned_to = ticket_client_id WHERE ticket_schedule IS NOT NULL");
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$event_id = intval($row['ticket_id']); $event_id = intval($row['ticket_id']);
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " " . $row['ticket_subject']); if (!empty($username)) {
$username = "Unassigned";
} else {
$username = $row['user_name'];
}
if (strtotime($row['ticket_schedule']) < time()) {
if ($row['ticket_status'] == 'Scheduled') {
$event_color = "red";
}else {
$event_color = "green";
}
} else {
$event_color = "grey";
}
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " " . $row['ticket_subject'] . " [" . $username . "]");
$event_start = json_encode($row['ticket_schedule']); $event_start = json_encode($row['ticket_schedule']);
echo "{ id: $event_id, title: $event_title, start: $event_start, color: 'red', url: 'ticket.php?ticket_id=$event_id' },"; echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
} }
//Vendors Added Created //Vendors Added Created
+59 -6
View File
@@ -539,7 +539,54 @@ function sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_
// Content // Content
$mail->isHTML(true); // Set email format to HTML $mail->isHTML(true); // Set email format to HTML
$mail->Subject = "$subject"; // Subject $mail->Subject = "$subject"; // Subject
$mail->Body = "$body"; // Content $mail->Body = "<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
color: #333;
line-height: 1.6;
}
.email-container {
max-width: 600px;
margin: auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.header {
font-size: 18px;
margin-bottom: 20px;
}
.link-button {
display: inline-block;
background-color: #007bff;
color: #ffffff;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
margin: 10px 0;
}
.footer {
font-size: 14px;
color: #666;
margin-top: 20px;
border-top: 1px solid #ddd;
padding-top: 10px;
}
.no-reply {
color: #999;
font-size: 12px;
}
</style>
</head>
<body>
<div class='email-container'>
$body
</div>
</body>
</html>
"; // Content
// Attachments - todo // Attachments - todo
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
@@ -983,25 +1030,31 @@ function calculateInvoiceBalance($mysqli, $invoice_id) {
} }
function createCalendarEvent($datetime, $title, $description, $location) { function createiCalStr($datetime, $title, $description, $location) {
//Use The Zap Cal PHP Library to create a calendar event and return the ics feed
require_once "plugins/zapcal/zapcallib.php"; require_once "plugins/zapcal/zapcallib.php";
// Create the iCal object
$cal_event = new ZCiCal(); $cal_event = new ZCiCal();
$event = new ZCiCalNode("VEVENT", $cal_event->curnode); $event = new ZCiCalNode("VEVENT", $cal_event->curnode);
// Set the method to REQUEST to indicate an invite
$event->addNode(new ZCiCalDataNode("METHOD:REQUEST"));
$event->addNode(new ZCiCalDataNode("SUMMARY:" . $title)); $event->addNode(new ZCiCalDataNode("SUMMARY:" . $title));
$event->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($datetime))); $event->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($datetime)));
// Assuming the end time is the same as start time.
// Todo: adjust this for actual duration
$event->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($datetime))); $event->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($datetime)));
$event->addNode(new ZCiCalDataNode("DTSTAMP:" . ZCiCal::fromSqlDateTime())); $event->addNode(new ZCiCalDataNode("DTSTAMP:" . ZCiCal::fromSqlDateTime()));
$uid = date('Y-m-d-H-i-s') . "@" . $_SERVER['SERVER_NAME']; $uid = date('Y-m-d-H-i-s') . "@" . $_SERVER['SERVER_NAME'];
$event->addNode(new ZCiCalDataNode("UID:" . $uid)); $event->addNode(new ZCiCalDataNode("UID:" . $uid));
$event->addNode(new ZCiCalDataNode("LOCATION:" . $location)); $event->addNode(new ZCiCalDataNode("LOCATION:" . $location));
$event->addNode(new ZCiCalDataNode("DESCRIPTION:" . $description)); $event->addNode(new ZCiCalDataNode("DESCRIPTION:" . $description));
// Todo: add organizer details
// $event->addNode(new ZCiCalDataNode("ORGANIZER;CN=Organizer Name:MAILTO:organizer@example.com"));
// Export the iCal object to a string
$ics_feed = $cal_event->export(); $ics_feed = $cal_event->export();
return $ics_feed; return $ics_feed;
} }
+83 -66
View File
@@ -125,7 +125,6 @@ if (isset($_POST['add_ticket'])) {
'subject' => $subject, 'subject' => $subject,
'body' => $body 'body' => $body
]; ];
} }
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
} }
@@ -137,7 +136,6 @@ if (isset($_POST['add_ticket'])) {
$_SESSION['alert_message'] = "You created Ticket $ticket_subject <strong>$config_ticket_prefix$ticket_number</strong>"; $_SESSION['alert_message'] = "You created Ticket $ticket_subject <strong>$config_ticket_prefix$ticket_number</strong>";
header("Location: ticket.php?ticket_id=" . $ticket_id); header("Location: ticket.php?ticket_id=" . $ticket_id);
} }
if (isset($_POST['edit_ticket'])) { if (isset($_POST['edit_ticket'])) {
@@ -165,7 +163,6 @@ if (isset($_POST['edit_ticket'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> updated"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_priority'])) { if (isset($_POST['edit_ticket_priority'])) {
@@ -184,7 +181,6 @@ if (isset($_POST['edit_ticket_priority'])) {
$_SESSION['alert_message'] = "Ticket priority updated"; $_SESSION['alert_message'] = "Ticket priority updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_contact'])) { if (isset($_POST['edit_ticket_contact'])) {
@@ -204,7 +200,6 @@ if (isset($_POST['edit_ticket_contact'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> contact updated"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> contact updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['add_ticket_watcher'])) { if (isset($_POST['add_ticket_watcher'])) {
@@ -224,7 +219,6 @@ if (isset($_POST['add_ticket_watcher'])) {
$_SESSION['alert_message'] = "You added $watcher_email as a watcher to Ticket <strong>$ticket_number</strong>"; $_SESSION['alert_message'] = "You added $watcher_email as a watcher to Ticket <strong>$ticket_number</strong>";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_watchers'])) { if (isset($_POST['edit_ticket_watchers'])) {
@@ -254,7 +248,6 @@ if (isset($_POST['edit_ticket_watchers'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> watchers updated"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> watchers updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_GET['delete_ticket_watcher'])) { if (isset($_GET['delete_ticket_watcher'])) {
@@ -269,7 +262,6 @@ if (isset($_GET['delete_ticket_watcher'])) {
$_SESSION['alert_message'] = "You <b>removed</b> a ticket watcher"; $_SESSION['alert_message'] = "You <b>removed</b> a ticket watcher";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_asset'])) { if (isset($_POST['edit_ticket_asset'])) {
@@ -289,7 +281,6 @@ if (isset($_POST['edit_ticket_asset'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> asset updated"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> asset updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_vendor'])) { if (isset($_POST['edit_ticket_vendor'])) {
@@ -309,7 +300,6 @@ if (isset($_POST['edit_ticket_vendor'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> vendor updated"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_number</strong> vendor updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_priority'])) { if (isset($_POST['edit_ticket_priority'])) {
@@ -328,7 +318,6 @@ if (isset($_POST['edit_ticket_priority'])) {
$_SESSION['alert_message'] = "Ticket priority updated"; $_SESSION['alert_message'] = "Ticket priority updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['assign_ticket'])) { if (isset($_POST['assign_ticket'])) {
@@ -422,13 +411,11 @@ if (isset($_POST['assign_ticket'])) {
]; ];
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
} }
} }
$_SESSION['alert_message'] = "Ticket <strong>$ticket_prefix$ticket_number</strong> assigned to <strong>$agent_name</strong>"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_prefix$ticket_number</strong> assigned to <strong>$agent_name</strong>";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_GET['delete_ticket'])) { if (isset($_GET['delete_ticket'])) {
@@ -463,7 +450,6 @@ if (isset($_GET['delete_ticket'])) {
header("Location: tickets.php"); header("Location: tickets.php");
} }
} }
if (isset($_POST['bulk_assign_ticket'])) { if (isset($_POST['bulk_assign_ticket'])) {
@@ -526,7 +512,6 @@ if (isset($_POST['bulk_assign_ticket'])) {
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Edit', log_description = '$session_name reassigned ticket $ticket_prefix$ticket_number - $ticket_subject to $agent_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id"); mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Edit', log_description = '$session_name reassigned ticket $ticket_prefix$ticket_number - $ticket_subject to $agent_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id");
$tickets_assigned_body .= "$ticket_prefix$ticket_number - $ticket_subject<br>"; $tickets_assigned_body .= "$ticket_prefix$ticket_number - $ticket_subject<br>";
} // End For Each Ticket ID Loop } // End For Each Ticket ID Loop
// Notification // Notification
@@ -560,14 +545,12 @@ if (isset($_POST['bulk_assign_ticket'])) {
]; ];
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
} }
} }
} }
$_SESSION['alert_message'] = "You assigned <b>$ticket_count</b> Tickets to <b>$agent_name</b>"; $_SESSION['alert_message'] = "You assigned <b>$ticket_count</b> Tickets to <b>$agent_name</b>";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['bulk_edit_ticket_priority'])) { if (isset($_POST['bulk_edit_ticket_priority'])) {
@@ -603,14 +586,12 @@ if (isset($_POST['bulk_edit_ticket_priority'])) {
// Logging // Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Edit', log_description = '$session_name updated the priority on ticket $ticket_prefix$ticket_number - $ticket_subject from $current_ticket_priority to $priority', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id"); mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Edit', log_description = '$session_name updated the priority on ticket $ticket_prefix$ticket_number - $ticket_subject from $current_ticket_priority to $priority', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id");
} // End For Each Ticket ID Loop } // End For Each Ticket ID Loop
} }
$_SESSION['alert_message'] = "You updated the priority for <b>$ticket_count</b> Tickets to <b>$priority</b>"; $_SESSION['alert_message'] = "You updated the priority for <b>$ticket_count</b> Tickets to <b>$priority</b>";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['bulk_close_tickets'])) { if (isset($_POST['bulk_close_tickets'])) {
@@ -722,7 +703,6 @@ if (isset($_POST['bulk_close_tickets'])) {
$_SESSION['alert_message'] = "You closed <b>$ticket_count</b> Tickets"; $_SESSION['alert_message'] = "You closed <b>$ticket_count</b> Tickets";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['bulk_ticket_reply'])) { if (isset($_POST['bulk_ticket_reply'])) {
@@ -769,7 +749,9 @@ if (isset($_POST['bulk_ticket_reply'])) {
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Create', log_description = '$session_name replied to ticket $ticket_prefix$ticket_number - $ticket_subject and was a $ticket_reply_type reply', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_reply_id"); mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Create', log_description = '$session_name replied to ticket $ticket_prefix$ticket_number - $ticket_subject and was a $ticket_reply_type reply', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_reply_id");
// Get Contact Details // Get Contact Details
$sql = mysqli_query($mysqli,"SELECT contact_name, contact_email, ticket_created_by, ticket_assigned_to $sql = mysqli_query(
$mysqli,
"SELECT contact_name, contact_email, ticket_created_by, ticket_assigned_to
FROM tickets FROM tickets
LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN contacts ON ticket_contact_id = contact_id
WHERE ticket_id = $ticket_id" WHERE ticket_id = $ticket_id"
@@ -828,7 +810,6 @@ if (isset($_POST['bulk_ticket_reply'])) {
'subject' => $subject, 'subject' => $subject,
'body' => $body 'body' => $body
]; ];
} }
} }
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
@@ -845,7 +826,6 @@ if (isset($_POST['bulk_ticket_reply'])) {
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = '$session_name updated Ticket $ticket_prefix$ticket_number - Subject: $ticket_subject that you opened', notification_action = 'ticket.php?ticket_id=$ticket_id', notification_client_id = $client_id, notification_user_id = $ticket_created_by"); mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = '$session_name updated Ticket $ticket_prefix$ticket_number - Subject: $ticket_subject that you opened', notification_action = 'ticket.php?ticket_id=$ticket_id', notification_client_id = $client_id, notification_user_id = $ticket_created_by");
} }
} // End Ticket Lopp } // End Ticket Lopp
} }
@@ -853,7 +833,6 @@ if (isset($_POST['bulk_ticket_reply'])) {
$_SESSION['alert_message'] = "You updated <b>$ticket_count</b> tickets"; $_SESSION['alert_message'] = "You updated <b>$ticket_count</b> tickets";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['add_ticket_reply'])) { if (isset($_POST['add_ticket_reply'])) {
@@ -933,15 +912,12 @@ if (isset($_POST['add_ticket_reply'])) {
if ($ticket_status == 'Closed') { if ($ticket_status == 'Closed') {
$subject = "Ticket closed - [$ticket_prefix$ticket_number] - $ticket_subject | (do not reply)"; $subject = "Ticket closed - [$ticket_prefix$ticket_number] - $ticket_subject | (do not reply)";
$body = "Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been closed.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>We hope the issue was resolved to your satisfaction. If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; $body = "Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been closed.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>We hope the issue was resolved to your satisfaction. If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
} elseif ($ticket_status == 'Auto Close') { } elseif ($ticket_status == 'Auto Close') {
$subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)"; $subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been updated and is pending closure.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>If your issue is resolved, you can ignore this email. If you need further assistance, please respond! <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; $body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been updated and is pending closure.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>If your issue is resolved, you can ignore this email. If you need further assistance, please respond! <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
} else { } else {
$subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject"; $subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been updated.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; $body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Your ticket regarding $ticket_subject has been updated.<br><br>--------------------------------<br>$ticket_reply<br>--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
} }
$data = []; $data = [];
@@ -972,7 +948,6 @@ if (isset($_POST['add_ticket_reply'])) {
'subject' => $subject, 'subject' => $subject,
'body' => $body 'body' => $body
]; ];
} }
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
} }
@@ -997,7 +972,6 @@ if (isset($_POST['add_ticket_reply'])) {
$_SESSION['alert_message'] = "Ticket <strong>$ticket_prefix$ticket_number</strong> has been updated with your reply and was <strong>$ticket_reply_type</strong>"; $_SESSION['alert_message'] = "Ticket <strong>$ticket_prefix$ticket_number</strong> has been updated with your reply and was <strong>$ticket_reply_type</strong>";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_reply'])) { if (isset($_POST['edit_ticket_reply'])) {
@@ -1018,7 +992,6 @@ if (isset($_POST['edit_ticket_reply'])) {
$_SESSION['alert_message'] = "Ticket reply updated"; $_SESSION['alert_message'] = "Ticket reply updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_GET['archive_ticket_reply'])) { if (isset($_GET['archive_ticket_reply'])) {
@@ -1036,7 +1009,6 @@ if (isset($_GET['archive_ticket_reply'])) {
$_SESSION['alert_message'] = "Ticket reply archived"; $_SESSION['alert_message'] = "Ticket reply archived";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['merge_ticket'])) { if (isset($_POST['merge_ticket'])) {
@@ -1090,7 +1062,6 @@ if (isset($_POST['merge_ticket'])) {
$_SESSION['alert_message'] = "Ticket merged into $ticket_prefix$merge_into_ticket_number"; $_SESSION['alert_message'] = "Ticket merged into $ticket_prefix$merge_into_ticket_number";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['change_client_ticket'])) { if (isset($_POST['change_client_ticket'])) {
@@ -1113,7 +1084,6 @@ if (isset($_POST['change_client_ticket'])) {
$_SESSION['alert_message'] = "Ticket client updated"; $_SESSION['alert_message'] = "Ticket client updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_GET['close_ticket'])) { if (isset($_GET['close_ticket'])) {
@@ -1199,13 +1169,11 @@ if (isset($_GET['close_ticket'])) {
} }
addToMailQueue($mysqli, $data); addToMailQueue($mysqli, $data);
} }
} }
//End Mail IF //End Mail IF
$_SESSION['alert_message'] = "Ticket Closed, this cannot not be reopened but you may start another one"; $_SESSION['alert_message'] = "Ticket Closed, this cannot not be reopened but you may start another one";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['add_invoice_from_ticket'])) { if (isset($_POST['add_invoice_from_ticket'])) {
@@ -1216,7 +1184,9 @@ if (isset($_POST['add_invoice_from_ticket'])) {
$category = intval($_POST['category']); $category = intval($_POST['category']);
$scope = sanitizeInput($_POST['scope']); $scope = sanitizeInput($_POST['scope']);
$sql = mysqli_query($mysqli, "SELECT * FROM tickets $sql = mysqli_query(
$mysqli,
"SELECT * FROM tickets
LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN clients ON ticket_client_id = client_id
LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN contacts ON ticket_contact_id = contact_id
LEFT JOIN assets ON ticket_asset_id = asset_id LEFT JOIN assets ON ticket_asset_id = asset_id
@@ -1347,7 +1317,6 @@ if (isset($_POST['export_client_tickets_csv'])) {
fpassthru($f); fpassthru($f);
} }
exit; exit;
} }
if (isset($_POST['add_scheduled_ticket'])) { if (isset($_POST['add_scheduled_ticket'])) {
@@ -1376,7 +1345,6 @@ if (isset($_POST['add_scheduled_ticket'])) {
$_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> created"; $_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> created";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_scheduled_ticket'])) { if (isset($_POST['edit_scheduled_ticket'])) {
@@ -1404,7 +1372,6 @@ if (isset($_POST['edit_scheduled_ticket'])) {
$_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> updated"; $_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_GET['delete_scheduled_ticket'])) { if (isset($_GET['delete_scheduled_ticket'])) {
@@ -1455,7 +1422,6 @@ if (isset($_POST['bulk_delete_scheduled_tickets'])) {
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name bulk deleted $count scheduled tickets', 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 = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name bulk deleted $count scheduled tickets', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Deleted $count scheduled ticket(s)"; $_SESSION['alert_message'] = "Deleted $count scheduled ticket(s)";
} }
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
@@ -1468,7 +1434,8 @@ if(isset($_POST['set_billable_status'])) {
$ticket_id = intval($_POST['ticket_id']); $ticket_id = intval($_POST['ticket_id']);
$billable_status = sanitizeInput($_POST['billable_status']); $billable_status = sanitizeInput($_POST['billable_status']);
mysqli_query($mysqli, mysqli_query(
$mysqli,
"UPDATE tickets SET "UPDATE tickets SET
ticket_billable = '$billable_status' ticket_billable = '$billable_status'
WHERE ticket_id = $ticket_id" WHERE ticket_id = $ticket_id"
@@ -1490,27 +1457,31 @@ if(isset($_POST['set_billable_status'])) {
$_SESSION['alert_message'] = "Ticket billable status updated"; $_SESSION['alert_message'] = "Ticket billable status updated";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
if (isset($_POST['edit_ticket_schedule'])) { if (isset($_POST['edit_ticket_schedule'])) {
validateTechRole(); validateTechRole();
$ticket_id = intval($_POST['ticket_id']); $ticket_id = intval($_POST['ticket_id']);
$onsite = intval($_POST['onsite']);
$schedule = sanitizeInput($_POST['scheduled_date_time']); $schedule = sanitizeInput($_POST['scheduled_date_time']);
$ticket_link = "ticket.php?ticket_id=$ticket_id"; $ticket_link = "ticket.php?ticket_id=$ticket_id";
$full_ticket_url = "https://$config_base_url/portal/ticket.php?ticket_id=$ticket_id"; $full_ticket_url = "https://$config_base_url/portal/ticket.php?ticket_id=$ticket_id";
$ticket_link_html = "<a href=\"$full_ticket_url\">$ticket_link</a>"; $ticket_link_html = "<a href=\"$full_ticket_url\">$ticket_link</a>";
mysqli_query($mysqli, mysqli_query(
$mysqli,
"UPDATE tickets SET "UPDATE tickets SET
ticket_schedule = '$schedule', ticket_schedule = '$schedule',
ticket_status = 'Scheduled' ticket_status = 'Scheduled'
WHERE ticket_id = $ticket_id" WHERE ticket_id = $ticket_id"
); );
// Check for other conflicting scheduled items based on 2 hr window // Check for other conflicting scheduled items based on 2 hr window
//TODO make this configurable
$start = date('Y-m-d H:i:s', strtotime($schedule) - 7200); $start = date('Y-m-d H:i:s', strtotime($schedule) - 7200);
$end = 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'"); $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_schedule BETWEEN '$start' AND '$end' AND ticket_id != $ticket_id AND ticket_status = 'Scheduled'");
@@ -1519,19 +1490,16 @@ if (isset($_POST['edit_ticket_schedule'])) {
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$conflicting_tickets[] = $row['ticket_id'] . " - " . $row['ticket_subject'] . " @ " . $row['ticket_schedule']; $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 $sql = mysqli_query($mysqli, "SELECT * FROM tickets
LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN clients ON ticket_client_id = client_id
LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN contacts ON ticket_contact_id = contact_id
LEFT JOIN locations on contact_location_id = location_id
LEFT JOIN users ON ticket_assigned_to = user_id LEFT JOIN users ON ticket_assigned_to = user_id
WHERE ticket_id = $ticket_id WHERE ticket_id = $ticket_id
"); ");
$row = mysqli_fetch_array($sql); $row = mysqli_fetch_array($sql);
$client_id = intval($row['ticket_client_id']); $client_id = intval($row['ticket_client_id']);
@@ -1542,33 +1510,58 @@ if (isset($_POST['edit_ticket_schedule'])) {
$ticket_prefix = sanitizeInput($row['ticket_prefix']); $ticket_prefix = sanitizeInput($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']); $ticket_number = intval($row['ticket_number']);
$ticket_subject = sanitizeInput($row['ticket_subject']); $ticket_subject = sanitizeInput($row['ticket_subject']);
$user_name = sanitizeInput($row['user_name']);
$user_email = sanitizeInput($row['user_email']);
$cal_subject = $ticket_number . ": " . $client_name . " - " . $ticket_subject; $cal_subject = $ticket_number . ": " . $client_name . " - " . $ticket_subject;
$cal_description = $ticket_details . " - " . $full_ticket_url; $cal_description = $ticket_details . " - " . $full_ticket_url;
$cal_location = sanitizeInput($row["location_address"]);
$email_datetime = date('l, F j, Y \a\t g:ia', strtotime($schedule));
$cal_str = createCalendarEvent($schedule, $cal_subject, $cal_description, $cal_location); /// Create iCal event
$cal_str = createiCalStr($schedule, $cal_subject, $cal_description, $cal_location);
$data = [ $data = [
[ [ //Client Contact Email
'from' => $config_ticket_from_email, 'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name, 'from_name' => $config_ticket_from_name,
'recipient' => $contact_email, 'recipient' => $contact_email,
'recipient_name' => $contact_name, 'recipient_name' => $contact_name,
'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject", 'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject",
'body' => "Hello, $contact_name<br><br>Your ticket regarding $ticket_subject has been scheduled for $schedule.<br><br>--------------------------------<br><a href=\"$full_ticket_url\">$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/portal/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email<br>$company_phone", 'body' => mysqli_escape_string($mysqli, "<div class='header'>
Hello, $contact_name
</div>
Your 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'>Access your ticket here</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>
<br><br>
<div class='footer'>
~<br>
$session_company_name<br>
Support Department<br>
$config_ticket_from_email<br>
</div>
<div class='no-reply'>
This is an automated message. Please do not reply directly to this email.
</div>"),
'cal_str' => $cal_str 'cal_str' => $cal_str
], ],
[ [
// User Email
'from' => $config_ticket_from_email, 'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name, 'from_name' => $config_ticket_from_name,
'recipient' => $row['user_email'], 'recipient' => $user_email,
'recipient_name' => $row['user_first_name'] . ' ' . $row['user_last_name'], 'recipient_name' => $user_name,
'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject", 'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject",
'body' => "Hello, " . $row['user_first_name'] . "<br><br>The ticket regarding $ticket_subject has been scheduled for $schedule.<br><br>--------------------------------<br><a href=\"$full_ticket_url\">$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/portal/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email<br>$company_phone", 'body' => "Hello, " . $user_name . "<br><br>The ticket regarding $ticket_subject has been scheduled for $email_datetime.<br><br>--------------------------------<br><a href=\"https://$config_base_url/portal/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 'cal_str' => $cal_str
] ]
]; ];
//Send all watchers an email //Send all watchers an email
$sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id"); $sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id");
@@ -1580,17 +1573,35 @@ if (isset($_POST['edit_ticket_schedule'])) {
'recipient' => $watcher_email, 'recipient' => $watcher_email,
'recipient_name' => $watcher_email, 'recipient_name' => $watcher_email,
'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject", 'subject' => "Ticket Scheduled - [$ticket_prefix$ticket_number] - $ticket_subject",
'body' => "Hello, " . $watcher_email . "<br><br>The ticket regarding $ticket_subject has been scheduled for $schedule.<br><br>--------------------------------<br><a href=\"$full_ticket_url\">$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/portal/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email<br>$company_phone", 'body' => mysqli_escape_string($mysqli, nullable_htmlentities("<div class='header'>
Hello,
</div>
Your 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>
<br><br>
<div class='footer'>
~<br>
$session_company_name<br>
Support Department<br>
$config_ticket_from_email<br>
</div>
<div class='no-reply'>
This is an automated message. Please do not reply directly to this email.
</div>")),
'cal_str' => $cal_str 'cal_str' => $cal_str
]; ];
} }
$response = addToMailQueue($mysqli, $data); $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 // 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"); 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");
@@ -1607,10 +1618,16 @@ if (isset($_POST['edit_ticket_schedule'])) {
log_entity_id = $ticket_id" log_entity_id = $ticket_id"
); );
$_SESSION['alert_message'] = "Ticket schedule updated";
if(empty($conflicting_tickets)){
$_SESSION['alert_message'] = "Ticket scheduled for $email_datetime";
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} else {
$_SESSION['alert_type'] = "error";
$_SESSION['alert_message'] = "Ticket scheduled for $email_datetime. Yet there are conflicting tickets scheduled for the same time: <br>" . implode(", <br>", $conflicting_tickets);
header("Location: calendar_events.php");
} }
exit;
} }
+1
View File
@@ -59,6 +59,7 @@ if (isset($_GET['ticket_id'])) {
$ticket_priority = nullable_htmlentities($row['ticket_priority']); $ticket_priority = nullable_htmlentities($row['ticket_priority']);
$ticket_billable = intval($row['ticket_billable']); $ticket_billable = intval($row['ticket_billable']);
$ticket_scheduled_for = nullable_htmlentities($row['ticket_schedule']); $ticket_scheduled_for = nullable_htmlentities($row['ticket_schedule']);
$ticket_onsite = nullable_htmlentities($row['ticket_onsite']);
//Set Ticket Bage Color based of priority //Set Ticket Bage Color based of priority
if ($ticket_priority == "High") { if ($ticket_priority == "High") {
+7
View File
@@ -24,6 +24,13 @@
<?php } ?> <?php } ?>
</div> </div>
<div class="form-group">
<label>Onsite</label>
<select class="form-control" name="onsite">
<option value="0" <?php if ($ticket_onsite == 0) echo "selected"; ?>>No</option>
<option value="1" <?php if ($ticket_onsite == 1) echo "selected"; ?>>Yes</option>
</select>
</div>
</div> </div>
<div class="modal-footer bg-white"> <div class="modal-footer bg-white">