Home > osTicket > Recording and Displaying The Last Client and Staff Visit in osTicket v1.6 RC5

Recording and Displaying The Last Client and Staff Visit in osTicket v1.6 RC5

It is necessary or even important for staff to know when a ticket being accessed for the very last time both by client/customer and staff in osTicket. I have successfully created a modification about it. This modification will record and display the date and time when the certain ticket being accessed for the very last time. If staff accesses a ticket, then he/she will be able to know when client accessed that ticket for the very last time. Also, staff will be able to know who is the staff accessed that ticket for the very last time. If that ticket is being accessed for the very first time, then there will be no staff information accessed that ticket, until the current staff refresh and reload that viewticket page.

  1. First of all, you have to create a new table named ost_ticket_visit inside your osTicket database. Use this SQL from your phpMyAdmin or your another MySQL tools:

    CREATE TABLE `ost_ticket_visit` (
      `ticketID` int(11) NOT NULL,
      `lastvisitclient` datetime default NULL,
      `lastvisitstaff` datetime default NULL,
      `staff_id` int(10) NOT NULL,
      PRIMARY KEY  (`ticketID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  2. Open index.php file, and find this code:

    45
    
      <form class="status_form" action="tickets.php" method="post">

    then replace with this following code:

    45
    
      <form class="status_form" action="login.php" method="post">

    Note: Please avoid this step if you already have the modification version.

  3. Open your main.inc.php file, and find this code:

    121
    
        define('TICKET_LOCK_TABLE',TABLE_PREFIX.'ticket_lock');

    after the last line of that code above, please insert this following code:

    122
    
        define('TICKET_VISIT_TABLE',TABLE_PREFIX.'ticket_visit'); // MOD Check lastlogin/lastlogout, added by Masino Sinaga, Oct 19, 2009
  4. Open your login.php file, and find this code:

    65
    66
    67
    
                @header("Location: tickets.php");
                require('tickets.php'); //Just incase. of header already sent error.
                exit;

    then replace with this following code:

    65
    66
    67
    68
    69
    70
    
                //@header("Location: tickets.php");
                // MOD Last visit by client and staff, Added by Masino Sinaga, Oct 19, 2009
                $ticket->updateLastVisit($ticketID);
                @header("Location: tickets.php?id=" . $ticketID . ""); 
                require('tickets.php'); //Just incase. of header already sent error.           
                exit;
  5. Open your tickets.php file, and find this code:

    34
    35
    
            //Everything checked out.
            $inc='viewticket.inc.php';

    then replace with this following code:

    34
    35
    36
    37
    
            // MOD Last visit by client and staff, Added by Masino Sinaga, Oct 19, 2009
            $ticket->updateLastVisit($id);
            //Everything checked out.
            $inc='viewticket.inc.php';
  6. Open \include\class.ticket.php file, and find this code:

    1336
    1337
    
    }
    ?>

    then replace with this following code:

    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    
       // MOD Last Visit by client and staff, Added by Masino Sinaga, Oct 19, 2009
       function updateLastVisit($ticketID, $staffId=0) {
         if ($staffId==0) {	
           if(db_query('UPDATE '.TICKET_VISIT_TABLE.' 
    	                SET lastvisitclient=NOW() 
     		        WHERE ticketID='.db_input($ticketID)) && db_affected_rows()){
              return true;
            } else {
              $sqlinsert = 'REPLACE INTO '.TICKET_VISIT_TABLE.' 
    			   SET ticketID = '.db_input($ticketID).', 
    			   lastvisitclient = NOW()';					
              if(db_query($sqlinsert) && ($msgid=db_insert_id())) {
                return true;	
              }
            }
          } else { 
    	if(db_query('UPDATE '.TICKET_VISIT_TABLE.' 
    	                 SET lastvisitstaff=NOW(), staff_id='.db_input($staffId).' 
    		         WHERE ticketID='.db_input($ticketID)) && db_affected_rows()){
              return true;
            } else {
              $sqlinsert = 'REPLACE INTO '.TICKET_VISIT_TABLE.' 
    	                   SET ticketID='.db_input($ticketID).', 
    	                   lastvisitstaff=NOW(), 
    			   staff_id='.db_input($staffId).'';					
              if(db_query($sqlinsert) && ($msgid=db_insert_id())) {
                return true;	
              }
            }			
          }
          return false;
       }
    }
    ?>
  7. Create a new blank file, copy-paste this following code into it, and save it as class.visit.php, and put this file in \include\ sub directory:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    
    <?php
     
    /*********************************************************************
        class.visit.php
     
        Handles the last ticket visiting, both for client and staff
     
        Masino Sinaga <masino_sinaga@posindonesia.co.id>
        Copyright (c)  2006,2007,2008,2009 osTicket
        http://www.openscriptsolution.com
     
        Released under the GNU General Public License WITHOUT ANY WARRANTY.
        See LICENSE.TXT for details.
     
        $Id: $
    **********************************************************************/
     
    class Visit {
     
        var $id;
        var $ticketID;
        var $udata;
        var $lastvisitclient;
        var $lastvisitstaff;
        var $staff_id;
        var $staff_name;
     
        function Visit($id){
            $this->id =0;
            return ($this->lookup($id));
        }
     
        function lookup($id){
            $sql='SELECT * FROM '.TICKET_VISIT_TABLE.' WHERE ticketID='.db_input($id);
            $res=db_query($sql);
            if(!$res || !db_num_rows($res))
                return NULL;
     
            $row=db_fetch_array($res);
            $this->udata=$row;
            $this->id = $row['ticketID']; 
            $this->lastvisitclient = $row['lastvisitclient'];
            $this->lastvisitstaff = $row['lastvisitstaff'];
            $this->staff_id = $row['staff_id'];
     
            return($this->id);
        }
     
        function getClientLastVisit(){
            return($this->lastvisitclient);
        }
     
        function getStaffLastVisit(){
            return($this->lastvisitstaff);
        }
     
        function getStaffID(){
            return($this->staff_id); 
        }
     
        function getStaffName(){
            $sql='SELECT username FROM '.STAFF_TABLE.' WHERE staff_id='.db_input($this->getStaffID());
            if(($res=db_query($sql)) && db_num_rows($res)) {
              $row=db_fetch_array($res);
              $this->staff_name = $row['username'];
            }
            return($this->staff_name);
        }
     
    }
    ?>
  8. Open \include\staff\viewticket.inc.php file, and find this code:

    41
    42
    
         <td width=50%>	
        <table align="center" class="ticketinfo" cellspacing="1" cellpadding="3" width="100%" border=0>

    then replace with this following code:

    41
    42
    43
    44
    45
    46
    47
    
         <td width=50%>	
        <table align="center" class="ticketinfo" cellspacing="1" cellpadding="3" width="100%" border=0>
          <tr>
            <th>
                Client Last Visit: </th>
            <td><?php echo Format::db_datetime($visit->getClientLastVisit()); ?></td>
          </tr>

    Find again this code:

    67
    68
    69
    
         </td>
         <td width=50% valign="top">
            <table align="center" class="ticketinfo" cellspacing="1" cellpadding="3" width="100%" border=0>

    then replace with this following code:

    67
    68
    69
    70
    71
    72
    73
    74
    75
    
         </td>
         <td width=50% valign="top">
            <table align="center" class="ticketinfo" cellspacing="1" cellpadding="3" width="100%" border=0>
          <tr>
            <th>
                Staff Last Visit: </th>
            <td><?php echo Format::db_datetime($visit->getStaffLastVisit());
    				      echo ($visit->getStaffName() != '') ? ' ('.$visit->getStaffName().')' : ''; ?></td>
          </tr>
  9. Open your \scp\tickets.php file, and find this code:

    21
    
    require_once(INCLUDE_DIR.'class.banlist.php');

    then replace with this following code:

    21
    22
    
    require_once(INCLUDE_DIR.'class.banlist.php');
    require_once(INCLUDE_DIR.'class.visit.php'); // MOD Last Visit by client and staff, Added by Masino Sinaga, October 19, 2009

    Find again this code:

    34
    35
    
        if(!$errors && $ticket->getId()==$id)
            $page='viewticket.inc.php'; //Default - view

    then replace with this following code:

    34
    35
    36
    37
    38
    39
    40
    
        if(!$errors && $ticket->getId()==$id) { 
            // MOD Last visit by client and staff, Added by Masino Sinaga, October 19, 2009
            $ticketID = $ticket->getExtId();
            $visit= new Visit($ticketID);
            $page='viewticket.inc.php'; //Default - view
            $ticket->updateLastVisit($ticketID, $thisuser->getId());
        }

    Find again this code:

    180
    181
    
                    $msg='Ticket updated successfully';
                    $page='viewticket.inc.php';

    then replace with this following code:

    180
    181
    182
    183
    184
    185
    186
    
                    $msg='Ticket updated successfully';
                    //$page='viewticket.inc.php';
                    // MOD Last visit by client and staff, Added by Masino Sinaga, October 19, 2009
    	        $ticketID = $ticket->getExtId();
                    $visit= new Visit($ticketID);
                    $page='viewticket.inc.php'; //Default - view
                    $ticket->updateLastVisit($ticketID, $thisuser->getId());

    Find again this code:

    369
    370
    
                            $page='viewticket.inc.php';
                            $ticket->reload(); //Reload ...possibly assigned!

    then replace with this following code:

    369
    370
    371
    372
    373
    374
    375
    
                            //$page='viewticket.inc.php';
    	                // MOD Last visit by client and staff, Added by Masino Sinaga, October 19, 2009
                            $ticketID = $ticket->getExtId();
                            $visit= new Visit($ticketID);
                            $page='viewticket.inc.php'; //Default - view
                            $ticket->updateLastVisit($ticketID, $thisuser->getId());
                            $ticket->reload(); //Reload ...possibly assigned!

That’s all. Now as a staff, you are able to see when the last time your customer access that ticket from the viewticket page, including when you or another staff access that ticket for the very last time.

Last Visit Information both by Client and Staff in osTicket v1.6 RC5

  • Share/Bookmark
340 views Print This Post Print This Post

  1. yarfik
    December 5th, 2009 at 16:42 | #1

    nanya lagi ya mas.. ^_^

    catatan pada langkah no2 itu maksudnya apa?

    -> Note: Please avoid this step if you already have the modification version.

    trims.

  2. yarfik
    December 5th, 2009 at 17:26 | #2

    satu lagi mas..

    ini berlaku surut g mas? berlaku untuk ticket2 sebelum script ini di masukkan g?

    thanks.

  3. December 6th, 2009 at 11:41 | #3

    @yarfik

    Itu maksudnya, kalau kode yang akan diubah sudah dalam bentuk versi yang dimodifikasi, maka perintah pada langkah modifikasi nomor 2 tersebut diabaikan saja, karena ada kemungkinan modifikasi nomor 2 tersebut sudah pernah dilakukan secara terpisah untuk mengatasi cek tiket dari halaman index di sisi klien.

  4. December 6th, 2009 at 11:45 | #4

    @yarfik

    Bisa ya, dan bisa tidak. Nah, lho? Bingung? Hehe, jangan bingung dulu!

    Maksudnya begini: Kalau tiket yang dimasukkan sebelum modifikasi ini dikunjungi kembali setelah modifikasi diterapkan, maka info kunjungan terakhir tersebut akan terekam. Tapi kalau tiket tersebut tidak pernah dikunjungi lagi setelah modifikasi diterapkan, maka info kunjungan terakhir tersebut tidak akan terekam dan tidak ditampilkan.

    Semoga dapat dipahami.

  1. No trackbacks yet.