Файл: public_html/modules/mini_chat/index.php
Строк: 115
<?php
/**********************************
* @package: PerfCMS *
* @year: 2012 *
* @author: Artas *
* @link: http://perfcms.net *
* ------------------------------- *
* @package: PerfCMS Ultra *
* @year: 2013 *
* @author: wanya26ua & Tesla *
* @link: http://perfclub.ru *
**********************************/
if(!isset($user)) {
header('location: /');
exit;
}
if(isset($_GET['act']) && $_GET['act'] == 'add') {
if(!empty($_POST['text'])) {
$text = substr(input($_POST['text']), 0, 5000);
} else { $err = ''.$lang->word('chat_mess_n').''; }
if(isset($user)) { $userid = $user['id']; } else { $userid = '0'; }
$s = $db->query("SELECT * FROM `mini_chat` WHERE `user_id` = '". $user['id'] ."' AND `time` > '". (time()-$system['spam']) ."'")->rowCount();
if ($s>0) {
header('location: /mini_chat/?act=spam');
} else {
if(!isset($err)) {
$db->query("UPDATE `users` SET `balans` = '".($user['balans']+$system[balans_chat])."' WHERE `id` = '".$user['id'] . "'");
$db->query("INSERT INTO `mini_chat` SET `text` = '$text', `user_id` = '$userid', `time` = '". time() ."'");
header('location: /mini_chat/?');
exit;
} else {
$tpl->div('error', $err);
}
}
}
if(isset($_GET['act']) && $_GET['act'] == 'delete') {
$mini_chat_del = $db->query("SELECT * FROM `mini_chat` WHERE `id` = '".$_GET['id']."'")->fetch();
if(($_GET['id'] != 0 || !empty($_GET['id'])) && $user['level'] >= 5 || $user['level'] == 2 || $mini_chat_del['user_id'] == $user['id']) {
$db->query("DELETE FROM `mini_chat` WHERE `id` = '". abs(intval($_GET['id'])) ."'");
header('location: /mini_chat/');
exit;
} else { $tpl->div('error', $lang->word('chat_not_g')); }
}
if(isset($_GET['act']) && $_GET['act'] == 'edit') {
if(isset($_POST['edit'])) {
if(!empty($_POST['text'])) {
$text = substr(input($_POST['text']), 0, 5000);
$db->query("UPDATE `mini_chat` SET `text` = '". $text ."' WHERE `id` = '".abs(intval($_GET['id']))."'");
}
header('location: /mini_chat/');
exit;
}
$mini_chat_ed = $db->query("SELECT * FROM `mini_chat` WHERE `id` = '".$_GET['id']."'")->fetch();
if(($_GET['id'] != 0 || !empty($_GET['id'])) && $user['level'] >= 5 || $user['level'] == 2 || $mini_chat_ed['user_id'] == $user['id']) {
$title = $lang->word('edit_post');
require_once(SYS.'/view/header.php');
$tpl->div('title', $lang->word('edit_post'));
echo '<form action="" method="post">
<div class="menu">
<b>'. $lang->word('message') .'</b>:<br/>
<textarea name="text" rows="5" cols="26">'.$mini_chat_ed['text'].'</textarea><br/>
<input name="edit" type="submit" value="'. $lang->word('edit') .'" /><br/>
</div>
</form>';
$tpl->div('block', NAV .'<a href="/mini_chat/">'. $lang->word('mini_chat') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
require_once(SYS.'/view/footer.php');
exit;
} else { $tpl->div('error', $lang->word('chat_not_g')); }
}
$locate = 'in_mini_chat';
$title = $lang->word('mini_chat');
require_once(SYS.'/view/header.php');
$tpl->div('title', $lang->word('mini_chat'));
if(isset($_GET['act']) && $_GET['act'] == 'spam') {
$tpl->div('block', $lang->word('spam') .' <b>'.$system['spam'].'</b> '.$lang->word('sec'));
}
echo '<div class="menu">'.$lang->word('chat_write_mess').':<br/>
<form action="/mini_chat/?act=add" method="post">
<textarea name="text" rows="5" cols="26">'.(isset($_GET['reply']) ? '[b]'.tnick(abs(intval($_GET['reply']))).'[/b], ' : NULL).'</textarea><br/>
[ <a href="/pages/smiles.php">'. $lang->word('smiles') .'</a> | <a href="/pages/tags.php">'. $lang->word('tags') .'</a> ]<br/><input type="submit" value="'. $lang->word('chat_mess_send') .'" /> <a href="/mini_chat/" title="'. $lang->word('update') .'">'.img('refresh.png').'</a>
</form>
</div>';
$mini_chat_r = $db->query("SELECT * FROM `mini_chat` ")->rowCount();
$pages = new Paginator($mini_chat_r, $ames);
if($mini_chat_r == 0) {
$tpl->div('menu', $lang->word('chat_not_mess'));
} else {
$mini_chat_q = $db->query("SELECT * FROM `mini_chat` ORDER BY `time` DESC LIMIT $start, $ames");
while($mini_chat = $mini_chat_q->fetch()) {
$tpl->div('post', nick($mini_chat['user_id']) .' ('. rtime($mini_chat['time']) .') <span style="float:right">'.($mini_chat['user_id'] != $user['id'] ? ' <a href="/mini_chat/?reply='.$mini_chat['user_id'].'" title="'. $lang->word('reply') .'">'. img('reply_11.png').'</a> ':NULL) .' '.($user['level'] >= 5 || $user['level'] == 2 || $mini_chat['user_id'] == $user['id'] ? ' <a href="/mini_chat/?act=delete&id='.$mini_chat['id'].'" title="'. $lang->word('delete') .'">'. img('delete_11.png').'</a> <a href="/mini_chat/?act=edit&id='.$mini_chat['id'].'" title="'. $lang->word('edit') .'">'. img('edit_11.png').' </a>' : NULL).'</span><br/>
'.output($mini_chat['text']));
}
$pages->view('/mini_chat/?');
}
$tpl->div('block', HICO .'<a href="/">'. $lang->word('home') .'</a>');
require_once(SYS.'/view/footer.php');
?>