diff --git a/js/ticket_collision_detection.js b/js/ticket_collision_detection.js new file mode 100644 index 00000000..f1b98e41 --- /dev/null +++ b/js/ticket_collision_detection.js @@ -0,0 +1,33 @@ +// Collision detection +// Adds a "view" entry of the current ticket every 2 mins into the database +// Updates the currently viewing (ticket_collision_viewing) element with anyone that's looked at this ticket in the last two mins +function ticket_collision_detection() { + + // Get the page ticket id + var ticket_id = document.getElementById("ticket_id").value; + + //Send a GET request to ajax.php as ajax.php?ticket_add_view=true&ticket_id=NUMBER + jQuery.get( + "ajax.php", + {ticket_add_view: 'true', ticket_id: ticket_id}, + function(data) { + // We don't care about a response + } + ); + + //Send a GET request to ajax.php as ajax.php?ticket_query_views=true&ticket_id=NUMBER + jQuery.get( + "ajax.php", + {ticket_query_views: 'true', ticket_id: ticket_id}, + function(data) { + //If we get a response from ajax.php, parse it as JSON + const ticket_view_data = JSON.parse(data); + document.getElementById("ticket_collision_viewing").innerText = ticket_view_data.message; + } + ); +} +// Call on page load +ticket_collision_detection(); + +// Run every 2 mins +setInterval(ticket_collision_detection, 120*1000); \ No newline at end of file diff --git a/js/ticket_merge.js b/js/ticket_merge.js new file mode 100644 index 00000000..dc8e6408 --- /dev/null +++ b/js/ticket_merge.js @@ -0,0 +1,40 @@ +// Ticket merging + +// Gets details of the ticket we're going to merge this ticket into +// Shows the details under the comments box & enables the merge button if the status of the merge into ticket is not closed +function merge_into_number_get_details() { + + // Get the ticket number to merge into + var merge_into_ticket_number = document.getElementById("merge_into_ticket_number").value; + + // Reset the form + document.getElementById("merge_ticket_btn").disabled = true; + document.getElementById("merge_into_details_div").hidden = true; + + // Send a GET request to post.php as post.php?merge_ticket_get_json_details=true&merge_into_ticket_number=NUMBER + jQuery.get( + "ajax.php", + {merge_ticket_get_json_details: 'true', merge_into_ticket_number: merge_into_ticket_number}, + function(data){ + // If we get a response from post.php, parse it as JSON + const merge_into_ticket_info = JSON.parse(data); + + // Check that the current ticket ID isn't also the new/merge ticket ID + if(parseInt(merge_into_ticket_info.ticket_id) !== parseInt(document.getElementById("current_ticket_id").value)){ + + // Show the div with the master ticket details, populate + document.getElementById("merge_into_details_div").hidden = false; + document.getElementById("merge_into_details_number").innerText = "Master ticket details: " + merge_into_ticket_info.ticket_prefix + merge_into_ticket_info.ticket_number; + document.getElementById("merge_into_details_client").innerText = "Client Contact: " + merge_into_ticket_info.client_name + " / " + merge_into_ticket_info.contact_name; + document.getElementById("merge_into_details_subject").innerText = "Subject: " + merge_into_ticket_info.ticket_subject; + document.getElementById("merge_into_details_priority").innerText = "Priority: " + merge_into_ticket_info.ticket_priority; + document.getElementById("merge_into_details_status").innerText = "Status: " + merge_into_ticket_info.ticket_status; + + // Enable the merge button if the merge into ticket isn't in a closed state + if(merge_into_ticket_info.ticket_status.toLowerCase() != "closed"){ + document.getElementById("merge_ticket_btn").disabled = false; + } + } + } + ); +} \ No newline at end of file diff --git a/js/ticket_time_tracking.js b/js/ticket_time_tracking.js new file mode 100644 index 00000000..7c2b2ef1 --- /dev/null +++ b/js/ticket_time_tracking.js @@ -0,0 +1,49 @@ +// Ticket time tracking + +// Default values +var hours = 0; +var minutes = 0; +var seconds = 0; +setInterval(countTime, 1000); + +// Counter +function countTime() +{ + ++seconds; + if (seconds == 60) { + seconds = 0; + minutes++; + } + if (minutes == 60) { + minutes = 0; + hours++; + } + + // Total timeworked + var time_worked = pad(hours) + ":" + pad(minutes) + ":" + pad(seconds); + document.getElementById("time_worked").value = time_worked; +} + +// Allows manually adjusting the timer +function setTime() +{ + var time_as_text = document.getElementById("time_worked").value; + const time_text_array = time_as_text.split(":"); + hours = parseInt(time_text_array[0]); + minutes = parseInt(time_text_array[1]); + seconds = parseInt(time_text_array[2]); +} + +// This function "pads" out the values, adding zeros if they are required +function pad(val) +{ + var valString = val + ""; + if (valString.length < 2) + { + return "0" + valString; + } + else + { + return valString; + } +} \ No newline at end of file diff --git a/ticket.php b/ticket.php index 9b714163..ad940591 100644 --- a/ticket.php +++ b/ticket.php @@ -2,717 +2,590 @@

