<?php
//v1.8 www.exoops.info 2006/03
// 
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Pascal Le Boustouller
// Author Website : http://www.perso-search.com/e-xoopsien/
// Licence Type   : GPL
// ------------------------------------------------------------------------- //
function ann_search($queryarray, $andor, $limit, $offset, $userid){
	global $db;
	$sql = "SELECT lid,usid,title,date FROM ".$db->prefix("ann_annonces")." WHERE valid='Yes' AND date<=".time()."";
	if ( $userid != 0 ) {
		$sql .= " AND usid=".$userid." ";
	} 
	// because count() returns 1 even if a supplied variable
	// is not an array, we must check if $querryarray is really an array
	if ( is_array($queryarray) && $count = count($queryarray) ) {
		$sql .= " AND ((description LIKE '%$queryarray[0]%' OR title LIKE '%$queryarray[0]%')";
		for($i=1;$i<$count;$i++){
			$sql .= " $andor ";
			$sql .= "(description LIKE '%$queryarray[$i]%' OR title LIKE '%$queryarray[$i]%')";
		}
		$sql .= ") ";
	}
	$sql .= "ORDER BY date DESC";
	$result = $db->query($sql,$limit,$offset);
	$ret = array();
	$i = 0;
 	while($myrow = $db->fetchArray($result)){
		$ret[$i]['image'] = "images/cat/default.gif";
		$ret[$i]['link'] = "index.php?pa=viewannonces&lid=".$myrow['lid']."";
		$ret[$i]['title'] = $myrow['title'];
		$ret[$i]['time'] = $myrow['date'];
		$ret[$i]['uid'] = $myrow['usid'];
		$i++;
	}
	return $ret;
}
?>