<?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) {
            if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ocenky` WHERE `id_user` = '$user[id]'"), 0) == 0) {
                mysql_query("INSERT INTO `ocenky` (`id_user`, `stav`, `time`) values('$user[id]', '$st', '$tm')");
            } else {
                mysql_query("UPDATE `ocenky` SET `time` = '$tm', `stav` = '$st' WHERE `id_user` = '$user[id]'");
            }
            mysql_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='count'>$user[money]</span></div>";

    $c2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `ocenky` WHERE `id_user` = '$user[id]' AND `time` > '$time'"), 0);
    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';
