<?php
define('NTOP', 1);
$title = 'Поиск сайта';
require_once('system/connect.php');
require_once('system/core.php');
require_once('system/function.php');
require_once('str/head.php');
switch($act){
default:
echo '<div class="topik">Введите слово поиска</div><div class="stat">';
		echo '<form action="search.php?act=view" method="POST">
		Текст поиска (max.50):<br />
		<input type="text" name="text" maxlength="50" /><br />
		Искать по:<br />
		<select name="type">
		<option value="id">ID</option>
		<option value="url">URL</option>
		<option value="about">Описанию</option>
		</select><br />
		Сортировать по:<br />
		<select name="sort">
		<option value="id">ID</option>
		<option value="hosts">Хостам</option>
		<option value="hits">Хитам</option>
		</select><br />
		<input name="search" type="submit" class="go" value="Искать" />
		</form></div>';
		break;
case 'view':
                echo '<div class="topik">Вывод результатов</div>';
		if(isset($_POST['search'])){
				$text = filter($_POST['text']);
				$order = filter($_POST['type']);
				$sort = filter($_POST['sort']);
				$error = '';
				if(empty($text) OR empty($order) OR empty($sort))
					{
						$error .= 'Ошибка! Не заполнены поля! <br/>';
					}
				if(mb_strlen($text) > 50)
					{
						$error .= 'Ошибка! Поле "Текст поиска" больше 50 символов! <br/>';
					}
				if(!empty($error))
					{
						echo '<div class="stat">';
						echo $error;
						echo '</div>';
					}
				else
					{
						$count = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `".$order."` LIKE '%".$text."%'"));
						if($count > 0)
							{
								$total=intval(($count-1)/$page_sait)+1; 
								$page=abs(intval($_GET['page'])); 
								if(empty($page) OR $page < 0)
									{
										$page = 1; 
									}
								if($page > $total)
									{
										$page = $total; 
									}
								$past=intval($count/$page_sait);  
$start=$page*$page_sait-$page_sait; 
$saits = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `".$order."` LIKE '%".$text."%' ORDER BY `".$sort."` DESC LIMIT ".$start.",".$page_sait."");
while($row = mysql_fetch_array($saits)){
if($row['id'] == $id){
$start++;
echo '<div class="topni">'.$start.'. <a href="/out.php?id='.$row['id'].'"><span class="site"><b><font color=red>'.$row['url'].'</font></b></span></a> <small>('.$row['hosts'].'/'.$row['hits'].'';
//echo ($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits']);
if($row['mem'] == 0){
echo')</small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo')</small> <img src="/images/d.gif" alt="*">';}
} else {
$start++;
echo '<div class="topni">'.$start.'. <a href="/out.php?id='.$row['id'].'"><span class="site">'.$row['url'].'</span></a> <small>('.$row['hosts'].'/'.$row['hits'].'';
//echo ($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits']);
if($row['mem'] == 0){
echo')</small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo')</small> <img src="/images/d.gif" alt="*">';}}
echo'<div class="info">'.$row['about'].'</div></div>';

}
navigation($count,$page_sait,$page,'/search.php?act=view&',$total);
							}
						else
							{
echo '<div class="stat">';
echo 'По вашему запросу ничего не найдено!<br/>';
echo '</div>';
}
}
} else {
				$count = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait`"));
				if($count > 0)
					{
						$total=intval(($count-1)/$page_sait)+1; 
						$page=abs(intval($_GET['page'])); 
						if(empty($page) OR $page < 0)
							{
								$page = 1; 
							}
						if($page > $total)
							{
								$page = $total; 
							}
						$past=intval($count/$page_sait);  
						$start=$page*$page_sait-$page_sait; 
$saits = mysql_query("SELECT * FROM `".$prefix."sait` ORDER BY `hosts` DESC LIMIT ".$start.",".$page_sait."");
while($row = mysql_fetch_array($saits)) {
if($row['id'] == $id){
$start++;
echo '<div class="topni">'.$start.'. <a href="/out.php?id='.$row['id'].'"><span class="site"><b><font color=red>'.$row['url'].'</font></b></span></a> <small>('.$row['hosts'].'/'.$row['hits'].'';
//echo ($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits']);
if($row['mem'] == 0){
echo')</small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo')</small> <img src="/images/d.gif" alt="*">';}
} else {
$start++;
echo '<div class="topni">'.$start.'. <a href="/out.php?id='.$row['id'].'"><span class="site">'.$row['url'].'</span></a> <small>('.$row['hosts'].'/'.$row['hits'].'';
//echo ($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits']);
if($row['mem'] == 0){
echo')</small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo')</small> <img src="/images/d.gif" alt="*">';}}
echo'<div class="info">'.$row['about'].'</div></div>';

}
						navigation($count,$page_sait,$page,'/search.php?act=view&',$total);
					}
				else
					{
						echo '<div class="stat">';
						echo 'Площадок нет! <br/>';
						echo '</div>';
					}
			}
break;
}
require_once('str/foot.php');
?>