<?php

/* DCMS Special
 * Дата последнего редактирования 05.02.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['people'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` <=> '" . mysql_real_escape_string($search_text) . "' OR `nick` like '%" . mysql_real_escape_string($search_text) . "%' OR (`ank_icq` <=> '" . mysql_real_escape_string($search_text) . "' AND `ank_icq` != '0') OR (`ank_city` = '" . mysql_real_escape_string($search_text) . "') OR (`ip` <=> '" . ip2long($search_text) . "' AND `ip` != NULL) OR `ank_mail` <=> '" . $search_text . "'"), 0);
    $count['obmen'] = mysql_result(mysql_query("SELECT 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) . "%'"), 0);
    $count['diary'] = mysql_result(mysql_query("SELECT 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) . "%'"), 0);
    $count['forum'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_themes` WHERE `name` like '%" . $search_text . "%' OR `description` like '%" . $search_text . "%'"), 0);

    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 ($count['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'>$count[people]</span>";
            echo '</div>';
            ++$i;
        }

        if ($count['obmen'] != 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'>$count[obmen]</span>";
            echo '</div>';
            ++$i;
        }

        if ($count['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'>$count[diary]</span>";
            echo '</div>';
            ++$i;
        }

        if ($count['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'>$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';
