<?

/************************************************************************/
/* XChat Version 0.9.8                                                  */
/* ==================================================================== */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if (eregi("block-4nChat1.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}
global $cookie, $prefix, $currentlang;
$modulename = "4nChat";
$basepath   = "modules/$modulename";

if(file_exists("$basepath/language/lang-".$currentlang.".php")) {
        include("$basepath/language/lang-".$currentlang.".php");
}
else {
        include("$basepath/language/lang-$language.php");
}

require "$basepath/inc/config.php";
$tstamp = time();
$tstamp -= $usertime;

$q=mysql_query("delete from ".$prefix."_4nchatuser where last < ".$tstamp);


  $content = "<table border=\"0\" cellspacing=\"3\">";
  $content .= "<tr valign=\"top\">";
  $content .= "<td><font class=\"content\" align=\"left\">"._WCROOMNAME."</td>";
  $content .= "<td><font class=\"content\" align=\"right\">"._WCROOMOCCUPANTS."</td>";
  $sql = "select ".$prefix."_4nchatroom.*, count(".$prefix."_4nchatuser.rid) as users from ".$prefix."_4nchatroom left join ".$prefix."_4nchatuser on ".$prefix."_4nchatuser.rid = ".$prefix."_4nchatroom.rid group by ".$prefix."_4nchatroom.rid order by ".$prefix."_4nchatroom.typ, ".$prefix."_4nchatroom.name";
  $q = mysql_query($sql);
  if(mysql_num_rows($q) == 0){
    $content .= _WCNOACTIVE;
  } else {
    $roomtype = "P";
    while($result = mysql_fetch_array($q)) {
      if($row[refresh]) {
        if($roomtype != $result[typ])
          $top = true;
        else
          $top = false;
        if($top)
          if($result[typ] == "N")
            $content .= "<tr valign=\"top\" align=\"left\"><td colspan=\"2\"><font class=\"content\"><b>"._4n003."</b></font></td></tr>";
          else
            $content .= "<tr valign=\"top\" align=\"left\"><td colspan=\"2\"><font class=\"content\"><b>"._4n004."</b></font></td></tr>";
        $top = false;
      }
      $content .= "<tr valign=\"top\">";
      $content .= "<td><font class=\"content\"><a href=\"modules.php?op=modload&name=".$modulename."&file=index&roomid=$result[rid]\">$result[name]</a></font></td>";
      $content .= "<td align=\"center\" valign=\"middle\">".$result[users].($result[users]==1?" ":"");
      if($row[url] && $result[users] != 0){
        $content .= "<br><i>";
        $first = true;
        $q2 = mysql_query("select name from ".$prefix."_4nchatuser where rid = ".$result[rid]);
        while($result2 = mysql_fetch_array($q2)){
          if($first) {
            $first = false;
            $content .= $result2[name];
          } else
            $content .= ", ".$result2[name];
        }
        $content .= "</i>";
      }
      $content .= "</td></tr>";
      $roomtype = $result[typ];
    }
  }
  $content .= "</table>";
  $row[content] = $content;
$content .= "<br><center>[ <a href=\"modules.php?op=modload&name=4nChat\">$modulename</a> ]</center>";


?>