<?php
// $Id: search.inc.php,v 1.1 2004/07/11 10:28:25 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

function newbb_search($queryarray, $andor, $limit, $offset, $userid) {
global $db;

$sql = "
	SELECT
	f.forum_id,
	p.post_id,
	p.topic_id,
	p.post_time,
	p.uid,
	p.subject,
	LEFT(p.post_text, 95) AS content
	FROM ".$db->prefix("bb_posts")." p
	INNER JOIN ".$db->prefix("bb_forums")." f ON f.forum_id = p.forum_id
	WHERE
	f.forum_type = 0";

if ( $userid != 0 ) {
	$sql .= " AND p.uid=".$userid." ";
}

// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
$count = count($queryarray);
if ( $count > 0 && is_array($queryarray) ) {
	$sql .= " AND ((p.subject LIKE '%$queryarray[0]%' OR p.post_text LIKE '%$queryarray[0]%')";
	for ($i=1; $i<$count; $i++) {
		$sql .= " $andor ";
		$sql .= "(p.subject LIKE '%$queryarray[$i]%' OR p.post_text LIKE '%$queryarray[$i]%')";
	}
	$sql .= ") ";
}

$sql   .= " ORDER BY p.post_time DESC";
$result = $db->query($sql, $limit, $offset);

$i = 0;
if ($result) {
	while ($myrow = $db->fetch_array($result)) {
		$ret[$i]['image']   = "images/info.gif";
		$ret[$i]['link']    = "viewtopic.php?topic_id=".$myrow['topic_id']."&amp;forum=".$myrow['forum_id']."#".$myrow['post_id']."";
		$ret[$i]['title']   = $myrow['subject'];
		$ret[$i]['content'] = $myrow['content'];
		$ret[$i]['time']    = $myrow['post_time'];
		$ret[$i]['uid']     = $myrow['uid'];
		$i++;
	}
}
return $ret;
}
?>
