<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle('Панель управления - Модерация файлов');
$title->GetHeader();
if ($b['level'] < 3) {
header('location:/');
die();
}
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: <a href="/administration/"style="text-decoration:none; color:white;"> Дата-центр</a> :: Модерация файлов</div></div></div>';

if (isset($_GET['da'])) {
$file = DB::$dbs->queryFetch("SELECT * FROM `downs` WHERE `id` = ?", [abs((int)$_GET['da'])]);
DB::$dbs->query("UPDATE `downs` SET `mod` = ? WHERE `id` = ? LIMIT 1", [0,abs((int)$_GET['da'])]);

$raz = DB :: $dbs -> queryFetch("SELECT * FROM `down_r` WHERE `id` = ?", [$file['rid']]);
if ($raz['id'] == 6) {
$t = 2;
$tt = 8;
} elseif ($raz['id'] == 5) {
$t = 4;
$tt = 22;
} elseif ($raz['id'] == 1) {
$t = 2;
$tt = 13;
} else {
$t = 2;
$tt = 13;
}
if ($file['thema'] == 1) {
DB::$dbs->query("INSERT INTO forum_topic SET name = ?, user_id = ?, time = ?, rid = ?, prid = ?, last = ?", [$file['name'],$file['user_id'],time(),$t,$tt,time()]);
$tid = DB::$dbs->lastInsertId();
$infs = $file['info'].'<br/><br/>Обсуждение файла: [url=http://'.homeurl.'/downs/file.html?id='.$file['id'].']'.$file['name'].'[/url]';
DB::$dbs->query("INSERT INTO forum_mess SET text = ?, user_id = ?, time = ?, rid = ?, prid = ?, tid = ?", [$infs,$file['user_id'],time(),$t,$tt,$tid]);
}
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE id = ?", [1,$b['id']]);
$message = Nick($file['user_id']).' добавил <a href="/downs/file.html?id='.$file['id'].'">[новый файл]</a> в Файловый обменник!';
lenta($message);
$mess = 'Ваш файл <a href="/downs/file.html?id='.$file['id'].'">'.$file['name'].'</a> прошел модерацию!';
jurnal($file['user_id'],$mess,5);
header('location: ?');
die();
}
if (isset($_GET['no'])) {
$file = DB::$dbs->queryFetch("SELECT * FROM `downs` WHERE `id` = ?", [abs((int)$_GET['no'])]);
unlink('/'.$file['url']);
jurnal($file['user_id'], 'Ваш файл [b]'.$file['name'].'[/b] не прошел модерацию!', 5);
DB::$dbs->query("DELETE FROM `downs` WHERE `id` = ?", [abs((int)$_GET['no'])]);
header('location: ?');
die();
}
$total = DB::$dbs->querySingle("SELECT COUNT(id) FROM `downs` WHERE `mod` = ?", [1]);
if ($total == 0) echo '<div class="alert alert-danger" role="alert">Файлов на модерации нет!</div>';
$sql = DB::$dbs->query("SELECT * FROM `downs` WHERE `mod` = ? ORDER BY `id` DESC",[1]);
while($a = $sql ->fetch()) {
$url = $_SERVER['DOCUMENT_ROOT'].'/'.$a['url'];
$raz = DB::$dbs->queryFetch("SELECT * FROM `down_r` WHERE `id` = ?", [$a['rid']]);
$praz = DB::$dbs->queryFetch("SELECT * FROM `down_pr` WHERE `id` = ?", [$a['prid']]);
echo '<div class="list-group-item media"><a href="/downs/file.php?id='.$a['id'].'"><i class="zmdi zmdi-shuffle"></i>    '.$a['name'].'</a> (<a href="/downs/file.php?id='.$a['id'].'&down">скачать</a>)</br>Вес файла: '.get_size(filesize($url)).'<br/>Выгрузил: '.Nick($a['user_id']).'<br/>Категория: <a href="/downs/show_dir.html?id='.$raz['id'].'">'.$raz['name'].'</a> -> <a href="/downs/show_kat.html?id='.$praz['id'].'">'.$praz['name'].'</a><br/><i class="zmdi zmdi-shuffle"></i> [<a href="?da='.$a['id'].'">Допустить</a>] [<a href="?no='.$a['id'].'">Отклонить</a>]</div>';
}
$title->GetMenu();
$title->GetFooter();
?>
