<?php
// $Id: search.inc.php,v 1.1 2004/07/11 10:28:43 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

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

$sql = "
	SELECT
	storyid,
	uid,
	title,
	created,
	LEFT(hometext, 95) AS content
	FROM ".$db->prefix("stories")."
	WHERE
	published > 0
	AND
	published < ".time()."";

if ( $userid != 0 ) {
	$sql .= " AND 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 ((hometext LIKE '%$queryarray[0]%' OR bodytext LIKE '%$queryarray[0]%' OR title LIKE '%$queryarray[0]%')";
	for ($i=1; $i<$count; $i++) {
		$sql .= " $andor ";
		$sql .= "(hometext LIKE '%$queryarray[$i]%' OR bodytext LIKE '%$queryarray[$i]%' OR title LIKE '%$queryarray[$i]%')";
	}
	$sql .= ") ";
}

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

$i = 0;
if ($result) {
	while ($myrow = $db->fetch_array($result)) {
		$ret[$i]['image']   = "images/content.gif";
		$ret[$i]['link']    = "article.php?storyid=".$myrow['storyid']."";
		$ret[$i]['title']   = $myrow['title'];
		$ret[$i]['content'] = $myrow['content'];
		$ret[$i]['time']    = $myrow['created'];
		$ret[$i]['uid']     = $myrow['uid'];
		$i++;
	}
}
return $ret;
}
?>
