<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/loads.php';
include_once '../sys/inc/user.php';



$set['title']='Обменник - Поиск файлов'; // заголовок страницы
include_once '../sys/inc/thead.php';
title();
aut();

$search=NULL;
if (isset($_SESSION['search']))$search=$_SESSION['search'];
if (isset($_POST['search']))$search=$_POST['search'];
$_SESSION['search']=$search;

$search=ereg_replace("( ){2,}"," ",$search);
$search=ereg_replace("^( ){1,}|( ){1,}$","",$search);



if (isset($_GET['go']) && $search!=NULL)
{
$search_a=explode(' ', $search);

for($i=0;$i<count($search_a);$i++)
{
$search_a2[$i]='<span class="search_c">'.stripcslashes(htmlspecialchars($search_a[$i])).'</span>';
$search_a[$i]=stripcslashes(htmlspecialchars($search_a[$i]));
}

$q_search=str_replace('%','',$search);
$q_search=str_replace(' ','%',$q_search);
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `name` like '%".mysql_escape_string($q_search)."%'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
if ($k_post==0)echo "<div class=\"post\">\nИзвините, по Вашему запросу ничего не найдено</div>\n";
$q=mysql_query("SELECT * FROM `obmennik_files` WHERE `name` like '%".mysql_escape_string($q_search)."%' ORDER BY `k_loads` DESC LIMIT $start, $set[p_str]");
$i=0;

echo "<table class='post'>\n";

while ($post = mysql_fetch_assoc($q))
{



$ras=strtolower(eregi_replace('^.*\.', NULL, $dirlist[$i]));
$name=eregi_replace('\.[^\.]*$', NULL, $dirlist[$i]);
if (is_file($dir_loads.'/'.$dirlist[$i].'.name'))
$name2=trim(esc(file_get_contents($dir_loads.'/'.$dirlist[$i].'.name')));
elseif (function_exists('iconv'))
$name2=iconv('windows-1251', 'utf-8', $name);
else $name2=$name;
$size=filesize($dir_loads.'/'.$dirlist[$i]);

echo "   <tr>\n";


$reww = mysql_fetch_array(mysql_query("SELECT * FROM `obmennik_files` WHERE `id` LIKE '".$post['id']."'"));
$redd = mysql_fetch_array(mysql_query("SELECT dir FROM `obmennik_dir` WHERE `id` LIKE '".$reww['id_dir']."'"));
//echo '<br/><img src="Категория: <a href="category/'.$_Result['id_kat'].'/">'.$_Category['name'].'</a><br />';

echo "  <td class='p_t'>\n";
echo "# <a href='/obmen".$redd['dir']."/".$post['name'].".".$post['ras']."?showinfo'>".$post['name']."</a>";
echo "  </td>\n";
echo "   </tr>\n";
echo "   <tr>\n";
include 'inc/opis_s.php';
//echo "  </td>\n";
echo "   </tr>\n";

$i++;
}
echo "</table>\n";
if ($k_page>1)str("search.php?go&amp;",$k_page,$page); // Вывод страниц
}
else
echo "Что будем искать? ;)";


echo "<form method=\"post\" action=\"search.php?go\" class=\"search\">\n";
$search=stripcslashes(htmlspecialchars($search));
echo "<input type=\"text\" name=\"search\" maxlength=\"64\" value=\"$search\" /><br />\n";
echo "<input type=\"submit\" value=\"Поиск\" />\n";
echo "</form>\n";
echo "<div class=\"foot\">\n";
echo "&laquo;<a href='/obmen/'>Обменник</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
?>