<?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'] < 5) {
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="/panel" 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"><a href="/panel"><i class="md-format-list-bulleted"></i> Админка</a> - <a href="billing.html"> Биллинг</a> - Вывод средств</div>';

if (isset($_GET['ok'])) {
$arr = DB::$dbs->queryFetch("SELECT * FROM billing_out WHERE id = ? LIMIT 1", [abs((int)$_GET['ok'])]);
DB::$dbs->query("UPDATE `blogger` SET `rur` = `rur` - ? WHERE `id` = ?", [$arr['rur'],$arr['user_id']]);
DB::$dbs->query("UPDATE `billing_out` SET `type` = ? WHERE `id` = ?", [1,$arr['id']]);

$kom = 'На ваш WMR кошелек выведено [b]'.$arr['rur'].'p.[/b]';
jurnal($arr['user_id'],$kom,6);
DB::$dbs->query("INSERT INTO `billing_hist` (`user_id`,`text`,`time`) VALUES (?,?,?)", [$arr['user_id'],$kom,time()]);
header('location: ?');
}
if (isset($_GET['ot'])) {
$arr = DB::$dbs->queryFetch("SELECT * FROM billing_out WHERE id = ? LIMIT 1", [abs((int)$_GET['ot'])]);
DB::$dbs->query("UPDATE `billing_out` SET `type` = ? WHERE `id` = ?", [2,$arr['id']]);
$kom = 'Ваша заявка на вывод [b]'.$arr['prim'].'[/b] руб аннулирована!';
jurnal($arr['user_id'],$kom,6);
DB::$dbs->query("INSERT INTO `billing_hist` (`user_id`,`text`,`time`) VALUES (?,?,?)", array($arr['user_id'],$kom,time()));
header('location: ?');
}
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM billing_out WHERE type = ?", [0]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM billing_out WHERE type = ? ORDER BY id DESC LIMIT $start,$num", [0]);
if ($sql -> rowCount() == 0) {
err('Нет заявок на вывод средств!');
} else {
while($a = $sql->fetch()) {
$arrtype = [0 => 'Не оплачен', 1 => 'Оплачен', 2 => 'Аннулирован'];
$type = strtr($a['type'], $arrtype);
echo '<div class="row text_box"><i class="md-shuffle"></i> Запрос от: '.Nick($a['user_id']).' ('.vr($a['time']).')<br/>Cумма: <b>'.$a['rur'].'р.</b> <br/>Кошелек: <b>R'.user_inf($a['user_id'], 'wmr').'</b><br/>';
echo ($a['type'] == 0 ? '<b><a href="?ok='.$a['id'].'">[Подтвердить]</a></b> или <b><a href="?ot='.$a['id'].'">[Отменить]</a></b>':NULL);
echo '<br/>Статус: <font color="red"><b>'.$type.'</b></font></div>';
}
}
if ($k_page > 1) {
str('?',$k_page,$page);
}

///Подключаем меню
$title->GetMenu();


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