Файл: chat.php
Строк: 150
<?php
include 'inc/mysql.php';
include 'inc/check.php';
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include 'inc/shapka.php';
echo'<div class="menudiv">Общий чат</div>';
echo'<div class="text">';
if(isset($_POST['msg'])){
$_POST['msg'] = trim($_POST['msg']);
$faq = mysql_query("SELECT * FROM `config`");
$base = mysql_fetch_array($faq);
if($account[lvl]<$base[chat_lvl]){
$err[]='<center><img src="/pic/main/znak.png" alt="*"/><font color=00CC00> Писать в чате можно с '.$base[chat_lvl].' уровня.</font></center><div class="separ2"></div>';
}else{
if(!empty($_POST['msg'])){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `chat` WHERE `account`='".$account['id']."'"),0)>0 AND 5>(time()-mysql_result(mysql_query("SELECT `time` FROM `chat` WHERE `account`='".$account['id']."' ORDER BY `id` DESC LIMIT 1"),0)))$err[]='<center><img src="/pic/main/znak.png" alt="*"/><font color=00CC00> Нельзя писать так часто!</font></center><div class="separ2"></div>';
if(strlen($_POST['msg'])>1000) $err[]='<center><img src="/pic/main/znak.png" alt="*"/><font color=00CC00> Слишком длинное сообщение!</font></center><div class="separ2"></div>';
if(strlen($_POST['msg'])<2) $err[]='<center><img src="/pic/main/znak.png" alt="*"/><font color=00CC00> Слишком короткое сообщение!</font></center><div class="separ2"></div>';
}else{
$err[]='<center><img src="/pic/main/znak.png" alt="*"/><font color=00CC00> Пустое сообщение!</font></center><div class="separ2"></div>';
}}
if(!$err){
$msg=$_POST['msg'];
$msg=substr($msg, 0, 1000);
$msg=str_replace("<","",$msg);
$msg=str_replace(">","",$msg);
$msg = addslashes($msg);
$msg=preg_replace ("|[rn]+|si","",$msg);
include ("inc/antireklama.php");
mysql_query("INSERT INTO `chat`(`account`,`msg`,`time`) VALUES('".$account['id']."','$msg','".time()."')");
header("Location: chat.php"); exit;
echo '</div>';
}else{
foreach($err as $value){
echo '
'.$value.'
';
}
}
}
echo '
<img src="/pic/main/chats.png" alt="*"/> <a href="chat.php?">Обновить</a> <img src="/pic/main/smils.png" alt="*"/> <a href="/smile.php">Смайлы</a>
';
if($_GET['go']=='delete' && ($account['status']=="moder" || $account['status']=="gm")){
mysql_query("DELETE FROM `chat` WHERE `id`='".intval($_GET['id'])."'");
header ("Location: chat.php");
exit;
}
if ($_GET['say']){
$say=mysql_result(mysql_query("SELECT `login` FROM `account` WHERE `id`='".intval($_GET['say'])."'"),0);
$say = str_replace("$say","$say, ",$say);
}else{
$say='';
}
echo '<form name="form" action="chat.php" method="post">'.bbpanel('form', 'msg').'<script type="text/javascript">
function ctrlEnter(event, formElem)
{
if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)))
{
formElem.form.submit();
}
}
</script>
<textarea name="msg" style="width:50%;resize:vertical;" placeholder="Введите сообщение..." rows="1" onkeypress="ctrlEnter(event, this);">'.$say.'</textarea><br>
<input type="submit" class="submit" value="Написать">
</form>
</div>
';
echo '<div class="text2">';
$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `chat`"),0);
$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';
$q=mysql_query("SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start,$cop");
$avto = mysql_num_rows($q);
if($avto>=1){
While($result= mysql_fetch_array($q))
{
$_user = mysql_fetch_assoc(mysql_query("SELECT * FROM `account` WHERE `id`='".$result['account']."'"));
if($_user['status']=="gm"){
$nik = gradient(''.$_user[login].'','00FF00', '00CC00');
echo '<img src="pic/main/'.$_user[sex].'.png" alt="*"/> <a href="?say='.$_user['id'].'">'.$nik.'</a> <a href="infa.php?id='.$_user['id'].'"><img src="/pic/main/info.gif" alt="*"/></a>:<br />';
}else{
if($_user['status']=="moder"){
$nik = gradient(''.$_user[login].'','0066CC', 'AB82FF');
echo '<img src="pic/main/'.$_user[sex].'.png" alt="*"/> <a href="?say='.$_user['id'].'">'.$nik.'</a> <a href="infa.php?id='.$_user['id'].'"><img src="/pic/main/info.gif" alt="*"/></a>:<br />';
}else{
if($_user['status']=="bot"){
$nik = gradient(''.$_user[login].'','FFCC00', 'FF9933');
echo '<img src="pic/main/'.$_user[sex].'.png" alt="*"/> <a href="?say='.$_user['id'].'">'.$nik.'</a> <a href="infa.php?id='.$_user['id'].'"><img src="/pic/main/info.gif" alt="*"/></a>:<br />';
}else{
echo '
<img src="pic/main/'.$_user[sex].'.png" alt="*"/> <a href="?say='.$_user['id'].'">'.$_user['login'].'</a> <a href="infa.php?id='.$_user['id'].'"><img src="/pic/main/info.gif" alt="*"/></a>:<br />';
}}}
$koment = strip_tags($result['msg']);
$koment = smiles($koment);
if($result[tyrney]=="1"){
echo "$result[msg]";
}else{
if($_user[status]=="gm"){
echo "<font color=LightCoral>$koment</font><br />";
}
if($_user[status]=="moder"){
echo "<font color=#1E90FF>$koment</font><br />";
}
if($_user[status]=="bot"){
echo "<font color=gold>$koment</font><br />";
}
if($_user[status]=="user"){
echo "$koment<br />";
}
}
$d = time()-$result['time'];
echo '<font color=00CC00><small>('.sec2day($d).' назад)</font></small>';
if ($account['status']=='moder' OR $account['status']=='gm'){
echo ' <a href="?go=delete&id='.$result['id'].'"><img src='pic/main/!.png'></a>';
}
echo '<br /><br />';
if ($dlist == 'list1'){
$dlist = 'list2';
}else{
$dlist = 'list1';
}
}
echo '
<center>
Навигация:
';
if($page-1>0){
echo '<a href="?page='.($page-1).'"><</a> ';
}
if($page-1>0){
echo '<a href="?page='.($page-1).'">'.($page-1).'</a> ';
}
echo '<b>'.$page.'</b>';
if($page+1<=$cp){
echo ' <a href="?page='.($page+1).'">'.($page+1).'</a>';
}
if($page+1<=$cp){
echo ' <a href="?page='.($page+1).'">></a>';
}
echo '</center>';
echo '</div>';
}else{
echo '<img src='pic/index/!.png'> Нет сообщений.';
echo '</div>';
}
}else{
header ("Location: index.php"); exit;
}
include 'inc/nogi.php';
?>