<?php

/* DCMS Special
 * Дата последнего редактирования 01.10.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'adm_check', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}

$set['title'] = 'Оценка 5+';
require_once H . 'sys/inc/thead.php';

if (!isset($user)) {
    header("location: /index.php?");
}

err();
aut();

if (isset($user)) {
    if (isset($_POST['stav'])) {
        if ($_POST['stav'] == 1) {
            $st = 20;
            $tm = $time + 86400;
        } else if ($_POST['stav'] == 2) {
            $st = 35;
            $tm = $time + 172800;
        } else if ($_POST['stav'] == 3) {
            $st = 50;
            $tm = $time + 259200;
        } else if ($_POST['stav'] == 4) {
            $st = 65;
            $tm = $time + 345600;
        } else if ($_POST['stav'] == 5) {
            $st = 90;
            $tm = $time + 432000;
        } else if ($_POST['stav'] == 6) {
            $st = 110;
            $tm = $time + 518400;
        } else if ($_POST['stav'] == 7) {
            $st = 125;
            $tm = $time + 604800;
        }

        if ($user['money'] >= $st) {
            $k = $db->super_query("SELECT COUNT(*) as count FROM `user_set` WHERE `ocenka_user` = '$user[id]'");
            if ($k['count'] == 0) {
                $db->query("INSERT INTO `user_set` (`ocenka_user`, `ocenka_stav`, `ocenka_time`) values('$user[id]', '$st', '$tm')");
            } else {
                $db->query("UPDATE `user_set` SET `ocenka_time` = '$tm', `ocenka_stav` = '$st' WHERE `ocenka_user` = '$user[id]'");
            }
            $db->query("UPDATE `user` SET `money` = '" . ($user['money'] - $st) . "' WHERE `id` = '$user[id]' LIMIT 1");
            $_SESSION['message'] = lang('Услуга успешно подключена');
            header("Location: /modules/shop/plus5.php");
        } else {
            $err = lang('У вас не достаточно средств');
        }
    }
    err();

    #Навигация
    echo "<div class='list-group-item-null list-group-item-grey'><small>";
    echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='/?umenu'>" . lang('Кабинет') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='/modules/shop/'>" . lang('Магазин') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Оценка 5+');
    echo "</small></div><br />";

    echo "<div class='list-group-item-null list-group-item-grey'><i class='fa fa-money fa-fw'></i> " . lang('Рубли') . " <span class='tag tag-info right'>$user[money]</span></div>";

    $c2 = $db->super_query("SELECT COUNT(*) as count FROM `user_set` WHERE `ocenka_user` = '$user[id]' AND `ocenka_time` > '$time'");
    $c2 = $c2['count'];

    echo "<div class='list-group-item-null'><i class='fa fa-html5 fa-fw'></i> " . lang('Услуга') . " " . ($c2 == 0 ? lang('Не активирована') : lang('активирована')) . "</div>";

    echo"<div class='list-group-item-null list-group-item-grey'>\n";
    echo lang('Услуга') . " <img src='/style/icons/6.png' /><br /> 20 рублей = 1 день пользования превилегией.";
    echo"</div>\n";

    echo "<form method=\"post\" action=\"?\" class='list-group-item-null'>\n";
    echo 'Ставка: <select name="stav">
	<option value="1">20</option>
	<option value="2">35</option>
	<option value="3">50</option>
	<option value="4">65</option>
	<option value="5">90</option>
	<option value="6">110</option>
	<option value="7">125</option>
	</select> рублей<br /><br />';

    $doc->Button('btn btn-primary btn-sm', null, 'shopping-basket', 'Купить услугу');

    echo "</form>\n";
}

require_once H . 'sys/inc/tfoot.php';
