<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$str['mesto'] = 'Поиск';
$str['block'] = $set['site'].' / <a href="index.php">Форум</a> / Поиск';
include '../style/'.$style.'/head.php';
if(isset($_GET['in']) == 1)
{
$query = mysql_query("select * from `forum_topics` where `title` LIKE '%".protect($_GET['query'])."%' order by `id` limit ".$page.",".$set['str']."");
$total = mysql_result(mysql_query("select count(*) from `forum_topics` where `title` LIKE '%".protect($_GET['query'])."%'"),0);
if($total == 0)
{
     echo '<div class="forum1">Совпадений не найдено!</div>';
}
else
{
while($row = mysql_fetch_assoc($query))
{
    $i++;
    if($i%2)
    {
        echo '<div class="forum1">';
    }
    else
    {
        echo '<div class="forum2">';
    }
        echo '<img class="ico" src="../style/'.$style.'/ico/ftems.png" alt="" /> <a href="topic.php?id='.$row['id'].'">'.$row['title'].'</a></div>';
    if($total > $set['str'])
    {
        pages($page, $total, 'search.php?in='.int($_GET).'&amp;query='.protect($_GET['query']).'', $set['str']);
    }
}
}
}
if(isset($_GET['in']) == 2)
{
	$query = mysql_query("select * from `forum_posts` where `text` LIKE '%".protect($_GET['query'])."%' order by `id` limit ".$page.",".$set['str']."");
$total = mysql_result(mysql_query("select count(*) from `forum_posts` where `text` LIKE '%".protect($_GET['query'])."%'"),0);
if($total == 0)
{
     echo '<div class="forum1">Совпадений не найдено!</div>';
}
else
{
while($row = mysql_fetch_assoc($query))
{
    $i++;
    if($i%2)
    {
        echo '<div class="forum1">';
    }
    else
    {
        echo '<div class="forum2">';
    }
    $topic = mysql_fetch_assoc(mysql_query("select * from `forum_topics` where `id` = ".$row['id_topic'].""));
    echo '<img class="ico" src="../style/'.$style.'/ico/ftems.png" alt="" /> <a href="topic.php?id='.$topic['id'].'">'.$topic['title'].'</a></div>';
    if($total > $set['str'])
    {
        pages($page, $total, 'search.php?in='.int($_GET).'&amp;query='.protect($_GET['query']).'', $set['str']);
    }
}
}
}
echo '<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="new.php">Новые</a><br/>
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="index.php?act=search">Поиск</a>
</div>';
include '../style/'.$style.'/foot.php';
?>