Файл: WM-Koder/downloads/search.php
Строк: 57
<?php
require '../system/sid.php';
require '../system/config.php';
include '../system/user.php';
whorm(0, 'fo');
include '../system/head.php';
include '../system/navigator.php';
$do = (isset($_GET['do'])) ? $_GET['do'] : NULL;
switch($do) {
default:
echo $div_title . 'Обменник' . $div_end .
$div_menu . '
<img src="../ico/up.gif" alt=""/> <a href="index.php?">Обменник</a>
' . $block . '
<b>Поиск</b><br/>
<a href="pop.php?">Популярные</a> |
<a href="new.php?">Новые</a>
' . $div_end;
if (isset($_GET['reload'])) {
// новый поиск
unset($_SESSION['Fsearch']);
header('Location: search.php?');
}
if (isset($_REQUEST['go'])) {
if (empty($_POST['Fsearch'])) $Fsearch = my_check($_POST['fo_search']);
if (empty($_SESSION['Fsearch'])) $_SESSION['Fsearch'] = $Fsearch;
$where = my_int($_POST['where']);
if ($where == 1) $_where = '`title`';
elseif ($where == 2) $_where = '`info`';
if (empty($_SESSION['Fwhere'])) $_SESSION['Fwhere'] = $_where;
if (empty($_SESSION['Fsearch'])) {
err('Поисковой запрос не введен!');
include '../system/foot.php';
exit();
}
// общее число найденых файлов
$s = mysql_result(mysql_query("SELECT COUNT(*) FROM `fo_files` WHERE $_where LIKE '%$_SESSION[Fsearch]%' AND `moder` = '0'"), 0);
$n = new navigator($s, 10, '?go&');
$view = mysql_query("SELECT DISTINCT `fo_pod`.*,
(SELECT COUNT(id) FROM `fo_files` WHERE `fo_files`.$_where LIKE '%$_SESSION[Fsearch]%' AND `fo_files`.`cat` = `fo_pod`.`id` AND `fo_files`.`rid` = `fo_pod`.`cid` AND `fo_files`.`moder` = '0') AS c FROM `fo_pod`
LEFT JOIN `fo_files`
ON (`fo_files`.`rid` = `fo_pod`.`cid`
AND `fo_pod`.`id` = `fo_files`.`cat`)
WHERE `fo_files`.`moder` = '0'
AND `fo_files`.$_where LIKE '%$_SESSION[Fsearch]%'
ORDER BY `fo_files`.`id` DESC {$n->limit}");
if ($s != FALSE) {
$i = 0;
echo 'Вы искали: <b>' . $_SESSION['Fsearch'] . '</b>
<a href="search.php?reload"><img src="../ico/delete.gif" alt=""/></a>' . $block;
while($a = mysql_fetch_assoc($view)) {
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo '<img src="../ico/dir.gif" alt=""/> <a href="search.php?do=result&p='.$a['id'].'">' . $a['title'] . '</a> (' . $a['c'] . ')' . $div_end;
}
echo $n->navi();
} else {
unset($_SESSION['Fsearch']);
echo 'По запросу ' . $Fsearch . ' ничего не найдено!<br/>';
}
}
echo '<FORM method="POST" action="search.php?">
<label>Найти:</label><br/>
<input type="text" name="fo_search"/>
<br/>
<label>Искать по:</label><br/>
<select name="where">
<option value="1">названию</option>
<option value="2">описанию</option>
</select>
<br/>
<input type="submit" name="go" value="Найти"/>
</FORM>';
break;
case result:
echo $div_title . 'Обменник' . $div_end .
$div_menu . '
<img src="../ico/up.gif" alt=""/> <a href="index.php?">Обменник</a>
' . $block . '
<b>Поиск</b><br/>
<a href="pop.php?">Популярные</a> |
<a href="new.php?">Новые</a>
' . $div_end;
$p = my_int($_GET['p']);
$empty = mysql_query("SELECT `id` FROM `fo_pod` WHERE `id` = '$p' LIMIT 1");
if (mysql_num_rows($empty) == FALSE) {
header('Location: search.php?');
die();
}
echo 'Вы искали: <b>' . $_SESSION['Fsearch'] . '</b>
<a href="search.php?reload"><img src="../ico/delete.gif" alt=""/></a>' . $block;
$s = mysql_result(mysql_query("SELECT COUNT(id) FROM `fo_files` WHERE $_SESSION[Fwhere] LIKE '%".$_SESSION['Fsearch']."%' AND `moder` = '0' AND `cat` = '$p'"), 0);
$n = new navigator($s, 10, '?do=result&');
$view = mysql_query("SELECT * FROM `fo_files` WHERE `moder` = '0' AND $_SESSION[Fwhere] LIKE '%".$_SESSION['Fsearch']."%' AND `cat` = '$p' ORDER BY `id` DESC {$n->limit}");
if ($s != FALSE) {
$i = 0;
while($a = mysql_fetch_assoc($view)) {
$ext = strtolower(end(explode('.', $a['url'])));
#######################
if ($ext == 'zip') $format = '<img src="img/zip.gif" alt="*"/> ';
elseif ($ext == 'rar') $format = '<img src="img/rar.gif" alt="*"/> ';
elseif ($ext == 'gz') $format = '<img src="img/gz.gif" alt="*"/> ';
elseif ($ext == 'tar') $format = '<img src="img/tar.gif" alt="*"/> ';
else $format = '<img src="img/unknown.gif" alt="*"/> ';
#######################
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo $format . ' <a href="info.php?i='.$a['id'].'">' . $a['title'] . '</a>' . $div_end;
}
} else {
echo $n->navi();
echo 'По запросу ' . $_SESSION['Fsearch'] . ' ничего не найдено!';
unset($_SESSION['Fwhere']);
unset($_SESSION['Fsearch']);
}
break;
}
include '../system/foot.php';
?>