<?session_start();

  include ("option.php");

  if (!file_exists($msg_file)) { $fo = fopen($msg_file, "w"); fclose($fo); }

  include("chatfun.php");
  $chatname = login($_SESSION["username"]);
  require_once("../config.php");
  $userst=mysql_query("select user_status from tb_users where username='$chatname'");
  $ust=mysql_fetch_assoc($userst);
  mysql_close($con);
  $fl = file($msg_file);
  $count_fl = count($fl);
  $msg = mess($_POST['message']);
  $person = trim($chatname);
  if (($msg != "") && ($person != ""))
  {
    if ($count_fl >= $msg_xron)
    {
      $fw = fopen($msg_file, "w");
      for($i=1;$i<$msg_xron;$i++){
      		fwrite($fw, trim($fl[$i])."\r\n");
      }
    }
    $time = date("Â H:i");
    if(strtolower($nicadmin)==strtolower($chatname)){$bold="<font color=\"#dd0000\">";$bolden="</font>";$person=$nicadminot;$person1="Î_î";$cvet="#f0f0f0";}
    if(strtolower($nicadmina)==strtolower($chatname)){$bold="<font color=\"green\">";$bolden="</font>";$person=$nicadminota;}
    if(strtolower($nicadmina)==strtolower($chatname)){$bold="<font color=\"green\">";$bolden="</font>";$person1="Î_î";$cvet="#f0f0f0";}
    elseif($ust["user_status"]=="user"){$bold="<font color=\"#279dbc\">";$bolden="</font>";$cvet="#e6edf4";}
    $cmess = "<thead style='background:".$cvet.";'><tr><td align=\"left\" style='color:#5d5d5d ;border:solid 1px #ccc; border-bottom:0px; border-right:0px; font:12px Tahoma; padding:4px; padding-left:5px;'><font color='#f49e22'>".$person1."</font> <a onclick=\"insert_text('','[b]".$person."[/b]')\" class='chat' style='text-decoration:none;'>".$bold."". $person .":</a> ".$bolden."&nbsp;".$msg." </td><td align='right' width='40px' style='color:red; border:solid 1px #ccc; font:12px Tahoma; padding:4px; padding-left:5px;border-bottom:0px;border-left:0px;'><span class=mstime>".$time."</span></td></tr></thead>\r\n";
    $cmess = Encode($cmess,"w");

    $fp = fopen($msg_file, "a+");
    $fw = fwrite($fp, $cmess);
    fclose($fp);
  }
?>