Nothing to see here

Go Back"; + if (mysqli_num_rows($sql) == 0) { + echo "

Nothing to see here

Go Back
"; - include("footer.php"); + include("footer.php"); - }else{ + }else{ - $row = mysqli_fetch_array($sql); - $client_id = $row['client_id']; - $client_name = htmlentities($row['client_name']); - $client_type = htmlentities($row['client_type']); - $client_website = htmlentities($row['client_website']); - $client_net_terms = htmlentities($row['client_net_terms']); - if($client_net_terms == 0){ - $client_net_terms = $config_default_net_terms; - } - - $ticket_prefix = htmlentities($row['ticket_prefix']); - $ticket_number = htmlentities($row['ticket_number']); - $ticket_category = htmlentities($row['ticket_category']); - $ticket_subject = htmlentities($row['ticket_subject']); - $ticket_details = $row['ticket_details']; - $ticket_priority = htmlentities($row['ticket_priority']); - $ticket_feedback = htmlentities($row['ticket_feedback']); - $ticket_status = htmlentities($row['ticket_status']); - $ticket_created_at = $row['ticket_created_at']; - $ticket_date = date('Y-m-d',strtotime($ticket_created_at)); - $ticket_updated_at = $row['ticket_updated_at']; - $ticket_closed_at = $row['ticket_closed_at']; - $ticket_created_by = $row['ticket_created_by']; - - if($ticket_status == "Open"){ - $ticket_status_display = "$ticket_status"; - }elseif($ticket_status == "Working"){ - $ticket_status_display = "$ticket_status"; - }else{ - $ticket_status_display = "$ticket_status"; - } - - //Set Ticket Bage Color based of priority - if($ticket_priority == "High"){ - $ticket_priority_display = "$ticket_priority"; - }elseif($ticket_priority == "Medium"){ - $ticket_priority_display = "$ticket_priority"; - }elseif($ticket_priority == "Low"){ - $ticket_priority_display = "$ticket_priority"; - }else{ - $ticket_priority_display = "-"; - } - - $contact_id = $row['contact_id']; - $contact_name = htmlentities($row['contact_name']); - $contact_title = htmlentities($row['contact_title']); - $contact_email = htmlentities($row['contact_email']); - $contact_phone = formatPhoneNumber($row['contact_phone']); - $contact_extension = htmlentities($row['contact_extension']); - $contact_mobile = formatPhoneNumber($row['contact_mobile']); - - $asset_id = $row['asset_id']; - $asset_ip = htmlentities($row['asset_ip']); - $asset_name = htmlentities($row['asset_name']); - $asset_type = htmlentities($row['asset_type']); - $asset_make = htmlentities($row['asset_make']); - $asset_model = htmlentities($row['asset_model']); - $asset_serial = htmlentities($row['asset_serial']); - $asset_os = htmlentities($row['asset_os']); - $asset_warranty_expire = $row['asset_warranty_expire']; - - $location_name = htmlentities($row['location_name']); - $location_address = htmlentities($row['location_address']); - $location_city = htmlentities($row['location_city']); - $location_state = htmlentities($row['location_state']); - $location_zip = htmlentities($row['location_zip']); - $location_phone = formatPhoneNumber($row['location_phone']); - - $ticket_assigned_to = $row['ticket_assigned_to']; - if(empty($ticket_assigned_to)){ - $ticket_assigned_to_display = "Not Assigned"; - }else{ - $ticket_assigned_to_display = htmlentities($row['user_name']); - } - //Ticket Created By - $ticket_created_by = $row['ticket_created_by']; - $ticket_created_by_sql = mysqli_query($mysqli,"SELECT user_name FROM users WHERE user_id = $ticket_created_by"); - $row = mysqli_fetch_array($ticket_created_by_sql); - $ticket_created_by_display = htmlentities($row['user_name']); - - //Ticket Assigned To - if(empty($ticket_assigned_to)){ - $ticket_assigned_to_display = "Not Assigned"; - }else{ - $ticket_assigned_to_display = htmlentities($row['user_name']); - } - -// if($contact_id == $primary_contact){ -// $primary_contact_display = "Primary Contact"; -// }else{ -// $primary_contact_display = "Needs approval"; -// } - - if($contact_id){ - //Get Contact Ticket Stats - $ticket_related_open = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_open FROM tickets WHERE ticket_status != 'Closed' AND ticket_contact_id = $contact_id "); - $row = mysqli_fetch_array($ticket_related_open); - $ticket_related_open = $row['ticket_related_open']; - - $ticket_related_closed = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_closed FROM tickets WHERE ticket_status = 'Closed' AND ticket_contact_id = $contact_id "); - $row = mysqli_fetch_array($ticket_related_closed); - $ticket_related_closed = $row['ticket_related_closed']; - - $ticket_related_total = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_total FROM tickets WHERE ticket_contact_id = $contact_id "); - $row = mysqli_fetch_array($ticket_related_total); - $ticket_related_total = $row['ticket_related_total']; - } - - //Get Total Ticket Time - $ticket_total_reply_time = mysqli_query($mysqli,"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ticket_reply_time_worked))) AS ticket_total_reply_time FROM ticket_replies WHERE ticket_reply_archived_at IS NULL AND ticket_reply_ticket_id = $ticket_id"); - $row = mysqli_fetch_array($ticket_total_reply_time); - $ticket_total_reply_time = $row['ticket_total_reply_time']; - - //Client Tags - $client_tag_name_display_array = array(); - $client_tag_id_array = array(); - $sql_client_tags = mysqli_query($mysqli,"SELECT * FROM client_tags LEFT JOIN tags ON client_tags.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id"); - while($row = mysqli_fetch_array($sql_client_tags)){ - - $client_tag_id = $row['tag_id']; - $client_tag_name = htmlentities($row['tag_name']); - $client_tag_color = htmlentities($row['tag_color']); - $client_tag_icon = htmlentities($row['tag_icon']); - if(empty($client_tag_icon)){ - $client_tag_icon = "tag"; - } - - $client_tag_id_array[] = $client_tag_id; - $client_tag_name_display_array[] = " $client_tag_name"; - } - $client_tags_display = implode(' ', $client_tag_name_display_array); - - // Get & format asset warranty expiry - $date = date('Y-m-d H:i:s'); - $dt_value = $asset_warranty_expire; //sample date - $warranty_check = date('m/d/Y',strtotime('-8 hours')); - - if($dt_value <= $date){ - $dt_value = "Expired on $asset_warranty_expire"; $warranty_status_color ='red'; - }else{ - $warranty_status_color = 'green'; - } - - if($asset_warranty_expire == '0000-00-00'){ - $dt_value = "None"; $warranty_status_color ='red'; - } - - -?> - - - - -
-
-

