<?php
require_once('system/func.php');
auth(); // Закроем от не авторизованных
$title = 'Сумка';
require_once('system/header.php');


$inv = mysql_result(mysql_query("SELECT COUNT(*) FROM `inv` WHERE `odeta` = 'net' AND `id_user` = '$myID'"), 0);

if ($inv > 1) {
    echo "<center><a class = 'bbtn mb5' href = '?c'>Продать все вещи  </a></center>";
}
if (isset($_GET['c'])) {
    echo "
<div class='header'>Продать все  ненужные вещи?<br>
<div class='btn_grey'><span class='cb_end'><span class='cb_ttl'><a  href = '?sale'><center>Да</div></span><span></a>
<div class='btn_grey'><span class='cb_end'><span class='cb_ttl'><a  href = '/inv'><center>Нет</div></span><span></a></div>
";
}


$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `inv` WHERE `odeta` = 'net' AND `id_user` = '$myID'"), 0);
$q = mysql_query("SELECT * FROM `inv` WHERE `odeta` = 'net' AND `id_user` = '$myID' ORDER BY `skill` DESC");

if ($k_post == 0) {
    echo "<div class='main_link center'><a href='/shop?act=shop?'>Купить вещи </a></div>";
} else {


    if (isset($_GET['sale'])) {
        while ($post = mysql_fetch_assoc($q)) {
            switch ($post['skill']) {
                case '0':
                    $cena = 100;
                    break;
                case '100':
                    $cena = 1000;
                    break;
                case '500':
                    $cena = 10000;
                    break;
                case '2500':
                    $cena = 25000;
                    break;
                case '5000':
                    $cena = 75000;
                    break;

            }

            $scena = $cena;

        }
        $_SESSION['msg'] = "Вы продали ненужные вещи  и получили " . ico('icons', 'gold.png') . "  $scena золота";

        //Кампания
        //if($campaign['id_camp'] == 1)
        //("UPDATE `campaign` SET `itemSell`='".($campaign['itemSell'] + $k_post)."' WHERE `id_user`='".$myID."'");
        //Задание
        $quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '13'"));
        $q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
        if ($q['last'] < time()) {
            mysql_query("update `quest_user` set `koll` = `koll`+'$k_post' where (`id` = '" . $q['id'] . "')");
        }


        mysql_query("DELETE FROM `inv` WHERE `id_user` = '" . ($user['id']) . "' AND `odeta` = 'net'  ");
        mysql_query("UPDATE `users` SET `gold` = `gold` + '" . $scena . "'  WHERE `id` = '" . ($user['id']) . "' ");
        header("Location: /inv ");
        exit;

    } else {

        while ($post = mysql_fetch_assoc($q)) {
            switch ($post['skill']) {
                case '0':
                    $color = '<font color="green">';
                    $bonus = 10;

                    break;
                case '100':
                    $color = '<font color="#1E90FF">';
                    $bonus = 20;
                    break;
                case '500':
                    $color = '<font color="violet">';
                    $bonus = 40;

                    break;
                case '2500':
                    $color = '<font color="gold"> ';
                    $bonus = 70;

                    break;

                case '5000':
                    $color = '<font color="Darkorange"> ';
                    $bonus = 100;

                    break;
            }

            echo div('wrapper');

            echo "<li><img src='/images/items/$post[tip]/$post[item].png' class='bord'><a href='/item/$post[id]'>";
            if ($post['bonus'] >= 0) {
                echo "  <span class='info' style='float:right;'>  $color [$post[bonus]/$bonus]</font></span>";
            }
            echo "<span class='item-" . skill($post['skill']) . "'><small>$color$post[name] </small></font>+ $post[smitch]</span></a></li>";
            $item_snars = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $myID . "' AND `tip` = '" . $post['tip'] . "' AND `odeta` = 'da'");
            $item_snars = mysql_fetch_array($item_snars);

            $param_1 = $item_snars['str'] + $item_snars['def'] + $item_snars['health'];
            $param_2 = $post['str'] + $post['def'] + $post['health'];
            if ($param_1 > $param_2) {
                $status = "<small><font color='red'>-" . ($param_1 - $param_2) . "</font> </small>";
            } elseif ($param_1 < $param_2) {
                $status = " <small><font color='lime'>+" . ($param_2 - $param_1) . "</font></small> ";
            }

            echo "<center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'><a href='/item/$post[id]?equipItem' >Надеть $status </div></span></span></a>";
            echo "</div>";


            switch ($post['skill']) {
                case '0':
                    $cena = 100;
                    break;
                case '100':
                    $cena = 1000;
                    break;
                case '500':
                    $cena = 10000;
                    break;
                case '2500':
                    $cena = 25000;
                    break;
                case '5000':
                    $cena = 75000;
                    break;

            }


        }
        $inv = mysql_result(mysql_query("SELECT COUNT(*) FROM `inv` WHERE `odeta` = 'net' AND `id_user` = '$myID'"), 0);


    }
}

require_once('system/footer.php');
?>