<?php
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

/*
** DGS Search
** config.php written by James M. Sella
** Copyright (c) 2000-2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
// changed 24/6/2004 to search Site@school modules  Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: config.php,v 1.1 2006/10/03 08:54:49 fstuurman Exp $
*/

/* Change options below as needed. */
$config['debug'] = false; /* Displays a lot of slightly useful or annoying information. */
$config['maxResults'] = 999;
$database[0]['table'] = array (
	"$table_pages"
); /* The table in database to search. */

$database[0]['searchField'] = array (
	'name',
	'content'
); /* The fields to search. */

$database[0]['returnField'] = array (
	'id',
	'name',
	'content',
	'section'
); /* Fields returned from db. Can be used to sub into link, url and desc. */

$database[0]['link'] = '@1@'; /* The link used for results. */
$database[0]['url'] = $site_url . "index.php?section=@3@&page=@0@"; /* The URL used for display the data from your database. */
$database[0]['desc'] = array (
	'@2@.'
); /* The description to display. */

if ($sas_config['search_module_invisible'] == 0)
{
	$database[0]['select'] = " and invisible != 'yes'";
} /* Only search visible pages */

//get the module search options from the config table 
$result = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_name%'");
$result2 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_searchfield%' ORDER BY config_key");
$result3 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_returnfield%' ORDER BY config_key");
$result4 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_url%' ORDER BY config_key");
$result5 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_pageid%' ORDER BY config_key");
$result6 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_extra_select%' ORDER BY config_key");

$i = 0;
$k = 1;
while ($mod_list = mysql_fetch_array($result))
{
	$search_modules = explode(",", $mod_list[0]);
	$location = $search_modules[0];
	$module_table = $dbprefix . $search_modules[1];
	if ($site == "protected") /* if we are on protected area active bit */
	{
		$search_active = $search_modules[4];
	}
	else
	{
		$search_active = $search_modules[3];
	}

	if ($search_active == 1)
	{
		$result1 = mysql_query("SELECT name FROM $table_modules WHERE location = '$location'");
		$database[$k]['table'] = array (
			$module_table
		); /* The next table in database to search. */
		$database[$k]['searchField'] = explode(",", mysql_result($result2, $i)); /* The next fields to search. */
		$database[$k]['returnField'] = explode(",", mysql_result($result3, $i)); /* Fields returned from db. Can be used to sub into link, url and desc. */
		$database[$k]['link'] = '@1@'; /* The next link used for results. */
		$database[$k]['desc'] = array (
			'@2@.'
		); /* The description to display. */

		$pag_sec = explode(",", mysql_result($result5, $i));
		if ($site == "protected") /* if we are on protected area use other page and section id */
		{
			$sectionid = $pag_sec[2];
			$pageid = $pag_sec[3];
		}
		else
		{
			$sectionid = $pag_sec[0];
			$pageid = $pag_sec[1];
		}
		$options = mysql_result($result4, $i);
		$database[$k]['url'] = $site_url . "index.php?page=$pageid&section=$sectionid$options"; /* The URL used for display the data from your database for the next table. */
		$database[$k]['select'] = mysql_result($result6, $i); /* extra conditions for the search query*/

		if ($search_modules[2] == 1) /* Has the module a public field in the table?*/
		{
			if ($site == "protected") /* if we are on protected area add public = 1 to WHERE statement */
			{
				$database[$k]['select'] .= " AND public = 1";
			}
			else
			{
				$database[$k]['select'] .= " AND public = 0";
			}
		}
	}
	$i++;
	$k++;
}
//
?>