Файл: shared_zone/index.php
Строк: 144
<?
include('../core/core.php');
include(MAINDIR.'style/head.php');
title('Загруз-центр');
$id = abs(intval($_GET['id']));
$my = DB::run() -> queryFetch("SELECT * FROM `users` WHERE `login`=? LIMIT 1",array(check($_COOKIE['login'])));
switch ($mode):
case 'fil':
echo'<div class="title">Загруз-центр</div>';
$obmen = DB::run() -> query("SELECT * FROM `obmen`") -> rowCount();
if($obmen != 0){
$int = DB::run()->query("SELECT * FROM `obmen` ORDER BY `id` ");
$int = $int -> fetchAll();
foreach($int AS $u){
echo'<div class="menu"><img src="/images/folder_green_4326.png"> <a href="/shared_zone/index.php?mode=index&id='.$u['id'].'">'.$u['name'].'</a>';
$inte = DB::run()->query("SELECT * FROM `obmen_cat` WHERE id_obmen=?",array($u['id']));
$inte = $inte -> fetchAll();
foreach($inte AS $uz){
echo'<br /><small>>> <a href="/shared_zone/?mode=file&id='.$uz['id'].'">'.$uz['name'].'</a> ('.count_all('files','id_obmen',$uz['id']).')</small>';
}
echo'</div>';
}
} else {echo'<div class="error">Разделы не созданы!</div>';}
break;
case 'index':
$rusz = DB::run() -> query("SELECT * FROM `obmen` WHERE `id`=? ",array($id)) -> rowCount();
if($rusz != 0){
$ru = DB::run() -> queryFetch("SELECT * FROM `obmen` WHERE `id`=? ",array($id));
echo'<div class="title">'.$ru['name'].'</div>';
define('TOPAGE',10); $num = TOPAGE;
$links = '?mode=index&id='.$id.'&page=';
$page = intval($_GET['page']);
$posts = DB::run() -> query("SELECT * FROM `obmen_cat` WHERE `id_obmen`=?",array($id)) -> rowCount();
$total = intval(($posts - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$themesz = DB::run()->query("SELECT * FROM `obmen_cat` WHERE `id_obmen`=? ORDER BY `id` LIMIT $start,".TOPAGE."",array($id));
$themesz = $themesz -> fetchAll();
foreach($themesz AS $u){
echo'<div class="menu"><img src="/images/folder_green_4326.png"> <a href="?mode=file&id='.$u['id'].'">'.$u['name'].'</a> ('.count_all('files','id_obmen',$u['id']).')</div>';
}
if ($page != 1) $pervpage = '<a href= '.$links.'1><<</a> <a href= '.$links.''. ($page - 1) .'><</a> ';
if ($page != $total) $nextpage = ' <a href= '.$links.''. ($page + 1) .'>></a> <a href= '.$links.'' .$total. '>>></a>';
if($page - 2 > 0) $page2left = ' <a href= '.$links.''. ($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = '<a href= '.$links.''. ($page - 1) .'>'. ($page - 1) .'</a> | ';
if($page + 2 <= $total) $page2right = ' | <a href= '.$links.''. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a href= '.$links.''. ($page + 1) .'>'. ($page + 1) .'</a>';
if($posts != 0){echo '<div class="menu_2">'.$pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage.'</div>'; } else {echo'<div class="error">Разделы еще не существуют!</div>';}
} else {echo'<div class="error">Данной категории не существует!</div>';}
break;
case 'file':
$rusz = DB::run() -> query("SELECT * FROM `obmen_cat` WHERE `id`=? ",array($id)) -> rowCount();
if($rusz != 0){
$ru = DB::run() -> queryFetch("SELECT * FROM `obmen_cat` WHERE `id`=? ",array($id));
$ru1 = DB::run() -> queryFetch("SELECT * FROM `obmen` WHERE `id`=? ",array($ru['id_obmen']));
echo'<div class="title">'.$ru1['name'].' -> '.$ru['name'].'</div>';
if(is_admin() || is_user() && $my['level'] >= 1){echo'<div class="menu"><a href="upload.php?mode=index&id='.$id.'">Загрузить файл</a></div>';}
###########################
$links = '?mode=file&id='.$id.'&page=';
define('TOPAGE',10); $num = TOPAGE;
$page = intval($_GET['page']);
$posts = DB::run() -> query("SELECT * FROM `files` WHERE `id_obmen`=?",array($id)) -> rowCount();
$total = intval(($posts - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$filez = DB::run()->query("SELECT * FROM `files` WHERE `id_obmen`=? ORDER BY `id` LIMIT $start,".TOPAGE."",array($id));
$filez = $filez -> fetchAll();
foreach($filez AS $z){
echo'<div class="menu">'.file_icon($z['type']).' '.$z['link'].'</div>';
}
if ($page != 1) $pervpage = '<a href= '.$links.'1><<</a> <a href= '.$links.''. ($page - 1) .'><</a> ';
if ($page != $total) $nextpage = ' <a href= '.$links.''. ($page + 1) .'>></a> <a href= '.$links.'' .$total. '>>></a>';
if($page - 2 > 0) $page2left = ' <a href= '.$links.''. ($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = '<a href= '.$links.''. ($page - 1) .'>'. ($page - 1) .'</a> | ';
if($page + 2 <= $total) $page2right = ' | <a href= '.$links.''. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a href= '.$links.''. ($page + 1) .'>'. ($page + 1) .'</a>';
if($posts != 0){echo '<div class="menu_2">'.$pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage.'</div>'; } else {echo'<div class="error">Файлов в данной категории не обнаружено!</div>';}
} else {echo'<div class="error">Данной категории не существует!</div>';}
break;
case 'rat':
echo '<div class="title">Голосование за файл.</div>';
if(is_user()){
$id = abs(intval($_GET['id']));
$file = DB::run() -> queryFetch("SELECT * FROM `files` WHERE `id`=? LIMIT 1",array($id));
$r = DB::run() -> queryFetch("SELECT * FROM files_rat WHERE file = ? AND `login` = ?",array($file['name'],$my['login']));
if($file['id'] == !NULL){
if($r['login'] == NULL){
$cm = check($_GET['cm']);
if($cm == 'p'){
DB::run() -> query("UPDATE `files` SET `plus`=`plus` + ? WHERE id =?",array(1,$id));
DB::run() -> query("INSERT INTO `files_rat`(`file`, `login`) VALUES (?,?)",array($file['name'],$my['login']));
header ('location: /'.$id.'/');
}
if($cm == 'm'){
DB::run() -> query("INSERT INTO `files_rat`(`file`, `login`) VALUES (?,?)",array($file['name'],$my['login']));
DB::run() -> query("UPDATE `files` SET `minus`=`minus` + ? WHERE id =?",array(1,$id));
header ('location: /'.$id.'/');
}
} else {echo'<div class="menu">Вы уже голосовали за этот файл</div>'; }
} else {echo'<div class="menu">Файла не существует!</div>'; }
} else {echo'<div class="menu">Ошибка голосовать могут только пользователи сайта!</div>'; }
break;
default:
header ('location: ?mode=index');
endswitch;
include(MAINDIR.'style/foot.php');
?>