diff --git a/functions.php b/functions.php index 13459581..31c7e575 100644 --- a/functions.php +++ b/functions.php @@ -1091,3 +1091,33 @@ function isMobile() // Check if the user agent is a mobile device return preg_match('/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|palm|phone|pie|tablet|up.browser|up.link|webos|wos)/i', $_SERVER['HTTP_USER_AGENT']); } + +function createiCalStrCancel($originaliCalStr) { + require_once "plugins/zapcal/zapcallib.php"; + + // Import the original iCal string + $cal_event = new ZCiCal($originaliCalStr); + + // Iterate through the iCalendar object to find VEVENT nodes + foreach($cal_event->tree->child as $node) { + if($node->getName() == "VEVENT") { + // Check if STATUS node exists, update it, or add a new one + $statusFound = false; + foreach($node->data as $key => $value) { + if($key == "STATUS") { + $value->setValue("CANCELLED"); + $statusFound = true; + break; // Exit the loop once the STATUS is updated + } + } + // If STATUS node is not found, add a new STATUS node + if (!$statusFound) { + $node->addNode(new ZCiCalDataNode("STATUS:CANCELLED")); + } + } + } + + // Return the modified iCal string + return $cal_event->export(); +} + diff --git a/post/ticket.php b/post/ticket.php index 260004b3..e006319f 100644 --- a/post/ticket.php +++ b/post/ticket.php @@ -1632,3 +1632,138 @@ if (isset($_POST['edit_ticket_schedule'])) { exit; } + +if (isset($_GET['cancel_ticket_schedule'])) { + + validateTechRole(); + + $ticket_id = intval($_GET['cancel_ticket_schedule']); + + $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = $ticket_id"); + $row = mysqli_fetch_array($sql); + + $client_id = intval($row['ticket_client_id']); + $ticket_prefix = sanitizeInput($row['ticket_prefix']); + $ticket_number = intval($row['ticket_number']); + $ticket_subject = sanitizeInput($row['ticket_subject']); + $ticket_schedule = sanitizeInput($row['ticket_schedule']); + $ticket_cal_str = sanitizeInput($row['ticket_cal_str']); + + mysqli_query($mysqli, "UPDATE tickets SET ticket_schedule = NULL, ticket_status = 'Open' WHERE ticket_id = $ticket_id"); + + //Create iCal event + $cal_str = createiCalStrCancel($ticket_cal_str); + + //Send emails + + $sql = mysqli_query($mysqli, "SELECT * FROM tickets + LEFT JOIN clients ON ticket_client_id = client_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 + WHERE ticket_id = $ticket_id + "); + $row = mysqli_fetch_array($sql); + + $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']); + $user_name = sanitizeInput($row['user_name']); + $user_email = sanitizeInput($row['user_email']); + + $data = [ + [ //Client Contact Email + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $contact_email, + 'recipient_name' => $contact_name, + 'subject' => "Ticket Schedule Cancelled - [$ticket_prefix$ticket_number] - $ticket_subject", + 'body' => mysqli_escape_string($mysqli, "