Ticket

-
- -
- -
- -
- -
- -
- -
-
-

-
-
- -
-
- - - -
- -
- -
-
-
-
-
-
- -
- -
-
-
- -
-
- -
-
- - - -
-
-
- - -
-
-
- - - -
- -
- -
- -

- -
- - - - -
mb-3"> -
-

-
- - User Avatar - - - - - - $ticket_status"; + }elseif ($ticket_status == "Working") { + $ticket_status_display = "$ticket_status"; + }else{ + $ticket_status_display = "$ticket_status"; + } + + //Set Ticket Bage Color based of priority + if ($ticket_priority == "High") { + $ticket_priority_display = "$ticket_priority"; + }elseif ($ticket_priority == "Medium") { + $ticket_priority_display = "$ticket_priority"; + }elseif ($ticket_priority == "Low") { + $ticket_priority_display = "$ticket_priority"; + }else{ + $ticket_priority_display = "-"; + } + + $contact_id = $row['contact_id']; + $contact_name = htmlentities($row['contact_name']); + $contact_title = htmlentities($row['contact_title']); + $contact_email = htmlentities($row['contact_email']); + $contact_phone = formatPhoneNumber($row['contact_phone']); + $contact_extension = htmlentities($row['contact_extension']); + $contact_mobile = formatPhoneNumber($row['contact_mobile']); + + $asset_id = $row['asset_id']; + $asset_ip = htmlentities($row['asset_ip']); + $asset_name = htmlentities($row['asset_name']); + $asset_type = htmlentities($row['asset_type']); + $asset_make = htmlentities($row['asset_make']); + $asset_model = htmlentities($row['asset_model']); + $asset_serial = htmlentities($row['asset_serial']); + $asset_os = htmlentities($row['asset_os']); + $asset_warranty_expire = $row['asset_warranty_expire']; + + $location_name = htmlentities($row['location_name']); + $location_address = htmlentities($row['location_address']); + $location_city = htmlentities($row['location_city']); + $location_state = htmlentities($row['location_state']); + $location_zip = htmlentities($row['location_zip']); + $location_phone = formatPhoneNumber($row['location_phone']); + + $ticket_assigned_to = $row['ticket_assigned_to']; + if (empty($ticket_assigned_to)) { + $ticket_assigned_to_display = "Not Assigned"; + }else{ + $ticket_assigned_to_display = htmlentities($row['user_name']); + } + + //Ticket Created By + $ticket_created_by = $row['ticket_created_by']; + $ticket_created_by_sql = mysqli_query($mysqli,"SELECT user_name FROM users WHERE user_id = $ticket_created_by"); + $row = mysqli_fetch_array($ticket_created_by_sql); + $ticket_created_by_display = htmlentities($row['user_name']); + + //Ticket Assigned To + if (empty($ticket_assigned_to)) { + $ticket_assigned_to_display = "Not Assigned"; + }else{ + $ticket_assigned_to_display = htmlentities($row['user_name']); + } + + if ($contact_id) { + //Get Contact Ticket Stats + $ticket_related_open = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_open FROM tickets WHERE ticket_status != 'Closed' AND ticket_contact_id = $contact_id "); + $row = mysqli_fetch_array($ticket_related_open); + $ticket_related_open = $row['ticket_related_open']; + + $ticket_related_closed = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_closed FROM tickets WHERE ticket_status = 'Closed' AND ticket_contact_id = $contact_id "); + $row = mysqli_fetch_array($ticket_related_closed); + $ticket_related_closed = $row['ticket_related_closed']; + + $ticket_related_total = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_total FROM tickets WHERE ticket_contact_id = $contact_id "); + $row = mysqli_fetch_array($ticket_related_total); + $ticket_related_total = $row['ticket_related_total']; + } + + //Get Total Ticket Time + $ticket_total_reply_time = mysqli_query($mysqli,"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ticket_reply_time_worked))) AS ticket_total_reply_time FROM ticket_replies WHERE ticket_reply_archived_at IS NULL AND ticket_reply_ticket_id = $ticket_id"); + $row = mysqli_fetch_array($ticket_total_reply_time); + $ticket_total_reply_time = $row['ticket_total_reply_time']; + + //Client Tags + $client_tag_name_display_array = array(); + $client_tag_id_array = array(); + $sql_client_tags = mysqli_query($mysqli,"SELECT * FROM client_tags LEFT JOIN tags ON client_tags.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id"); + while ($row = mysqli_fetch_array($sql_client_tags)) { + + $client_tag_id = $row['tag_id']; + $client_tag_name = htmlentities($row['tag_name']); + $client_tag_color = htmlentities($row['tag_color']); + $client_tag_icon = htmlentities($row['tag_icon']); + if (empty($client_tag_icon)) { + $client_tag_icon = "tag"; } - ?> -
- -
- -
- - Time worked: - -
-
-

