Location: PHPKode > projects > Lan Action > lanaction-0.6-rc1/include/module_header.php
<?php
/* $Id: module_header.php,v 1.20 2004/01/25 17:51:08 pbaecher Exp $ */
/*
          LanAction - PHP/MySQL Lan orga system
        ==============================================
            (c) 2002-2004 by
               Paul Baecher       <hide@address.com>
          Johannes Zuendel <joh-hide@address.com>

          This  program is  free  software;  you can
          redistribute it and/or modify it under the
          terms of the GNU General Public License as
          published by the Free Software Foundation;
          either  version 2 of  the License,  or (at
          your option) any later version.

        ==============================================

*/


/* =---- module flags ----= */
/* 1 unused (was adminonly) */
define('MOD_DIST', 2);						/* included in the main release of lanaction */
define('MOD_IGNORE_VER_MISMATCH', 4);		/* don't complain about api_vers mismatches */
define('MOD_GUESTONLY', 8);					/* DONT USE -- DEPRECATED */
define('MOD_NOGUESTS', 16);					/* DONT USE -- DEPRECATED */
define('MOD_NODELETE', 32);					/* module is not removeable - do not use */

/* =---- configuration array hashs ----= */
define('CFG_TYPE', 0);
define('CFG_DEF_VAL', 1);
define('CFG_DESC', 2);
define('CFG_VALUE', 3);

/* menu defines */
define('MENU_GUEST', 0);
define('MENU_USER', 1);
define('MENU_ORGA', 2);
define('MENU_ROOT', 2);

/* base class */
class module
{
	function module()
	{
		$this->init_cfg_data();
	}

	function info_value($key)
	{
		if( isset($this->a_info[$key]) )
			return $this->a_info[$key];
		else
			return 'n/a';
	}
	
	function init_cfg_data()
	{
		/* overwrite a_cfg with actual db values */
		$r_registry = query("SELECT keyname, value, type FROM ".PREF."registry WHERE module='".$this->info_value('unixname')."'");
		while( $registry = mysql_fetch_array($r_registry) )
		{
			$this->set_cfg_var($registry['keyname'], $registry['value']);
		}
		
		mysql_free_result($r_registry);
	}
	
	function set_cfg_var($key, $value)
	{
		$this->a_cfg[$key][CFG_VALUE] = $value;
	}
	
	function get_cfg_var($key)
	{
		return $this->a_cfg[$key][CFG_VALUE];
	}
	
	function register_cfg_var($key, $value, $type, $desc)
	{
		query("INSERT INTO ".PREF."registry (keyname, value, type, description, module) VALUES
			('".addslashes($key)."',
			'".addslashes($value)."',
			'".addslashes($type)."',
			'".addslashes($desc)."',
			'".addslashes($this->info_value('unixname'))."') ");
	}
	
	function unregister_cfg_var($key)
	{
		query("DELETE FROM ".PREF."registry WHERE module='".$this->info_value('unixname')."' AND keyname='".$key."'");
	}
	
	function install()
	{
		global $a_installedmod;
		
		if( isset($a_installedmod[$this->info_value('unixname')]) )
			return;

		/* make req_group */
		if( is_array($this->info_value('req_group')) )
		{
			foreach( $this->info_value('req_group') as $req_group )
			{
				$r_test_group = query("SELECT groupid FROM ".PREF."group WHERE groupname='".$req_group."'");
				if(!mysql_num_rows($r_test_group))

				{
					query("INSERT INTO ".PREF."group set
						groupname='".$req_group."',
						system='1',
						active='1'
					");
				}
			}
		}

		/* action stuff */
		$a_function = get_class_methods($this->info_value('unixname'));

		foreach($a_function as $function)
		{
			if( substr($function, 0, 6) == 'action' )
				query("INSERT INTO ".PREF."func set modulename='".$this->info_value('unixname')."', funcname='".$function."' ");
		}

		/* info_value('action') */
		foreach( $this->info_value('action') as $action_name => $action )
		{
			/* get funcid */
			$r_funcid = query("SELECT funcid FROM ".PREF."func
					WHERE modulename='".$this->info_value('unixname')."'
					AND funcname='".$action_name."'
			");
			list($funcid) = mysql_fetch_row($r_funcid);

			if($funcid)
			{
				/* set menu stuff*/
				if(isset($action['menu_name']))
				{
					$r_menu = query("SELECT MAX(displayorder) FROM ".PREF."menu");
					list($maxdisplayorder) = mysql_fetch_row($r_menu);

					query("INSERT INTO ".PREF."menu (funcid, title, location, displayorder) VALUES (
						'".$funcid."',
						'".addslashes($action['menu_name'])."',
						'".addslashes($action['menu_location'])."',
						'".($maxdisplayorder++)."'
					)");
				}

				/*set default_groups */
				if( is_array($action['default_group']) )
				{
					foreach( $action['default_group'] as $group_name )
					{
						$r_groupid = query("SELECT groupid FROM ".PREF."group WHERE groupname='".$group_name."' ");
						list($groupid) = mysql_fetch_row($r_groupid);

						if($groupid)
						{
							query("INSERT INTO ".PREF."funcgroup (funcid, groupid ) VALUES (
								'".$funcid."',
								'".$groupid."'
							)");
						}
					}
				}
			}
		}

		/*register cfg form module*/
		$a_cfg = $this->a_cfg;
		while( list($key, $data) = each($a_cfg) )
			$this->register_cfg_var($key, $data[CFG_DEF_VAL], $data[CFG_TYPE], $data[CFG_DESC]);

		/*set module installed*/
		query("INSERT INTO ".PREF."module (unixname) VALUES ('".$this->info_value('unixname')."')");
	}

	function uninstall()
	{
		global $a_installedmod;
		
		if( !isset($a_installedmod[$this->info_value('unixname')]) )
			return;

		$a_cfg = $this->a_cfg;

		while( list($key, $data) = each($a_cfg) )
			$this->unregister_cfg_var($key);

		/*access stuff*/
		$r_funcid = query("SELECT funcid FROM ".PREF."func WHERE modulename='".$this->info_value('unixname')."' ");
		while(list($funcid) = mysql_fetch_row($r_funcid))
		{
			/***************
			verändern, in  funcid IN ( "","","")
			***************/

			/* remove function */
			query("DELETE FROM ".PREF."func WHERE funcid='".$funcid."'");

			/*remove group settings */
			query("DELETE FROM ".PREF."funcgroup WHERE funcid='".$funcid."'");

			/* remove menu suff */
			query("DELETE FROM ".PREF."menu WHERE funcid='".$funcid."'");
		}

		/* remove req_group */
		if( is_array($this->info_value('req_group')) )
		{
			foreach( $this->info_value('req_group') as $req_group )
			{
				query("DELETE FROM ".PREF."group WHERE groupname='".$req_group."' ");
			}
		}

		/*unset module installed*/
		query("DELETE FROM ".PREF."module WHERE unixname='".$this->info_value('unixname')."'");
	}
}

?>
Return current item: Lan Action