<?php

include_once('../../sys/inc/core.php');
include_once H . 'user/cover/inc/configs.php';
only_reg();
$result = array();
$result['error'] = false;
if (isset($_GET['cover_id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `profileCoversList` WHERE `id` = '" . intval($_GET['cover_id']) . "'"), 0)) {
    $cover = mysql_fetch_array(mysql_query("SELECT * FROM `profileCoversList` WHERE `id` = '" . intval($_GET['cover_id']) . "'"));
    if ($user['profileCover'] != intval($_GET['cover_id'])) {
        if ($user['money'] >= $cover['price']) {
            mysql_query("UPDATE `user` SET `profileCover` = '$cover[id]', `money` = '" . ($user['money'] - $cover['price']) . "' WHERE `id` = '$user[id]'");
            $result['coverSrc'] = '/style/covers/' . $cover['id'] . '.jpg';
        } else {
            $result['error'] = 'Вам не хватает ' . $sklon_balance_array[2];
        }
    } else {
        $result['error'] = 'Эта обложка уже установлена';
    }
} else {
    $result['error'] = 'Обложка не найдена';
}
header("Content-type: application/json");
echo json_encode($result);
?>