<?php

/*
** DGS Search
** $Id: nav.php,v 1.3 2004/01/19 07:34:25 sella Exp $
** Copyright (c) 2000-2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

function nav($retVal, $sq, $timer) {
	global $config, $css, $lang, $data;

	$o = $sq['o'];
	$r = $sq['r'];
	$size = ($sq['s'] < 1) ? count($retVal) : $sq['s'];
	$target = $config['target'];

	if (!isset($config['script'])) {
		$installBase = $config['installBase'];
		$urlBase = $config['urlBase'];
		$siteBase = $config['siteBase'];
		$searchURL = explode($siteBase, $installBase);
		$searchURL = $urlBase . str_replace('\\', '/', $searchURL[1]) . '/search.php';
	} else {
		$searchURL = $config['script'];		
	}

	if ($size > 0) {
		printf("\t<DIV CLASS=\"%s\"> <!-- Display Module: nav -->\n\t\t<DL>\n\t\t\t<DT>\n\t\t\t\t%s: ", $css['nav'], $lang['resultPages']);
		$dispR = ($r == $config["maxResults"]) ? 0 : $r;
		$currPage = (int) (($o + $r) / $r);
		if ($currPage > 1)
			printf("<A CLASS=\"%s\" HREF=\"%s?q=%s&r=%d&o=%d&s=%d&function=%s&rand=%d\" TARGET=\"%s\">%s</A> ", $css['navLink'], $searchURL, $sq['encQ'], $r, $o - $r, $size, $data['function'], rand(0, getrandmax()), $target, $lang['prev']);
		$navSize = (int) ($size / $r) + 1;
		$underflow = ($currPage - 5 <= 0) ? $currPage - 5 : 0;
		$overflow = ($currPage + 5 >= ($navSize + 1)) ? ($currPage + 5 - ($navSize + 1)) : 0;
		$dx = $currPage - (7 + $overflow);
		$dy = $currPage + (5 - $underflow);
		for ($i = 0; $i < $navSize; $i++) {
			if ($i == 0 || ($i > $dx && $i < $dy) || $i + 1 == $navSize) {
				if ($currPage == $i + 1) {
					printf("<STRONG>%d</STRONG> ", $i + 1);
				} else {
					printf("<A CLASS=\"%s\" HREF=\"%s?q=%s&r=%d&o=%d&s=%d&function=%s&rand=%d\" TARGET=\"%s\">%d</A> ", $css['navLink'], $searchURL, $sq['encQ'], $dispR, $i * $dispR, $size, $data['function'], rand(0, getrandmax()), $target, $i + 1);
				}
			} else if ($i == 1 || $i + 2 == $navSize) {
					printf(".. ");
			}
		}
		if ($currPage <= (int) ($size / $r))
			printf("<A CLASS=\"%s\" HREF=\"%s?q=%s&r=%d&o=%d&s=%d&function=%s&rand=%d\" TARGET=\"%s\">%s</A> ", $css['navLink'], $searchURL, $sq['encQ'], $r, $o + $r, $size, $data['function'], rand(0, getrandmax()), $target, $lang['next']);
		printf("\n\t\t\t</DT>\n\t\t</DL>\n\t</DIV>\n");
	}
	return true;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/

?>
