From fb4da5302640dbbbd17c2cd8dcf559008fade316 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sat, 26 Mar 2022 18:05:20 +0000 Subject: [PATCH 1/2] Show who else is viewing the same open ticket as you --- ajax.php | 32 +++++++++++++ cron.php | 3 ++ db.sql | 16 +++++++ ticket.php | 136 ++++++++++++++++++++++++++++++++++------------------- 4 files changed, 138 insertions(+), 49 deletions(-) diff --git a/ajax.php b/ajax.php index bc052352..060d52c6 100644 --- a/ajax.php +++ b/ajax.php @@ -153,4 +153,36 @@ if(isset($_POST['client_set_notes'])){ // Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Client', log_action = 'Modify', log_description = '$session_name modified client notes', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_created_at = NOW(), log_client_id = $client_id, log_user_id = $session_user_id, company_id = $session_company_id"); +} + +if(isset($_GET['ticket_add_view'])){ + $ticket_id = intval($_GET['ticket_id']); + + $a = mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = '$ticket_id', view_user_id = '$session_user_id', view_timestamp = NOW()"); +} + +if(isset($_GET['ticket_query_views'])){ + $ticket_id = intval($_GET['ticket_id']); + + $query = mysqli_query($mysqli, "SELECT user_name FROM ticket_views LEFT JOIN users ON view_user_id = user_id WHERE view_ticket_id = '$ticket_id' AND view_user_id != '$session_user_id' AND view_timestamp > DATE_SUB(NOW(), INTERVAL 2 MINUTE)"); + while($row = mysqli_fetch_array($query)){ + $users[] = $row['user_name']; + } + if(!empty($users)){ + $users = array_unique($users); + if(count($users) > 1){ + // Multiple viewers + $response['message'] = implode(", ", $users) . " are viewing this ticket."; + } + else{ + // Single viewer + $response['message'] = implode("", $users) . " is viewing this ticket."; + } + } + else{ + // No viewers + $response['message'] = ""; + } + echo json_encode($response); + } \ No newline at end of file diff --git a/cron.php b/cron.php index 0e73e5c1..48b7d782 100644 --- a/cron.php +++ b/cron.php @@ -257,6 +257,9 @@ while($row = mysqli_fetch_array($sql_companies)){ } } + // Clean-up ticket views table used for collision detection + mysqli_query($mysqli, "TRUNCATE TABLE ticket_views"); + // PAST DUE INVOICE Notifications //$invoiceAlertArray = [$config_invoice_overdue_reminders]; $invoiceAlertArray = [30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,590,620]; diff --git a/db.sql b/db.sql index a9cac9da..94fe7d77 100644 --- a/db.sql +++ b/db.sql @@ -1274,6 +1274,22 @@ CREATE TABLE `ticket_replies` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `ticket_views` +-- + +DROP TABLE IF EXISTS `ticket_views`; +CREATE TABLE IF NOT EXISTS `ticket_views` ( + `view_id` int(11) NOT NULL AUTO_INCREMENT, + `view_ticket_id` int(11) NOT NULL, + `view_user_id` int(11) NOT NULL, + `view_timestamp` datetime NOT NULL, + PRIMARY KEY (`view_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- -------------------------------------------------------- + -- -- Table structure for table `tickets` -- diff --git a/ticket.php b/ticket.php index d085e5bd..5364d564 100644 --- a/ticket.php +++ b/ticket.php @@ -216,7 +216,7 @@ if(isset($_GET['ticket_id'])){
- +
@@ -262,6 +262,8 @@ if(isset($_GET['ticket_id'])){ +

+
@@ -605,59 +607,95 @@ if(isset($_GET['ticket_id'])){ - - + // 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 From 42d917a0f4dfbf923ed0449a51de8e87f16ff2a0 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sat, 26 Mar 2022 18:11:03 +0000 Subject: [PATCH 2/2] Comments --- ajax.php | 13 +++++++++++-- ticket.php | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ajax.php b/ajax.php index 060d52c6..1841be1c 100644 --- a/ajax.php +++ b/ajax.php @@ -155,12 +155,22 @@ if(isset($_POST['client_set_notes'])){ } +/* + * Collision Detection/Avoidance + * Called upon loading a ticket, and every 2 mins thereafter + * Is used in conjunction with ticket_query_views to show who is currently viewing a ticket + */ if(isset($_GET['ticket_add_view'])){ $ticket_id = intval($_GET['ticket_id']); - $a = mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = '$ticket_id', view_user_id = '$session_user_id', view_timestamp = NOW()"); + mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = '$ticket_id', view_user_id = '$session_user_id', view_timestamp = NOW()"); } +/* + * Collision Detection/Avoidance + * Returns formatted text of the agents currently viewing a ticket + * Called upon loading a ticket, and every 2 mins thereafter + */ if(isset($_GET['ticket_query_views'])){ $ticket_id = intval($_GET['ticket_id']); @@ -184,5 +194,4 @@ if(isset($_GET['ticket_query_views'])){ $response['message'] = ""; } echo json_encode($response); - } \ No newline at end of file diff --git a/ticket.php b/ticket.php index 5364d564..44288283 100644 --- a/ticket.php +++ b/ticket.php @@ -668,8 +668,8 @@ if($ticket_status !== "Closed"){ ?> \ No newline at end of file