<?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 == false) {
header('location: /');
die();
}
echo '<div class="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Биллинг панель </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li typeof="v:Breadcrumb"><a href="/billing" rel="v:url" property="v:title">Биллинг</a></li><li typeof="v:Breadcrumb"><a href="/billing/usl" rel="v:url" property="v:title">Услуги</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title">Очистить нарушения</span></li></ol></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';
echo '<div class="catSides"><i class="md-format-list-bulleted"></i> <a href="/billing">Биллинг</a> - <a href="/billing/usl">Услуги</a> - Очистить нарушения</div>';

$bill = DB::$dbs->queryFetch("SELECT * FROM billing_set WHERE id = ? LIMIT 1",[1]);

if (isset($_GET['ok'])) echo '<div class="row text_box">Успешно удалено!</div>';

if (isset($_GET['del'])) {
$arr = DB::$dbs->queryFetch("SELECT * FROM nar WHERE id = ? LIMIT 1",[abs((int)$_GET['del'])]);
if (empty($arr['id']) OR $arr['user_id'] != $b['id']) {
header('Location: ?');
die();
}
if ($bill['nar'] > $b['rur']) {
err('Недостаточно средств!');
} else {
DB::$dbs->query("UPDATE `blogger` SET `rur` = `rur` - ? WHERE `id` = ? LIMIT 1", [$bill['nar'],$arr['user_id']]);
DB::$dbs->query("DELETE FROM `nar` WHERE `id` = ? LIMIT 1", [$arr['id']]);
$text = 'Удаленo нарушение за [b]'.$bill['nar'].' руб.[/b]';
DB::$dbs->query("INSERT INTO `billing_hist` SET `user_id` = ?, `text` = ?, `time` = ?", [$b['id'],$text,time()]);
header('Location: ?ok');
die();
}
}
$look = DB::$dbs -> querySingle("SELECT COUNT(id) FROM nar WHERE type != ? AND user_id = ?",[3,$b['id']]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
if ($look == 0) {
echo '<div class="error">У вас нет нарушений!</div>';
} else {
$sql = DB::$dbs->query("SELECT * FROM nar WHERE type != ? AND user_id = ? ORDER BY time DESC LIMIT $start,$num",[3,$b['id']]);
while ($arr = $sql -> fetch()) {
$_del = (($arr['user_id']  == $b['id']) ? ' [<a href="?del='.$arr['id'].'">Удалить за '.$bill['nar'].' руб.</a>]':NULL);
echo'<div class="row text_box">Нарушение: <b>'.text($arr['text']) .'</b>'. $_del.'</div>';
}
}
if ($k_page>1) {
str('?', $k_page,$page);
}
///Подключаем меню
$title->GetMenu();


///Подключаем футер
$title->GetFooter();
?>