View file public_html/chat.php

File size: 3.83Kb
<?

require_once ('system/core.php');

require_once ('system/head.php');

echo '<div class="title"><center> Чат </a></center></div>';

if($_GET['chat'] == restart && $user['id'] == 1) {
    
mysql_query("truncate table `chat`");

header('location: ?');

exit;

}

if(isset($_GET['new_msg'])){

if(isset($_POST['text'])){

$text = guard($_POST['text']);

if(strlen($text) < 1 or strlen($text) > 1000) {
    
echo '<div class="block center">Длина сообщения 1-1000 символов!<br>Вернуться в <a href="/chat.php">Чат</a></div>';

require_once ('system/foot.php');

exit;

}
 
if($user['level'] < 3) {
    
echo '<div class="link"> Отправлять сообщения разрешено с 3 уровня! </br> Вернуться в <a href="/chat.php">Чат</a></div>';

require_once ('system/foot.php');

exit;

}

mysql_query("INSERT INTO `chat` SET `id_user` = '$user[id]', `time` = '".time()."', `text` = '".text($text)."'");

mysql_query("update `users` set `zoloto` = `zoloto` +3, `serebro` = `serebro` +10, `exp` = `exp` + 5 where `id` = '".$user['id']."'");

mysql_query("update `users` set `exp` = `exp` + 5 where `id` = '".$user['id']."'");

$_SESSION['result'] = '<font color="green"><b> Сообщение отправлено </br> <img src="/style/icons/serebro.png" width="16px" alt="TheSom"> + 10 

<img src="/style/icons/zoloto.png" width="16px" alt="TheSom"> + 3 <img src="/style/icons/exp.png" width="16px" alt="TheSom"> + 5 </b></font>';

header('Location: /chat.php');

exit();

}

else

{

header('Location: /chat.php');

exit();

}

}

if(isset($_GET['delete_post']) and $user['admin'] == 1){
    
mysql_query("DELETE FROM `chat` WHERE `id` = '".$_GET['delete_post']."'");

header('Location: ?');

exit();

}

echo "<div class='link'>";

if(isset($_GET['to'])){

echo "<form method='post' action='?new_msg=$_GET[to]'>";

$opponent = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = $_GET[to] LIMIT 1"));

echo "<textarea name='text' style='width: 100%'>$opponent[login], </textarea>";

echo "<input type='submit' value='Отправить'></form>";

}

else

{

echo "<form method='post' action='?new_msg'>";

echo "<textarea name='text' style='width: 100%'> </textarea>";

echo "<input type='submit' value='Отправить'></form>";

}

echo '</div>';

$set['p_str'] = 10;

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `chat`"),0);

$k_page = k_page($k_post,$set['p_str']);

$page = page($k_page);

$start = $set['p_str']*$page-$set['p_str'];

$q = mysql_query("SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start, $set[p_str]");

while($post = mysql_fetch_assoc($q)) {
    
echo " <div class='link'> ";

$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = $post[id_user] LIMIT 1"));

echo ' '.(($ank['sex'] == 1) ? '<img src="/style/icons/man.png" width="18px" alt="TheSom">' : '<img src="/style/icons/woman.png" width="18px" alt="TheSom">') .' ';

echo " <a href='/profile.php?id=$ank[id]'> $ank[login] </a> </br>";

if($user['id'] == $ank['id'])echo "";

if($user['id'] != $ank['id'])echo "<span style='float: right'>[<a href='?to=$ank[id]'>Ответить</a>]</a></span>";

$msg = str_replace(array($user[login].','), "<b>$user[login],</b> ", $post['text']);

echo " ".text($msg)." ";

if($user['admin'] == 0) echo "</div>";

if($user['admin'] == 1)

echo "<span style='float: right'> <a href='?delete_post=$post[id]'>[<font color='red'>Удалить</font>]</a></span></div>";

echo '</div>';

}

echo '</div>';

echo '</div>';

if($k_post<1) {
    
echo '<div class="foot"><center> Чат пустой </center></div>';
    
}

if($k_post>0 && $user['id']==1) {
    
echo "<div class='foot'>";

echo '<img src="/style/icons/delete.png"><a href="?chat=restart"><b> Очистить чат </b></a></div>';

}

if($k_page>1)  echo str('?',$k_page,$page);

require_once ('system/foot.php');

?>