<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* 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.       */
/************************************************************************/
/************************************************************************/
/* based on ChatBox Michael Yarbrough (http://www.comediccadavers.com/) */
/* Mod by Jules / OVNI (webmaster@lajec.com) for NPDS 5.0               */
/* Mod by Siem for NPDS SABLE                                           */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
if (!function_exists("makeChatBox")) {include ("powerpack_f.php");}
include("functions.php");
global $repere; settype ($repere, "integer");

   if (!autorisation_block("makeChatBox")) {die();}

   if (isset($user)) {
      if ($cookie[9]=="") $cookie[9]=$Default_Theme;
      if (isset($theme)) $cookie[9]=$theme;
      $tmp_theme=$cookie[9];
      if (!$file=@opendir("themes/$cookie[9]")) {
         $tmp_theme=$Default_Theme;
         include("themes/$Default_Theme/theme.php");
      } else {
         include("themes/$cookie[9]/theme.php");
      }
   } else {
      $tmp_theme=$Default_Theme;
      include("themes/$Default_Theme/theme.php");
   }
   global $site_font, $sitename;

   $result = mysql_query("SELECT username, message, dbname, date FROM chatbox where date>'$repere' ORDER BY date ASC");
   $thing="";
   if ($result){
      while(list($username, $message, $dbname, $date_message) = mysql_fetch_array($result)) {
         $thing.="<div class='TEXTBOX_STANDARD' style='margin: 0px; padding: 2px;'><div class='ChatHeure'>".date(pp_translate("Chatdate"),$date_message+($gmt*3600))."</div>";
         if ($dbname==1) {
            if ((!$user) and ($member_list==1) and (!$admin)) {
               $thing.="<div class='ChatNom'>$username</div>";
            } else {
               $thing.="<div class='ChatNom'><a href='user.php?op=userinfo&amp;uname=$username' target='_blank'>$username</a></div>";
            }
         } else {
            $thing.="<div class='ChatNom'>$username</div>";
         }
         $message=Smilie($message);
         $chat_forbidden_words=array(
         "'\"'i"=>"&quot;",
         "'OxOA'i"=>"",
         "'OxOD'i"=>"",
         "'\n'i"=>"",
         "'\r'i"=>"",
         "'\t'i"=>"");
         $message=preg_replace(array_keys($chat_forbidden_words),array_values($chat_forbidden_words), $message);
         $message=make_clickable($message);
         $thing.="<div class='ChatTexte'>".removeHack($message)."</div></div>";
         $repere=$date_message;
      }
      $thing="\"".$thing."\"";
   }

   if ($aff_entetes=="1") {
      $meta_op=true;
      include("meta/meta.php");
      $Xthing.=$l_meta;
      $Xthing.=import_css($tmp_theme, $language, $site_font);
      $Xthing.="<title></title></head><body id='chat'>";
      $Xthing="\"".str_replace("'","\'",$Xthing)."\"";
   }

   $result = mysql_query("SELECT DISTINCT ip FROM chatbox WHERE date >= ".(time()-(60*2))."");
   $numofchatters = mysql_num_rows($result);

   $rafraich_connectes=0;
   if (intval($connectes)!=$numofchatters) {
      $rafraich_connectes=1;
      if (($numofchatters==1) or ($numofchatters==0)) {
         $nbre_connectes="'".$numofchatters." ".utf8_java(pp_translate("person chatting right now."))."'";
      } else {
         $nbre_connectes="'".$numofchatters." ".utf8_java(pp_translate("people chatting right now."))."'";
      }
   }
   $commande="self.location='chatrafraich.php?repere=".$repere."&amp;aff_entetes=0"."&amp;connectes=".$numofchatters."'";
   include("meta/meta.php");
   echo "</head>\n<body onload='sur_chargement();' id='chat'>
   <script type='text/javascript' language='JavaScript'>

   function scroll_messages() {
      if (typeof(scrollBy) != 'undefined') {
         parent.frames[1].scrollBy(0, 20000);
         parent.frames[1].scrollBy(0, 20000);
      }
      else if (typeof(scroll) != 'undefined') {
         parent.frames[1].scroll(0, 20000);
         parent.frames[1].scroll(0, 20000);
      }
   }

   function rafraichir() {
      $commande;
   }

   function sur_chargement() {
      setTimeout(\"rafraichir();\", 6000);";
      if ($aff_entetes=="1")  echo "parent.frames[1].document.write($Xthing);";
      if ($thing!="\"\"") {
         echo "parent.frames[1].document.write($thing);
               setTimeout(\"scroll_messages();\", 300);
               ";
      }
      if ($rafraich_connectes==1) {
         echo "parent.document.title=$nbre_connectes;";
      }
   echo "}
   </script>
   </body></html>";
?>