Add Who’s Online Feature into osTicket v1.6 RC5
Today I successfully created another modification by adding a new feature about Who’s Online into osTicket v1.6 RC5. This modification will add a new sub tab under Dashboard tab, with named: User Online, and you can access this from Admin Panel. For those of you who need this feature, you may use this following modification code.
-
First of all, add a new table named ost_useronline by using this following SQL script. Please note that the ost_ is the table prefix name. It could be different with yours. In case it differs with yours, please adjust it by yourself, and please be kind of it!
CREATE TABLE `ost_useronline` ( `date_online` datetime NOT NULL default '0000-00-00 00:00:00', `username` varchar(20) NOT NULL default '', `useragent` varchar(255) NOT NULL default '', `ip` varchar(40) NOT NULL default '', `location` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', `referral` varchar(255) NOT NULL default '', PRIMARY KEY (`username`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
Open your main.inc.php file, and find this code:
122
define('TICKET_LOCK_TABLE',TABLE_PREFIX.'ticket_lock');
after that line, please insert this following code:
123
define('USERONLINE_TABLE',TABLE_PREFIX.'useronline');
-
Open your \include\class.staff.php file, and find this code:
327 328
} ?>
before the first line of that code, please insert this following code:
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
function useronline() { if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip_address = $_SERVER["REMOTE_ADDR"]; } else { $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"]; } if(strpos($ip_address, ',') !== false) { $ip_address = explode(',', $ip_address); $ip_address = $ip_address[0]; } $url = $_SERVER['REQUEST_URI']; $referral = ''; $user_agent = $_SERVER['HTTP_USER_AGENT']; $current_user = $this->getUserName(); if(!empty($_SERVER['HTTP_REFERER'])) { $referral = $_SERVER['HTTP_REFERER']; } $user_agent = addslashes($user_agent); if (!isset($_GET['t'])) { $str_url = explode('/', $url); $arr_url = array_reverse($str_url); $t=$arr_url[0]; } else { $t = $_GET['t']; } $page_title = $t; $insert_user = db_query("REPLACE INTO ".USERONLINE_TABLE." SET date_online=NOW(), username='$current_user', useragent='$user_agent', ip='$ip_address', location='$page_title', url='$url', referral='$referral'"); }
-
Open your \include\staff\header.inc.php file, and find this code:
53
<div id="content" width="100%">
after that line, please insert this following code:
54 55 56
<?php $thisuser->useronline(); ?>
-
Create a new file, copy-paste this following code into it, and then save it as useronline.inc.php file, and put this file into your \include\staff\ sub directory of your osTicket:
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 72 73 74
<?php /** * @filename \include\staff\useronline.inc.php * @author Masino Sinaga, http://www.openscriptsolution.com * @copyright October 31, 2009 */ if(!defined('OSTSCPINC') || !@$thisuser->isStaff()) die('Access Denied'); $qstr='&t=useronline'; //Query string collector $qwhere =' WHERE 1'; $qselect = 'SELECT * '; $qfrom=' FROM '.USERONLINE_TABLE.' '; $total=db_count("SELECT count(*) $qfrom $qwhere"); if($_GET['limit']){ $qstr.='&limit='.urlencode($_GET['limit']); } $pagelimit=$_GET['limit']?$_GET['limit']:5; $page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1; $title='Who\'s Online'; //pagenate $pageNav=new Pagenate($total,$page,$pagelimit); $pageNav->setURL('admin.php',$qstr); $query="$qselect $qfrom $qwhere ORDER BY date_online DESC LIMIT ".$pageNav->getStart().",".$pageNav->getLimit(); //echo $query; $result = db_query($query); $total = db_num_rows($result); $showing=$total?$pageNav->showing():""; ?> <div class="msg">User Online (<?php echo $total; ?>)</div> <div style="margin-bottom:20px; padding-top:0px;"> <table width="100%" border="0" cellspacing=1 cellpadding=2> <tr><td> <table width="100%" border="0" cellspacing=0 cellpadding=2 class="logs" align="center"> <b><?=$showing?></b> <a href="admin.php?t=useronline" title="Reload"><span class="Icon refresh"> </span></a> <tr><th> <?=$title?></th></tr> <? $class = "row1"; $total=0; if($result && ($num=db_num_rows($result))): while ($row = db_fetch_array($result)) { $icon='assignedTicket'; ?> <tr class="<?=$class?>" id="<?=$row['username']?>"> <td> <a href="javascript:toggleMessage('<?=$row['username']?>');"> <img border="0" align="left" id="img_<?=$row['username']?>" src="images/plus.gif"> <span style="color:000; float: left; width:190px;"><?=Format::db_daydatetime($row['date_online'])?></span> <span class="Icon <?=$icon?>"><?=Format::htmlchars($row['username'])?></span></a> <div id="msg_<?=$row['username']?>" class="hide"> <hr> <b>Location:</b> <?=Format::display($row['location'])?><br /> <b>Referral:</b> <?=Format::htmlchars($row['referral'])?> <br /> <b>IP Address:</b> <?=Format::htmlchars($row['ip'])?> <br /> </div> </td> </tr> <? $class = ($class =='row2') ?'row1':'row2'; } //end of while. else: //no useronline found!! ?> <tr class="<?=$class?>"><td><b>Query returned 0 results.</b></td></tr> <? endif; ?> </table> </td></tr> <? if($num>0){ ?> <tr><td style="padding-left:20px">page:<?=$pageNav->getPageLinks()?></td></tr> <? } ?> </table> </div>
-
Open your \scp\admin.php file, and find this code:
527 528 529 530 531 532
case 'dashboard': case 'syslog': $nav->setTabActive('dashboard'); $nav->addSubMenu(array('desc'=>'System Logs','href'=>'admin.php?t=syslog','iconclass'=>'syslogs')); $page='syslogs.inc.php'; break;
and then replace with this following code:
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
case 'dashboard': case 'syslog': case 'useronline': // MOD User Online, Added by Masino Sinaga, October 31, 2009 $nav->setTabActive('dashboard'); $nav->addSubMenu(array('desc'=>'System Logs','href'=>'admin.php?t=syslog','iconclass'=>'syslogs')); $nav->addSubMenu(array('desc'=>'User Online','href'=>'admin.php?t=useronline','iconclass'=>'syslogs')); $page='syslogs.inc.php'; switch(strtolower($_REQUEST['t'])): case 'syslog': $page='syslogs.inc.php'; break; case 'useronline': // MOD User Online Added by Masino Sinaga, October 31, 2009 $page='useronline.inc.php'; break; endswitch; break;
That’s all. Enjoy the result, and let me know your feedback.
Print This Post
Is there any way to see that the person has logged off and is not on the system. It appears that work, but doesn’t clear the userids that are not logged in anymore..
great work btw…