예제 #1
0
 $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "' Order by whendone DESC";
 $page_trail = $mydatabase->query($sqlquery);
 $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
 $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $visitor['department'] . "'";
 $tmp = $mydatabase->query($sqlquery);
 $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
 $nameof = $nameof['nameof'];
 $query = "SELECT whendone from livehelp_visit_track WHERE sessionid='" . filter_sql($visitor['sessionid']) . "' Order by whendone LIMIT 1";
 $page_tmprow = $mydatabase->query($query);
 $tmprow = $page_tmprow->fetchRow(DB_FETCHMODE_ASSOC);
 $later = $tmprow['whendone'];
 $DIVS .= "<DIV ID=\"info-" . $visitor['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n<TABLE BORDER=\"0\" WIDTH=\"300\"><TR BGCOLOR=\"#000000\"><TD> \n<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n<FONT COLOR=\"#000000\">\n<b>Referer:</b><br>" . $user_info['camefrom'] . "<br>";
 if (empty($page['location'])) {
     $page['location'] = "";
 }
 $DIVS .= "<b>" . $lang['timeonline'] . ":</b>" . secondstoHHmmss(timediff($later, date("YmdHis"))) . "<br> \n<b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n<b>url:</b><br>" . $page['location'] . "<br>";
 $now = date("YmdHis");
 $thediff = $now - $user_info['lastaction'];
 $DIVS .= "<b>" . $lang['lastact'] . ":</b><br>{$thediff} " . $lang['Seconds'] . "<br>\n </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
 $html .= "</td>";
 switch ($visitor['status']) {
     case "DHTML":
         $html .= "<td>L:<img src=images/invited.gif> ";
         break;
     case "request":
         $html .= "<td>P:<img src=images/invited.gif> ";
         break;
     case "invited":
         $html .= "<td><img src=images/invited2.gif>  ";
         break;
     case "qna":
예제 #2
0
    if (!empty($dataset[1])) {
        $fieldid = str_replace("field_", "", $dataset[0]);
        $query = "SELECT * FROM livehelp_questions WHERE id=" . intval($fieldid);
        $questiondata = $mydatabase->query($query);
        $question_row = $questiondata->fetchRow(DB_FETCHMODE_ASSOC);
        print "<b> " . $question_row['headertext'] . ":</b> <br><font color=000000>" . urldecode($dataset[1]) . "</font><br>";
    }
}
$now = date("YmdHis");
$thediff = $now - $user_info['lastaction'];
print "<b>" . $lang['txt65'] . "</b> {$thediff} sec. <br>";
// time online:
$query = "SELECT whendone from livehelp_visit_track WHERE sessionid='" . filter_sql($user_info['sessionid']) . "' Order by whendone LIMIT 1";
$page_trail = $mydatabase->query($query);
$page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
$later = $page['whendone'];
print "<b>Time online:</b>" . secondstoHHmmss(timediff($later, date("YmdHis"))) . "<br>";
print "<b>" . $lang['txt66'] . "</b><br>";
$query = "SELECT * from livehelp_visit_track WHERE sessionid='" . filter_sql($user_info['sessionid']) . "' Order by whendone DESC";
$page_trail = $mydatabase->query($query);
print "<table border=1><tr bgcolor=FFFFFF><td>" . $lang['txt67'] . "</td><td>url</td><td>" . $lang['date'] . "</td></tr>";
while ($page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC)) {
    $when = mktime(substr($page['whendone'], 8, 2), substr($page['whendone'], 10, 2), substr($page['whendone'], 12, 2), substr($page['whendone'], 4, 2), substr($page['whendone'], 6, 2), substr($page['whendone'], 0, 4));
    print "<tr><td>" . $page['title'] . "</td><td><a href=" . $page['location'] . "  target=_blank>" . $page['location'] . "</a></td><td>";
    print date("F j, Y, g:i a", $when);
    print "</td></tr>";
}
print "</table><br><center><a href=javascript:window.close()>" . $lang['txt40'] . "</a>";
if (!$serversession) {
    $mydatabase->close_connect();
}
$OnlineStatus = "N";
$ChatCount = 0;
$UserInfo = "";
$TimeOnline = "";
$CurLocation = "";
while ($visitor = $visitors->fetchRow(DB_FETCHMODE_ASSOC)) {
    if ($visitor['isoperator'] == "N") {
        if ($visitor['status'] == "chat") {
            $ChatCount++;
        }
        $TrackQuery = "SELECT * FROM livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "'";
        $Tracks = $mydatabase->query($TrackQuery);
        while ($tracking = $Tracks->fetchRow(DB_FETCHMODE_ASSOC)) {
            $CurLocation = $tracking['location'];
            $later = $tracking['whendone'];
            $TimeOnline = secondstoHHmmss(timediff($later, date("YmdHis")));
        }
        $UserInfo = $visitor['user_id'] . "::" . $visitor['username'] . "::" . $visitor['ipaddress'] . "::" . $visitor['status'] . "::" . $visitor['camefrom'] . "::" . $TimeOnline . "::" . $CurLocation . ",," . $UserInfo;
    }
    if ($visitor['username'] == $_GET['username']) {
        $OnlineStatus = $visitor['isonline'];
        $MyUserID = $visitor['user_id'];
    }
}
// get the count of active visitors in the system right now.
$timeof = date("YmdHis");
$prev = mktime(date("H"), date("i") - 4, date("s"), date("m"), date("d"), date("Y"));
$oldtime = date("YmdHis", $prev);
$sqlquery = "SELECT * FROM livehelp_users WHERE lastaction>'{$oldtime}' AND isoperator!='Y' ";
// make list of ignored visitors:
$MyOwnIP = $_SERVER['REMOTE_ADDR'];
function gethtml()
{
    global $alertinsite, $alertchat, $insitewav, $soundwav, $hidechatters, $color_alt2, $color_alt4, $color_background, $numchatsnow, $UNTRUSTED, $CSLH_Config, $operators, $operators_array, $ignorelist_array, $ignorelist, $lang, $show_arrival, $mydatabase, $identity, $onload, $myid, $stuffatbottom, $user_alert;
    $onload = "";
    $DIVS = " ";
    $lasthtml = "";
    $timeof = rightnowtime();
    // update operators timestamp .
    $sql = "UPDATE livehelp_users set lastaction='{$timeof}' WHERE sessionid='" . $identity['SESSIONID'] . "' ";
    $mydatabase->query($sql);
    /// Current Chat Requests: -----------------------------------------------------------
    $html = "<table width=100% bgcolor=" . $color_alt2 . "><tr>";
    $html .= "<td width=20>&nbsp;</td>";
    $html .= "<td><b>" . $lang['txt230'] . "</b></td></tr></table>";
    $prev = mktime(date("H"), date("i") - 10, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' AND isoperator='N' ORDER by showedup";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    $html .= "<table width=100%>";
    $chatrequests = 0;
    while ($visitor = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
        $actionlink = "";
        $chatting = "";
        // see if we are in the same department as this user..
        $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
        $data_check = $mydatabase->query($sqlquery);
        if ($data_check->numrows() == 0) {
            // we are not in the department that this user is chatting in..
        } else {
            // see if anyone is chatting with this person.
            $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $visitor['onchannel'] . "'";
            $counting = $mydatabase->query($sqlquery);
            $showedup = substr($visitor['showedup'], 8, 2) . ":" . substr($visitor['showedup'], 10, 2);
            if ($counting->numrows() == 0) {
                $updated_ignore = $ignorelist . "," . $visitor['user_id'];
                $chatting = "<img src=images/needaction.gif width=21 height=20 border=0>";
                $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=activiate&who=" . $visitor['user_id'] . "&whatchannel=" . $visitor['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "&needaction=1>" . $lang['Activate'] . "</a>]\n";
                if ($UNTRUSTED['autoanswer'] == "Y") {
                    print "<script>window.location.replace('admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=activiate&who=" . $visitor['user_id'] . "&whatchannel=" . $visitor['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "&needaction=1');</script>";
                }
                if (!in_array($visitor['user_id'], $ignorelist_array)) {
                    $actionlink .= "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$updated_ignore}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&showvisitors=" . $UNTRUSTED['showvisitors'] . ">" . $lang['Ignore'] . "</a>]\n";
                    $onload = " setTimeout(\"tellme(0);\",500); ";
                    $chatrequests++;
                    if ($user_alert == "N" || $user_alert == "") {
                        $soundwav = " <embed src=\"sounds/" . $alertchat . "\" autostart=true loop=false width=1 height=1> ";
                        $stuffatbottom .= "\n<SCRIPT type=\"text/javascript\">top.status=\"[activate]\";top.status=\"\"; setTimeout(\"tellme(0);\",1500); </SCRIPT>\n";
                    }
                }
                if (!in_array($visitor['user_id'], $ignorelist_array)) {
                    $html .= "<tr><td width=10> {$showedup} </td><td nowrap=nowrap><table><tr><td>{$chatting}</td><td><a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>  {$actionlink} </td></tr></table></td></tr>\n";
                } else {
                    $html .= "<tr bgcolor=#DDDDDD><td width=10> {$showedup} </td><td nowrap=nowrap><table><tr><td>{$chatting}</td><td><a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "');} catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>  {$actionlink} </td></tr></table></td></tr>\n";
                }
                $chatrequests++;
                $sqlquery = "SELECT * from livehelp_users WHERE sessionid='" . $visitor['sessionid'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "' Order by whendone DESC LIMIT 1";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $visitor['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $DIVS .= "<DIV ID=\"info-" . $visitor['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n      <TABLE BORDER=\"0\" WIDTH=\"250\"><TR BGCOLOR=\"#000000\"><TD> \n      <TABLE BORDER=\"0\" WIDTH=\"248\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n      <FONT COLOR=\"#000000\">\n      <b>" . $lang['referer'] . ":</b><br>" . $user_info['camefrom'] . "<br>\n      <b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n      <b>Url:</b><br><a href=" . $page['location'] . "  target=_blank>" . $page['location'] . "</a><br>";
                $now = date("YmdHis");
                if ($user_info['lastaction'] == "" || $user_info['lastaction'] < 20002020202020) {
                    $user_info['lastaction'] = $now;
                }
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['txt65'] . ":</b><br>{$thediff} Seconds ago<br> \n       </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
            }
        }
    }
    if ($chatrequests == 0) {
        $html .= "<tr><td>" . $lang['txt231'] . "</td></tr>";
        if ($UNTRUSTED['autoanswer'] == "Y") {
            $html .= "<tr><td><i>Auto Answer:</i> <b>ON</b> (<a href=admin_users_refresh.php>Turn OFF</a>)</td></tr>";
            if (!empty($UNTRUSTED['notit'])) {
                $html .= "<tr bgcolor=FFFFCC><td><i> <b><font color=#990000>NOTE : </font></b> it is recommended you have <b>Typing Alert</b> set to ON so you can be alerted of chats while this is ON . After answering a chat you can turn it OFF.. </td></tr>";
                $query = "UPDATE livehelp_users set typing_alert='Y' WHERE sessionid='" . $identity['SESSIONID'] . "'";
                $mydatabase->query($query);
                print "<script type=\"text/javascript\"> window.parent.rooms.location='admin_rooms.php';</script>";
            }
        } else {
            // used for social panel:
            //	$html .= "<tr><td><i>Auto Answer:</i> <b>Off</b> (<a href=admin_users_refresh.php?autoanswer=Y&notit=2>Turn ON</a>)</td></tr>";
        }
    }
    $html .= "</table>";
    $html .= "<table width=100% bgcolor=" . $color_alt2 . "><tr>";
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' AND isoperator='N'";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    while ($visitor = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
        $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $visitor['onchannel'] . "'";
        $counting = $mydatabase->query($sqlquery);
        if ($counting->numrows() == 0 && !in_array($visitor['user_id'], $ignorelist_array)) {
            $UNTRUSTED['hidechatters'] = 0;
        }
    }
    if ($UNTRUSTED['hidechatters'] == 1) {
        $html .= "<td width=20><a href=admin_users_refresh.php?hidechatters=0&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&hidechatters=0 onclick=\"javascript:shouldireloadbot();\" ><img src=images/plus.gif border=0></a></td>";
    } else {
        $html .= "<td width=20><a href=admin_users_refresh.php?hidechatters=1&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&hidechatters=1 onclick=\"javascript:shouldireloadbot();\" ><img src=images/minus.gif border=0></a></td>";
    }
    $html .= "<td><b> " . $lang['chat_text'] . " </b></td></tr></table>";
    $prev = mktime(date("H"), date("i") - 4, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    // select out all of the operators that are online chatting:
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' ORDER by showedup";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    $chatboxes = 0;
    $OPhiddennow = 0;
    $OPonlinenow = 0;
    $html .= "<table width=100% cellpadding=0 cellspacing=0 border=0>";
    if ($UNTRUSTED['hidechatters'] != 1) {
        $html .= "<tr><td colspan=4 NOWRAP=NOWRAP align=right><b><font color=007700>[OPonlinenow] " . $lang['online'] . "</font> <font color=777777>[OPhiddennow] " . $lang['Hidden'] . "</font></b></td></tr>";
        if ($chatcheck->numrows() == 0) {
            $html .= "<tr><td>" . $lang['no_chat'] . "</td></tr>";
        }
        //--List of Chatting users by Operator----------------------------------------------------------------------
        $sqlquery = "SELECT * FROM livehelp_users WHERE isonline='Y' and isoperator='Y' ORDER by username";
        $chatcheck = $mydatabase->query($sqlquery);
        while ($operatorsarray = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
            $actionlink = "";
            $chatting = "";
            $operatorhtml = "";
            $operatorlasthtml = "";
            $htmlgray = "";
            $lasthtmlgray = "";
            $showgray = 0;
            // Operators can be on multiple channels so see if one of the channels they are on is one we are on.
            $foundcommonchannel = 0;
            $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='" . $operatorsarray['user_id'] . "'";
            $mychannels = $mydatabase->query($sqlquery);
            while ($rowof = $mychannels->fetchRow(DB_FETCHMODE_ASSOC)) {
                $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='{$myid}' And channel='" . $rowof['channel'] . "'";
                $counting = $mydatabase->query($sqlquery);
                if ($counting->numrows() != 0) {
                    $foundcommonchannel = $rowof['channel'];
                }
            }
            // Operators can be on multiple departements so see if this operator is on our department:
            $foundcommondepartment = 0;
            $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='" . $operatorsarray['user_id'] . "'";
            $mychannels = $mydatabase->query($sqlquery);
            while ($rowof = $mychannels->fetchRow(DB_FETCHMODE_ASSOC)) {
                $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' And department='" . $rowof['department'] . "'";
                $counting = $mydatabase->query($sqlquery);
                if ($counting->numrows() != 0) {
                    $foundcommondepartment = 1;
                }
            }
            // update the action links acccording to if we are on the same channel or not..
            if ($foundcommonchannel == 0) {
                $chatting = "<img src=images/noton.gif width=19 height=18 border=0>";
                if ($myid != $operatorsarray['user_id']) {
                    $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&numchats={$numchatsnow}&operators={$operators}&action=activiate&who=" . $operatorsarray['user_id'] . "&whatchannel=" . $operatorsarray['onchannel'] . "&conferencein=yes&showvisitors=" . $UNTRUSTED['showvisitors'] . "><font color=007700>" . $lang['begin'] . "</font></a>]\n";
                } else {
                    $actionlink = "";
                    $chatting = "<img src=images/active.gif width=19 height=18 border=0>\n";
                }
            } else {
                $chatting = "<table cellpadding=0 cellspacing=0 border=0 bgcolor=" . $rowof['txtcolor_alt'] . "><tr><td><img src=images/active.gif width=19 height=18 border=0></td></tr></table>\n";
                if ($operatorsarray['user_id'] != $myid) {
                    $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=leave&who=" . $operatorsarray['user_id'] . "&whatchannel={$foundcommonchannel}&clearchannel=N&showvisitors=" . $UNTRUSTED['showvisitors'] . ">" . $lang['stop_chat'] . "</a>]\n";
                }
            }
            // if we are in the same department as this operator show them.. if not show them in gray if and only if
            // we have a chatter in common...
            if ($foundcommondepartment) {
                $OPonlinenow++;
                if ($myid != $operatorsarray['user_id']) {
                    $operatorhtml .= "<tr><td width=21><img src=images/operator.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
                } else {
                    $operatorlasthtml .= "<tr><td width=21><img src=images/operator.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
                }
            } else {
                $OPhiddennow++;
                if ($myid != $operatorsarray['user_id']) {
                    $htmlgray .= "<tr><td width=21><img src=images/operator_gray.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
                } else {
                    $lasthtmlgray .= "<tr><td width=21><img src=images/operator_gray.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
                }
            }
            // show all of this operators chats:
            $q = "SELECT livehelp_users.* FROM livehelp_users,livehelp_operator_channels WHERE livehelp_users.user_id=livehelp_operator_channels.userid AND livehelp_users.status='chat' AND livehelp_operator_channels.user_id=" . $operatorsarray['user_id'] . " ORDER by showedup";
            $sth = $mydatabase->query($q);
            $showgray = 0;
            while ($chatters = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
                $inthedepartment = 1;
                $ischattingwith = 0;
                // see if we are in the same department as this user..
                $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $chatters['department'] . "' ";
                $data_check = $mydatabase->query($sqlquery);
                if ($data_check->numrows() == 0) {
                    // we are not in the department that this user is chatting in..
                    $OPhiddennow++;
                    $inthedepartment = 0;
                }
                // see if we are chatting with them
                $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='{$myid}' And channel='" . $chatters['onchannel'] . "'";
                $counting = $mydatabase->query($sqlquery);
                $checkbox = "";
                $actionlinkouter = "";
                if ($counting->numrows() == 0) {
                    $chatting = "<img src=images/noton.gif width=19 height=18 border=0>";
                    $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=activiate&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "&conferencein=yes><font color=007700>Join Chat</font></a>]\n";
                    $actionlinkouter = $actionlink;
                } else {
                    $ischattingwith = 1;
                    $chatboxes++;
                    $rowof = $counting->fetchRow(DB_FETCHMODE_ASSOC);
                    $chatting = "<table cellpadding=0 cellspacing=0 border=0 bgcolor=" . $rowof['channelcolor'] . "><tr><td><img src=images/active.gif width=19 height=18 border=0></td></tr></table>\n";
                    $showgray = 1;
                    $actionlink = "";
                    $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $chatters['onchannel'] . "'";
                    $counting = $mydatabase->query($sqlquery);
                    if ($counting->numrows() > 1) {
                        $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=leave&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . ">Un-Conference</a>]\n ";
                    }
                    $checkbox = "<input type=checkbox name=session__" . $chatters['user_id'] . " value=" . $chatters['sessionid'] . " border=0>";
                    $actionlink .= "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators={$operators}&action=stop&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "><font color=990000>" . $lang['stop'] . "</font></a>]\n";
                }
                // see if anyone is chatting with this person.
                $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $chatters['onchannel'] . "'";
                $counting = $mydatabase->query($sqlquery);
                if ($counting->numrows() == 0 && !in_array($chatters['user_id'], $ignorelist_array)) {
                    // no one is chatting with this person..... they are listed in requested chats...
                } else {
                    $intheuserdepartment = 0;
                    $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' And department='" . $chatters['department'] . "'";
                    $counting = $mydatabase->query($sqlquery);
                    if ($counting->numrows() != 0) {
                        $intheuserdepartment = 1;
                    }
                    $OPonlinenow++;
                    if ($myid != $operatorsarray['user_id']) {
                        if (!($intheuserdepartment == 0 && preg_match("/noton/", $chatting))) {
                            $operatorhtml .= "<tr bgcolor=#EFEFEF><td> &nbsp;</td><td><img src=images/blank.gif width=5 height=5 border=0></td><td nowrap=nowrap>{$chatting}</td><td width=90% align=left><a href=javascript:seepages(" . $chatters['user_id'] . ") onMouseOver=\" try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $chatters['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $chatters['username'] . "');} catch(dam){} return true;\">" . $chatters['username'] . "</a>  {$actionlinkouter} </td></tr>\n";
                        }
                    } else {
                        if (!($intheuserdepartment == 0 && preg_match("/noton/", $chatting))) {
                            $operatorlasthtml .= "<tr bgcolor=#EFEFEF><td> &nbsp;</td><td>{$checkbox}</td><td nowrap=nowrap>{$chatting}</td><td width=90% align=left><a href=javascript:seepages(" . $chatters['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $chatters['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $chatters['username'] . "'); } catch(dam){} return true;\">" . $chatters['username'] . "</a>  {$actionlink} </td></tr>\n";
                        }
                    }
                }
                $sqlquery = "SELECT * from livehelp_users WHERE sessionid='" . $chatters['sessionid'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $chatters['sessionid'] . "' Order by whendone DESC LIMIT 1";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $chatters['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $DIVS .= "<DIV ID=\"info-" . $chatters['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n<TABLE BORDER=\"0\" WIDTH=\"250\"><TR BGCOLOR=\"#000000\"><TD> \n<TABLE BORDER=\"0\" WIDTH=\"248\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n<FONT COLOR=\"#000000\">\n<b>" . $lang['referer'] . ":</b><br>" . $user_info['camefrom'] . "<br>\n<b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n<b>Url:</b><br><a href=" . $page['location'] . "  target=_blank>" . $page['location'] . "</a><br>";
                $now = date("YmdHis");
                if ($user_info['lastaction'] == "" || $user_info['lastaction'] < 20002020202020) {
                    $user_info['lastaction'] = $now;
                }
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['txt65'] . ":</b><br>{$thediff} " . $lang['Seconds'] . "<br>\n </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
            }
            if (preg_match("/active/", $operatorhtml)) {
                $html .= $htmlgray;
                $lasthtml .= $lasthtmlgray;
            }
            $html .= $operatorhtml;
            $lasthtml .= $operatorlasthtml;
        }
    }
    $html = str_replace("[OPonlinenow]", $OPonlinenow, $html);
    $html = str_replace("[OPhiddennow]", $OPhiddennow, $html);
    $html .= $lasthtml . "</table>";
    $html .= "<DIV ID=\"chattersdiv\" STYLE=\"z-index: 2;\">";
    if ($UNTRUSTED['hidechatters'] != 1 && $chatboxes > 0) {
        $html .= "<table cellpadding=0 cellspacing=0 border=0>";
        $html .= "<tr><td><img src=images/blank.gif width=18 height=22 border=0></td><td align=left><img src=images/arrow_ltr.gif width=38 height=22><select name=whattodochat onchange=updatepeople(1)>";
        $html .= "<option value=\"\">" . $lang['txt207'] . ":</option>";
        $html .= "<option value=stop>" . $lang['stop_chat'] . "</option>";
        $html .= "<option value=transfer>" . $lang['transfer_chat'] . "</option>";
        $html .= "<option value=conference>" . $lang['conference_chats'] . "</option>";
        $html .= "</select> <a href=javascript:updatepeople(1)><img src=images/go.gif border=0 width=20 height=20></a></td></tr>";
        $html .= "</table>";
    }
    $html .= "</DIV>";
    ///--------------------------------------------------------------------------------------------------
    // get the count of active visitors in the system right now.
    $timeof = rightnowtime();
    $prev = mktime(date("H"), date("i") - 4, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    $sqlquery = "SELECT * FROM livehelp_users WHERE lastaction>'{$oldtime}' AND status!='chat' AND isoperator!='Y' ";
    // make list of ignored visitors:
    $ipadd = explode(",", $CSLH_Config['ignoreips']);
    for ($i = 0; $i < count($ipadd); $i++) {
        if (!empty($ipadd[$i])) {
            $sqlquery .= " AND ipaddress NOT LIKE '" . $ipadd[$i] . "%' ";
        }
    }
    $sqlquery .= " ORDER by lastaction DESC";
    $visitors = $mydatabase->query($sqlquery);
    $onlinenow = $visitors->numrows();
    $hiddennow = 0;
    $html .= "<SCRIPT type=\"text/javascript\">\n \n   function stopajax(){\n      //document.admin_actions.togglerefresh.SelectedIndex=2;\n     // alert(1);\n      //document.admin_actions.submit();\n   }\n   </SCRIPT>";
    $html .= "<table width=100% cellpadding=0 cellspacing=0 bgcolor=" . $color_alt2 . "><tr><td>";
    if ($UNTRUSTED['showvisitors'] != 3) {
        if ($UNTRUSTED['showvisitors'] == 1) {
            $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=2  onclick=\"javascript:shouldireloadbot();\" ><img src=images/minus.gif border=0></a>";
        } else {
            if ($CSLH_Config['admin_refresh'] == "auto") {
                $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=3&togglerefresh=AJAX  onclick=\"javascript:shouldireloadbot();\" ><img src=images/plus.gif border=0></a>AJAX&nbsp;";
                $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1  onclick=\"javascript:shouldireloadbot();\" ><img src=images/plus.gif border=0></a>AUTO";
            } else {
                $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1  onclick=\"javascript:shouldireloadbot();\" ><img src=images/plus.gif border=0></a>";
            }
        }
    } else {
        $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=2&togglerefresh=auto  onclick=\"javascript:shouldireloadbot();\" ><img src=images/minus.gif border=0></a>";
    }
    if ($UNTRUSTED['showvisitors'] == 1) {
        $html .= "</td><td><b>" . $lang['visit'] . "</b></td></tr></table>";
        $html .= "<table width=100%><tr><td align=right><b><font color=007700>[onlinenow] " . $lang['online'] . "</font> <font color=777777>[hiddennow] " . $lang['Hidden'] . "</font></b></td></tr></table>";
        $html .= "<table width=100%><tr bgcolor={$color_background}><td>&nbsp;</td><td><b>ID</b></td><td><b>" . $lang['status'] . ":</b></td><td><b>pg#</b></td>";
        if ($CSLH_Config['maxrequests'] < 9999) {
            $html .= "<td>rq#</td>";
        }
        $html .= "</tr>";
        $insitewav = "";
        while ($visitor = $visitors->fetchRow(DB_FETCHMODE_ASSOC)) {
            $chatting = "";
            // see if we are in the same department as this user..
            $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
            $data_check = $mydatabase->query($sqlquery);
            if ($visitor['department'] != 0 && $data_check->numrows() == 0) {
                $hiddennow++;
                $onlinenow--;
            } else {
                if (empty($visitor['user_alert'])) {
                    $visitor['user_alert'] = 0;
                }
                if ($visitor['isoperator'] != "Y" && $visitor['user_alert'] != 1) {
                    $onload = " setTimeout(\"doorbell();\",700); ";
                    if ($user_alert == "N" || $user_alert == "") {
                        if ($show_arrival != "N") {
                            $insitewav = " <EMBED SRC=sounds/" . $alertinsite . " AUTOSTART=TRUE width=1 height=1  LOOP=FALSE> \n";
                        }
                    }
                    $sql = "UPDATE livehelp_users SET user_alert='1' WHERE user_id='" . $visitor['user_id'] . "' ";
                    $mydatabase->query($sql);
                }
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "'";
                $my_count = $mydatabase->query($sqlquery);
                $my_count = $my_count->numrows();
                $html .= "<tr><td width=10><input type=checkbox name=session__" . $visitor['user_id'] . " value=" . $visitor['sessionid'] . " border=0></td><td>";
                $html .= "<a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\" try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>";
                $sqlquery = "SELECT * from livehelp_users WHERE user_id='" . $visitor['user_id'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "' Order by whendone DESC";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $visitor['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $query = "SELECT whendone from livehelp_visit_track WHERE sessionid='" . filter_sql($visitor['sessionid']) . "' Order by whendone LIMIT 1";
                $page_tmprow = $mydatabase->query($query);
                $tmprow = $page_tmprow->fetchRow(DB_FETCHMODE_ASSOC);
                $later = $tmprow['whendone'];
                $DIVS .= "<DIV ID=\"info-" . $visitor['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n<TABLE BORDER=\"0\" WIDTH=\"300\"><TR BGCOLOR=\"#000000\"><TD> \n<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n<FONT COLOR=\"#000000\">\n<b>Referer:</b><br>" . $user_info['camefrom'] . "<br>";
                if (empty($page['location'])) {
                    $page['location'] = "";
                }
                $DIVS .= "<b>" . $lang['timeonline'] . ":</b>" . secondstoHHmmss(timediff($later, date("YmdHis"))) . "<br> \n<b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n<b>url:</b><br>" . $page['location'] . "<br>";
                $now = date("YmdHis");
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['lastact'] . ":</b><br>{$thediff} " . $lang['Seconds'] . "<br>\n </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
                $html .= "</td>";
                switch ($visitor['status']) {
                    case "DHTML":
                        $html .= "<td>L:<img src=images/invited.gif> ";
                        break;
                    case "request":
                        $html .= "<td>P:<img src=images/invited.gif> ";
                        break;
                    case "invited":
                        $html .= "<td><img src=images/invited2.gif>  ";
                        break;
                    case "qna":
                        $html .= "<td><img src=images/qna.gif>";
                        break;
                    case "stopped":
                        $html .= "<td><img src=images/stopped.gif> {<a href=layer.php?selectedwho=" . $visitor['user_id'] . " target=_blank>RE-" . $lang['invite'] . "</a>}";
                        break;
                    case "message":
                        $html .= "<td><img src=images/message.gif> ";
                        break;
                    default:
                        $html .= "<td><a href=layer.php?selectedwho=" . $visitor['user_id'] . " target=_blank>" . $lang['invite'] . "</a> ";
                        break;
                }
                $html .= "</td>";
                $html .= "<td>{$my_count}</td>";
                if ($CSLH_Config['maxrequests'] < 9999) {
                    if ($user_info['visits'] > $CSLH_Config['maxrequests'] - 16) {
                        if ($user_info['visits'] < $CSLH_Config['maxrequests']) {
                            $html .= "<td><font color=#770000>" . $user_info['visits'] . "</font><br><a href=javascript:resetpages(" . $visitor['user_id'] . ")>reset</a></td>";
                        } else {
                            $html .= "<td><font color=#CC0000><b>" . $user_info['visits'] . "</b></font><br><a href=javascript:resetpages(" . $visitor['user_id'] . ")>reset</a></td>";
                        }
                    } else {
                        $html .= "<td>" . $user_info['visits'] . "</td>";
                    }
                }
                $html .= "</tr>";
            }
        }
        $html = str_replace("[onlinenow]", $onlinenow, $html);
        $html = str_replace("[hiddennow]", $hiddennow, $html);
        $html .= "</table>";
        $html .= "<DIV ID=\"visitorsdiv\" STYLE=\"z-index: 2;\">";
        if ($onlinenow > 0) {
            $html .= "<table>";
            $html .= "<tr><td><img src=images/arrow_ltr.gif width=38 height=22><select name=whattodo onchange=updatepeople(2)>";
            $html .= "<option value=\"\">" . $lang['txt207'] . ":</option>";
            $html .= "<option value=DHTML>" . $lang['Invite'] . ":" . $lang['layer'] . "</option>";
            $html .= "<option value=pop>" . $lang['Invite'] . ":" . $lang['popup'] . "</option>";
            $html .= "<option value=insite>" . $lang['Invite'] . ":" . insite . "</option>";
            $html .= "</select> <a href=javascript:updatepeople(2)><img src=images/go.gif border=0 width=20 height=20></a></td></tr>";
            $html .= "</table><center><a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=2>" . $lang['txt208'] . "</a><br></center>";
        }
        $html .= "</DIV>";
    } else {
        while ($visitor = $visitors->fetchRow(DB_FETCHMODE_ASSOC)) {
            $chatting = "";
            // see if we are in the same department as this user..
            $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
            $data_check = $mydatabase->query($sqlquery);
            if ($visitor['department'] != 0 && $data_check->numrows() == 0) {
                $hiddennow++;
                $onlinenow--;
            }
        }
        if ($UNTRUSTED['showvisitors'] == 2) {
            $html .= "</td><td><b>" . $lang['visit'];
            if ($CSLH_Config['admin_refresh'] == "auto") {
                $html .= "<br>";
            }
            $html .= " <font color=007700>{$onlinenow} " . $lang['online'] . "</font> <font color=777777>{$hiddennow} " . $lang['Hidden'] . "</font> </b></td></tr></table>";
            if ($CSLH_Config['admin_refresh'] == "auto") {
                $html .= "<table width=100%><tr bgcolor={$color_background}><td colspan=4 align=center><font color=#990000><i>" . $lang['Hidden'] . "</i></a></font><br>To monitor visitors click either:";
                $html .= " { <a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=3&togglerefresh=AJAX onclick=\"javascript:shouldireloadbot();\"> AJAX </a> | ";
                $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1 onclick=\"javascript:shouldireloadbot();\"> AUTO</a> }";
            } else {
                $html .= "<table width=100%><tr bgcolor={$color_background}><td colspan=4 align=center><font color=#990000><i>" . $lang['Hidden'] . "</i></a></font><br><a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&autoanswer=" . $UNTRUSTED['autoanswer'] . "&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1 onclick=\"javascript:shouldireloadbot();\">" . $lang['txt209'] . "</a>";
            }
            $html .= "</td></tr></table>";
        } else {
            $html .= "</td><td><b>" . $lang['visit'] . "</b></td></tr></table>";
            $html .= "<DIV  id=\"visitorschatdiv\"> ...... Loading ..... </DIV>";
        }
    }
    $html = $html . $DIVS;
    return $html;
}
?>
</b></td></tr>
<?php 
$query = "SELECT * FROM livehelp_transcripts  WHERE  endtime>{$whatYm_b} AND endtime<{$whatYm_e} {$whichdepartmentsql} {$keywordssql} order by endtime DESC LIMIT " . intval($UNTRUSTED['offset']) . "," . intval($perpage);
$data = $mydatabase->query($query);
$bgcolor = "{$color_alt2}";
while ($row = $data->fetchRow(DB_FETCHMODE_ASSOC)) {
    if ($bgcolor == "{$color_alt2}") {
        $bgcolor = "{$color_alt1}";
    } else {
        $bgcolor = "{$color_alt2}";
    }
    print "<tr bgcolor={$bgcolor}><td>";
    print substr($row['endtime'], 4, 2) . "-" . substr($row['endtime'], 6, 2) . "-" . substr($row['endtime'], 0, 4) . " (" . substr($row['endtime'], 8, 2) . ":" . substr($row['endtime'], 10, 2) . ":" . substr($row['endtime'], 12, 2) . ")";
    print "</td>";
    $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $row['department'] . "'";
    $tmp = $mydatabase->query($sqlquery);
    $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
    $nameof = $nameof['nameof'];
    print "<td>{$nameof}</td>";
    print "<td>" . listoperators($row['operators']) . "</td>";
    print "<td>" . $row['who'] . "</td>";
    print "<td NOWRAP=NOWRAP>" . secondstoHHmmss($row['duration']) . "</td>";
    print "<td><a href=mailto:\"" . $row['email'] . "\">" . $row['email'] . "</td><td> <a href=view_transcript.php?view=" . $row['recno'] . " target=_blank>VIEW</a> ";
    if ($isadminsetting == "Y") {
        print " <a href=data.php?tab=" . $UNTRUSTED['tab'] . "&top=" . $UNTRUSTED['top'] . "&remove=" . $row['recno'] . " onClick=\"return confirm('" . $lang['areyousure'] . "')\"><font color=990000>" . $lang['REMOVE'] . "</font></a> ";
    }
    print "</td></tr>";
}
?>
</table>
        print "<td><a href=data.php?tab=" . $UNTRUSTED['tab'] . "&month=" . $UNTRUSTED['month'] . "&year=" . $UNTRUSTED['year'] . "&typeofview=" . $UNTRUSTED['typeofview'] . "&show=" . $UNTRUSTED['show'] . "&expand={$contract}&offset=" . $UNTRUSTED['offset'] . "><img src=images/minus.gif border=0></a></td>";
    } else {
        print "<td><a href=data.php?tab=" . $UNTRUSTED['tab'] . "&month=" . $UNTRUSTED['month'] . "&year=" . $UNTRUSTED['year'] . "&typeofview=" . $UNTRUSTED['typeofview'] . "&show=" . $UNTRUSTED['show'] . "&expand=" . $UNTRUSTED['expand'] . "," . $id . "&offset=" . $UNTRUSTED['offset'] . "><img src=images/plus.gif border=0></a></td>";
    }
    print "<td>" . substr($dateof, 4, 2) . "-" . substr($dateof, 0, 4) . "</td><td>" . $username . "</a></td><td>" . $ipaddress . "</td><td>" . $uservisits . "</td><td>" . secondstoHHmmss($seconds) . "</td>";
    print "</tr>";
    // look for daily records:
    if (in_array($id, $expand_array)) {
        if ($UNTRUSTED['typeofview'] == "groupusername") {
            $query = "SELECT * FROM livehelp_identity_daily WHERE username='******' AND dateof>" . intval($whatYm) . "00 AND dateof<" . intval($whatYm) . "32  ORDER by dateof DESC";
        } else {
            $query = "SELECT * FROM livehelp_identity_daily WHERE identity='" . $identity . "' AND username='******' AND dateof>" . intval($whatYm) . "00 AND dateof<" . intval($whatYm) . "32 ORDER by dateof DESC";
        }
        $inner_sth = $mydatabase->query($query);
        while ($innerrow = $inner_sth->fetchRow(DB_FETCHMODE_ASSOC)) {
            if ($bgcolor == "F7FAFF") {
                $bgcolor = "F0F1E1";
            } else {
                $bgcolor = "F7FAFF";
            }
            print "<tr bgcolor=" . $bgcolor . "><td>&nbsp;</td><td>" . substr($innerrow['dateof'], 4, 2) . "-" . substr($innerrow['dateof'], 6, 2) . "-" . substr($innerrow['dateof'], 0, 4) . "</td><td>" . $innerrow['username'] . "</a></td><td>" . $innerrow['ipaddress'] . "</td><td>" . $innerrow['uservisits'] . "</td><td>" . secondstoHHmmss($innerrow['seconds']) . "</td></tr>";
        }
    }
}
print "</table>";
?>
<table width=600><tr><td><?php 
echo $lang['txt216'];
?>
</td></tr></table>
  
function gethtml()
{
    global $alertchat, $insitewav, $soundwav, $hidechatters, $color_alt2, $color_alt4, $color_background, $numchatsnow, $UNTRUSTED, $CSLH_Config, $operators, $operators_array, $ignorelist_array, $ignorelist, $lang, $show_arrival, $mydatabase, $identity, $onload, $myid, $stuffatbottom, $user_alert;
    $onload = "";
    $DIVS = " ";
    $lasthtml = "";
    $timeof = rightnowtime();
    // update operators timestamp .
    $sql = "UPDATE livehelp_users set lastaction='{$timeof}' WHERE sessionid='" . $identity['SESSIONID'] . "' ";
    $mydatabase->query($sql);
    /// Current Chat Requests: -----------------------------------------------------------
    $html = "<table width=100% bgcolor=" . $color_alt2 . "><tr>";
    $html .= "<td width=20>&nbsp;</td>";
    $html .= "<td><b>" . $lang['txt230'] . "</b></td></tr></table>";
    $prev = mktime(date("H"), date("i") - 10, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' AND isoperator='N' ORDER by showedup";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    $html .= "<table width=100%>";
    $chatrequests = 0;
    while ($visitor = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
        $actionlink = "";
        $chatting = "";
        // see if we are in the same department as this user..
        $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
        $data_check = $mydatabase->query($sqlquery);
        if ($data_check->numrows() == 0) {
            // we are not in the department that this user is chatting in..
        } else {
            // see if anyone is chatting with this person.
            $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $visitor['onchannel'] . "'";
            $counting = $mydatabase->query($sqlquery);
            $showedup = substr($visitor['showedup'], 8, 2) . ":" . substr($visitor['showedup'], 10, 2);
            if ($counting->numrows() == 0) {
                $updated_ignore = $ignorelist . "," . $visitor['user_id'];
                $chatting = "<img src=images/needaction.gif width=21 height=20 border=0>";
                $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=activiate&who=" . $visitor['user_id'] . "&whatchannel=" . $visitor['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "&needaction=1>" . $lang['Activate'] . "</a>]\n";
                if (!in_array($visitor['user_id'], $ignorelist_array)) {
                    $actionlink .= "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$updated_ignore}&numchats={$numchatsnow}&operators={$operators}&showvisitors=" . $UNTRUSTED['showvisitors'] . ">" . $lang['Ignore'] . "</a>]\n";
                    $onload = " setTimeout(\"tellme(0);\",500); ";
                    $chatrequests++;
                    if ($user_alert == "N" || $user_alert == "") {
                        $soundwav = "<SCRIPT  type=\"text/javascript\">\n";
                        $soundwav .= "var MSIE=navigator.userAgent.indexOf(\"MSIE\");\n";
                        $soundwav .= "var NETS=navigator.userAgent.indexOf(\"Netscape\");\n";
                        $soundwav .= "var OPER=navigator.userAgent.indexOf(\"Opera\");\n";
                        $soundwav .= "if((MSIE>-1) || (OPER>-1)) {\n";
                        $soundwav .= "document.write(\"<BGSOUND SRC=sounds/{$alertchat} LOOP=1>\");\n";
                        $soundwav .= "} else {\n";
                        $soundwav .= "document.write(\"<EMBED SRC=sounds/{$alertchat} AUTOSTART=TRUE HIDDEN=true VOLUME=100 LOOP=FALSE><noembed><BGSOUND SRC={$alertchat} LOOP=1></noembed>\");\n";
                        $soundwav .= "}\n";
                        $soundwav .= "</SCRIPT>\n";
                        $stuffatbottom .= "\n<SCRIPT type=\"text/javascript\">top.status=\"[activate]\";top.status=\"\"; setTimeout(\"tellme(0);\",1500); </SCRIPT>\n";
                    }
                }
                if (!in_array($visitor['user_id'], $ignorelist_array)) {
                    $html .= "<tr><td width=10> {$showedup} </td><td nowrap=nowrap><table><tr><td>{$chatting}</td><td><a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>  {$actionlink} </td></tr></table></td></tr>\n";
                } else {
                    $html .= "<tr bgcolor=#DDDDDD><td width=10> {$showedup} </td><td nowrap=nowrap><table><tr><td>{$chatting}</td><td><a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "');} catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>  {$actionlink} </td></tr></table></td></tr>\n";
                }
                $chatrequests++;
                $sqlquery = "SELECT * from livehelp_users WHERE sessionid='" . $visitor['sessionid'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "' Order by whendone DESC LIMIT 1";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $visitor['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $DIVS .= "<DIV ID=\"info-" . $visitor['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n      <TABLE BORDER=\"0\" WIDTH=\"250\"><TR BGCOLOR=\"#000000\"><TD> \n      <TABLE BORDER=\"0\" WIDTH=\"248\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n      <FONT COLOR=\"#000000\">\n      <b>" . $lang['referer'] . ":</b><br>" . $user_info['camefrom'] . "<br>\n      <b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n      <b>Url:</b><br><a href=" . $page['location'] . "  target=_blank>" . $page['location'] . "</a><br>";
                $now = date("YmdHis");
                if ($user_info['lastaction'] == "" || $user_info['lastaction'] < 20002020202020) {
                    $user_info['lastaction'] = $now;
                }
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['txt65'] . ":</b><br>{$thediff} Seconds ago<br> \n       </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
            }
        }
    }
    if ($chatrequests == 0) {
        $html .= "<tr><td>" . $lang['txt231'] . "</td></tr>";
    }
    $html .= "</table>";
    //------------------------------------------------------------------------
    $html .= "<table width=100% bgcolor=" . $color_alt2 . "><tr>";
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' AND isoperator='N'";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    while ($visitor = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
        $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $visitor['onchannel'] . "'";
        $counting = $mydatabase->query($sqlquery);
        if ($counting->numrows() == 0 && !in_array($visitor['user_id'], $ignorelist_array)) {
            $UNTRUSTED['hidechatters'] = 0;
        }
    }
    if ($UNTRUSTED['hidechatters'] == 1) {
        $html .= "<td width=20><a href=admin_users_refresh.php?hidechatters=0&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&hidechatters=0><img src=images/plus.gif border=0></a></td>";
    } else {
        $html .= "<td width=20><a href=admin_users_refresh.php?hidechatters=1&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&hidechatters=1><img src=images/minus.gif border=0></a></td>";
    }
    $html .= "<td><b> " . $lang['chat_text'] . " </b></td></tr></table>";
    $prev = mktime(date("H"), date("i") - 4, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    // select out all of the operators that are online chatting:
    $sqlquery = "SELECT * FROM livehelp_users WHERE status='chat' ORDER by showedup";
    $chatcheck = $mydatabase->query($sqlquery);
    $numchatnow = $chatcheck->numrows();
    $chatboxes = 0;
    $html .= "<table width=100% cellpadding=0 cellspacing=0 border=0>";
    if ($UNTRUSTED['hidechatters'] != 1) {
        if ($chatcheck->numrows() == 0) {
            $html .= "<tr><td>" . $lang['no_chat'] . "</td></tr>";
        }
        $sqlquery = "SELECT * FROM livehelp_users WHERE isonline='Y' and isoperator='Y' ORDER by username";
        $chatcheck = $mydatabase->query($sqlquery);
        while ($operatorsarray = $chatcheck->fetchRow(DB_FETCHMODE_ASSOC)) {
            $actionlink = "";
            $chatting = "";
            // Operators can be on multiple channels so see if one of the channels they are on is one we are on.
            $foundcommonchannel = 0;
            $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='" . $operatorsarray['user_id'] . "'";
            $mychannels = $mydatabase->query($sqlquery);
            while ($rowof = $mychannels->fetchRow(DB_FETCHMODE_ASSOC)) {
                $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='{$myid}' And channel='" . $rowof['channel'] . "'";
                $counting = $mydatabase->query($sqlquery);
                if ($counting->numrows() != 0) {
                    $foundcommonchannel = $rowof['channel'];
                }
            }
            if ($foundcommonchannel == 0) {
                $chatting = "<img src=images/noton.gif width=19 height=18 border=0>";
                if ($myid != $operatorsarray['user_id']) {
                    $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=activiate&who=" . $operatorsarray['user_id'] . "&whatchannel=" . $operatorsarray['onchannel'] . "&conferencein=yes&showvisitors=" . $UNTRUSTED['showvisitors'] . "><font color=007700>" . $lang['begin'] . "</font></a>]\n";
                } else {
                    $actionlink = "";
                    $chatting = "<img src=images/active.gif width=19 height=18 border=0>\n";
                }
            } else {
                $chatting = "<table cellpadding=0 cellspacing=0 border=0 bgcolor=" . $rowof['txtcolor_alt'] . "><tr><td><img src=images/active.gif width=19 height=18 border=0></td></tr></table>\n";
                if ($operatorsarray['user_id'] != $myid) {
                    $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=leave&who=" . $operatorsarray['user_id'] . "&whatchannel={$foundcommonchannel}&clearchannel=N&showvisitors=" . $UNTRUSTED['showvisitors'] . ">" . $lang['stop_chat'] . "</a>]\n";
                }
            }
            if ($myid != $operatorsarray['user_id']) {
                $html .= "<tr><td width=21><img src=images/operator.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
            } else {
                $lasthtml = "<tr><td width=21><img src=images/operator.gif width=21 height=20 border=0></td><td colspan=3><table><tr><td>{$chatting}</td><td width=90% align=left>  <b>" . $operatorsarray['username'] . "</b>  {$actionlink} </td></tr></table></td></tr>\n";
            }
            // show all the operators chats:
            $q = "SELECT livehelp_users.* FROM livehelp_users,livehelp_operator_channels WHERE livehelp_users.user_id=livehelp_operator_channels.userid AND livehelp_users.status='chat' AND livehelp_operator_channels.user_id=" . $operatorsarray['user_id'] . " ORDER by showedup";
            $sth = $mydatabase->query($q);
            while ($chatters = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
                // see if we are in the same department as this user..
                $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $chatters['department'] . "' ";
                $data_check = $mydatabase->query($sqlquery);
                if ($data_check->numrows() == 0) {
                    // we are not in the department that this user is chatting in..
                } else {
                    // see if we are chatting with them
                    $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE user_id='{$myid}' And channel='" . $chatters['onchannel'] . "'";
                    $counting = $mydatabase->query($sqlquery);
                    $checkbox = "";
                    $actionlinkouter = "";
                    if ($counting->numrows() == 0) {
                        $chatting = "<img src=images/noton.gif width=19 height=18 border=0>";
                        $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=activiate&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "&conferencein=yes><font color=007700>Join Chat</font></a>]\n";
                        $actionlinkouter = $actionlink;
                    } else {
                        $chatboxes++;
                        $rowof = $counting->fetchRow(DB_FETCHMODE_ASSOC);
                        $chatting = "<table cellpadding=0 cellspacing=0 border=0 bgcolor=" . $rowof['channelcolor'] . "><tr><td><img src=images/active.gif width=19 height=18 border=0></td></tr></table>\n";
                        $actionlink = "";
                        $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $chatters['onchannel'] . "'";
                        $counting = $mydatabase->query($sqlquery);
                        if ($counting->numrows() > 1) {
                            $actionlink = "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=leave&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . ">Un-Conference</a>]\n ";
                        }
                        $checkbox = "<input type=checkbox name=session__" . $chatters['user_id'] . " value=" . $chatters['sessionid'] . " border=0>";
                        $actionlink .= "[<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators={$operators}&action=stop&who=" . $chatters['user_id'] . "&whatchannel=" . $chatters['onchannel'] . "&showvisitors=" . $UNTRUSTED['showvisitors'] . "><font color=990000>" . $lang['stop'] . "</font></a>]\n";
                    }
                    // see if anyone is chatting with this person.
                    $sqlquery = "SELECT * FROM livehelp_operator_channels WHERE channel='" . $chatters['onchannel'] . "'";
                    $counting = $mydatabase->query($sqlquery);
                    if ($counting->numrows() == 0 && !in_array($chatters['user_id'], $ignorelist_array)) {
                    } else {
                        if ($myid != $operatorsarray['user_id']) {
                            $html .= "<tr bgcolor=#EFEFEF><td>&nbsp;</td><td><img src=images/blank.gif width=5 height=5 border=0></td><td nowrap=nowrap>{$chatting}</td><td width=90% align=left><a href=javascript:seepages(" . $chatters['user_id'] . ") onMouseOver=\" try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $chatters['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $chatters['username'] . "');} catch(dam){} return true;\">" . $chatters['username'] . "</a>  {$actionlinkouter} </td></tr>\n";
                        } else {
                            $lasthtml .= "<tr bgcolor=#EFEFEF><td>&nbsp;</td><td>{$checkbox}</td><td nowrap=nowrap>{$chatting}</td><td width=90% align=left><a href=javascript:seepages(" . $chatters['user_id'] . ") onMouseOver=\"try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $chatters['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $chatters['username'] . "'); } catch(dam){} return true;\">" . $chatters['username'] . "</a>  {$actionlink} </td></tr>\n";
                        }
                    }
                }
                $sqlquery = "SELECT * from livehelp_users WHERE sessionid='" . $chatters['sessionid'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $chatters['sessionid'] . "' Order by whendone DESC LIMIT 1";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $chatters['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $DIVS .= "<DIV ID=\"info-" . $chatters['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n<TABLE BORDER=\"0\" WIDTH=\"250\"><TR BGCOLOR=\"#000000\"><TD> \n<TABLE BORDER=\"0\" WIDTH=\"248\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n<FONT COLOR=\"#000000\">\n<b>" . $lang['referer'] . ":</b><br>" . $user_info['camefrom'] . "<br>\n<b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n<b>Url:</b><br><a href=" . $page['location'] . "  target=_blank>" . $page['location'] . "</a><br>";
                $now = date("YmdHis");
                if ($user_info['lastaction'] == "" || $user_info['lastaction'] < 20002020202020) {
                    $user_info['lastaction'] = $now;
                }
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['txt65'] . ":</b><br>{$thediff} " . $lang['Seconds'] . "<br>\n </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
            }
        }
    }
    $html .= $lasthtml . "</table>";
    $html .= "<DIV ID=\"chattersdiv\" STYLE=\"z-index: 2;\">";
    if ($UNTRUSTED['hidechatters'] != 1 && $chatboxes > 0) {
        $html .= "<table cellpadding=0 cellspacing=0 border=0>";
        $html .= "<tr><td><img src=images/blank.gif width=18 height=22 border=0></td><td align=left><img src=images/arrow_ltr.gif width=38 height=22><select name=whattodochat onchange=updatepeople(1)>";
        $html .= "<option value=\"\">" . $lang['txt207'] . ":</option>";
        $html .= "<option value=stop>" . $lang['stop_chat'] . "</option>";
        $html .= "<option value=transfer>" . $lang['transfer_chat'] . "</option>";
        $html .= "<option value=conference>" . $lang['conference_chats'] . "</option>";
        $html .= "</select> <a href=javascript:updatepeople(1)><img src=images/go.gif border=0 width=20 height=20></a></td></tr>";
        $html .= "</table>";
    }
    $html .= "</DIV>";
    ///--------------------------------------------------------------------------------------------------
    // get the count of active visitors in the system right now.
    $timeof = rightnowtime();
    $prev = mktime(date("H"), date("i") - 4, date("s"), date("m"), date("d"), date("Y"));
    $oldtime = date("YmdHis", $prev);
    $sqlquery = "SELECT * FROM livehelp_users WHERE lastaction>'{$oldtime}' AND status!='chat' AND isoperator!='Y' ";
    // make list of ignored visitors:
    $ipadd = explode(",", $CSLH_Config['ignoreips']);
    for ($i = 0; $i < count($ipadd); $i++) {
        if (!empty($ipadd[$i])) {
            $sqlquery .= " AND ipaddress NOT LIKE '" . $ipadd[$i] . "%' ";
        }
    }
    $sqlquery .= " ORDER by lastaction DESC";
    $visitors = $mydatabase->query($sqlquery);
    $onlinenow = $visitors->numrows();
    $hiddennow = 0;
    $html .= "<table width=100% cellpadding=0 cellspacing=0 bgcolor=" . $color_alt2 . "><tr><td>";
    if ($UNTRUSTED['showvisitors'] == 1) {
        $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&showvisitors=2><img src=images/minus.gif border=0></a>";
    } else {
        $html .= "<a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1><img src=images/plus.gif border=0></a>";
    }
    if ($UNTRUSTED['showvisitors'] == 1) {
        $html .= "</td><td><b>" . $lang['visit'] . " <font color=007700>[onlinenow] " . $lang['online'] . "</font> <font color=777777>[hiddennow] " . $lang['Hidden'] . "</font> </td></tr></table>";
        $html .= "<table width=100%><tr bgcolor={$color_background}><td>&nbsp;</td><td><b>ID</b></td><td><b>" . $lang['status'] . ":</b></td><td><b>pages</b></td>";
        if ($CSLH_Config['maxrequests'] < 9999) {
            $html .= "<td>rq#</td>";
        }
        $html .= "</tr>";
        while ($visitor = $visitors->fetchRow(DB_FETCHMODE_ASSOC)) {
            $chatting = "";
            // see if we are in the same department as this user..
            $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
            $data_check = $mydatabase->query($sqlquery);
            if ($visitor['department'] != 0 && $data_check->numrows() == 0) {
                $hiddennow++;
                $onlinenow--;
            } else {
                if (empty($visitor['user_alert'])) {
                    $visitor['user_alert'] = 0;
                }
                if ($visitor['isoperator'] != "Y" && $visitor['user_alert'] != 1) {
                    $onload = " setTimeout(\"doorbell();\",700); ";
                    if ($user_alert == "N" || $user_alert == "") {
                        if ($show_arrival != "N") {
                            $insitewav = "<SCRIPT  type=\"text/javascript\">\n";
                            $insitewav .= "var MSIE=navigator.userAgent.indexOf(\"MSIE\");\n";
                            $insitewav .= "var NETS=navigator.userAgent.indexOf(\"Netscape\");\n";
                            $insitewav .= "var OPER=navigator.userAgent.indexOf(\"Opera\");\n";
                            $insitewav .= "if((MSIE>-1) || (OPER>-1)) {\n";
                            $insitewav .= "document.write(\"<BGSOUND SRC=sounds/" . $alertinsite . " LOOP=1>\");\n";
                            $insitewav .= "} else {\n";
                            $insitewav .= "document.write(\"<EMBED SRC=sounds/" . $alertinsite . " AUTOSTART=TRUE HIDDEN=true VOLUME=100 LOOP=FALSE><noembed><BGSOUND SRC=" . $alertinsite . " LOOP=1></noembed>\");\n";
                            $insitewav .= "}\n";
                            $insitewav .= "</SCRIPT>\n";
                        }
                    }
                    $sql = "UPDATE livehelp_users SET user_alert='1' WHERE user_id='" . $visitor['user_id'] . "' ";
                    $mydatabase->query($sql);
                }
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "'";
                $my_count = $mydatabase->query($sqlquery);
                $my_count = $my_count->numrows();
                $html .= "<tr><td width=10><input type=checkbox name=session__" . $visitor['user_id'] . " value=" . $visitor['sessionid'] . " border=0></td><td>";
                $html .= "<a href=javascript:seepages(" . $visitor['user_id'] . ") onMouseOver=\" try { hide('visitorsdiv');hide('chattersdiv');show(event, 'info-" . $visitor['username'] . "'); } catch(dam){} return true;\" onMouseOut=\"try { showit('chattersdiv');showit('visitorsdiv');hide('info-" . $visitor['username'] . "'); } catch(dam){} return true;\">" . $visitor['username'] . "</a>";
                $sqlquery = "SELECT * from livehelp_users WHERE user_id='" . $visitor['user_id'] . "'";
                $user_info = $mydatabase->query($sqlquery);
                $user_info = $user_info->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_visit_track WHERE sessionid='" . $visitor['sessionid'] . "' Order by whendone DESC";
                $page_trail = $mydatabase->query($sqlquery);
                $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC);
                $sqlquery = "SELECT * from livehelp_departments WHERE recno='" . $visitor['department'] . "'";
                $tmp = $mydatabase->query($sqlquery);
                $nameof = $tmp->fetchRow(DB_FETCHMODE_ASSOC);
                $nameof = $nameof['nameof'];
                $query = "SELECT whendone from livehelp_visit_track WHERE sessionid='" . filter_sql($visitor['sessionid']) . "' Order by whendone LIMIT 1";
                $page_tmprow = $mydatabase->query($query);
                $tmprow = $page_tmprow->fetchRow(DB_FETCHMODE_ASSOC);
                $later = $tmprow['whendone'];
                $DIVS .= "<DIV ID=\"info-" . $visitor['username'] . "\" STYLE=\"position: absolute; z-index: 20; visibility: hidden; top: 0px; left: 0px;\">\n<TABLE BORDER=\"0\" WIDTH=\"300\"><TR BGCOLOR=\"#000000\"><TD> \n<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD width=1 BGCOLOR=#" . $color_alt2 . "><img src=images/blank.gif width=7 height=120></TD><TD BGCOLOR=\"#" . $color_alt2 . "\" valign=top>\n<FONT COLOR=\"#000000\">\n<b>Referer:</b><br>" . $user_info['camefrom'] . "<br>";
                if (empty($page['location'])) {
                    $page['location'] = "";
                }
                $DIVS .= "<b>" . $lang['timeonline'] . ":</b>" . secondstoHHmmss(timediff($later, date("YmdHis"))) . "<br> \n<b>" . $lang['txt43'] . ":</b><br>{$nameof}<br>\n<b>url:</b><br>" . $page['location'] . "<br>";
                $now = date("YmdHis");
                $thediff = $now - $user_info['lastaction'];
                $DIVS .= "<b>" . $lang['lastact'] . ":</b><br>{$thediff} " . $lang['Seconds'] . "<br>\n </FONT></TD></TR></TABLE></TD></TR></TABLE></DIV>";
                $html .= "</td>";
                switch ($visitor['status']) {
                    case "DHTML":
                        $html .= "<td>L:<img src=images/invited.gif> ";
                        break;
                    case "request":
                        $html .= "<td>P:<img src=images/invited.gif> ";
                        break;
                    case "invited":
                        $html .= "<td><img src=images/invited2.gif>  ";
                        break;
                    case "qna":
                        $html .= "<td><img src=images/qna.gif>";
                        break;
                    case "stopped":
                        $html .= "<td><img src=images/stopped.gif> ";
                        break;
                    case "message":
                        $html .= "<td><img src=images/message.gif> ";
                        break;
                    default:
                        $html .= "<td><a href=layer.php?selectedwho=" . $visitor['user_id'] . " target=_blank>" . $lang['invite'] . "</a> ";
                        break;
                }
                $html .= "</td>";
                $html .= "<td>{$my_count}</td>";
                if ($CSLH_Config['maxrequests'] < 9999) {
                    if ($user_info['visits'] > $CSLH_Config['maxrequests'] - 16) {
                        if ($user_info['visits'] < $CSLH_Config['maxrequests']) {
                            $html .= "<td><font color=#770000>" . $user_info['visits'] . "</font><br><a href=javascript:resetpages(" . $visitor['user_id'] . ")>reset</a></td>";
                        } else {
                            $html .= "<td><font color=#CC0000><b>" . $user_info['visits'] . "</b></font><br><a href=javascript:resetpages(" . $visitor['user_id'] . ")>reset</a></td>";
                        }
                    } else {
                        $html .= "<td>" . $user_info['visits'] . "</td>";
                    }
                }
                $html .= "</tr>";
            }
        }
        $html = str_replace("[onlinenow]", $onlinenow, $html);
        $html = str_replace("[hiddennow]", $hiddennow, $html);
        $html .= "</table>";
        $html .= "<DIV ID=\"visitorsdiv\" STYLE=\"z-index: 2;\">";
        if ($onlinenow > 0) {
            $html .= "<table>";
            $html .= "<tr><td><img src=images/arrow_ltr.gif width=38 height=22><select name=whattodo onchange=updatepeople(2)>";
            $html .= "<option value=\"\">" . $lang['txt207'] . ":</option>";
            $html .= "<option value=DHTML>" . $lang['Invite'] . ":" . $lang['layer'] . "</option>";
            $html .= "<option value=pop>" . $lang['Invite'] . ":" . $lang['popup'] . "</option>";
            $html .= "</select> <a href=javascript:updatepeople(2)><img src=images/go.gif border=0 width=20 height=20></a></td></tr>";
            $html .= "</table><center><a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&showvisitors=2>" . $lang['txt208'] . "</a><br></center>";
        }
        $html .= "</DIV>";
    } else {
        while ($visitor = $visitors->fetchRow(DB_FETCHMODE_ASSOC)) {
            $chatting = "";
            // see if we are in the same department as this user..
            $sqlquery = "SELECT * FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . $visitor['department'] . "' ";
            $data_check = $mydatabase->query($sqlquery);
            if ($visitor['department'] != 0 && $data_check->numrows() == 0) {
                $hiddennow++;
                $onlinenow--;
            }
        }
        $html .= "</td><td><b>" . $lang['visit'] . " <font color=007700>{$onlinenow} " . $lang['online'] . "</font> <font color=777777>{$hiddennow} " . $lang['Hidden'] . "</font></b></td></tr></table>";
        $html .= "<table width=100%><tr bgcolor={$color_background}><td colspan=4 align=center><font color=#990000><i>" . $lang['Hidden'] . "</i></a></font><br><a href=admin_users_refresh.php?hidechatters=" . $hidechatters . "&ignorelist={$ignorelist}&numchats={$numchatsnow}&operators=" . $UNTRUSTED['operators'] . "&showvisitors=1>" . $lang['txt209'] . "</a></td></tr></table>";
    }
    $html = $html . $DIVS;
    return $html;
}
><td><b>Total Time Online:</b></td><td><?php 
echo secondstoHHmmss($totalonline);
?>
</td></tr>
<tr bgcolor=<?php 
echo $color_background;
?>
><td><b>Total Time Monitoring Traffic:</b></td><td><?php 
echo secondstoHHmmss($totalmono);
?>
</td></tr>  
<tr bgcolor=<?php 
echo $color_background;
?>
><td><b>Total Time Chatting:</b></td><td><?php 
echo secondstoHHmmss($totalchat);
?>
</td></tr>    
</table>
<hr>
<table width=450><tr><td>
Note: Total Time Online/Monitoring Traffic and Chattings is calculated when the operator logs out so does not include current active session.   
</td></tr></table>
</FORM>

<?php 
if ($isadminsetting == "Y") {
    ?>
<br><br><br><br>

<table bgcolor=DDDDDD width=600><tr><td>