<?php
define('NTOP', 1);
$title = 'Центр поддержки';
require_once ('system/connect.php');
require_once ('system/core.php');
require_once ('system/function.php');
require_once ('m/head.php');
reg();
switch($act){
default:
$p=rand(100,100000);

echo'<div class="title2">Список сообщений</div>
<div class="rek"><form action="add_sms.php" method="post">
<textarea name="sms" cols="17" rows="2">'.$_POST['sms'].'</textarea>
<br><input name="ok" type="submit" value="написать" />
<a href="chat.php?p='.$p.'">обн.</a></form></div>';

$all = mysql_num_rows(mysql_query("SELECT * FROM `sms`"));
if($all != 0){
$total=intval(($all-1)/$page_top)+1;
$page=abs(intval($_GET['page']));
if(empty($page) OR $page < 0){
$page = 1;
}
if($page > $total){
$page = $total;
}
$past=intval($all/$page_top);
$start=$page*$page_top-$page_top;
$top = mysql_query("SELECT * FROM `sms` ORDER BY `id` DESC LIMIT ".$start.",".$page_top."");

while($row = mysql_fetch_array($top)){
$user = mysql_fetch_array(mysql_query("SELECT * FROM `top_users` WHERE `login` = '".$row['author']."'"));
$start++;
echo '<div class="main">';
if ($user['level'] == 2){
echo '<img src="images/admin.png">';
}else{
echo '<img src="images/user.png">';
}
echo ' <a href="/m/info.php?id='.$user['id'].'">'.$row['author'].'</a> ['.data($row['data']).']';
if($user_data['level'] == 2)echo'<a href="chat.php?act=del_sms&id='.$row['id'].'">[x]</a>';
echo'<br>'.$row['smska'].'</div>'; 
}
navigation($all,$page_top,$page,'chat.php?page=',$total);
} else {
echo '<div class="stat">';
echo 'Сообщений пока нет.';
echo '</div>';
}

require_once ('m/foot.php');
break;
case 'del_sms':
if ($user_data['level'] == 2){
echo '<div class="title">Управление сообщениями</div>';
$del = mysql_query("DELETE FROM `sms` WHERE `id` = '".$id."'");
if($del){
echo '<div class="stat">Сообщение успешно удалено<br/></div>';
} else {
echo '<div class="error">Сообщение не удалено<br/></div>';
}
} else {echo'Запрещено!';
}
break;
}

require_once ('m/foot.php');
?>