<?php
$title = $l = "Мои стикеры";
$lBack ="/stickers";
require(CORE . 'head.php');
?>
<div class="app-block">
    <?
    $quotes[] = '<img src="/template/icons/Stickers/1.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';
    $quotes[] = '<img src="/template/icons/Stickers/2.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';
    $quotes[] = '<img src="/template/icons/Stickers/3.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';
    $quotes[] = '<img src="/template/icons/Stickers/4.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';
    $quotes[] = '<img src="/template/icons/Stickers/5.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';
    $quotes[] = '<img src="/template/icons/Stickers/6.png" style="width: 100%;max-height: 170px;position: inherit;background-size: cover;border-radius: 10px;">';

    srand ((double) microtime() * 1000000);
    $random_number = rand(0,count($quotes)-1);
    echo "<div style='background-color: white;padding: 3px 3px 0;'>";
    echo ($quotes[$random_number]);
    echo"</div>";
    ?>
    <div class="list" style="border-bottom: 0">
        <div class="sw-block_">
            <div class="sw-cont sw-4">
                <div class="sw-item"><a href="?" class="sw-c">Магазин</a>
                </div>
                <div class="sw-item"><a href="?tab=new" class="sw-c">Новые</a>
                </div>
                <div class="sw-item"><a href="?tab=free" class="sw-c">Бесплатные</a>
                </div>
                <div class="sw-item"><a href="?tab=my" class="sw-c sw-act">Мои</a>
                </div>
            </div>
        </div>
    </div>
    <?php
    $getData = (array)DB::$pdo->query("
        SELECT b.*, s.cover, s.title, (SELECT CONCAT(IF(`info_first_name` = '', 'Имя', `info_first_name`), ' ', `info_last_name`)
        FROM `users` WHERE `id` = `s`.`id_user` LIMIT 1) as author
        FROM `stickers_buy` as b
        INNER JOIN `stickers_cat` as s ON s.id = b.id_cat
        WHERE b.`id_user` = ?
        ORDER BY s.`id` DESC
        ", [$user['id']])->fetchAll();
    if (count($getData) > 0) {

        $getDataNoHide = array_filter($getData, function($var){
            return (int)$var['hide'] === 0;
        });

        $getDataYesHide = array_filter($getData, function($var){
            return (int)$var['hide'] === 1;
        });

        foreach ($getDataNoHide as $item) {
            ?>
            <div class="stickers_item">
                <div class="stickers_thumb">
                    <img src="<?= filesServerStickers . $item['cover'] ?>" class="th_img">
                </div>
                <div class="stickers_body">
                    <div class="stickers_name"><?= $item['title'] ?></div>
                    <div class="stickers_author"><?= $item['author'] ?></div>
                    <div class="si_links">
                        <a href="/stickers/?tab=hide&amp;id=<?= $item['id'] ?>">Скрыть</a>
                    </div>
                </div>
            </div>
            <?
        }

        if(count($getDataYesHide) > 0) {
            ?><h4 class="slim_header">Неактивные</h4><?
            foreach ($getDataYesHide as $item) {
                ?>
                <div class="stickers_item">
                    <div class="stickers_thumb">
                        <img src="<?= filesServerStickers . $item['cover'] ?>" class="th_img">
                    </div>
                    <div class="stickers_body">
                        <div class="stickers_name"><?= $item['title'] ?></div>
                        <div class="stickers_author"><?= $item['author'] ?></div>
                        <div class="si_links">
                            <a href="/stickers/?tab=hide&amp;id=<?= $item['id'] ?>">Вернуть</a>
                        </div>
                    </div>
                </div>
                <?
            }
        }
    } else {
        ?>
        <div id="show_msg_box" class="service_msg_box">
            <div class="service_msg service_msg_null">У Вас еще нет стикеров.</div>
        </div>
        <?
    }
    ?>
</div>
