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

	#----------------------------------------------------------------------
	# $Id: nbrowse.php3,v 1.112 2000/12/20 19:09:21 nclemons Exp $
	#----------------------------------------------------------------------
	
	#----------------------------------------------------------------------
	#		This is the heart of Keystone.  All brokering of functions are
	#		done via calls to this file.  Tread carefully when editing.
	#----------------------------------------------------------------------
	
	include "./conf/keystone.conf.default";
	if (file_exists("./conf/keystone.conf")) {
		include "./conf/keystone.conf";
	}

	include "./conf/colors.conf.default";
	if (file_exists("./conf/colors.conf")) {
		include "./conf/colors.conf";
	}

	include "./db.php3";
	$result = db_connect("");
	include "./utils.php3";
	include "./login.php3";
	LogIt("DEBUG","nbrowse.php","Ping. [f_func is '$f_func', f_process is '$f_process'] ");
	
	#
	# The end result of all this mishmash is that '$curruser' should
	# be set to whomever is logging in, and the cookie should be set
	# in the browser properly.  Authentication happens on every
	# login, etc etc.
	#
	if (($sys_refresh) && (! ereg("add",$f_func))) {
		$page_meta_html = "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"$sys_refresh ; URL=nbrowse.php3\">";
	}

        $page_title = "Keystone $sys_version";

        include "./header.php3";
