}
 $externalchats_array = explode(",", $externalchats);
 if (!isset($UNTRUSTED['channelsplit'])) {
     $UNTRUSTED['channelsplit'] = "__";
 }
 if (!isset($UNTRUSTED['starttimeof'])) {
     $UNTRUSTED['starttimeof'] = 0;
 }
 $mychannelcolor = $color_background;
 $myusercolor = "000000";
 if (!isset($UNTRUSTED['whattodo'])) {
     $UNTRUSTED['whattodo'] = "";
 }
 $usercolor = "";
 $myuser = "";
 $timeof = rightnowtime();
 $array = explode("__", $UNTRUSTED['channelsplit']);
 if (empty($array[0])) {
     $array[0] = "";
 }
 if (empty($array[1])) {
     $array[1] = "";
 }
 $saidto = intval($array[1]);
 $channel = intval($array[0]);
 if ($saidto == "") {
     $channel = -1;
 }
 // alternate whattodo for keystroke return
 if (isset($UNTRUSTED['alt_what'])) {
     $UNTRUSTED['whattodo'] = "send";
 function arrayofchats()
 {
     global $mydatabase, $CSLH_Config, $UNTRUSTED, $identity;
     $arrayforoperator = array();
     $query = "SELECT livehelp_operator_channels.id,livehelp_operator_channels.txtcolor,livehelp_operator_channels.txtcolor_alt,livehelp_operator_channels.channelcolor,livehelp_operator_channels.userid,livehelp_users.user_id,livehelp_users.isoperator,livehelp_users.ipaddress,livehelp_users.username,livehelp_users.onchannel,livehelp_users.lastaction FROM livehelp_operator_channels,livehelp_users where livehelp_operator_channels.userid=livehelp_users.user_id AND livehelp_operator_channels.user_id=" . intval($this->myid);
     $mychannels = $mydatabase->query($query);
     $counting = $mychannels->numrows();
     $wearelinking = false;
     // flag for if we are linking the chat tabs or not.
     $alltabs = array();
     $j = 0;
     while ($channel_a = $mychannels->fetchRow(DB_FETCHMODE_ASSOC)) {
         $prev = mktime(date("H"), date("i") - 3, date("s"), date("m"), date("d"), date("Y"));
         $oldtime = date("YmdHis", $prev);
         $alltabs[$j] = $channel_a;
         $j++;
     }
     // Update operator History for when operator is chatting
     $q = "SELECT chataction,user_id FROM livehelp_users WHERE sessionid='" . $identity['SESSIONID'] . "' LIMIT 1";
     $sth = $mydatabase->query($q);
     $row = $sth->fetchRow(DB_FETCHMODE_ORDERED);
     $rightnow = rightnowtime();
     $chataction = $row[0];
     $opid = $row[1];
     if ($j > 0) {
         $q = "UPDATE livehelp_users SET chataction='{$rightnow}' WHERE sessionid='" . $identity['SESSIONID'] . "'";
         $mydatabase->query($q);
     } else {
         // get when they logged in and how many seconds they have been online:
         $query = "SELECT dateof FROM livehelp_operator_history WHERE opid=" . $opid . " AND action='Started Chatting' ORDER by dateof DESC LIMIT 1";
         $data3 = $mydatabase->query($query);
         $row3 = $data3->fetchRow(DB_FETCHMODE_ASSOC);
         $seconds = timediff($chataction, $row3['dateof']);
         if ($chataction > 10) {
             // update history for operator to show login:
             $query = "UPDATE livehelp_users set chataction='0' WHERE sessionid='" . $identity['SESSIONID'] . "'";
             $mydatabase->query($query);
         }
     }
     for ($k = 0; $k < count($alltabs); $k++) {
         $channel_a = $alltabs[$k];
         if (!empty($alltabs[$k + 1])) {
             $channel_b = $alltabs[$k + 1];
         } else {
             $channel_b['onchannel'] = -1;
         }
         if ($channel_a['isoperator'] == "Y") {
             // Operators can be on multiple channels so see if one of the channels they are on is one we are on.
             $foundcommonchannel = 0;
             $query = "SELECT * FROM livehelp_operator_channels WHERE user_id=" . intval($channel_a['user_id']);
             $mychannels2 = $mydatabase->query($query);
             while ($rowof = $mychannels2->fetchRow(DB_FETCHMODE_ASSOC)) {
                 $query = "SELECT * FROM livehelp_operator_channels WHERE user_id=" . intval($myid) . " And channel=" . intval($rowof['channel']);
                 $countingthem = $mydatabase->query($query);
                 if ($countingthem->numrows() != 0) {
                     $foundcommonchannel = $rowof['channel'];
                 }
             }
             $channel_a['onchannel'] = $foundcommonchannel;
             $channel = $foundcommonchannel;
         }
         $thischannel = $channel_a['onchannel'] . "__" . $channel_a['userid'];
         $usercolor = $channel_a['txtcolor'];
         $usercolor_alt = $channel_a['txtcolor_alt'];
         if ($UNTRUSTED['channelsplit'] == $thischannel) {
             $myuser = $channel_a['username'];
             $myuser_ip = $channel_a['ipaddress'];
             $myusercolor = $usercolor;
             $mychannelcolor = $channel_a['channelcolor'];
             $txtcolor = $channel_a['channelcolor'];
             if (in_array($channel_a['onchannel'], $externalchats_array)) {
                 $external = true;
             } else {
                 $external = false;
             }
         } else {
             $txtcolor = "DDDDDD";
             $txtcolor = $channel_a['channelcolor'];
         }
         $dakineuser = substr($channel_a['username'], 0, 15);
         array_push($arrayforoperator, array($txtcolor, $channel_a['onchannel'], $channel_a['userid'], $dakineuser));
     }
     return $arrayforoperator;
 }
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;
}
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;
}