<?php

class module_text extends admin_module{

	function admin_panels(){
		$panels=array(array("add_text","Text hinzuf&uuml;gen","page_add"),array("edit_text","Text editieren","page_edit"),array("group_only","Textkategorien"),array("addcategory_text","Kategorie hinzuf&uuml;gen","tag_blue_add"),array("editcategory_text","Kategorie editieren","tag_blue_edit"));
		return $panels;
	}	
	
	function get_info(){
		$info["name"]="Textverwaltung";
		$info["file"]="text";
		$info["author"]="BeCast";
		$info["version"]="1.0.1";
		$info["url"]="http://www.becast.at";
		return $info;
	}	

	function install(){
		global $config, $db;
		$db->query("CREATE TABLE IF NOT EXISTS `" . $config["prefix"] . "article` (
		  `id` int(11) NOT NULL auto_increment,
		  `text` text NOT NULL,
		  `date` int(11) NOT NULL default '0',
		  `author` int(11) NOT NULL default '0',
		  `eid` int(11) NULL default NULL,
		  `edittime` int(11) NULL default NULL,
		  `menue` int(11) NOT NULL default '0',
		  `title` varchar(80) NOT NULL default '',
		  `url` varchar(120) NOT NULL,
		  `rightnavi` enum('false','true') NOT NULL,
		  `active` enum('true','false') NOT NULL,
		  PRIMARY KEY  (`id`),
		  KEY `author` (`author`),
		  KEY `menue` (`menue`),
		  KEY `eid` (`eid`)
		) ENGINE=MyISAM");
		
		$db->query("CREATE TABLE IF NOT EXISTS `" . $config["prefix"] . "article_categorys` (
		  `id` int(11) NOT NULL auto_increment,
		  `categoryname` varchar(80) NOT NULL default '',
		  `picture` varchar(80) NOT NULL default '',
		  `active` enum('true','false') NOT NULL,
		  PRIMARY KEY  (`id`),
		  KEY `active` (`active`)
		) ENGINE=MyISAM");
		
		
		$db->query("CREATE TABLE `" . $config["prefix"] . "article_category` (
		`a_id` int(11) NOT NULL,
		`c_id` int(11) NOT NULL,
		KEY `a_id` (`a_id`),
		KEY `c_id` (`c_id`)
		) ENGINE=MyISAM");
		
		$db->query("CREATE TABLE `" . $config["prefix"] . "article_menue` (
		`id` int(11) NOT NULL auto_increment,
		`sort` int(11) NOT NULL,
		`name` text NOT NULL,
		PRIMARY KEY  (`id`),
		KEY `sort` (`sort`)
		) ENGINE=MyISAM");
		
		mkdir ($_SERVER["DOCUMENT_ROOT"]."/catimages", 0777);
		return TRUE;
	}

	function uninstall(){
		global $config, $db;
		$db->query("DROP TABLE `" . $config["prefix"] . "article`");
		$db->query("DROP TABLE `" . $config["prefix"] . "article_categorys`");
		$db->query("DROP TABLE `" . $config["prefix"] . "article_category`");
		$db->query("DROP TABLE `" . $config["prefix"] . "article_menue`");
		@$this->recursive($_SERVER["DOCUMENT_ROOT"]."/catimages");
		return TRUE;
	}
	
	function recursive($dest){
		$list = array_diff(scandir($dest), array('.', '..'));
		foreach ($list as $value) {
			$file = $dest.'/'.$value;
			if (is_dir($file)) { 
			recursive($file);
			}else{
			unlink($file);
			}
		}
		return rmdir($dest);
	}
}

?>