?>
<font color="#FFFFFF">
<? 
	# ----------------------------------------------------------------
	# NBROWSE - main browse screen for Keystone
	# ----------------------------------------------------------------
	
	# 
	# Process form switches from previous update, if any.
	#

	# On occasion, we get odd $state states.  This just makes sure it doesn't 
	# happen.
	$state[mdataset]="blah";
	
	if (! empty($curruser)) {

		if (IsSet($f_minimize)) { 
			$uquery=db_query("delete from statelist where sl_login='$curruser' and sl_table='$f_minimize' and sl_flags!='FILT' and sl_column!='0'");
		} 

		if (IsSet($f_cancel)) {
			LogIt("DEBUG","nbrowse.php3","Cancelling (process was $f_process, func was $f_func)");
			if ($f_func == "medit") {
				LogIt("DEBUG","nbrowse.php3","Doing magic voodoo to exit maintenance stuff.");
				$f_mdataset="maint";
				unset($table);
			}
			if ($f_func == "addfilter") {
				LogIt("DEBUG","nbrowse.php3","Doing magic voodoo to exit filter stuff.");
				$f_mdataset="slips";
			}
			unset($f_process);
			unset($f_func);
		}

		if (IsSet($f_resset)) {
			$lastresult[0]=0;
			$lastresult[1]="Switched to $f_resset";
			$uquery=db_query("update state set resset='$f_resset' where uid='$curruser'");
		}
			
		if (IsSet($f_mslip)) {
			$lastresult[0]=0;
			$lastresult[1]="Toggled Slips";
			$uquery=db_query("update state set mslip=$f_mslip where uid='$curruser'");
		}
	
		if (IsSet($f_mcont)) {
			$lastresult[0]=0;
			$lastresult[1]="Toggled Contacts";
			$uquery=db_query("update state set mcont=$f_mcont where uid='$curruser'");
		}
	
		if (IsSet($f_mresource)) {
			$lastresult[0]=0;
			$lastresult[1]="Toggled Resources";
			$uquery=db_query("update state set mresource=$f_mresource where uid='$curruser'");
		}

		if (IsSet($f_mlibrary)) {
			$lastresult[0]=0;
			$lastresult[1]="Toggled Library";
			$uquery=db_query("update state set mlibrary=$f_mlibrary where uid='$curruser'");
		}
	
		if (IsSet($f_mdataset)) {
			$uquery=db_query("update state set mdataset='$f_mdataset' where uid='$curruser'");
		}
		
		if (IsSet($f_mother)) {
			$lastresult[0]=0;
			$lastresult[1]="Toggled Other";
			$uquery=db_query("update state set mother='$f_mother' where uid='$curruser'");
		}
		
		if (IsSet($f_filters)) {
			LogIt("DEBUG","nbrowse.php3","f_filters set to '$f_filters'");
			$uquery=db_query("update state set filters=$f_filters,sbgn=0 where uid='$curruser'");
		}
		
		if (IsSet($f_filtset)) {
			# The value in 'f_filtset' will be something like 'table:filterrow'.  So, split
			# the value, and update the statelist with the correct values.

			$pieces = explode(":",$f_filtset);
			$oq = db_query("delete from statelist where sl_login='$curruser' and sl_table='$pieces[0]' and sl_flags='FILT'");
			$nq = db_query("insert into statelist values ('$curruser','$pieces[0]','FILT','$pieces[1]')");
		}
			
		if (IsSet($f_slipzoom)) {
			# check to see if we were already zoomed.
			$check=db_query("select slipzoom from state where uid='$curruser'");
			$oldzoom=db_result($check,0,0);
			if ($oldzoom == $f_slipzoom) {
				$newval=0;
			} else {
				$newval=$f_slipzoom;
				$f_expand=$f_slipzoom;
				$f_sid=$f_slipzoom;
				$f_stflag='M';
			}
			$lastresult[0]=0;
			$lastresult[1]="Zoomed to slip # $f_slipzoom";
			$uquery=db_query("update state set slipzoom=$newval where uid='$curruser'"); 
		}
		
		if (IsSet($f_resazoom)) {
			$lastresult[0]=0;
			$lastresult[1]="Zoomed to resource # $f_resazoom";
			$uquery=db_query("update state set resazoom='$f_resazoom' where uid='$curruser'");
		}

		if (IsSet($f_resrzoom)) {
			$lastresult[0]=0;
			$lastresult[1]="Zoomed to resource # $f_resrzoom";
			$uquery=db_query("update state set resrzoom='$f_resrzoom' where uid='$curruser'");
		}

		if (IsSet($f_contzoom)) {
			# check to see if we were already zoomed.
			$check=db_query("select contzoom from state where uid='$curruser'");
			$oldzoom=db_result($check,0,0);
			if ($oldzoom == $f_contzoom) {
				$newval=0;
			} else {
				$newval=$f_contzoom;
				$f_expand=1;
				$f_contact=$f_contzoom;
			}
			$lastresult[0]=0;
			$lastresult[1]="Zoomed to contact $f_contzoom";
			$uquery=db_query("update state set contzoom='$newval' where uid='$curruser'");
		}
		
		if (IsSet($f_collapse)) {
			if (IsSet($f_sid)) {
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='slips' and sl_flags='$f_stflag' and sl_column='$f_collapse'");
			}
			if (IsSet($f_contact)) {
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='contacts' and sl_flags='$f_stflag' and sl_column='$f_contact'");
			}
			if (IsSet($f_resource)) {
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='resources' and sl_flags='$f_stflag' and sl_column='$f_resource'");
			}	
		}
		
		if (IsSet($f_expand)) {
	
			#		
			# What was the state table set to?
			#
			
			if (IsSet($f_sid)) {
				
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='slips' and sl_flags='$f_stflag' and sl_column='$f_sid'");
				$uquery = db_query("insert into statelist values ('$curruser','slips','$f_stflag','$f_sid')");

			}
		
			if (IsSet($f_resource)) {
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='resources' and sl_flags='$f_stflag' and sl_column='$f_resource'");
				$uquery = db_query("insert into statelist values ('$curruser','resources','$f_stflag','$f_resource')");
			} 
			
			if (IsSet($f_contact)) {
				$uquery = db_query("delete from statelist where sl_login='$curruser' and sl_table='contacts' and sl_flags='M' and sl_column='$f_contact'");
				$uquery = db_query("insert into statelist values('$curruser','contacts','M','$f_contact')");
			}
		}

		if (IsSet($f_topslip)) {
			$uquery = db_query("update state set sbgn=$f_topslip where uid='$curruser'");
		}
	
		if (IsSet($f_topcont)) {
			$uquery = db_query("update state set cbgn=$f_topcont where uid='$curruser'");
		}

		if (IsSet($f_topares)) {
			$uquery = db_query("update state set rabgn=$f_topares where uid='$curruser'");
		}
	
		if (IsSet($f_toprres)) {
			$uquery = db_query("update state set rrbgn=$f_toprres where uid='$curruser'");
		}
		
		# 
		# Right, that's done, pull current state info into vars.
		#
	
		$uquery = db_query("select * from state where uid='$curruser'");
		$state = db_fetch_array($uquery);

		# Well, we're in... better load the user defaults.

		$optq = db_query("select * from preferences where pr_uid='$curruser' and pr_table='$state[mdataset]'");
		while ($optd = db_fetch_array($optq)) {
			$prefs[$optd[pr_tag]] = $optd[pr_value];
		}

	}	

	#-------------------------------------------------------------------------
	# It doth occasionally happen that things need to be done _BEFORE_ the 
	# frame is drawn.  If there's an f_process that should happen before
	# the frame (usually something that is shown in the frame itself, such
	# as filters) then it should go here.  Make sure you don't also put it
	# in the big switch statement after the frame drawing.

	if (! empty($curruser)) {
		if (IsSet($f_process)) {
			switch ($f_process) {
				case "props" : {
					include "./properties.php3";
					break;;
				}
			}
		}
	}

	# End of pre-frame functions
	#-------------------------------------------------------------------------

