@@ -48,7 +48,7 @@ public function __construct(Ticket $tickets)
4848 {
4949 $ this ->middleware ('PanicHD\PanicHD\Middleware\EnvironmentReadyMiddleware ' , ['only ' => ['create ' ]]);
5050 $ this ->middleware ('PanicHD\PanicHD\Middleware\UserAccessMiddleware ' , ['only ' => ['show ' , 'downloadAttachment ' , 'viewAttachment ' ]]);
51- $ this ->middleware ('PanicHD\PanicHD\Middleware\AgentAccessMiddleware ' , ['only ' => ['edit ' , 'update ' , 'changeAgent ' , 'changePriority ' , 'changeStatus ' , 'hide ' ]]);
51+ $ this ->middleware ('PanicHD\PanicHD\Middleware\AgentAccessMiddleware ' , ['only ' => ['edit ' , 'update ' , 'changeRead ' , ' changeAgent ' , 'changePriority ' , 'changeStatus ' , 'hide ' ]]);
5252 $ this ->middleware ('PanicHD\PanicHD\Middleware\IsAdminMiddleware ' , ['only ' => ['destroy ' ]]);
5353 $ this ->middleware ('PanicHD\PanicHD\Middleware\IsAgentMiddleware ' , ['only ' => ['search_form ' , 'register_search_fields ' ]]);
5454
@@ -258,7 +258,7 @@ public function get_last_update($ticketList)
258258 *
259259 * @return String
260260 */
261- public function last_update_string ($ ticketList )
261+ public function last_update_string ($ ticketList = null )
262262 {
263263 $ last_update = Ticket::orderBy ('updated_at ' , 'desc ' )->first ();
264264
@@ -405,13 +405,22 @@ public function renderTicketTable($collection, $ticketList)
405405
406406 // Column edits
407407 $ collection ->editColumn ('id ' , function ($ ticket ) {
408- return '<div class="tooltip-wrap-15 ' . (($ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent == " 0 " ) ? ' unread_ticket_text" ' : '' ) . '"> '
408+ $ column = '<div class="tooltip-wrap-15 ' . (($ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent != " 1 " ) ? ' unread_ticket_text" ' : '' ) . '"> '
409409 .'<div class="tooltip-info" data-toggle="tooltip" title=" '
410410 .trans ('panichd::lang.creation-date ' , ['date ' => Carbon::parse ($ ticket ->created_at )->format (trans ('panichd::lang.datetime-format ' ))])
411411 .'"> ' .$ ticket ->id
412- .'</div> '
413- . (($ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent == "0 " ) ? '<div class="tooltip-info" data-toggle="tooltip" title=" ' . trans ('panichd::lang.updated-by-other ' ) . '"><i class="fas fa-user-edit"></i></div> ' : '' )
414412 .'</div> ' ;
413+
414+ if ($ this ->member ->id == $ ticket ->agent_id ){
415+ // For assigned agent: Mark ticket as read / unread
416+ $ column .= '<button class="btn btn-light btn-xs unread_toggle tooltip-info" data-ticket_id=" ' . $ ticket ->id . '" data-toggle="tooltip" '
417+ . ' title=" ' . ($ ticket ->read_by_agent == "2 " ? trans ('panichd::lang.mark-as-read ' ) : trans ('panichd::lang.mark-as-unread ' )) . '"> '
418+ . '<i class="fas ' . ($ ticket ->read_by_agent == "2 " ? 'fa-user-lock ' : ($ ticket ->read_by_agent == "1 " ? 'fa-user ' : 'fa-user-edit ' )) . '"></i></button> ' ;
419+ }
420+
421+ $ column .= '</div> ' ;
422+
423+ return $ column ;
415424 });
416425
417426 $ collection ->editColumn ('subject ' , function ($ ticket ) {
@@ -421,7 +430,7 @@ public function renderTicketTable($collection, $ticketList)
421430 $ ticket ->id
422431 );
423432
424- if ($ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent == " 0 " ){
433+ if ($ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent != " 1 " ){
425434 $ field = '<span class="unread_ticket_text"> ' . $ field . '</span> ' ;
426435 }
427436
@@ -1863,18 +1872,16 @@ public function show($id)
18631872
18641873 $ a_resend_notifications = $ this ->get_resend_notifications ($ ticket , $ all_comments );
18651874
1866- if ($ this ->member ->currentLevel () > 1 and $ this ->member ->id == $ ticket ->agent_id ){
1867- if ($ ticket ->read_by_agent == '0 ' ){
1868- // Mark ticket as read
1869- $ ticket ->read_by_agent = 1 ;
1870- $ ticket ->save ();
1871-
1872- // Mark comments as read
1873- foreach ($ all_comments ->get () as $ comment ){
1874- if ($ comment ->read_by_agent == '0 ' ){
1875- $ comment ->read_by_agent = 1 ;
1876- $ comment ->save ();
1877- }
1875+ if ($ this ->member ->currentLevel () > 1 and $ this ->member ->id == $ ticket ->agent_id and $ ticket ->read_by_agent == '0 ' ){
1876+ // Mark ticket as read
1877+ $ ticket ->read_by_agent = 1 ;
1878+ $ ticket ->save ();
1879+
1880+ // Mark comments as read
1881+ foreach ($ all_comments ->get () as $ comment ){
1882+ if ($ comment ->read_by_agent != '1 ' ){
1883+ $ comment ->read_by_agent = 1 ;
1884+ $ comment ->save ();
18781885 }
18791886 }
18801887 }
@@ -2005,7 +2012,7 @@ public function update(Request $request, $id)
20052012 $ ticket ->agent_id = $ request ->input ('agent_id ' );
20062013 }
20072014
2008- if ($ ticket ->agent_id != $ this ->member ->id ){
2015+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
20092016 // Ticket will be unread for assigned agent
20102017 $ ticket ->read_by_agent = 0 ;
20112018 }
@@ -2237,7 +2244,7 @@ public function complete(Request $request, $id)
22372244
22382245 $ ticket ->completed_at = Carbon::now ();
22392246
2240- if ($ ticket ->agent_id != $ this ->member ->id ){
2247+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
22412248 // Ticket will be unread for assigned agent
22422249 $ ticket ->read_by_agent = 0 ;
22432250 }
@@ -2300,7 +2307,7 @@ public function complete_change_actions($ticket, $member, $member_reason = false
23002307 $ comment ->user_id = $ this ->member ->id ;
23012308 $ comment ->ticket_id = $ ticket ->id ;
23022309
2303- if ($ ticket ->agent_id != $ this ->member ->id ){
2310+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
23042311 // Ticket will be unread for assigned agent
23052312 $ comment ->read_by_agent = 0 ;
23062313 }
@@ -2329,7 +2336,7 @@ public function reopen($id)
23292336 $ ticket ->intervention = $ ticket ->intervention . ' ' . $ date . ' ' . trans ('panichd::lang.reopened-by-user ' , ['user ' => $ this ->member ->name ]);
23302337 $ ticket ->intervention_html = $ ticket ->intervention_html . '<br /> ' . $ date . ' ' . trans ('panichd::lang.reopened-by-user ' , ['user ' => $ this ->member ->name ]);
23312338
2332- if ($ ticket ->agent_id != $ this ->member ->id ){
2339+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
23332340 // Ticket will be unread for assigned agent
23342341 $ ticket ->read_by_agent = 0 ;
23352342 }
@@ -2383,6 +2390,35 @@ public function agentList ($category_id)
23832390 }
23842391 }
23852392
2393+ /*
2394+ * AJAX Mark ticket as read / unread
2395+ *
2396+ * @return Response
2397+ */
2398+ public function changeRead (Request $ request )
2399+ {
2400+ $ result = "error " ;
2401+ $ message = trans ('panichd::lang.read-validation-error ' );
2402+
2403+ $ original_ticket = Ticket::findOrFail ($ request ->input ('ticket_id ' ));
2404+ $ ticket = clone $ original_ticket ;
2405+
2406+ if ($ ticket ->agent ->id == auth ()->user ()->id ){
2407+ $ ticket ->read_by_agent = $ ticket ->read_by_agent == "2 " ? "1 " : "2 " ;
2408+ $ ticket ->save ();
2409+
2410+ $ result = "ok " ;
2411+ $ message = trans ('panichd::lang.read-validation-ok- ' . ($ ticket ->read_by_agent == "1 " ? 'read ' : 'unread ' ));
2412+ }
2413+
2414+ return response ()->json ([
2415+ 'result ' => $ result ,
2416+ 'message ' => $ message ,
2417+ 'read_by_agent ' => $ ticket ->read_by_agent ,
2418+ 'last_update ' => $ this ->last_update_string ()
2419+ ]);
2420+ }
2421+
23862422 /*
23872423 * AJAX agent change in ticket list
23882424 *
@@ -2455,7 +2491,7 @@ public function changePriority(Request $request){
24552491 }else {
24562492 $ ticket ->priority_id = $ request ->input ('priority_id ' );
24572493
2458- if ($ ticket ->agent_id != $ this ->member ->id ){
2494+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
24592495 // Ticket will be unread for assigned agent
24602496 $ ticket ->read_by_agent = 0 ;
24612497 }
@@ -2501,7 +2537,7 @@ public function changeStatus(Request $request){
25012537 }else {
25022538 $ ticket ->status_id = $ request ->input ('status_id ' );
25032539
2504- if ($ ticket ->agent_id != $ this ->member ->id ){
2540+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
25052541 // Ticket will be unread for assigned agent
25062542 $ ticket ->read_by_agent = 0 ;
25072543 }
@@ -2539,7 +2575,7 @@ public function hide($value, $id)
25392575
25402576 $ ticket ->hidden = $ value =='true ' ? 1 : 0 ;
25412577
2542- if ($ ticket ->agent_id != $ this ->member ->id ){
2578+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
25432579 // Ticket will be unread for assigned agent
25442580 $ ticket ->read_by_agent = 0 ;
25452581 }
@@ -2572,7 +2608,7 @@ public function hide_actions($ticket)
25722608 $ comment ->user_id = $ this ->member ->id ;
25732609 $ comment ->ticket_id = $ ticket ->id ;
25742610
2575- if ($ ticket ->agent_id != $ this ->member ->id ){
2611+ if ($ ticket ->agent_id != $ this ->member ->id and $ ticket -> read_by_agent != " 2 " ){
25762612 // Ticket will be unread for assigned agent
25772613 $ comment ->read_by_agent = 0 ;
25782614 }
0 commit comments