<?php
/* daCode http://www.dacode.org
 * htdocs/dacode.php3
 * Fabien Penso <penso@linuxfr.org>
 * $Id: dacode.php3,v 1.41 2001/07/22 22:27:20 barbier Exp $
 *
*/

	if (empty($topdir)) {
		$topdir = './';
	} elseif ($topdir[strlen($topdir)-1] != '/') {
		$topdir .= '/';
	}
	$libdir = $topdir.'../phplib/';
	$php_ext = 'php3';
	
	// Ensure class files are loaded only once
	if (!defined("DACODE_PHP3")) {
		define("DACODE_PHP3", "1");
		include $libdir."config.".$php_ext;

		//   Load variables
		$config = new Config();
		$config->version = "1.2.0";

		include $libdir."session.".$config->php;
		include $libdir."cal.".$config->php;
		include $libdir."html.".$config->php;
		include $libdir."utils.".$config->php;
		include $libdir."db".$config->sql_backend.'.'.$config->php;
		include $libdir."cache.".$config->php;
		include $libdir."fortunes.".$config->php;
 		include $libdir."hits.".$config->php;
		include $libdir."lang.".$config->php;
		include $libdir."nospider.".$config->php;
		include $libdir."users.".$config->php;
		include $libdir."sidebox.".$config->php;
		include $libdir."news.".$config->php;
		include $libdir."comments.".$config->php;
		include $libdir."board.".$config->php;
		include $libdir."messages.".$config->php;
		include $libdir."redirects.".$config->php;
		include $libdir."admin.".$config->php;
		include $libdir."poll.".$config->php;
		include $libdir."backends.".$config->php;
		include $libdir."search.".$config->php;
		include $libdir."webcam.".$config->php;
		include $libdir."tar.".$config->php;
		include $libdir."libdacode.".$config->php;
		include $libdir."tips.".$config->php;
		include $libdir."ldap.".$config->php;

		//   Disable magic quotes for SQL queries
		set_magic_quotes_runtime(0);

		//  1) Unescape POST variables when magic_quotes_gpc are
		//     set to On. GET vars are used in search engine.
		//     There is no need to check COOKIE vars.
		//  2) Some browsers add \r and \n to POST variables
		$post_vars = array ();
		if (is_array($HTTP_POST_VARS)) {
			reset($HTTP_POST_VARS);
			while(list($key, $val) = each($HTTP_POST_VARS)) {
				$key = trim($key);
				if (is_array($val)) {
					while(list($k2, $v2) = each($val)) {
						$v2 = trim($v2);
						if (get_magic_quotes_gpc())
							$v2 = stripslashes($v2);
						$val[$k2] = $v2;
					}
				} else {
					$val = trim($val);
					if (get_magic_quotes_gpc())
						$val = stripslashes($val);
				}
				$post_vars[$key] = $val;
			}
		}
		$HTTP_POST_VARS = $post_vars;

		//  Some scripts also need this variable
		$post_vars = array ();
		if (isset($table) && is_array($table)) {
			reset($table);
			while(list($key, $val) = each($table)) {
				$key = trim($key);
				$val = trim($val);
				if (get_magic_quotes_gpc())
					$val = stripslashes($val);
				$post_vars[$key] = $val;
			}
		}
		$table = $post_vars;

		//  GET
		$get_vars = array ();
		if (is_array($HTTP_GET_VARS)) {
			reset($HTTP_GET_VARS);
			while(list($key, $val) = each($HTTP_GET_VARS)) {
				$key = trim($key);
				$val = trim($val);
				if (get_magic_quotes_gpc())
					$val = stripslashes($val);
				$get_vars[$key] = $val;
			}
		}
		$HTTP_GET_VARS = $get_vars;


		/*
		 * This might be optimized I think :-)

		 	Seems buggy !

        if (eregi("^/$",$REQUEST_URI)) {
            $config->basehref="";
        } else {
            $tmp	= preg_replace("/^\//","",$REQUEST_URI);
            $tmp    = preg_replace("/^.*?$config->newsfile?\??\//i","",$tmp);
            $tmp    = preg_replace("/[^\/]*$/i","",$tmp);
            $tmp    = preg_replace("/[^\/]*\//i","../",$tmp);
            $config->basehref=$tmp;
        }
		//$config->basehref=$config->topdir;
		*/

	}
?>
