<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
if ($aut) {
if ($id) {
$type = $db -> query("SELECT * FROM `reit` WHERE `komy` = '".$id."' and `where`='load'");
if ($type -> num_rows > 0) $the = $type -> fetch_assoc(); else $the = false;
} else $the = false;
switch($mode) {
case 'golos':
$text = shit($_POST['text']);
$te = $db -> query("SELECT * FROM `reit` WHERE `where`='load' and `komy` = '".$id."' and `kto` = '".$ya['id']."'");
if ($te -> num_rows > 0) {
     $diz -> head('Ошибка');
     $diz -> title('Ошибка');
     $msg .= '<div class="fon">Вы уже голосовали за данный файл!</div>';
     header('refresh: 3; url=reit'.$id.'');
     #####Копирайт#######
require_once (ROOT.'system/kopy.php');
     $diz -> out($msg);
}else{
$golos = (!empty($_POST['golos'])) ? abs((int)$_POST['golos']) : null;
$db -> multi_query("INSERT INTO `reit` SET `where`='load', `kto` = '".$ya['id']."', `komy` = '".$id."',`rei` = '".$golos."',`text` = '".$text."',`time` = '".time()."'");
header('location: reit.php?id='.$id.'&page='.$page);
}
break;

case 'del':
if ($aut == true and $id != false) {
$sql = $db -> query("SELECT * FROM `reit` WHERE `id` = '".$id."' LIMIT 1");
if ($sql -> num_rows > 0) {
$ass = $sql -> fetch_assoc();
if ($ya['level']>1) {
$db -> query("DELETE FROM `reit` WHERE `id` = '".$id."' LIMIT 1");
header('location: reit'.$ass['komy']);
} else header('location: reit'.$ass['komy']);
} else header('location: reit'.$ass['komy'].'');
} else header('location: reit'.$ass['komy'].'');
break;

default:
$diz -> head('Рейтинг файла');
$login = $db -> query("SELECT `name` FROM `load_files` WHERE `id` = '".$id."' LIMIT 1")-> fetch_assoc();
$diz -> title("<a href='./view/$id/'>$login[name]</a>/<b>Рейтинг файла</b>");
$count = $db -> dbcount('COUNT(`id`)','reit',"`komy` = '".$id."' and `where`='load'");
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1; 
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
if ($count>0){
$for = $db -> query("SELECT * FROM `reit` WHERE `komy` = '".$id."' and `where`='load' ORDER BY `id` DESC LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$arr = $db -> query("SELECT `login` FROM `users` WHERE `id` = '".$assoc['kto']."' LIMIT 1");
if ($arr -> num_rows > 0) {
$array = $arr -> fetch_assoc();
$array['login'] = '<a href="'.ROOT.'my/id'.$assoc['kto'].'">'.$array['login'].'</a>';
}
$dop = null;
if ($aut) {
if ($ya['level'] > 3) {
$dop = ' | <a href="reit.php?id='.$assoc['id'].'&amp;mode=del&amp;page='.$page.'">[Удалить]</a>';
}
}
$msg .= '<div class="top"><strong>'.$array['login'].' </strong>('.$func -> times(date('d m Y H:i:s',$assoc['time'])).')'.$dop.'<br/>';
if($assoc['rei']==1){$golos=$msg .='<b>Положительный</b></br>';}else{$golos=$msg .='<b>Отрицательный</b></br>';}
$text = $func -> smiles($assoc['text']);
$msg .=''.$text.'</div>';
}
}else{$msg .= '<div class="fon">Пока ни кто не проголосовал..</div>';}
if ($aut == true) {
$msg .= '<form action="reit.php?id='.$id.'&amp;mode=golos&amp;page='.$page.'" method="post" enctype="multipart/form-data"><div>';
$msg .= '<div class="fon">Голос:<br/><select name="golos"><option value="1">Положительный</option><option value="0">Отрицательный</option></select></br>
Комментарий:<br/>
<textarea name="text" rows="3" cols="15"></textarea><br/>
<input type="submit" value="Проголосовать!"/>
</form></div>';}
$act = 'index.php?id='.$id;
$msg .= ''.$func -> pagenav($act,$page,$total).'';
$msg .= '<div class="levo">'.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
#####Копирайт#######
require_once (ROOT.'system/kopy.php');
$diz -> out($msg);
}
} else header('location: ../aut.php');
?>