FrameTop();

	echo "<tr valign=top>";
	echo "<td bgcolor=\"$sys_col[bordbg]\" width=\"10%\" nowrap>";

	#---------------------------------------------------------------------------------------
	# This section builds the 'slips' menu in the left toolbar.
	echo "<font size=2 color=\"$sys_col[bordfg]\">";
	$pre = ("$state[mdataset]" == "slips") ? "$sys_graphics/" : "$sys_graphics/in";
	if ($state[mslip]) {
		echo "<a href=\"nbrowse.php3?f_mslip=0\">";
		echo "<img src=\"${pre}active-down.gif\" valign=center border=0 alt=\"Collapse Slips menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=slips\"><font color=\"$sys_col[bordfg]\">Slips</font></a>";
		echo "<table width=\"100%\"><tr>";
		echo "<td>&nbsp;</td>";
		echo "<td nowrap>";
		echo "<font size=2 color=\"$sys_col[bordfg]\">";
		echo "<a href=\"nbrowse.php3?f_func=addslip\">";
		echo "<img src=\"${sys_graphics}/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Add Slip</font></a><br>";
		$lpre = ($f_func == "addlslip") ? "$sys_graphics/active-" : "$sys_graphics/"; 
		echo "<a href=\"nbrowse.php3?f_func=addlslip\">";
		echo "<img src=\"${lpre}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Add (Long)</font></a><br>";
		echo "<a href=\"nbrowse.php3?f_mdataset=slips&f_slipzoom=0\">";
		echo "<img src=\"${sys_graphics}/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Unzoom</font></a><br>";
		$pre3 = (($f_func == "props") && ($proptable == "slips")) ? "$sys_graphics/active-" : "$sys_graphics/";
		echo "<a href=\"nbrowse.php3?f_func=props&proptable=slips\">";
		echo "<img src=\"${pre3}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Properties</font></a><br>";
		if (($f_func == "reports") && ($reptable == slips)) {$rpre = "active-";}
		echo "<img src=\"$sys_graphics/${rpre}circle.gif\">";
		echo "<a href=\"nbrowse.php3?f_func=reports&reptable=slips\"><font color=\"$sys_col[bordfg]\">Reports</font></a><br>";
		echo "<a href=\"nbrowse.php3?f_mdataset=slips&f_slipzoom=0&f_minimize=slips\">";
		echo "<img src=\"${sys_graphics}/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Collapse All</font></a><br>";
		echo "</td>";
		echo "</tr>";
		echo "</table>";
	} else {
		echo "<a href=\"nbrowse.php3?f_mslip=1\">";
		echo "<img src=\"${pre}active-right.gif\" valign=center border=0 alt=\"Expand Slips menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=slips\"><font color=\"$sys_col[bordfg]\">Slips</font></a>";
		echo "<br>";
	} 
	#---------------------------------------------------------------------------------------
	# This section builds the 'contacts' menu in the left toolbar.

	$pre = ("$state[mdataset]" <> "contacts") ? "$sys_graphics/in" : "$sys_graphics/";
	if ($state[mcont]) {
		echo "<a href=\"nbrowse.php3?f_mcont=0\">";
		echo "<img src=\"${pre}active-down.gif\" border=0 alt=\"Collapse Contacts menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=contacts\">";
		echo "<font color=\"$sys_col[bordfg]\">Contacts</font></a>";
		echo "<table width=\"100%\"><tr>";
		echo "<td>&nbsp</td>";
		echo "<td nowrap>";
		echo "<font size=2>";
		echo "<a href=\"nbrowse.php3?f_func=addcont\">";
		echo "<img src=\"$sys_graphics/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Add Contact</a><br>";
		$pre3 = (($f_func == "props") && ($proptable=="contacts")) ?  "$sys_graphics/active-" : "$sys_graphics/";
		echo "<a href=\"nbrowse.php3?f_func=props&proptable=contacts\">";
		echo "<img src=\"${pre3}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Properties</a><br>";
		$rpre = (($f_func == "reports") && ($reptable == "contacts")) ? "active-" : "";
		echo "<img src=\"$sys_graphics/${rpre}circle.gif\">";
		echo "<a href=\"nbrowse.php3?f_func=reports&reptable=contacts\"><font color=\"$sys_col[bordfg]\">Reports</a><br>";
		echo "<a href=\"nbrowse.php3?f_mdataset=contacts&f_slipzoom=0&f_minimize=contacts\">";
		echo "<img src=\"${sys_graphics}/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Collapse All</a><br>";
		echo "</td>";
		echo "</tr>";
		echo "</table>";
	} else {
		echo "<a href=\"nbrowse.php3?f_mcont=1\">";
		echo "<img src=\"${pre}active-right.gif\" border=0 alt=\"Expand Contacts menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=contacts\"><font color=\"$sys_col[bordfg]\">Contacts</font></a>";
		echo "<br>";
	}
	#---------------------------------------------------------------------------------------
	# This section builds the 'Resources' menu in the left toolbar.
	$pre=("$state[mdataset]" <> "resources") ? "$sys_graphics/in" : "$sys_graphics/";
	if ($state[mresource]) { 
		echo "<a href=\"nbrowse.php3?f_mresource=0\">";
		echo "<img src=\"${pre}active-down.gif\" border=0 alt=\"Collapse Resources menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=resources\"><font color=\"$sys_col[bordfg]\">Resources</font></a>";
		echo "<table width=\"100%\"><tr>";
		echo "<td>&nbsp</td>";
		echo "<td nowrap>";
		echo "<font size=2>";
		echo "<a href=\"nbrowse.php3?f_func=addres\">";
		echo "<img src=\"$sys_graphics/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Add Resource</a><br>";
		if (($f_func == "props") && ($proptable=="resources")) {$pre3="$sys_graphics/active-";} else {$pre3="$sys_graphics/";}
		echo "<a href=\"nbrowse.php3?f_func=props&proptable=resources\">";
		echo "<img src=\"${pre3}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Properties</a><br>";
		echo "<a href=\"nbrowse.php3?f_process=unzoomres\">";
		echo "<img src=\"$sys_graphics/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Unzoom all</a><br>";
		echo "<img src=\"$sys_graphics/circle.gif\">";
		echo "<a href=\"nbrowse.php3?f_func=reports&reptable=resources\"><font color=\"$sys_col[bordfg]\">Reports</a><br>";
		echo "</td>";
		echo "</tr>";
		echo "</table>";
	} else { 
		echo "<a href=\"nbrowse.php3?f_mresource=1\">";
		echo "<img src=\"${pre}active-right.gif\" border=0 alt=\"Expand Resources menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=resources\"><font color=\"$sys_col[bordfg]\">Resources</font></a>";
		echo "<br>";
	}
	#---------------------------------------------------------------------------------------
	# This section builds the 'Library' menu in the left toolbar.
	$pre = ("$state[mdataset]" <> "library") ? "$sys_graphics/in" : "$sys_graphics/";
	if ($state[mlibrary]) {
		echo "<a href=\"nbrowse.php3?f_mlibrary=0\">";
		echo "<img src=\"${pre}active-down.gif\" border=0 alt=\"Collapse Library menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=library\"><font color=\"$sys_col[bordfg]\">Library</font></a>";
		echo "<table width=\"100%\"><tr>";
		echo "<td>&nbsp;</td>";
		echo "<td nowrap>";
		echo "<font size=2>";
		echo "<a href=\"nbrowse.php3?f_func=newattach\">";
		echo "<img src=\"$sys_graphics/circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Add</a><br>";
		echo "<img src=\"$sys_graphics/circle.gif\"><font color=\"$sys_col[bordfg]\">Report<br>";
		echo "</td>";
		echo "</tr>";
		echo "</table>";
	} else { 
		echo "<a href=\"nbrowse.php3?f_mlibrary=1\">";
		echo "<img src=\"${pre}active-right.gif\" border=0 alt=\"Expand Library menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mdataset=library\"><font color=\"$sys_col[bordfg]\">Library</font></a>";
		echo "<br>";
	}
			
	#---------------------------------------------------------------------------------------
	# This section builds the 'Library' menu in the left toolbar.
	$pre = ("$state[mdataset]" <> "other") ? "$sys_graphics/in" : "$sys_graphics/";
	if ($state[mother]) {
		echo "<a href=\"nbrowse.php3?f_mother=0\">";
		echo "<img src=\"${pre}active-down.gif\" border=0 alt=\"Collapse Other menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mother=0\"><font color=\"$sys_col[bordfg]\">Other</font></a>";
		echo "<table width=\"100%\"><tr>";
		echo "<td>&nbsp;</td>";
		echo "<td nowrap>";
		echo "<font size=2>";
		if (($state[mdataset] == "maint") AND ( ! IsSet($f_func))) {
			$pre1="$sys_graphics/active-";
		} else {
			$pre1="$sys_graphics/";
		}
		if ($f_func == "changepw") {$pre2="$sys_graphics/active-";} else {$pre2="$sys_graphics/";}
		if ($state[mdataset] == "filters") {$pre4="$sys_graphics/active-";} else {$pre4="$sys_graphics/";}
		if (Member("$curruser","admin")) {
			echo "<a href=\"nbrowse.php3?f_mdataset=maint\">";
			echo "<img src=\"${pre1}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Maint</a><br>";
		}
		echo "<a href=\"nbrowse.php3?f_func=changepw\">";
		echo "<img src=\"${pre2}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Password</a><br>";
		echo "<a href=\"nbrowse.php3?f_mdataset=filters\">";
		echo "<img src=\"${pre4}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Filters</a><br>";
		$pre5=($f_func == "statereset") ? "$sys_graphics/active-" : "$sys_graphics/";
		if ($sys_reset) {
			echo "<a href=\"nbrowse.php3?f_func=statereset\">";
			echo "<img src=\"${pre5}circle.gif\" border=0><font color=\"$sys_col[bordfg]\">Reset</a><br>";
		}
		echo "</td>";
		echo "</tr>";
		echo "</table>";
	} else { 
		echo "<a href=\"nbrowse.php3?f_mother=1\">";
		echo "<img src=\"$sys_graphics/inactive-right.gif\" border=0 alt=\"Expand Other menu\"></a>";
		echo "<a href=\"nbrowse.php3?f_mother=1\"><font color=\"$sys_col[bordfg]\">Other</font></a><br>";
	}
	echo "<a href=\"index.php3\"><img src=\"$sys_graphics/circle.gif\" border=0></a>";
	echo "<a href=\"index.php3\"><font color=\"$sys_col[bordfg]\">Logout</font></a><br>";

	#----------------------------------------------------------------------------
	# This little doodad shows the filter list under the menu in the frame.  Only
	# show it if the user has requested it in their properties screen.

	if ("$prefs[opt_filtpick]") {
		echo "<hr>";
		echo "<font color=\"$sys_col[bordfg]\"><i>Select filter:</i><br>";
		$fq = db_query("select * from filters where (uid='$curruser' or fpublic=1) and ftable='$state[mdataset]' order by fdesc");
		if (db_numrows($fq)) {
			echo "<a href=\"nbrowse.php3?f_filters=0\">";
			if ($state[filters]) {
				$graphic = "$sys_graphics/circle.gif";
				$wfilt = db_query("select sl_column from statelist where sl_table='$state[mdataset]' and sl_login='$curruser' and sl_flags='FILT'");
				$colid = (db_numrows($wfilt)) ? db_result($wfilt,0,0) : 0;
			} else {
				$graphic = "$sys_graphics/active-circle.gif" ;
			}
			echo "<img src=$graphic border=0><font color=\"$sys_col[bordfg]\">No filter</font><br></a>";
			while ($fqr = db_fetch_array($fq)) {
				echo "<a href=\"nbrowse.php3?f_filtset=$fqr[ftable]:$fqr[_rowid]&f_filters=1\">";
				$graphic = ($fqr[_rowid] == $colid) ? "$sys_graphics/active-circle.gif" : "$sys_graphics/circle.gif" ;
				echo "<img src=$graphic border=0>";
				echo "<font color=\"$sys_col[bordfg]\">";
				echo "$fqr[fdesc]</font></a><br>";
			}
		} else {
			echo "<font color=\"$sys_col[bordfg]\">";
			echo "No filters available.";
			echo "</font>";
		}
	}
	?>
	<hr>
	<form method=post action="nbrowse.php3">
	<font size=1><i>Jump to...</i><br>
	<input type=text size=10 name="f_slipzoom">
	</form>
	<form method=post action="nbrowse.php3">
	<font size=1><i>Search for...</i><br>
	<input type=hidden name="f_func" value="search">
	<input type=hidden name="f_flag" value="skip">
	<!-- FIXME: needs maxsize based on database query -->
	<input type=text size=10 name="f_search">
	</form>
