<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#--------------------------------------------------------------------
	# $Id: resources.php3,v 1.28 2000/12/14 19:13:59 shevett Exp $
	#--------------------------------------------------------------------

	include "resutils.php3";

	# Load up the current statelist...

	$stq = db_query("select * from statelist where sl_login='$curruser' and sl_table='resources'");
	while ($std = db_fetch_array($stq)) {
		switch ($std[sl_flags]) {
			case 'A' : {
				$exp_accessories[$std[sl_column]] = 1;
				break;;
			}
			case 'C' : {
				$exp_children[$std[sl_column]] = 1;
				break;;
			}
			case 'S' : {
				$exp_slips[$std[sl_column]] = 1;
				break;;
			}
		}
	}

	# Okay, so we're looking at resources.  Show the top bar, highlighting which group we're in...

	# First, check the state
	
	echo "<tr bgcolor=$sys_col[back]>";
	echo "<td bgcolor=$sys_col[bglow]><table width=100% cellspacing=0 cellpadding=2><tr><td>";
	if ($state[resset]=="acc") {
		echo "<td bgcolor='$sys_col[bglow]' align=center><a href=\"nbrowse.php3?f_resset=res\">Resources</a></td>";
		echo "<td bgcolor='$sys_col[bghigh]' align=center><a href=\"nbrowse.php3?f_resset=acc\">Accessories</a></td>";
		$wstring = "where r_multi=1";
		if ($state[resazoom]) {
			$wstring = "$wstring and r_tag='$state[resazoom]'";
		}
	} else {
		echo "<td bgcolor='$sys_col[bghigh]' align=center><a href=\"nbrowse.php3?f_resset=res\">Resources</a></td>";
		echo "<td bgcolor='$sys_col[bglow]' align=center><a href=\"nbrowse.php3?f_resset=acc\">Accessories</a></td>";
		$wstring = "where r_multi=0";
		if ($state[resrzoom]) {
			$wstring = "$wstring and r_tag='$state[resrzoom]'";
		}
	}
	echo "</td></tr></table></td></tr>";
	
			
	$qstring = "select * from resources $wstring";
	LogIt("DEBUG","resources.php3","qstring is $qstring");
	$result = db_query("$qstring");
	if (! db_numrows($result)) {
		echo "<tr><td bgcolor='$sys_col[bghigh]' align=center>&nbsp;<p>No entries available.<p></td></tr>";
	}
	echo "<tr valign=top bgcolor=$sys_col[bghigh]>\n";
	echo "<td>";
	echo "<table bgcolor=$sys_col[bghigh]>";
	$colcount = 6;
	if (db_numrows($result) > 1) {
		echo "<tr bgcol=$sys_col[bgmed]>";
		echo "<th><font size=2>Tag</th>";
		echo "<th><font size=2>Manuf</th>";
		echo "<th><font size=2>Model</th>";
		echo "<th><font size=2>Desc</th>";
		echo "<th><font size=2>SerNum</th>";
		echo "<th><font size=2>Contact</th>\n";
		$eq = db_query("select elabel,eflags from eschema where etable='resources' and eflags like '%V%'");
		if (db_numrows($eq) > 0) {
			while ($erow=db_fetch_array($eq)) {
				echo "<th><font size=2>$erow[elabel]</th>";
				$colcount++;
			}
		}
		echo "</tr>";
	}

	$ShowResCounter = 0;
	$ShowResMax = ($prefs[opt_mxress]) ? $prefs[opt_mxress] : $sys_numshownress ;
	$ShowResAll = db_numrows($result);
	$ShowResBar = 0;

	$flipper=0;

	# Okay!  Here we go!

	while ($row=db_fetch_array($result)) {

		$print_row_tag = rawurlencode($row[r_tag]);

		if (($row[r_tag] == $state[resrzoom]) or ($row[r_tag]==$state[resazoom])) {
			ShowResource($row);
		} else {

			# Just like the other systems, now we're gonna display this row, time to 
			# start counting.

			$ShowResCounter++;

			$maxres = ($state[resset] == "res") ? $state[rrbgn] : $state[rabgn] ;
			if ($ShowResCounter < $maxres) {
				continue;
			}

			# have we reached the max yadda yadda

			if ($ShowResCounter > $ShowResMax + $maxres) {
				continue;
			}

			if ($flipper) {
				echo "<tr bgcolor=$sys_col[bgmed]>";
			} else {
				echo "<tr bgcolor=$sys_col[bgwhite]>";
			}
			$flipper = (! $flipper) ;
			echo "<td><font size=2>\n";
			if ($state[resset] == "res") {
				echo "<a href=\"nbrowse.php3?f_resrzoom=$print_row_tag\">";
			} else {
				echo "<a href=\"nbrowse.php3?f_resazoom=$print_row_tag\">";
			}
			echo "<img src=\"$sys_graphics/active-right.gif\" border=0>$row[r_tag]</a>\n";
			echo "</td>\n";
			echo "<td><font size=2>" . CheckEmpty($row[r_mctag], "&nbsp;") . "</td>";
			echo "<td><font size=2>" . CheckEmpty($row[r_model], "&nbsp;") . "</td>";
			echo "<td><font size=2>" . CheckEmpty($row[r_desc], "&nbsp;") . "</td>";
			echo "<td><font size=2>" . CheckEmpty($row[r_serno], "&nbsp;") . "</td>";
			echo "<td><font size=2>" . CheckEmpty($row[r_ctag], "&nbsp;") . "</td>";
			echo "</tr>";
		
			if ((($ShowResCounter == $ShowResMax + $maxres) || ($ShowResCounter == $ShowResAll)) && (! $ShowResBar)) {
				$ShowResBar=1;
				$ccount = SizeOf($cscol) + 2;
				$prevset = $ShowResCounter - (2 * $ShowResMax);
				echo "<tr></tr>\n";
 				echo "<tr valign=top>\n";
				echo "<td colspan=$colcount bgcolor=#cccccc align=center>";
				echo "<table width=100% bgcolor=#cccccc><tr align=top>";
				echo "<td width=33% align=left><font size=2>";
				if ($prevset < 0) { 
					$prevset = 0; 
				}
				$fname = ($state[resset] == "acc") ? "f_topares" : "f_toprres" ;
				if ($maxres > 0) {
					echo "<a href=\"nbrowse.php3?$fname=$prevset\">Prev ";
					echo "<img src=\"$sys_graphics/active-left.gif\" border=0 alt=\"Previous Set\"></a>";
				}
				echo "</td>";
				echo "<td width=33% align=center><font size=2>$maxres - $ShowResCounter displayed out of $ShowResAll</td>";
				$nextset = $ShowResCounter;
				echo "<td width=33% align=right><font size=2>";
				if ($ShowResCounter <> $ShowResAll) {
					echo "<a href=\"nbrowse.php3?$fname=$nextset\">";
					echo "<img src=\"$sys_graphics/active-right.gif\" border=0 alt=\"Next Set\"> Next</a> ";
				}
				echo "</td>";
				echo "</tr>";
				echo "</table></td></tr>";
				continue;
			}
		}
	}
	echo "</table>";
	echo "</td></tr>";

?>
