<?
	if (empty($INCL_MODULES)) {
	
	function get_module_list() {
		global $site_path;
		if (!empty($site_path)) {
			$mod_path = $site_path;
		} else if (file_exists("install") && is_dir("install")) {
			$mod_path = "./";
		} else if (file_exists("../install") && is_dir("../install")) {
			$mod_path = "../";
		}
		$mod_dirs = array();
		if ($dir = opendir($mod_path)) {
		    while (($file = readdir($dir)) !== false) {
		        if ($file != "." && $file != ".." && is_dir($mod_path . $file)) {
		            if (file_exists($mod_path . $file . "/install.phtml")) {
		            	$mod_dirs[] = $file;
		            }
		        }
		    }
		    closedir($dir); 
		}
		return $mod_dirs;
	}
	
	function init_modules() {
		// Include all module's site_vars files.
		$modules = get_module_list();
		foreach ($modules as $mod) {
			$p = "${mod}/incl_$mod.phtml";
			if (file_exists($p)) {
				@require_once($p);
			}
		}
	}
	
	function init_module_preinstall_hooks() {
		$modules = get_module_list();
		foreach ($modules as $mod) {
			$p = "${mod}/preinstall_$mod.phtml";
			if (file_exists($p)) {
				@require_once($p);
			}
		}
	}

	function init_module_postinstall_hooks() {
		$modules = get_module_list();
		foreach ($modules as $mod) {
			$p = "${mod}/postinstall_$mod.phtml";
			if (file_exists($p)) {
				@require_once($p);
			}
		}
	}

	$INCL_MODULES = 1;
	}
?>