<?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($_POST['add'])) {
$fnames = $_FILES['file']['name'];
$pictures = ['.png','.gif'];
$ext = strtolower(strrchr($_FILES['file']['name'], '.'));
$par = getimagesize($_FILES['file']['tmp_name']);
if ($par[0] > 16 || $par[1] > 16) {
err('Большое расширение файла!');
} elseif (preg_match('/(\.php|\.pl|\.htaccess)/i', $fnames) || !in_array($ext, $pictures)) {
err('Запрещенный формат файла!');
} elseif ($_FILES['file']['size'] > 1024 * 100) {
err('Большой размер файла!');
} else {
if ($b['icon'] == null) {
if ($bill['icon'] > $b['rur']) {
err('Недостаточно средств!');
$title->GetMenu();
$title->GetFooter();
die();
}
}
$foto = 'icon_' . mt_rand(100000, 999999) . $ext;
copy($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/files/icons/'.$foto);
if ($b['icon'] == null) {
DB::$dbs->query("UPDATE `blogger` SET `rur` = `rur` - ? WHERE `id` = ? LIMIT 1", [$bill['icon'],$b['id']]);
DB::$dbs->query("UPDATE `blogger` SET `icon` = ? WHERE `id` = ? LIMIT 1", [$foto,$b['id']]);
$text = 'Установлена иконка за [b]'.$bill['icon'].' руб.[/b]';
DB::$dbs->query("INSERT INTO `billing_hist` SET `user_id` = ?, `text` = ?, `time` = ?", [$b['id'],$text,time()]);
DB::$dbs->query("UPDATE `users` SET `icon` = ? WHERE `id` = ? LIMIT 1", [1,$user['id']]);
} else {
DB::$dbs->query("UPDATE `users` SET `icon` = ? WHERE `id` = ? LIMIT 1", [$foto,$user['id']]);
}
header('Location: ?ok');
die();
}
}
echo '<div class="list-group-item media"><form enctype="multipart/form-data" method="post" action="?">'.($b['icon'] == NULL ? '* Цена смены иконки <b>'.$bill['icon'].' руб.</b><br/>После первой смены иконки вы можете бесплатно ее менять в дальнейшем.':'Иконка').': (*max. 16x16px. 100kb. формат .png и .gif)<br/><input name="file" type="file" accept="image/png"/><br/><input type="submit" name="add" class="btn btn-primary" value="Добавить"/></form></div>';
$title->GetMenu();
$title->GetFooter();
?>