<?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="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="/billing"style="text-decoration:none; color:white;">Биллинг</a> :: <a href="/billing/usl"style="text-decoration:none; color:white;">Услуги</a> :: Очистить нарушения</div></div></div>';
$bill = DB::$dbs->queryFetch("SELECT * FROM billing_set WHERE id = ? LIMIT 1",[1]);
if (isset($_GET['ok'])) echo '<div class="alert alert-success"role="alert">Успешно удалено!</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="alert alert-danger"role="alert">Список нарушений пуст!</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="list-group-item media">Нарушение: <b>'.text($arr['text']) .'</b>'. $_del.'</div>';
}
}
if ($k_page>1) {
str('?', $k_page,$page);
}
$title->GetMenu();
$title->GetFooter();
?>