<?php
require_once 'inc/core.php'; //ядро
$title = 'Поиск - Каталог сайтов';
require_once $inc.'head.php';
$page = 'search';
if (!empty($_REQUEST['search']))
{
$search = textEdit($_REQUEST['search'],64,true,false);
$search = preg_replace("/[^\w\x7F-\xFF\s]/", " ", $search);
$search = ereg_replace("[ ]+", " ", $search);
$t = (!empty($_REQUEST['t']) ? abs(intval($_REQUEST['t'])) : 0);
}
echo '<div class="nav"><b>Поиск</b></div>
<form action="'.$path.'search.php" class="list1" method="post">
Что ищем?<br/><input type="text" name="search" maxlength="64" value="'.@$search.'"/><br />
<input type="radio" name="t" value="0"' . (empty($t) || !empty($t) == 0 ? ' checked="checked"' : '') . '/> Искать в описании<br />
<input type="radio" name="t" value="1"' . (!empty($t) == 1 ? ' checked="checked"' : '') . '/> Искать в названии<br />
<input type="radio" name="t" value="2"' . (!empty($t) == 2 ? ' checked="checked"' : '') . '/> Искать в ссылке
<br/><input type="submit" name="submit" value="Искать" />
</form>';
if (!empty($search))
{
switch ($t)
{
case 2: $pole = 'link'; break;
case 1: $pole = 'name'; break;
default: $pole = 'opis';
}
$N=new N('SELECT COUNT(*) FROM `site` WHERE `'.$pole.'` LIKE "%'.$search.'%"',$onPage,'','?');
if($N->post)
{
$res=mysql_query("SELECT * FROM `site` WHERE `$pole` LIKE '%".$search."%' LIMIT ".$N->limit.";");
$i = ($N->page * $onPage - $onPage)+1;
if (mysql_num_rows(mysql_query("SELECT `id` FROM `search` WHERE `search` = '$search';")) == 0)
$insert = mysql_query("INSERT INTO `search` SET `search` = '$search', `t` = '$t', `date` = '$realtime';");
echo '<div class="nav">Найдено: '.$N->post.'</div>';
while($searchData = mysql_fetch_assoc($res))
{
$div = ceil(ceil($i / 2) - ($i / 2)) == 0 ? 'list' : 'list1';
//выделяем найденое
if ($pole == 'name') $name = str_replace($search,'<u>'.$search.'</u>', $searchData['name']);
else $name = str_replace($search,'<i>'.$search.'</i>', $searchData['name']);
if ($pole == 'link') $link = str_replace($search,'<u>'.$search.'</u>', $searchData['link']);
else $link = str_replace($search,'<i>'.$search.'</i>', $searchData['link']);
if ($pole == 'opis') $opis = str_replace($search,'<u>'.$search.'</u>', $searchData['opis']);
else $opis = str_replace($search,'<i>'.$search.'</i>', $searchData['opis']);
echo '<div class="'.$div.'">';
echo $i.($_COOKIE['theme'] == 'web' ? '. ' : '').' <a href="'.$path.'out/'.$searchData['id'].'">'.$name.'</a>
<br/><b>Cсылка:</b> http://'.$link.'<br/><b>Описание:</b> '.$opis.'</div>';
++$i;
}
//вывод навигации
echo '<div class="rec"><div class="rec1">';
unset($N);
echo '</div></div>';
} else echo '<div class="theme"><b>Ничего не найдено((</b></div>';
}
$lastSearch = mysql_query("SELECT `search`,`t` FROM `search` ORDER BY `id` DESC LIMIT 5;");
if (mysql_num_rows($lastSearch) != 0)
{
echo '<div class="menuMenu"><img src="img/menuimg.png" />Перед Вами искали: ';
while ($resa = mysql_fetch_array($lastSearch)) echo '<a href="'.$path.'search.php?search='.$resa['search'].'">'.$resa['search'].'</a>, ';
echo '</div>';
}
require_once $inc.'foot.php';
?>