<?
# Edit me to point to the config.php3 on your PC.
include "config.php3";
#----------------------------------------------------------------->
# Jan 28 2000
# Version: 0.5.2
# Website: http://mythreads.sourceforge.net
#
# Desc: Main script for maintaining a links database
#
#
# License: This code is released under the terms of the GNU GPL
# version 2 or later. Please refer to www.gnu.org for a copy
# of this license.
#
#----------------------------------------------------------------->

# main() : This function controls the script functions.
function main()
{
include("./lib/lib_main.php3");

	global $tpl, $HTTP_GET_VARS, $HTTP_POST_VARS, $admin_username, $admin_password,$add_link,$sug_category;

	DatabaseConnect();

	if (isset ($HTTP_GET_VARS[mode]))
	{
		if ($HTTP_GET_VARS[mode] == 'search')
		{	
		
		include("./lib/lib_search.php3");

		} 

		else if (eregi("(add_link|update_link|add_category)",$HTTP_GET_VARS[mode]))
		{		
			include("./lib/lib_addupdate.php3");
		}		
		else if ($HTTP_GET_VARS[mode] == 'admin')
		{	
			
			include("./lib/lib_admin.php3");
		} else {
			showMainPage();
		}
		
	}	 
	else if(isset ($HTTP_GET_VARS[count]))
	{
		countIt($HTTP_GET_VARS[count]);
	} 
	else if (isset ($HTTP_GET_VARS[category]))
	{	
	
	
  		# Get the content before showing the webpage
		$categories = viewPage($HTTP_GET_VARS[category]);
		$your_current_location = display_category($HTTP_GET_VARS[category]);
		$category_links = display_category_links($HTTP_GET_VARS[category], $HTTP_GET_VARS[view]);
		
		$searchFooter = Search_Footer();

		# Sets a few variables before we parse the HTML template
		
		$tpl->assign( array( ADD_LINK => "$add_link"."&category=$HTTP_GET_VARS[category]" ));
		$tpl->assign( array( SUG_CATEGORY => "$sug_category"."&category=$HTTP_GET_VARS[category]" ));
		$tpl->assign( array( SEARCH_FOOTER => $searchFooter ));
		$tpl->assign( array( SUB_CATEGORIES => $categories ));
		$tpl->assign( array( CATEGORY_LINKS => $category_links ));
		$tpl->assign( array( INFO => $your_current_location ));

		
		showStartTemplate();
				
	}
	
	else {
		showMainPage();
	}

} # End Main Function

function DatabaseConnect()
{
	global $database, $host, $username, $password;	
	
	if (!($mylink = mysql_connect( $host, $username, $password)))
	{
        	print  "<h3>could not connect to database</h3>\n";
        	exit;
    	}
    	mysql_select_db($database);
}



function showStartTemplate()
{
	global $tpl;

	$tpl->parse(start, array("start"));
	$tpl->FastPrint();
}




# Call the main function which controls everything
main();
?>

