<?php

#Переделано для более простого сценария

function rekl($sel) {
    global $set;
    global $db;
    if ($sel == 3 && $_SERVER['PHP_SELF'] != '/index.php') {
        $sel = 4;
    }

    $q = mysql_query("SELECT * FROM `rekl` WHERE `sel` = '$sel' AND `time_last` > '" . time() . "' ORDER BY id ASC");
    while ($post = mysql_fetch_assoc($q)) {

        #Главная страница (меню)
        if ($sel == 2) {
            if ($post['dop_str'] == 1) {
                echo "<a" . (IS_WEB ? " target='_blank'" : null) . " href='http://$_SERVER[SERVER_NAME]/go.php?go=$post[id]' class='list-group-item-null list-group-item-success'> ";
            } else {
                echo "<a" . (IS_WEB ? " target='_blank'" : null) . " href='$post[link]' class='list-group-item-null list-group-item-success'> ";
            }
            if ($post['img'] == NULL) {
                echo "<i class='fa fa-$post[icon] fa-fw'></i> $post[name]";
            } else {
                echo "<img src='$post[img]' alt='$post[name]' />";
            }
            echo "</a>\n";
        }

        #Низ сайта (остальные)
        if ($sel == 3) {
            if ($post['dop_str'] == 1) {
                echo "<center><a" . (IS_WEB ? " target='_blank'" : null) . " href='http://$_SERVER[SERVER_NAME]/go.php?go=$post[id]' class='list-group-item-null list-group-item-success'> ";
            } else {
                echo "<center><a" . (IS_WEB ? " target='_blank'" : null) . " href='$post[link]' class='list-group-item-null list-group-item-success'> ";
            }
            if ($post['img'] == NULL) {
                echo "<i class='fa fa-$post[icon] fa-fw'></i> $post[name]";
            } else {
                echo "<img src='$post[img]' alt='$post[name]' />";
            }
            echo "</a></center>\n";
        }

        #Реклама под заголовком
        if ($sel == 1) {
            if ($post['dop_str'] == 1) {
                echo "<a" . (IS_WEB ? " target='_blank'" : null) . " href='http://$_SERVER[SERVER_NAME]/go.php?go=$post[id]' class='list-group-item-null list-group-item-success'> ";
            } else {
                echo "<a" . (IS_WEB ? " target='_blank'" : null) . " href='$post[link]' class='list-group-item-null list-group-item-success'> ";
            }
            if ($post['img'] == NULL) {
                echo "<i class='fa fa-$post[icon] fa-fw'></i> $post[name]";
            } else {
                echo "<img src='$post[img]' alt='$post[name]' />";
            }
            echo "</a>\n";
        }

        if ($sel == 4) {
            if ($post['dop_str'] == 1) {
                echo "<center><a" . (IS_WEB ? " target='_blank'" : null) . " href='http://$_SERVER[SERVER_NAME]/go.php?go=$post[id]' class='list-group-item-null list-group-item-success'> ";
            } else {
                echo "<center><a" . (IS_WEB ? " target='_blank'" : null) . " href='$post[link]' class='list-group-item-null list-group-item-success'> ";
            }
            if ($post['img'] == NULL) {
                echo "<i class='fa fa-$post[icon] fa-fw'></i> $post[name]";
            } else {
                echo "<img src='$post[img]' alt='$post[name]' />";
            }
            echo "</center></a>\n";
        }
    }
}
