<?php

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

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

$doc->Title('Иконки');

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

aut();
err();
only_reg();

$m1 = 200; // 1 месяц
$m2 = 350; // 2 месяца
$m3 = 600; // 3 месяца
$m4 = 650; // 4 месяца
$m5 = 800; // 5 месяцев
$m6 = 1000; // 6 месяцев
$m7 = 1100; // 7 месяцев
$m8 = 1200; // 8 месяцев
$m9 = 1350; // 9 месяцев
$m10 = 1500; // 10 месяцев
$m11 = 1600; // 11 месяцев
$g1 = 1800; // 1 год

$GetIcon = intval($_GET['id']);

if ($GetIcon < 1 or $GetIcon > 125) {
    header('Location: index.php' . SID);
}

#Навигация
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('Иконки');
echo "</small></div><br />";

echo "<div class='list-group-item-null'>";
echo "<ul class='nav nav-pills'>";
echo "<li class='nav-item'><a class='nav-link active'>" . lang('Купить') . "</a></li>";
echo "<li class='nav-item'><a class='nav-link' href='index.php?get=my_icons'>" . lang('Мои иконки') . "</a></li>";
echo "</ul>";
echo "</div>";


if (isset($_POST['day']) and ( isset($_GET['get']))) {

    if ($_POST['day'] == 'm1') {
        if ($user['money'] >= $m1) {
            $m1_time = $time + 2592000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m1) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m1_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm2') {
        if ($user['money'] >= $m2) {
            $m2_time = $time + 5184000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m2) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m2_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm3') {
        if ($user['money'] >= $m3) {
            $m3_time = $time + 7776000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m3) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m3_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm4') {
        if ($user['money'] >= $m4) {
            $m4_time = $time + 10368000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m4) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m4_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm5') {
        if ($user['money'] >= $m5) {
            $m5_time = $time + 12960000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m5) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m5_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm6') {
        if ($user['money'] >= $m6) {
            $m6_time = $time + 15552000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m6) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m6_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm7') {
        if ($user['money'] >= $m7) {
            $m7_time = $time + 18144000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m7) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m7_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm8') {
        if ($user['money'] >= $m8) {
            $m8_time = $time + 20736000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m8) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m8_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm9') {
        if ($user['money'] >= $m9) {
            $m9_time = $time + 23328000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m9) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m9_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm10') {
        if ($user['money'] >= $m10) {
            $m10_time = $time + 25920000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m10) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m10_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'm11') {
        if ($user['money'] >= $m11) {
            $m11_time = $time + 28512000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $m11) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $m11_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }

    if ($_POST['day'] == 'g1') {
        if ($user['money'] >= $g1) {
            $g1_time = $time + 31103000;
            mysql_query("DELETE FROM `user_icon` WHERE `id_user` = '" . $user['id'] . "'");
            mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] - $g1) . "' WHERE `id` = '$user[id]' LIMIT 1");
            mysql_query("INSERT INTO `user_icon` (`id_user`, `id_icon`, `time`) VALUES ('" . $user['id'] . "', '" . $GetIcon . "', '" . $g1_time . "')");
            header('Location: index.php?get=my_icons' . SID);
            $_SESSION['message'] = lang('Иконка успешно приобретена');
        } else {
            $_SESSION['err'] = lang('Недостаточно средств');
            header('Location: index.php?get=my_icons' . SID);
        }
    }
}

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

echo "<div class='list-group-item-null list-group-item-grey'>";
echo lang('Вы выбрали') . ": <img src='png/$GetIcon.png' />";
echo '<hr>';
echo lang('Стоимость использования') . ':';

echo "<form action='pay.php?get=ok&amp;id=$GetIcon' method='POST'>";
$doc->Radio('day', "1 " . lang('месяц') . " - <i class='fa fa-money fa-fw'></i>$m1", 'm1');
$doc->Radio('day', "2 " . lang('месяца') . " - <i class='fa fa-money fa-fw'></i>$m2", 'm2');
$doc->Radio('day', "3 " . lang('месяца') . " - <i class='fa fa-money fa-fw'></i>$m3", 'm3');
$doc->Radio('day', "4 " . lang('месяца') . " - <i class='fa fa-money fa-fw'></i>$m4", 'm4');
$doc->Radio('day', "5 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m5", 'm5');
$doc->Radio('day', "6 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m6", 'm6');
$doc->Radio('day', "7 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m7", 'm7');
$doc->Radio('day', "8 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m8", 'm8');
$doc->Radio('day', "9 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m9", 'm9');
$doc->Radio('day', "10 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m10", 'm10');
$doc->Radio('day', "11 " . lang('месяцев') . " - <i class='fa fa-money fa-fw'></i>$m11", 'm11');
$doc->Radio('day', "1 " . lang('год') . " - <i class='fa fa-money fa-fw'></i>$g1", 'g1');


$doc->Button('btn btn-success btn-sm', null, 'cart-plus', 'Купить');

echo "</form>";
echo '</div>';

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