<?php
/* daCode
 * $Id: libdacode.php3,v 1.32 2001/07/21 21:28:45 penso Exp $
 */

// setcookie("id","",0,"/");

Function LoadClass($class,$opts="") {
	global $config;

	if ($class == 'Html') {
		$class .= $config->theme_name;
	}
//echo '<br>LoadClass:'.$class;

	//   First checks whether user overloaded this class
	if (defined('_'.$class.'Local')) {
		$class .= 'Local';
	}

	if (!isset($config->obj[$class]) || !is_object($config->obj[$class])) {
//echo ' ... loaded';
		if (empty($opts)) {
			$config->obj[$class] = new $class();
		} else {
			//  Warning: Do not remove quotes within parens here,
			//  otherwise it causes some memory leaks with PHP3
			$config->obj[$class] = new $class("$opts");
		}
	}
	return $config->obj[$class];
}

/*
This setup the langage that should be used depending of the preferences of
the browser
*/

//   Preload classes used by all documents
$config->obj = array();
$db = LoadClass("Db");
$config->obj['Db'] = $db;
$session = LoadClass("Session");
$config->obj['Session'] = $session;

/*$row = split(', ',$HTTP_ACCEPT_LANGUAGE);
$LANG="";
while(current($row)) {
	$cur = current($row);
	if (!empty($lang[$cur])) {
		$LANG   = $cur;
		break;
	}
	next($row);
}
if (empty($LANG))*/ $LANG = $config->defaultlang;

/* This is to activate the nospider */
if ($config->nospider) {
	$nospiderclass = new nospider();
	$nospiderclass->check();
}

//   Load Html derived classes for defined themes
reset($config->listofthemes);
while ($theme = each($config->listofthemes)) {
	$tmpl = $libdir."themes/".$theme[1]."/html.".$config->php;
	$tmpl_contrib = $libdir."themes/".$config->theme_subdir.$theme[1]."/html.".$config->php;
	if (file_exists($tmpl)) {
		include $tmpl;
	} elseif (file_exists($tmpl_contrib)) {
		include $tmpl_contrib;
	} else {
		$dft = $config->dft_prefs['theme'];
		include $libdir."themes/".$config->listofthemes[$dft]."/html.".$config->php;
	}
}

//   ... and local extensions
if (file_exists($libdir.'local') &&
	is_dir($libdir.'local')) {
	$handle=opendir($libdir.'local');
	while ($file = readdir($handle)) {
		if (is_file($libdir.'local/'.$file) &&
				ereg('\.'.$config->php.'$', $file)) {
			include $libdir."local/".$file;
		}
	}
	closedir($handle);
}

?>
