<?php
define('GCMS',true);
define('ROOT','../');
require_once (ROOT.'system/power.php');
$act = isset($_GET['act']) ? trim($_GET['act']) : false;
if ($aut) {
///Главная
$diz -> head('Поиск по форуму');
$diz -> title('Поиск по форуму');
if (!isset($_POST['submit'])) {
$msg.='<div class="fon">';
$msg .= '<form action="poisk.php" method="POST"><div>';
$msg .= 'Тип поиска:<br/><select name="tip"><option value="name">По темам</option><option value="text">В сообщениях</option></select><br/>';
$msg .= 'Запрос:<br/><input type="text" name="zap" value="" maxlength="40"/><br/>
<input type="submit" name="submit" value="Найти"/>
</div></form>';
$msg .= '</div><div class="levo">'.$diz -> img('back.png').'<a href="./">Форум</a></br>';
$msg .= ''.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
} else {
$diz -> head('результат поиска');
$zap = shit($_POST['zap']); 
if($_POST['tip']=='name')
{$coun = $db -> query("Select * FROM `forum_tems` WHERE `name` like '%".$zap."%'")-> fetch_assoc();}elseif($_POST['tip']=='text')
{$coun = $db -> query("Select * FROM `forum_posts` WHERE `text` like '%".$zap."%'")-> fetch_assoc();}

if($_POST['tip']=='name')
{$count = $db -> dbcount("COUNT(*)","forum_tems","`name` like '%".$zap."%'");}
elseif($_POST['tip']=='text')
{$count = $db -> dbcount("COUNT(*)","forum_posts","`text` like '%".$zap."%'");}

if ($coun > 0) {
if($_POST['tip']!='text'){
$sql = $db -> query("SELECT * FROM `forum_tems` WHERE `name` like '%".$zap."%' ORDER BY `id` DESC");
while ($arr = $sql -> fetch_assoc()) {
$p = $db -> query("SELECT * FROM `forum_posts` WHERE `tema` = '".$arr['id']."'")-> fetch_assoc();
if($arr['status']==0){$status=$diz -> img('r.png');}
elseif($arr['status']==1){$status=$diz -> img('close.gif');}
$poster = $db -> dbcount('login','users',"`id` = '".(int)$p['user']."'");
$cid = $db -> dbcount('COUNT(`id`)','forum_posts'," `tema` = '".$arr['id']."'");
$msg .= '<div class="spisok">'.$status.' <a href="tema'.$arr['id'].'">'.$arr['name'].'</a>('.$cid.')
<a href="tema.php?id='.$arr['id'].'&amp;page='.$tot.'">>></a></div><a href="'.ROOT.'my/id'.$p['user'].'">'.$poster.'</a> ('.$func -> times(date('d m Y H:i:s',$p['time'])).')';
}
}else{
$sql = $db -> query("SELECT * FROM `forum_posts` WHERE `text` like '%".$zap."%' ORDER BY `id` DESC");
while ($arr = $sql -> fetch_assoc()) {
$p = $db -> query("SELECT * FROM `forum_tems` WHERE `id` = '".$arr['tema']."'")-> fetch_assoc();
if($arr['status']==0){$status=$diz -> img('r.png');}
elseif($arr['status']==1){$status=$diz -> img('close.gif');}
$poster = $db -> dbcount('login','users',"`id` = '".$arr['user']."'");
$cid = $db -> dbcount('COUNT(`id`)','forum_posts');
$text = $func -> tags($func -> smiles($arr['text']));
$msg .= '<div class="spisok">'.$status.' <a href="tema'.$p['id'].'">'.$p['name'].'</a>('.$cid.')
<a href="tema.php?id='.$p['id'].'&amp;page='.$tot.'">>></a></div><a href="'.ROOT.'my/id'.$arr['user'].'">'.$poster.'</a> ('.$func -> times(date('d m Y H:i:s',$p['time'])).')</br>'.$text.'';
}
}
} else $msg.='<div class="fon">Ни чего не найдено,попробуйте уточнить запрос поиска!</div>';
$msg .= '<div class="levo">'.$diz -> img('back.png').'<a href="./poisk.php">Поиск по форуму</a></br>
'.$diz -> img('back.png').'<a href="./">Форум</a></br>';
$msg .= ''.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
    }
#####Копирайт#######
require_once (ROOT.'system/kopy.php');
$diz -> out($msg);
} else {
header('location: ../aut.php');
}
?>