<?php
$_getDataStickers = false;
if ($_actionGetId >= -1 && ($_getDataStickers = DB::$pdo->queryFetch("SELECT id, price 
                  FROM `stickers_cat` WHERE `id` = :id LIMIT 1",
        [':id' => $_actionGetId])) === false) {
    system:: redirect("Ошибка...<br/>Этой категории не существует", "/stickers/");
}
$message = null;

if((int)DB::$pdo->querySingle("SELECT COUNT(id) FROM `stickers_buy` WHERE `id_user` = ? AND `id_cat` = ?", [
    $user['id'], $_actionGetId
]) === 0) {

    if($_getDataStickers['price'] > $user['line']) {
        $message = "Ошибка...<br/>Недостаточно винетов для покупки стикеров";
    } else {

        DB::$pdo->query("UPDATE `users` SET `line` = `line` - ? WHERE `id` = ? LIMIT 1", [
            $_getDataStickers['price'], $user['id']
        ]);
        DB::$pdo->query("INSERT INTO `stickers_buy` (`id_user`, `id_cat`) VALUES(?, ?)", [
            $user['id'], $_actionGetId
        ]);
        $message = "Успешно...<br/>Вы успешно добавили новые стикеры";
    }
}
system:: redirect($message, "/stickers/?tab=show&id=" . $_actionGetId);