+ $client_tag_id_array[] = $client_tag_id; + $client_tag_name_display_array[] = " $client_tag_name"; + } + $client_tags_display = implode(' ', $client_tag_name_display_array); - -
- +
-
- -
-
+
- - include("ticket_reply_edit_modal.php"); +
+

+
- } - - ?> - -
- -
- - -
-
-
- - -
- - - -
-
- - - -
-
-

Contact

- -
- - - Related tickets: Open | Closed | Total -
- - -
- - - -
- - - -
- - - -
- -
-
- - - - -
-

Details

-
-
Created on:
-
Created by:
- -
Closed by:
-
Feedback:
- - -
Total time worked:
- -
- - - -
-
-

Asset

- -
- - - -
- - -
- - Model: -
- - Service Tag: -
- - - Warranty expires: -
- - - 0 ){ - ?> - - - - +
- +
+
+
+ + +
+ - } + +
+
- ?> + + +
+
+

Contact

+ +
+ Related tickets: Open | Closed | Total +
+ -
- + if (!empty($location_name)) { ?> + +
+ - -
- -
-
- -
- +
+ +
+
+ +
+ +
+ +
+
+
+ + + + + + +
- - -
- -
-
- - - - + include("ticket_edit_modal.php"); + include("ticket_merge_modal.php"); + include("ticket_invoice_add_modal.php"); -
- -
- - - - - - - - - - - - - // Collision detection - // Adds a "view" entry of the current ticket every 2 mins into the database - // Updates the currently viewing (ticket_collision_viewing) element with anyone that's looked at this ticket in the last two mins - function ticket_collision_detection() { - - // Get the page ticket id - var ticket_id = document.getElementById("ticket_id").value; - - //Send a GET request to ajax.php as ajax.php?ticket_add_view=true&ticket_id=NUMBER - jQuery.get( - "ajax.php", - {ticket_add_view: 'true', ticket_id: ticket_id}, - function(data){ - // We don't care about a response - } - ); - - //Send a GET request to ajax.php as ajax.php?ticket_query_views=true&ticket_id=NUMBER - jQuery.get( - "ajax.php", - {ticket_query_views: 'true', ticket_id: ticket_id}, - function(data){ - //If we get a response from ajax.php, parse it as JSON - const ticket_view_data = JSON.parse(data); - document.getElementById("ticket_collision_viewing").innerText = ticket_view_data.message; - } - ); - } - // Call on page load - ticket_collision_detection(); - - // Run every 2 mins - setInterval(ticket_collision_detection, 120*1000); - + + \ No newline at end of file diff --git a/ticket_add_modal.php b/ticket_add_modal.php index 6f9663a3..8df31684 100644 --- a/ticket_add_modal.php +++ b/ticket_add_modal.php @@ -1,158 +1,143 @@