<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko CMS
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	Class GekkoModule_Modules {
		function create_menu() {
			return false;
		}
		function configure() {
			$defmod = Conf::getKey("modules", "default", "blog", "string");

			$try = array($defmod, "blog", "pages", "categories");

			for ($i = 0; isset($try[$i]) && !file_exists(GEKKO_ROOT."modules/".$try[$i]);) {
				$defmod = isset($try[++$i]) ? $try[$i] : "";
			}

			Conf::setKey("modules", "default", $defmod, "string");
		}

		function install() {
			$GLOBALS["db"]->query("
			CREATE TABLE ".db_table("module")." (
				ID SMALLINT (8) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID),
				Module VARCHAR (64) NOT NULL,
				auth_Exec VARCHAR (255) NOT NULL,
				auth_Manage VARCHAR (255) NOT NULL,
				Modified INT (11) UNSIGNED NOT NULL,
				Hidden ENUM('0','1') NOT NULL default '0',
				Status ENUM('0','1') NOT NULL default '1'
			)
			",__FILE__, __LINE__, true);

			if (defined("IN-INSTALL")) {
				$GLOBALS["db"]->query("
					INSERT INTO ".db_table("module")." (
						ID, Module, auth_Exec, auth_Manage
					) VALUES (
						'{$GLOBALS["cgdb"]["modules"]}', 'modules', '#', '{$GLOBALS["cgdb"]["modules"]}'
					)
				",__FILE__, __LINE__, true);

				$GLOBALS["db"]->query("
					INSERT INTO ".db_table("module")." (
						ID, Module, auth_Exec, auth_Manage
					) VALUES (
						'{$GLOBALS["cgdb"]["conf"]}', 'conf', '#', '{$GLOBALS["cgdb"]["conf"]}'
					)
				",__FILE__, __LINE__, true);

			} else {
				modCore::registerModule($GLOBALS["cgdb"]["admin"], "admin", "#", $GLOBALS["cgdb"]["admin"]);
			}
		}
		function uninstall() {
			$GLOBALS["db"]->query("DROP TABLE IF EXISTS ".db_table("module"),__FILE__, __LINE__, true);
		}
		function upgrade($provided_v) {
			if (check_version("0.5.7", $provided_v) < 0) {
				$GLOBALS["db"]->query("ALTER TABLE ".db_table("module")."
				CHANGE COLUMN Status Status ENUM('0','1') NOT NULL default '1',
				CHANGE COLUMN Hidden Hidden ENUM('0','1') NOT NULL default '0'",
				__FILE__, __LINE__);
			}
		}
		function ext_uninstall($module) {

		}
	}

?>