Просмотр файла modules/forum/search.php

Размер файла: 4.13Kb
<?php
/**********************************
*	@package: PerfCMS			  *
*	@year: 2012					  *
*	@author: Artas				  *
*	@link: http://perfcms.ru	  *
**********************************/

$locate = 'forum';
$title = $lang->word('search').' | '. $lang->word('forum');
require_once(SYS .'/view/header.php');
if(isset($_GET['q']) && mb_strlen($_GET['q']) >= 3 && $_GET['where'] == 'topics') {
	$search_r = $db->query("SELECT * FROM `forum_t` WHERE `name` LIKE '%".input($_GET['q'])."%'")->rowCount();
	$tpl->div('title', $lang->word('search_topics'));
	$tpl->div('menu', $lang->word('found').': <b>'.$search_r.'</b>');
	$pages = new Paginator($search_r, $ames);
	if($search_r == 0) { 
		$tpl->div('menu', $lang->word('not_found'));
	} else {
		$search_q = $db->query("SELECT * FROM `forum_t` WHERE `name` LIKE '%".input($_GET['q'])."%' LIMIT $start, $ames");
		while($search = $search_q->fetch()) {
			$search['name'] = str_replace(input($_GET['q']), '<b>'.input($_GET['q']).'</b>', $search['name']);
			echo '<div class="post">';
				if ($search['closed'] == 1 && $search['attach'] == 1) echo img('pin-closed.png');
				else if ($search['attach'] == 1) echo img('pin.png');
				else if ($search['closed'] == 1) echo img('topic_closed.png');
				else echo img('topic.png');	
				echo '<a href="/forum/topic'.$search['id'].'">'.$search['name'].'</a> ('. $db->query("SELECT id FROM `forum_pt` WHERE `topic_id` = '". $search['id'] ."'")->rowCount().')<a href="/forum/topic'. $search['id'] .'/?page=end">»</a>
			</div>';
		}
	$pages->view('/forum/search?q='.input($_GET['q']).'&where=topics&');
	}
$tpl->div('block',  NAV .' <a href="/forum/search">'. $lang->word('search') .'</a><br/>'.
					img('forum.png') .' <a href="/forum/">'. $lang->word('forum') .'</a><br/>'
					. HICO .'<a href="/">'. $lang->word('home') .'</a>');
require_once(SYS .'/view/footer.php');
exit;
} elseif(isset($_GET['q']) && mb_strlen($_GET['q']) >= 3 && $_GET['where'] == 'messages') {
	$search_r = $db->query("SELECT * FROM `forum_pt` WHERE `text` LIKE '%".input($_GET['q'])."%'")->rowCount();
	$tpl->div('title', $lang->word('search_messages'));
	$tpl->div('menu', $lang->word('found').': <b>'.$search_r.'</b>');
	$pages = new Paginator($search_r, $ames);
	if($search_r == 0) { 
		$tpl->div('menu', $lang->word('not_found'));
	} else {
		$search_q = $db->query("SELECT * FROM `forum_pt` WHERE `text` LIKE '%".input($_GET['q'])."%' ORDER BY time DESC LIMIT $start, $ames");
		while($search = $search_q->fetch()) {
			$search['text'] = str_replace(input($_GET['q']), '<b>'.input($_GET['q']).'</b>', $search['text']);
			echo '<div class="post">';
			$search_u = $db->query("SELECT * FROM `forum_t` WHERE `id` = '". $search['topic_id']."' LIMIT 1")->fetch();
			$search_i = $db->query("SELECT * FROM `forum_pt` WHERE `id` = '". $search['id']."' ORDER BY time ASC LIMIT 1")->fetch();
			echo ''. nick($search_i['user_id']).'<br/> '. output($search['text']).'<br/> [<small class="gray">'. rtime($search_i['time']).' / <a href="/forum/topic'. $search['topic_id'] .'/?page=end">'. $search_u['name'] .'</a> </small>]
		</div>';
		}
	$pages->view('/forum/search?q='.input($_GET['q']).'&where=messages&');
	}
$tpl->div('block',  NAV .' <a href="/forum/search">'. $lang->word('search') .'</a><br/>'.
					img('forum.png') .' <a href="/forum/">'. $lang->word('forum') .'</a><br/>'
					. HICO .'<a href="/">'. $lang->word('home') .'</a>');
require_once(SYS .'/view/footer.php');
exit;
}
$tpl->div('title', $lang->word('search').' | '. $lang->word('forum'));
echo '<div class="menu">'.$lang->word('enter_search_key').':<br/>
		<form action="/forum/search?" method="get">
		<input type="text" name="q" /><br/>
		'. $lang->word('where') .':<br/>
		<select name="where">
		<option value="topics">'.$lang->word('in_topics_names').'</option>
		<option value="messages">'.$lang->word('in_messages').'</option>
		</select><br/>
		<input type="submit" value="'. $lang->word('search') .'" />
		</form>
		</div>';
$tpl->div('block', img('forum.png') .' <a href="/forum/">'. $lang->word('forum') .'</a><br/>'
					. HICO .'<a href="/">'. $lang->word('home') .'</a>');
require_once(SYS .'/view/footer.php');
?>