<?php
include_once '../../../inc/start.php';
if (empty($_POST['phpaction'])) {
	log_error("Прямой вызов actions.php"); 
	echo 'Ошибка: [Прямой вызов инклуда]';
	exit(json_encode(array('status' => '2')));
}
if($conf->token == 1 && ($_SESSION['token'] != clean($_POST['token'],null))) {
	log_error("Неверный токен");
	echo 'Ошибка: [Неверный токен]';
	exit(json_encode(array('status' => '2')));
}
if (isset($_POST['user_buy_gif'])) {
	
    $STH = $pdo->query("SELECT shilings FROM users WHERE id='$_SESSION[id]' LIMIT 1"); $STH->setFetchMode(PDO::FETCH_OBJ);
    $row = $STH->fetch();

    if($row->shilings >= '100'){
        $STH = $pdo->prepare("UPDATE users SET gif_avatar='1' WHERE id='$_SESSION[id]'");
        $STH->execute();

        $shilings_post = round_shilings($row->shilings - 100);

        $STH = $pdo->prepare("UPDATE users SET shilings='$shilings_post' WHERE id='$_SESSION[id]'");
        $STH->execute();

        $STH = $pdo->prepare("INSERT INTO `money__actions` (date,shilings,author,type) values (:date, :shilings, :author, :type)");
        $STH->execute(array( 'date' => date("Y-m-d H:i:s"),'shilings' => '-100', 'author' => $_SESSION[id], 'type' => '23' ));

        include_once "../../../inc/notifications.php";
        send_noty($pdo, 'Вы купили возможность установки GIF аватара', $_SESSION[id], 2);

        exit(json_encode(array('status' => '1', 'data' => 'Успешная покупка')));
    }else{
        exit(json_encode(array('status' => '2', 'data' => 'Недостаточно денег на балансе')));
    }
}