<?php	
/* $Id: step_5.inc.php,v 1.15 2004/05/10 10:33:10 liedekef Exp $ */
if(!defined("SETUP_RUNNING")) die('Use index.php for running setup!');

require("../include/version.inc.php");

if (!defined("MODULE_TYPE_SPACER")) define('MODULE_TYPE_SPACER', 0);
if (!defined("MODULE_TYPE_CORE")) define('MODULE_TYPE_CORE', 1);
if (!defined("MODULE_TYPE_BASE")) define('MODULE_TYPE_BASE', 2);
if (!defined("MODULE_TYPE_NORMAL")) define('MODULE_TYPE_NORMAL', 3);

if (!isset($_SESSION["SETUP"]["modules"])) $_SESSION["SETUP"]["modules"] = array();
    
$dir = @opendir(ROOTPATH."/modules");
$modules = array();
while (($file = readdir($dir)) !== false) {
    if ($file!="." and $file!=".." and $file!="CVS") {
	if (file_exists(ROOTPATH."/modules/".$file."/definition2.xml")) {

	    $data = implode("",file(ROOTPATH."/modules/".$file."/definition2.xml"));
	    $data = substr($data,strpos($data,"<mgw>"));
	    $parser = xml_parser_create();
	    xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
	    xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
	    xml_parse_into_struct($parser,$data,$values,$tags);
	    xml_parser_free($parser);

	    $module = array();
	    foreach ($values as $value) {
		if (isset($value["tag"]) and isset($value["value"])) $module[$value["tag"]] = $value["value"];
	    }

	    if (isset($module["name"]) and isset($module["version"])) {
		$module["name"] = $module["name"];
		$module["version"] = $module["version"];
		$module["version_mtime"] = filemtime(ROOTPATH."/modules/".$file."/definition2.xml");
		$module["type"] = $module["module_type"];
		unset($module["module_type"]);
		$module["date"] = $module["date"];
		$module["author"] = isset($module["author"])?$module["author"]:"";
		$module["email"] = isset($module["email"])?$module["email"]:"";
		$module["description"] = isset($module["description"])?$module["description"]:"";
		$module["compatibility"] = isset($module["compatibility"])?$module["compatibility"]:"";
		$module['dependancies'] = isset($module['dependancy'])?$module['dependancy']:array();
		$module['secure'] = ((isset($module["secure"]) and $module["secure"]=="true")?1:0);

		if (!isset($module["type"])) $module["type"] = 3;

		/* just as a memory aid:
		 * [0] -> name
		 * [1] -> selected for installation
		 * [2] -> module type
		 * [3] -> dependancies
		 * [4] -> enable (enter into mgw_modules) after setup
		 * [5] -> description
		 * [6] -> version
		 * [7] -> version_mtime
		 * [8] -> date
		 * [9] -> author
		 *[10] -> email
		 *[11] -> compatibility
		 *[12] -> secure
		 */
		if ($module["type"]==MODULE_TYPE_BASE) {
		    if (!isset($_SESSION["SETUP"]["modules"][$module["name"]])) {
			$_SESSION["SETUP"]["modules"][$module["name"]] = array($module["name"],1,$module["type"],$module['dependancies'],1,$module['description'],$module["version"],$module["version_mtime"],$module["date"],$module["author"],$module["email"],$module["compatibility"],$module["secure"]);
		    }
		    $b_modules[$module["name"]] = $module;
		} elseif ($module["type"]==MODULE_TYPE_CORE) {
		    if (!isset($_SESSION["SETUP"]["modules"][$module["name"]])) {
			$_SESSION["SETUP"]["modules"][$module["name"]] = array($module["name"],1,$module["type"],$module['dependancies'],0,$module['description'],$module["version"],$module["version_mtime"],$module["date"],$module["author"],$module["email"],$module["compatibility"],$module["secure"]);
		    }
		    $b_modules[$module["name"]] = $module;
		}
	    }
	}
    }
}
closedir($dir);

if (isset($b_modules)) ksort($b_modules); else $b_modules = array();
$smarty->assign("b_modules", $b_modules);
?>