</td>
<td>
	<table width="100%" cellspacing=0 border=0>
	<?
		if (empty($curruser)) {
			OpenMessage();
			echo "Not Logged In.<br>";
			if (! empty($logmsg)) {
				echo "($logmsg)<br>";
			}
			echo "<a href=\"index.php3\">Return to Login screen</a></font>";
			CloseMessage();
			$f_func="";
			$f_process="";
		}
		
		if (IsSet($f_func)) {
		
			# 
			# They've selected a specific function.  Show that in the main window.
			#
			
			switch ($f_func) {
				case "addacc" : {
					include "./accedit.php3";
					break;;
				}

				case "newattach" : {
					include "./addattach.php3";
					break;;
				}

				case "attachmenu" : {
					include "./attachmenu.php3";
					break;;
				}

				case "statereset" : {
					include "./reset.php3";
					break;;
				}

				case "addlslip" : {
					include "./addlong.php3";
					break;;
				}

				case "reports" : {
					include "./reports.php3";
					break;;
				}

				case "addradd" : {
					include "./addrmaint.php3";
					break;;
				}

				case "addredit" : {
					include "./addrmaint.php3";
					break;;
				}

				case "addphone" : {
					include "./phonemaint.php3";
					break;;
				}

				case "phonedit" : {
					include "./phonemaint.php3";
					break;;
				}

				case "search" : {
					include "./search.php3";
					break;;
				}
				case "props" : {
					include "./properties.php3";
					break;;
				}
				case "delcont" : {
					include "./delcontact.php3";
					break;;
				}
				case "modcont" : {
					include "./modcontact.php3";
					break;;
				}
				case "addcont" : {
					include "./addcontact.php3";
					break;;
				}
				case "sendmail" : {
					include "./genmail.php3";
					break;;
				}
				case "go_update" : {
					include "./update.php3";
					break;;
				}
				case "update" : {
					include "./update.php3";
					break;;
				}
				case "info" : {
					echo "<tr bgcolor=#FFFFFF>";
					echo "<td width=100% bgcolor=#999999 align=center>";
					phpinfo();
					echo "</td></tr>";
					break;;
				}
				case "addfilter" : {
					include "./addfilter.php3";
					break;;
				}
				case "modfilter" : {
					include "./addfilter.php3";
					break;;
				}
				case "delfilter" : {
					include "./delfilter.php3";
					break;;
				}
				case "addslip" : {
					include "./addslips.php3";
					break;;
				}
				case "delslip" : {
					include "./delslip.php3";
					break;;
				}
				case "closeslip" : {
					include "./closeslip.php3";
					break;;
				}
				case "modslip" : {
					include "./modslip.php3";
					break;;
				}
				case "modver" : {
					include "./modver.php3";
					break;;
				}
				case "addres" : { 
					include "./modres.php3";
					break;;
				}
				case "modres" : {
					include "./modres.php3";
					break;;
				}
				case "delres" : {
					include "./delres.php3";
					break;;
				}
				case "addfollow" : {
					include "./addfollow.php3";
					break;;
				}
				case "addchild" : {
					$parent=$sid;
					include "./addslips.php3";
					break;;
				}
				case "mbrowse" : {
					include "./mbrowse.php3";
					break;;
				}
				case "medit" : {
					include "./medit.php3";
					break;;
				}
				case "mdelete" : {
					include "./mdelete.php3";
					break;;
				}
				case "changepw" : {
					include "./changepw.php3";
					break;;
				}
				case "memedit" : {
					include "./memedit.php3";
					break;;
				}
			}
			
		} else {

			#
			# f_process switches which process to run befoire going back to whatever 
			# dataset we were wrking with before.  NOTE - if one of the process 
			#	functions does something that should NOT let the dataset browser
			#	kick in, set '$f_flag' to 'skip', and it will.
			#
			if (IsSet($f_process)) {
				switch ($f_process) {
					case "postver" : {
						include "postver.php3";
						break;;
					}
					case "addacc" : {
						include "accedit.php3";
						break;;
					}
					case "unzoomres" : {
						$uz = db_query("update state set resrzoom='0' where uid='$curruser'");
						$uz = db_query("update state set resazoom='0' where uid='$curruser'");
						$uquery = db_query("select * from state where uid='$curruser'");
						$state = db_fetch_array($uquery);
						break;;
					}
					case "statereset" : {
						include "./reset.php3";
						break;;
					}
					case "postattach" : {
						include "./postattach.php3";
						break;;
					}
					case "contphonesel" : {
						$ps = db_query("update phones set main=0 where tag='$f_contact'");
						$ps = db_query("update phones set main=1 where tag='$f_contact' and label='$f_label'");
					}
					case "contaddrsel" : {
						$ps = db_query("update addresses set main=0 where tag='$f_contact'");
						$ps = db_query("update addresses set main=1 where tag='$f_contact' and label='$f_label'");
					}
					case "addrpost" : {
						include "./addrpost.php3";
						break;;
					}
					case "phonepost" : {
						include "./phonepost.php3";
						break ;;
					}
					case "expaddr" : {
						$cq = db_query("insert into statelist values ('$curruser','contacts','A','$f_contact')");
						break;;
					}
					case "collapseaddr" : {
						$cq = db_query("delete from statelist where sl_login='$curruser' and sl_table='contacts' and sl_flags='A' and sl_column='$f_contact'");
						break;;
					}
					case "expphones" : {
						$cq = db_query("insert into statelist values ('$curruser','contacts','P','$f_contact')");
						break;;
					}
					case "collapsephones" : {
						$cq = db_query("delete from statelist where sl_login='$curruser' and sl_table='contacts' and sl_flags='P' and sl_column='$f_contact'");
						break;;
					}
					case "expcslips" : {
						$cq = db_query("insert into statelist values ('$curruser','contacts','S','$f_contact')");
						break;;
					}
					case "collapsecslips" : {
						$cq = db_query("delete from statelist where sl_login='$curruser' and sl_table='contacts' and sl_flags='S' and sl_column='$f_contact'");
						break;;
					}
					case "postcont" : {
						include "./postcontact.php3";
						break;;
					}
					case "sendmail" : {
						include "./genmail.php3";
						break;;
					}
#					case "props" : {
#						include "./properties.php3";
#						break;;
#					}
					case "postfilter" : {
						include "./postfilter.php3";
						break;;
					}
					case "delfilter" : {
						include "./delfilter.php3";
						break;;
					}
					case "postslip" : {
						include "./postslip.php3";
						break;;
					}
					case "postres" : {
						include "./postres.php3";
						break;;
					}
					case "postfoll" : {
						include "./postfoll.php3";
						break;;
					}
					case "delres" : {
						include "./delres.php3";
						break;;
					}
					case "closeslip" : {
						include "./closeslip.php3";
						break;;
					}
					case "delcont" : {
						include "./delcontact.php3";
						break;;
					}
					case "delslip" : {
						include "./delslip.php3";
						break;;
					}
					case "mpost" : {
						include "./mpost.php3";
						break;;
					}
					case "mdelete" : {
						include "./mdelete.php3";
						break;;
					}
					case "changepw" : {
						include "./changepw.php3";
						break;;
					}
					case "postmem" : {
						include "./memedit.php3";
						break;;
					}
				}
			}
	
			#
			# Need to select which dataset browser we're going to use.
			#

			if ($f_flag <> "skip") {
				switch ($state[mdataset]) {

					case "slips" 	:	{
						if ($prefs[opt_simpslips]) {
							include "./nslips.php3";
						} else {
							include "./slips.php3";
						}
						break;;
					}
			
					case "contacts" : 	{
						include "./contacts.php3";
						break;;
					}
				
					case "resources" : {
						include "./resources.php3";
						break;;
					}
					
					case "maint" : {
						include "./maintenance.php3";
						break;;
					}
					
					case "filters" : {
						include "./filters.php3";
						break;;
					}

					case "library" : {
						include "./library.php3";
						break;;
					}
				}				
			}
		}
	?>
	</table>
	<? FrameFoot() ?>
</table>

