<?php

/* DCMS Special
 * Дата последнего редактирования 10.10.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}

if (isset($_POST['search'])) {
    $_SESSION['search_'] = $_POST['search'];
}

if (!isset($_SESSION['search_'])) {
    $_SESSION['search_'] = NULL;
} else {
    $search_text = stripcslashes(htmlspecialchars($_SESSION['search_']));
}

include 'inc/config.php';

$set['title'] = $search_name;

include_once H . 'sys/inc/thead.php';

aut();
err();

echo "<div class='list-group-item-null'><i class='fa fa-search fa-fw'></i> ";
if (isset($_GET['search'])) {
    echo "<a href='?'>$search_name</a>";
} else {
    echo $search_name;
}
echo "</div>";

if (isset($_GET['search']) && isset($search_text)) {
    $count = $db->super_query("SELECT COUNT(*) as count FROM `user` WHERE `id` <=> '" . $db->safesql($search_text) . "' OR `nick` like '%" . $db->safesql($search_text) . "%' OR (`ank_icq` <=> '" . $db->safesql($search_text) . "' AND `ank_icq` != '0') OR (`ank_city` = '" . $db->safesql($search_text) . "') OR (`ip` <=> '" . ip2long($search_text) . "' AND `ip` != NULL) OR `ank_mail` <=> '" . $search_text . "'");
    $people = $count['count'];
    $count = $db->super_query("SELECT COUNT(*) as count FROM `loads_list` WHERE `name` like '%" . $search_text . "%' OR `name` like '%" . translit($search_text) . "%' OR `name` like '%" . retranslit($search_text) . "%' OR `opis` like '%" . $search_text . "%' OR `opis` like '%" . translit($search_text) . "%' OR `opis` like '%" . retranslit($search_text) . "%'");
    $loads = $count['count'];
    $count = $db->super_query("SELECT COUNT(*) as count FROM `diary` WHERE `name` like '%" . $search_text . "%' OR `name` like '%" . translit($search_text) . "%' OR `name` like '%" . retranslit($search_text) . "%' OR `msg` like '%" . $search_text . "%' OR `msg` like '%" . translit($search_text) . "%' OR `msg` like '%" . retranslit($search_text) . "%'");
    $diary = $count['count'];
    $count = $db->super_query("SELECT COUNT(*) as count FROM `forum_themes` WHERE `name` like '%" . $search_text . "%' OR `description` like '%" . $search_text . "%'");
    $forum = $count['count'];

    echo "<div class = 'list-group-item-null list-group-item-grey'>" . lang('Вы ввели') . ": <b>" . toOutput($_SESSION['search_']) . "</b></div>";

    if ($_GET['search'] == 'people') {
        include 'inc/people.php';
    } elseif ($_GET['search'] == 'obmen') {
        include 'inc/obmen.php';
    } elseif ($_GET['search'] == 'diary') {
        include 'inc/diary.php';
    } elseif ($_GET['search'] == 'forum') {
        include 'inc/forum.php';
    } else {
        $i = 0;

        if ($people != 0) {
            echo '<div class="list-group-item-null">';
            echo "<a href='?search=people'><i class='fa fa-user fa-fw'></i> " . lang('Пользователи') . "</a> <span class='count'>$people</span>";
            echo '</div>';
            ++$i;
        }

        if ($loads != 0) {
            echo '<div class="list-group-item-null">';
            echo "<a href='?search=obmen'><i class='fa fa-folder fa-fw'></i> " . lang('Файлы') . "</a> <span class='count'>$loads</span>";
            echo '</div>';
            ++$i;
        }

        if ($diary != 0) {
            echo '<div class="list-group-item-null">';
            echo "<a href='?search=diary'><i class='fa fa-book fa-fw'></i> " . lang('Дневники') . "</a> <span class='count'>$diary</span>";
            echo '</div>';
            ++$i;
        }

        if ($forum != 0) {
            echo '<div class="list-group-item-null">';
            echo "<a href='?search=forum'><i class='fa fa-clipboard fa-fw'></i> " . lang('Форум') . "</a> <span class='count'>$forum</span>";
            echo '</div>';
            ++$i;
        }

        if ($i == 0) {

            echo "<form action='?search' method='post' class='list-group-item-null'>";
            echo "$search_opis<br />";
            echo "<input type='text' name='search' required value='" . stripcslashes(htmlspecialchars($_SESSION['search_'])) . "' placeholder='$placeholder' class='form-control'/><br />";
            echo "<button class='btn btn-success btn-sm'>$submit</button>";
            echo "</form>";

            echo '<div class="list-group-item-null list-group-item-info">';
            echo 'По запросу <b>' . $search_text . '</b> ничего не найдено =(';
            echo '</div>';
        }
    }
} else {

    echo "<form action='?search' method='post' class='list-group-item-null'>";
    echo "$search_opis<br />";
    echo "<input type='text' name='search' required value='" . stripcslashes(htmlspecialchars($_SESSION['search_'])) . "' placeholder='$placeholder' class='form-control'/><br />";
    echo "<button class='btn btn-success btn-sm'>$submit</button>";
    echo "</form>";
}

include_once H . 'sys/inc/tfoot.php';
