<?php

/* 
 *	W-AGORA
 *	-------
 *	$Id: index.php,v 1.17 2005/02/10 16:57:50 mdruilhe Exp $
 *	Usage:		main program
 *	Author:		Marc Druilhe <mdruilhe@w-agora.com>
 */	

	require ("globals.inc");

	if ( ALLOWS_INFOS_URL &&  isset($QUERY_STRING) && ( ($QUERY_STRING == 'about') || ($QUERY_STRING == 'info') )) {
		include "$inc_dir/misc_func.$ext";
		include "$inc_dir/wa_info.$ext";
		wa_info();
		exit;
	}

# --------------------------------------
# Initialize configuration file and site
# --------------------------------------
	if (empty($bn)) {
# No forum selected -> default to 'site' configuration
		$site = empty($site) ? "agora" : $site;
		
		$cfg_file = "${cfg_dir}/site_${site}.${ext}";
		$expnd = "all";
	} else {
		$bn=trim(basename($bn));
		$cfg_file = "${cfg_dir}/${bn}.${ext}";
	}
	

# read configuration for this forum
# ---------------------------------
	if (file_exists ("${cfg_file}")) {
		include ("$cfg_file");
	} else {
		include "init.inc";
		die (ERROR_NO_CONFIG_FILE . $cfg_file);
	}

	$action = @isset($HTTP_GET_VARS['action']) ? trim(basename($HTTP_GET_VARS['action'])) : 'list';
	
# set script to be invoked in the main frame/page
# -----------------------------------------------
	$main_url = "$action.${ext}?site=$site";
	
	if (!empty($bn)) {
		$main_url .= "&bn=$bn";
	}

	if (!empty($key)) {
		$main_url .= "&key=$key";
	}

	if (!empty($expnd)) {
		$main_url .= "&expnd=$expnd";
	}

# Frame stuff
# -----------
	if ($bn_frames) {
		?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"><?php
		$title = (isset($bn_title) ) ? "<head><title>$bn_title</title></head>" : "";
		$dir = (isset($bn_html_dir) ) ? $bn_html_dir : 'ltr';
		echo "<html lang=\"$lang\" dir=\"$dir\">\n$title\n";
		printf ("<frameset %s>\n", $bn_frameset);
		printf (" <frame %s src=\"%s\" name=\"header\">\n", $bn_frame1, "header.${ext}?site=$site&bn=$bn");
		printf (" <frame src=\"%s\" name=\"main\" frameborder=0>\n", $main_url);
		if ($bn_frame2) {
 			printf (" <frame %s src=\"%s\" name=\"footer\">", $bn_frame2, "footer.${ext}?site=$site&bn=$bn");
		}

		?><noframes><?php 
		$lynx=1;
		$frameset=1;
		$no_cookie=1;
		include "$bin_dir/$action.$ext";
		echo "</noframes>\n</frameset>\n</html>\n";
	} else {
		include "$bin_dir/$action.$ext";
	}

?>

