<?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 sw-act">Бесплатные</a>
                </div>
                <div class="sw-item"><a href="?tab=my" class="sw-c">Мои</a>
                </div>
            </div>
        </div>
    </div>
    <?php
    $getData = (array)DB::$pdo->query("
                SELECT s.*, (SELECT CONCAT(IF(`info_first_name` = '', 'Имя', `info_first_name`), ' ', `info_last_name`) 
                  FROM `users` WHERE `id` = `s`.`id_user` LIMIT 1) as author, 
                  (SELECT COUNT(id) FROM `stickers_buy` WHERE id_cat = s.id AND id_user = ? LIMIT 1) AS is_buy
                FROM `stickers_cat` as s
                 WHERE s.`price` = '0' AND s.`is_show` = '1'
                  ORDER BY s.`id` DESC
            ", [$user['id']])->fetchAll();
    if (count($getData) > 0) {
        foreach ($getData as $item) {
            ?>
            <a href="/stickers/?tab=show&amp;id=<?= $item['id'] ?>" 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="stickers_price">
                        <?php if((int)$item['is_buy'] === 0) { ?>
                            <span class="sp_str">бесплатно</span>
                        <?php } else { ?>
                            <span class="sp_str sp_added_str">Добавлен</span>
                        <?php } ?>
                    </div>
                </div>
            </a>
            <?
        }
    } else {
        ?>
        <div id="show_msg_box" class="service_msg_box">
            <div class="service_msg service_msg_null">Ожидайте поступление бесплатных стикеров.</div>
        </div>
        <?
    }
    ?>
</div>
