<?php
// $Id: search.inc.php,v 1.3 2005/10/28 11:56:05 ohwada Exp $

// 2004-11-28 K.OHWADA
// write fair, delete unnecessary comments

// 2004/08/10 K.OHWADA
// enable to install this module two or more. 
// not use class weblinksLink

//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //

//=========================================================
// global search
// use class weblinksLink
// 2004/01/14 K.OHWADA
//=========================================================

// --- change function name ---
function weblinks_search($queryarray, $andor, $limit, $offset, $uid)
{
	global $xoopsDB;

// --- change dir name ---
	$MODULE_DIRNAME = 'weblinks';

	$table_link = $xoopsDB->prefix("{$MODULE_DIRNAME}_link");

	$where = '';
	if ( $uid != 0 ) 
	{	$where .= "uid=$uid ";	}

	if ( is_array($queryarray) && $count = count($queryarray) )
	{
		if ($where)  $where .= "AND ";
		$where .= "( search LIKE '%$queryarray[0]%' ";

		for ($i=1; $i<$count; $i++)
		{
			$where .= "$andor ";
			$where  .= "search LIKE '%$queryarray[$i]%' ";
		}
		$where .= ") ";
	}

	$sql = "SELECT * FROM $table_link WHERE $where ORDER BY time_update DESC";
	$result = $xoopsDB->query($sql, $limit, $offset);

	$ret = array();
	$i = 0;

	while( $row = $xoopsDB->fetchArray($result) )
	{
		$ret[$i]['link']  = "singlelink.php?lid={$row['lid']}";
		$ret[$i]['title'] = $row['title'];
		$ret[$i]['time']  = $row['time_update'];
		$ret[$i]['uid']   = $row['uid'];
		$ret[$i]['image'] = "images/home.gif";
		$i++;
	}

	return $ret;
}
?>
