<?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($_POST['add'])) {
$nick = check($_POST['nick']);
if (empty($nick)) {
err('Введите ник!');
} elseif ($bill['icon'] > $b['rur']) {
err('Недостаточно средств!');
}
elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM `blogger` WHERE `nick` = ?", [$nick]) > 0) {
err('Такой ник уже занят!');
} else {
DB::$dbs->query("UPDATE `blogger` SET `nick` = ? WHERE `id` = ? LIMIT 1", [$nick,$b['id']]);
DB::$dbs->query("UPDATE `blogger` SET `rur` = `rur` - ? WHERE `id` = ? LIMIT 1", [$bill['nick'],$b['id']]);
$text = 'Изменен ник за '.$bill['nick'].' руб.';
DB::$dbs->query("INSERT INTO `billing_hist` SET `user_id` = ?, `text` = ?, `time` = ?", [$b['id'],$text,time()]);
header('Location: ?ok');
die();
}
}
echo '<div class="row text_box"><form method="post" action="?">* Стоимость смены ника <b>'.$bill['nick'].' руб.</b><br/>Новый ник: (*max.:15)<br/><input name="nick" class="form-control" type="text"/><br/><input type="submit" name="add" class="btn btn-primary"
 value="Изменить"/></form></div>';

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


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