<?php
define('NTLCMS', 1);
$module = 'panel';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
include ('../system/head.php');
################################################################################
if ($active && $_USER['admin'] == '1'){
################################################################################
echo '<div class="title"><b>'.razd.' Админ панель | Очистка модулей</b></div>';
################################################################################
			
if (isset($_GET['mail']) && DB :: run() -> querySingle("select count(`id`) from `message`") != 0){					
DB :: run() -> query("truncate table `message`") && DB :: run() -> query("optimize table `message`");

$fdir = opendir(FOLDER.'/mail/files');
    
while ($file = readdir($fdir)){
if ($file != '.' and $file != '..' and $file != '.htaccess'){
            
if ($clean){
if (strpos($file, $clean) !== false) @unlink(FOLDER.'/mail/files/'.$file);
} else {
@unlink(FOLDER.'/mail/files/'.$file);
}
}
}

$_SESSION['success'] = 'Почта успешно очищена!';
header('Location: '.URL.'/_truncate'); 

}

if (isset($_GET['auth']) && DB :: run() -> querySingle("select count(`id`) from `auth`") != 0){					
DB :: run() -> query("truncate table `auth`") && DB :: run() -> query("optimize table `auth`");
$_SESSION['success'] = 'Логи авторизаций успешно очищены!';
header('Location: '.URL.'/_truncate');
}

if (isset($_GET['chat']) && DB :: run() -> querySingle("select count(`id`) from `chat`") != 0){					
DB :: run() -> query("truncate table `chat`") && DB :: run() -> query("optimize table `chat`");
$_SESSION['success'] = 'Мини-Чат успешно очищен!';
header('Location: '.URL.'/_truncate');
}

if (isset($_GET['notice']) && DB :: run() -> querySingle("select count(`id`) from `notice`") != 0){					
DB :: run() -> query("truncate table `notice`") && DB :: run() -> query("optimize table `notice`");
$_SESSION['success'] = 'Уведомления успешно очищены!';
header('Location: '.URL.'/_truncate');
}

if (isset($_GET['bank']) && DB :: run() -> querySingle("select count(`id`) from `bank`") != 0){					
DB :: run() -> query("truncate table `bank`") && DB :: run() -> query("optimize table `bank`");
$_SESSION['success'] = 'Операции банка успешно очищены!';
header('Location: '.URL.'/_truncate');
}

if (isset($_GET['sale']) && DB :: run() -> querySingle("select count(`id`) from `credit`") != 0){					
DB :: run() -> query("truncate table `credit`") && DB :: run() -> query("optimize table `credit`");
$_SESSION['success'] = 'Логи автопродажи успешно очищены!';
header('Location: '.URL.'/_truncate');
}

if (isset($_GET['purchase']) && DB :: run() -> querySingle("select count(`id`) from `purchase`") != 0){					
DB :: run() -> query("truncate table `purchase`") && DB :: run() -> query("optimize table `purchase`");
$_SESSION['success'] = 'Логи автопокупки успешно очищены!';
header('Location: '.URL.'/_truncate');
}

################################################################################
$chat = DB :: run() -> querySingle("select count(`id`) from `chat`");
$logauth = DB :: run() -> querySingle("select count(`id`) from `auth`");
$mails = DB :: run() -> querySingle("select count(`id`) from `message`");
$notice = DB :: run() -> querySingle("select count(`id`) from `notice`");
$bank = DB :: run() -> querySingle("select count(`id`) from `bank`");
$sale = DB :: run() -> querySingle("select count(`id`) from `credit`");
$purchase = DB :: run() -> querySingle("select count(`id`) from `purchase`");
$referers = DB :: run() -> querySingle("select count(`id`) from `referer`");

echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-bank">Операции банка</a> <span class="count">'.$bank.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-sale">Логи автопродажи</a> <span class="count">'.$sale.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-purchase">Логи автопокупки</a> <span class="count">'.$purchase.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-chat">Мини-Чат</a> <span class="count">'.$chat.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-notice">Уведомления</a> <span class="count">'.$notice.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-auth">Логи авторизаций</a> <span class="count">'.$logauth.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_truncate-mail">Личная почта</a> <span class="count">'.$mails.'</span></div>';
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/_referer">Переходы в клуб</a> <span class="count">'.$referers.'</span></div>';

################################################################################
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a> | <a href="'.URL.'/_control">Админ-Панель</a></div>';
################################################################################
} else {
echo '<div class="title"><b>'.razd.' Проверка прав доступа</b></div>';
echo '<div class="menu"><center><i class="fa fa-close fa-fw"></i> Доступ запрещен!</center></div>';
echo '<div class="block"><i class="fa fa-home fa-fw"></i> '.(isset($active) ? '<a href="'.URL.'/cabinet">В кабинет</a>' : '<a href="'.URL.'">На главную</a>').'</div>';
}

include ('../system/foot.php');
?>