<?php
require_once 'core/system.php';
include 'core/func_smiles.php';
include 'core/antimat.php';
date_default_timezone_set('Europe/Moscow');
reg();
head('Чат');
$times=time()-60*30;
$count = $dbc->query("SELECT (id) FROM `users` WHERE `time`> '$times'"); $count_online = $count->num_rows;
$dbc->query("UPDATE `users` SET `ch`=0 WHERE `id`='".$user['id']."'");
echo '<div class="lblue-panel">';
if(isset($_GET['dele']) and !empty($_GET['id']) and $user['admins']>0){
$post_id = int($_GET['id']);
$post = $dbc->query("SELECT `id`,`text` FROM `chat` WHERE `id`='".$post_id."' LIMIT 1")->fetch_assoc();
if(!$post){
header("Location: index.php");
exit;
}
$dbc->query("INSERT INTO `admin_log` SET
`text`='<a href=\"pers.php?ank=".$user['id']."\">".$user['login']."</a> удалил сообщение в чате <b>".$post['text']."</b>',
`time`='".time()."'");
#$dbc->queryquery("DELETE FROM `chat` WHERE `id`='".$post['id']."'");
$dbc->query("UPDATE `chat` SET
`text`='<span style=\"color: #999\"><a href=\"pers.php?ank=".$user['id']."\">".$user['login']."</a> удалил сообщение.</span>'
WHERE `id`='".$post['id']."'");
header("Location: chat");
}
if(isset($_GET['ban']) and !empty($_GET['ank']) and $user['admins']>0){
$ank_id = int($_GET['ank']);
$ank = $dbc->query("SELECT `login`,`id`,`admins` FROM `users` WHERE `id`='".$ank_id."' LIMIT 1")->fetch_assoc();
if($ank['id']==1){
header("Location: index.php");exit;}
if($ank['admins']==1){
header("Location: index.php");
exit;
}
if(!$ank){
header("Location: index.php");
exit;
}
$time_ban = (60*60*2)+time();
echo '<div class="row">';
echo'<a class="btn" href="chat?ban&ank='.$ank['id'].'&ok">Молчанка</a> <a class="btn" href="chat?">Снять Молчанку</a></div>';
if(isset($_GET['ok'])){
$dbc->query("UPDATE `users` SET `chat_ban`='".$time_ban ."' WHERE `id`='".$ank_id."'");
$dbc->query("INSERT INTO `chat` SET
`user_id`='".$user['id']."',
`text`='<span style=\"color: #999\">На <b>".$ank['login']."</b> действует молчанка.Он не может писать в чат.</span>',
`time`='".time()."'");
$dbc->queryquery("INSERT INTO `admin_log` SET
`text`='<a href=\"pers.php?ank=".$user['id']."\">".$user['login']."</a> кинул молчанку <a href=\"pers.php?ank=".$ank['id']."\">".$ank['login']."</a>(Чат)',
`time`='".time()."'");
$dbc->query("DELETE FROM `chat` WHERE `user_id`='".$ank['id']."'");
header("Location: chat");
}
foot();
exit;
}
if(isset($_GET['otv']) and !empty($_GET['ank'])){
$ank_id = int($_GET['ank']);
$ank = $dbc->query("SELECT `login`,`id`,`admins` FROM `users` WHERE `id`='".$ank_id."' LIMIT 1")->fetch_assoc();
if(!$ank){
header("Location: chat");
exit;
}
$_SESSION["jou"]=$ank['login'];
header('Location: chat');
foot();
exit;
}
if(isset($_GET['add'])){
if($user['level']<2){ $_SESSION['message']='Оставлять Сообщения в чате доступно с 2 уровня!'; header('location:chat');exit;}
if($user['chat_ban']> time()){
$ban_ost = $user['chat_ban'] - time();
echo '<div id="error">Вам запрещено писать в чате.<br>До разблокировки: '.Sec2Time($ban_ost) .'</div>';
foot();
exit;
}
$last_post = $dbc->query("SELECT `text` FROM `chat` WHERE `user_id`='".$user['id']."' ORDER BY `time` DESC LIMIT 1")->fetch_assoc();
if($last_post['text']==$_POST['text']){
header("Location: chat");
exit;
}
if(empty($_POST['text'])){
header("Location: chat");
}else{
$text = protect($_POST['text']);
if(iconv_strlen ($text, 'utf-8') < 2){
echo '<div id="error">Слишком короткое сообщение</div>';
foot();
exit;
}
$dbc->query("INSERT INTO `chat` SET
`user_id`='".$user['id']."',
`text`='".$text."',
`time`='".time()."'");
$dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' ")->fetch_assoc();
$dbc->query("UPDATE `dop` SET `orator_exp`=`orator_exp`+1 WHERE `user`='".$user['id']."'");
$dbc->query("UPDATE `users` SET `ch`=1 WHERE `ch`=0 and `id`!='".$user['id']."'");
}
}
?><script language='JavaScript' type='text/javascript'>
function sml(html) {
var e = document.getElementById('text');
if (e != null) {
e.value += ' ' + html + ' ';
e.focus();
}
}
function smiles() {
var e = document.getElementById('smiles');
if (e != null) {
if (e.style.display == 'block') e.style.display = 'none';
else e.style.display = 'block';
}
}
</script>
<form action="chat?add" method="post">
<textarea rows="2" cols="30" class="b-textarea" name="text" id="text" maxlength="256">
<?
if(isset($_SESSION['jou']) and !empty($_SESSION['jou'])){ $otvet = protect($_SESSION['jou']);
?><?=$otvet?>, <? }
?>
</textarea>
<button id="submitSent" type="submit" class="gr- btn">Отправить</button>
</form> <?
?><center><a href="help.php">Помощь</a> |
<a href="#" onclick="smiles();return false">Смайлы</a> | <a href="chat">Обновить</a>| <a href="all_us">Онлайн (<?=$count_online?>)</a></center><?
$smile_q = $dbc->query("SELECT * FROM `smiles` ORDER BY `id` ASC LIMIT 60");
?><div id="smiles" style="display:none;overflow: auto;max-height: 200px;"><?
while($smile = $smile_q->fetch_assoc()){
?><img onclick="sml('<?=$smile['value']?>')" src="/img/smiles/<?=$smile['img']?>" alt="<?=$smile['value']?>" style="box-shadow: 0px 0px 10px green; margin: 6px;"/>
<?
}
?></div><?
$sql_chat = $dbc->query("SELECT * FROM `chat` ORDER BY `time` DESC LIMIT ".$page.",".$set['str']." ");
$totall = $dbc->query("SELECT (id) FROM `chat`");
$total= $totall->num_rows;
if($total==0){
echo '<div class="block_zero center">В чате пусто. Будь первым!</div>'; }
while($chat=$sql_chat->fetch_assoc()){
#header('Refresh: 10; URL=chat');
$ank = $dbc->query("SELECT `login`,`id`,`level`,`admins`, `vip`,`storona`,`pers` FROM `users` WHERE `id`='".$chat['user_id']."' LIMIT 1")->fetch_assoc();
$post='';
$vip_active='';
if($ank['id']==1){$post='<span class="bluepost">[a]</span>';}
if($ank['id']==1283){$post='<span class="bluepost">[a]</span>';}
if($ank['admins']==1){$post='<span class="bluepost">[m]</span>';}
if($ank['vip']==1){ $vip_active='<img src="img/stat/vip.png">';}
$nick = '<span class="chat-el"><span class="btn name">
<img src="img/class/'.$ank['storona'].'/'.$ank['pers'].'/pers.png" width="12" height="12">
<a href="/pers.php?ank='.$ank['id'].'"><span>'.$ank['login'].'</a></span></span>'.$post.''.$vip_active.'';
echo '<div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><br/>'.$nick.' <small><span style="color: #9C9;">('.clock($chat['time']).')</span></small>';
if($user['id']!=$chat['user_id']){
echo '<a href="chat?otv&ank='.$chat['user_id'].'"> <img src="img/at/otvet.png"></a>';
}
if($user['admins']>0){
echo '<span style="float: right;"><a class="btn" href="chat?ban&ank='.$chat['user_id'].'">ban</a></span>';
}
If($user['admins']==2){echo ' удалить<a id="btn" href="chat?dele&id='.$chat['id'].'">[x]</a></span>';}
$chat['text'] = str_replace($user['login'].',','<span class="login">'.$user['login'].'</span>,',$chat['text']);
echo'<br> '.smile($chat['text']).'<br/>';
?></div></div><?
}
$max = array (0,20,50,100,200,350,400,600,800,1000,1500,2500,3500,4000,4500,5000,5500,6000,7000,8000,9000,10000,15000,20000,25000,30000,35000,40000,50000,60000,70000,80000,90000,10000,10000000);
$new_dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' ")->fetch_assoc();
$desi = $max[$new_dop['orator_lvl']];
if($new_dop['orator_exp']>=$desi){
$dbc->query("UPDATE `users` SET `max_health`=`max_health`+50, `strength`=`strength`+5, `defense`=`defense`+5, `gold`=`gold`+50 WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `dop` SET `orator_lvl`=`orator_lvl`+1 , `orator_exp`=0 WHERE `user`='".$user['id']."'");
$_SESSION['message'] = 'Навык Оратора Повышен! получено 50 золота';
header('location:chat');exit;
}
$_SESSION['jou']='';
if($total > $set['str']) {
pages($page, $total, 'chat?', $set['str']);
}
echo'</div>';
foot();
?>