<?php
//v1.8 www.exoops.info 2006/07 http://www.exoops.info/modules/newbb/viewtopic.php?topic_id=65&forum=9 <commit> http://www.milliondollarartistsad.com/community
//v1.7 www.exoops.info 2006/03 
// $Id: search.inc.php,v 1.6 2003/03/19 07:01:17 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
function ecal_search($queryarray, $andor, $limit, $offset, $userid) {
global $db;
$sql = "
	SELECT
	stamp,
	subject,
	description
	FROM ".$db->prefix("ecal")."
	WHERE
	valid = 'yes'
	";
if ( $userid != 0 ) {
	$sql2 = "SELECT uname FROM ".$db->prefix("users")." WHERE uid = '$userid'  ";
	$result2 = $db->query($sql2);
	list($username) = $db->fetchRow($result2);
	
	$sql .= " AND username = '$username' ";
}
// 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 ((subject LIKE '%$queryarray[0]%' OR description LIKE '%$queryarray[0]%' )";
	for ($i=1; $i<$count; $i++) {
		$sql .= " $andor ";
		$sql .= "(subject LIKE '%$queryarray[$i]%' OR description LIKE '%$queryarray[$i]%' )";
	}
	$sql .= ") ";
}
$sql   .= " ORDER BY stamp DESC";
$result = $db->query($sql, $limit, $offset);
$i = 0;
if ($result) {
	while ($myrow = $db->fetchArray($result)) {
	$date = strtotime($myrow['stamp']);
	$day = strftime("%d",$date);
	$month = strftime("%m",$date);
	$year = strftime("%Y",$date);
	
	$ret[$i]['image']   = "images/mini_calendar.gif";
	$ret[$i]['link']    = "display.php?day=$day&month=$month&year=$year";
	$ret[$i]['title']   = $myrow['subject'];
	$ret[$i]['content'] = $myrow['description'];
	$ret[$i]['time']    = strtotime($myrow['stamp']);
	$ret[$i]['uid']     = $userid;
	$i++;
	}
}
return $ret;
}
?>
