<?

include_once "../SYSTEM/include/functions.php";

include_once "../SYSTEM/include/mysql.php";

include_once "../SYSTEM/include/param.php";

include_once "../SYSTEM/include/ban.php";

include_once "../SYSTEM/include/sess.php";

include_once "../SYSTEM/include/ban_2.php";

include_once "../SYSTEM/include/theme.php";

head();

echo "<div class=\"forum_navig\">\n";

echo "<a href=\"index.php\" title=\"В форум\">Вернуться в форум</a>\n";

echo "</div>\n";



$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 `forum_p` WHERE `msg` 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 `forum_p` WHERE `msg` like '%".mysql_escape_string($q_search)."%' ORDER BY id DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_array($q))

{

$forum=mysql_fetch_array(mysql_query("SELECT * FROM `forum_f` WHERE `id` = '$post[id_f]' LIMIT 1"));

$razdel=mysql_fetch_array(mysql_query("SELECT * FROM `forum_r` WHERE `id` = '$post[id_r]' LIMIT 1"));

$them=mysql_fetch_array(mysql_query("SELECT * FROM `forum_t` WHERE `id` = '$post[id_t]' LIMIT 1"));

echo "<div class=\"post\">\n";

echo "<div class=\"post_title\">\n";

echo "<a href=\"index.php?fid=$forum[id]\" title=\"Подфорум\">$forum[name]</a>\n";

echo " &gt; ";

echo "<a href=\"index.php?fid=$forum[id]&amp;rid=$razdel[id]\" title=\"Раздел\">$razdel[name]</a>\n";

echo " &gt; ";

echo "<a href=\"index.php?fid=$forum[id]&amp;rid=$razdel[id]&amp;tid=$them[id]&amp;page=".(ceil($post['count']/$set['p_str']))."\" title=\"Тема\">$them[name]</a>\n";

echo "</div>\n";

echo "<div class=\"post_msg\">\n";

echo str_ireplace($search_a, $search_a2, trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['msg']))))))))."\n";

echo "</div>\n";

echo "</div>\n";



}



if ($k_page>1)str("search.php?go&amp;",$k_page,$page); // Вывод страниц

}

else echo "<div class=\"post\">\nВведите текст, который Вы хотите найти</div>\n";



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\" />\n";

echo "<input type=\"submit\" value=\"Поиск\" />\n";

echo "</form>\n";



foot();

?>

