<?php
class RCCWP_Application
{
	
	
	function GetWpCategories()
	{
		global $wpdb;
		//$sql = "SELECT cat_ID, cat_name FROM $wpdb->categories ORDER BY cat_name";

		if( $wpdb->terms != '' )
		{
			$sql = "SELECT t.term_id AS cat_ID, t.name AS cat_name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'category' ORDER BY t.name";
		}
		else
		{
			$sql = "SELECT cat_ID, cat_name FROM $wpdb->categories ORDER BY cat_name";
		}

		$results = $wpdb->get_results($sql);
		if (!isset($results))
			$results = array();
		return $results;
	}

	


	/**
	* Check whether this is wordpress mu and the logged in user is the top admin and it is the main blog
	*/
	function is_mu_top_admin(){
		global $wpdb;

		if ($wpdb->prefix != $wpdb->base_prefix.'1_') {
			return false;
		}

		return true;
	}

	/**
	* Import modules in default_modules folder
	*/
	function import_default_modules(){

		$modsFolder = dirname(__FILE__)."/default_modules/without_panel";
		if ($handle = opendir($modsFolder)) {
			while (false !== ($file = readdir($handle))) {
				if (is_file($modsFolder.'/'.$file))
					RCCWP_CustomWriteModule::Import($modsFolder.'/'.$file); 
			}
		}

		$modsFolder = dirname(__FILE__)."/default_modules/with_panel";
		if ($handle = opendir($modsFolder)) {
			while (false !== ($file = readdir($handle))) {
				if (is_file($modsFolder.'/'.$file))
					RCCWP_CustomWriteModule::Import($modsFolder.'/'.$file, false, true);
			}
		}

	}

	function ContinueInstallation(){
		//if (RCCWP_Application::IsWordpressMu()) {
			RCCWP_Application::SetCaps();
		//}
	}

	function SetCaps(){

		// Create capabilities if they are not installed
		if (!current_user_can(FLUTTER_CAPABILITY_PANELS)){
			$role = get_role('administrator');
			if (!(RCCWP_Application::IsWordpressMu()) || is_site_admin()){
				$role->add_cap(FLUTTER_CAPABILITY_PANELS);
				$role->add_cap(FLUTTER_CAPABILITY_MODULES);
			}
			$role->add_cap(FLUTTER_CAPABILITY_LAYOUT);
			$role->add_cap(FLUTTER_CAPABILITY_STYLE);
		}
	}

	function Install()
	{
		
		include_once('RCCWP_Options.php');
		global $wpdb;
	
		// First time installation
		if (get_option(RC_CWP_OPTION_KEY) === false){
	
			// Giving full rights to folders. 
			@chmod(FLUTTER_UPLOAD_FILES_DIR, 777);
			@chmod(FLUTTER_IMAGES_CACHE_DIR, 777);
			@chmod(FLUTTER_MODULES_DIR, 777);
			@chmod(FLUTTER_PURIFIER_CACHE_DIR, 777);
			
			//Initialize options
			$options['hide-write-post'] = 0;
			$options['hide-write-page'] = 0;
			$options['prompt-editing-post'] = 0;
			$options['assign-to-role'] = 0;
			$options['use-snipshot'] = 1;
			$options['enable-editnplace'] = 1;
			$options['enable-swfupload'] = 1 ;
			$options['default-custom-write-panel'] = "";
			if (version_compare(PHP_VERSION, '5.0.0') === 1)
				$options['enable-HTMLPurifier'] = 1;
			else
				$options['enable-HTMLPurifier'] = 0;
			$options['tidy-level'] = "medium";
			$options['canvas_show_instructions'] = 1;
			$options['canvas_show_zone_name'] = 0;
			$options['canvas_show'] = 1;
			$options['ink_show'] = 0;

			RCCWP_Options::Update($options);
			
		}
		
		

		// Check blog database
		if (get_option("RC_CWP_BLOG_DB_VERSION") == '') update_option("RC_CWP_BLOG_DB_VERSION", 0);
		
		if (get_option("RC_CWP_BLOG_DB_VERSION") < RC_CWP_DB_VERSION) 
			$BLOG_DBChanged = true;
		else
			$BLOG_DBChanged = false;
				
			
		// Install blog tables
		if (!$wpdb->get_var("SHOW TABLES LIKE '".RC_CWP_TABLE_POST_META."'") == RC_CWP_TABLE_POST_META ||
				$BLOG_DBChanged){	
			$blog_tables[] = "CREATE TABLE " . RC_CWP_TABLE_POST_META . " (
				id integer NOT NULL,
				group_count integer NOT NULL,
				field_count integer NOT NULL,
				post_id integer NOT NULL,
				field_name text NOT NULL,
				PRIMARY KEY (id) )" ;

			// try to get around
			// these includes like http://trac.mu.wordpress.org/ticket/384 
			// and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
			if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
				require_once(ABSPATH . 'wp-includes/pluggable.php');
			} else {
				require_once(ABSPATH . 'wp-includes/pluggable-functions.php');
			}
			require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
			
			foreach($blog_tables as $blog_table)
				dbDelta($blog_table);
		}
		canvas_install($BLOG_DBChanged);
		
		// Upgrade Blog
		if ($BLOG_DBChanged)	RCCWP_Application::UpgradeBlog();

				
		if (RCCWP_Application::IsWordpressMu()){	
			if (get_site_option("RC_CWP_DB_VERSION") == '') update_site_option("RC_CWP_DB_VERSION", 0);
			if (get_site_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) 
				$DBChanged = true;
			else
				$DBChanged = false;
		}
		else{
			if (get_option("RC_CWP_DB_VERSION") == '') update_option("RC_CWP_DB_VERSION", 0);
			if (get_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) 
				$DBChanged = true;
			else
				$DBChanged = false;
		}
		
		
		// -- Create Tables if they don't exist or the database changed
		if(!$wpdb->get_var("SHOW TABLES LIKE '".RC_CWP_TABLE_PANELS."'") == RC_CWP_TABLE_PANELS) 	$not_installed = true;

		if( $not_installed ||
			$DBChanged){ 

			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANELS . " (
				id int(11) NOT NULL auto_increment,
				name varchar(50) NOT NULL,
				description varchar(255),
				display_order tinyint,
				capability_name varchar(50) NOT NULL,
				type varchar(50) NOT NULL,
				PRIMARY KEY (id) )";
			
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " (
				id tinyint(11) NOT NULL auto_increment,
				name varchar(50) NOT NULL,
				description varchar(100),
				has_options enum('true', 'false') NOT NULL,
				has_properties enum('true', 'false') NOT NULL,
				allow_multiple_values enum('true', 'false') NOT NULL,
				PRIMARY KEY (id) )";
				
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_GROUP_FIELDS . " (
				id int(11) NOT NULL auto_increment,
				group_id int(11) NOT NULL,
				name varchar(50) NOT NULL,
				description varchar(255),
				display_order tinyint,
				display_name enum('true', 'false') NOT NULL,
				display_description enum('true', 'false') NOT NULL,
				type tinyint NOT NULL,
				CSS varchar(100),
				required_field tinyint,
				duplicate boolean NOT NULL,
				PRIMARY KEY (id) )";
				
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS . " (
				custom_field_id int(11) NOT NULL,
				options text,
				default_option text,
				PRIMARY KEY (custom_field_id) )";
			
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANEL_CATEGORY . " (
				panel_id int(11) NOT NULL,
				cat_id int(11) NOT NULL,
				PRIMARY KEY (panel_id, cat_id) )";
				
			/*$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_STANDARD_FIELDS . " (
				id int(11) NOT NULL AUTO_INCREMENT,
				name VARCHAR(50) NOT NULL,
				css_id VARCHAR(50) NOT NULL,
				default_inclusion ENUM('true', 'false') NOT NULL,
				advanced_field ENUM('true', 'false') NOT NULL,
				exclude_version float(11) NOT NULL,
				for_post ENUM('true', 'false') NOT NULL,
				PRIMARY KEY  (id)
				);";*/
			
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANEL_STANDARD_FIELD . " (
				panel_id int(11) NOT NULL,
				standard_field_id int(11) NOT NULL,
				PRIMARY KEY (panel_id, standard_field_id) )";
			
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES . " (
				custom_field_id int(11) NOT NULL AUTO_INCREMENT,
				properties TEXT,
				PRIMARY KEY (custom_field_id)
				);";
			
			/*$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANEL_HIDDEN_EXTERNAL_FIELD . " (
				panel_id int(11) NOT NULL,
				css_id varchar(50) NOT NULL,
				PRIMARY KEY (panel_id, css_id) )";*/
	
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_MODULES . " (
				id int(11) NOT NULL auto_increment,
				name varchar(50) NOT NULL,
				description text,
				PRIMARY KEY (id) )";
	
			$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANEL_GROUPS . " (
				id int(11) NOT NULL auto_increment,
				panel_id int(11) NOT NULL,
				name varchar(50) NOT NULL,
				duplicate boolean NOT NULL,
				at_right boolean NOT NULL,
				PRIMARY KEY (id) )";
	
			/*$qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANEL_MODULES . " (
				id int(11) NOT NULL auto_increment,
				panel_id int(11) NOT NULL,
				module_id int(11) NOT NULL,
				PRIMARY KEY (id) )";*/

			// try to get around
			// these includes like http://trac.mu.wordpress.org/ticket/384 
			// and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
			if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
				require_once(ABSPATH . 'wp-includes/pluggable.php');
			} else {
				require_once(ABSPATH . 'wp-includes/pluggable-functions.php');
			}
			require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
			
			foreach($qst_tables as $qst_table)
				dbDelta($qst_table);

			if (RCCWP_Application::IsWordpressMu()) {
					update_site_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
			}
			else{
					update_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
			}
		
		}

		// Insert standard fields definition
		if($not_installed){
		
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (1, 'Textbox', NULL, 'false', 'true', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (2, 'Multiline Textbox', NULL, 'false', 'true', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (3, 'Checkbox', NULL, 'false', 'false', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (4, 'Checkbox List', NULL, 'true', 'false', 'true')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (5, 'Radiobutton List', NULL, 'true', 'false', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (6, 'Dropdown List', NULL, 'true', 'false', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (7, 'Listbox', NULL, 'true', 'true', 'true')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (8, 'File', NULL, 'false', 'false', 'false')";
			$wpdb->query($sql6);
			
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (9, 'Image', NULL, 'false', 'true', 'false')";
			$wpdb->query($sql6);
	
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (10, 'Date', NULL, 'false', 'true', 'false')";
			$wpdb->query($sql6);
	
			$sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (11, 'Audio', NULL, 'false', 'false', 'false')";
			$wpdb->query($sql6);
			
			
			// -- Panel standard fields
			
			//$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (1, 'Title', 'titlediv', 'true', 'false', 1000)";
			//$wpdb->query($sql9);
			
			/*$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (12, 'Post/Page', 'postdivrich', 'true', 'false', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (2, 'Categories', 'categorydiv', 'false', 'false', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (3, 'Discussion', 'commentstatusdiv', 'true', 'true', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (4, 'Post Password', 'passworddiv', 'true', 'true', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (5, 'Post Slug', 'slugdiv', 'false', 'false', 2.5)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (6, 'Post Status', 'poststatusdiv', 'false', 'false', 2.5)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (7, 'Post Timestamp', 'posttimestampdiv', 'false', 'false', 2.5)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (8, 'Upload', 'uploading', 'false', 'false', 2.5)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (9, 'Optional Excerpt', 'postexcerpt', 'true', 'true', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (10, 'Trackbacks', 'trackbacksdiv', 'true', 'true', 1000)";
			$wpdb->query($sql9);
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (11, 'Custom Fields', 'postcustom', 'true', 'true', 1000)";
			$wpdb->query($sql9);
			
			
			
			$sql9 = "INSERT IGNORE INTO " . RC_CWP_TABLE_STANDARD_FIELDS . " VALUES (13, 'Post Author', 'authordiv', 'false', 'false', 2.5)";
			$wpdb->query($sql9);*/
		}
		
		// Upgrade Blog site
		if ($DBChanged) RCCWP_Application::UpgradeBlogSite();
		
		
		
		//Import Default modules 
		if (RCCWP_Application::IsWordpressMu()){
			if (get_site_option('FLUTTER_fist_time') == ''){
				RCCWP_Application::import_default_modules();
				update_site_option('FLUTTER_fist_time', '1');
			}
		}
		else{
			if (get_option('FLUTTER_fist_time') == ''){
				RCCWP_Application::import_default_modules();
				update_option('FLUTTER_fist_time', '1');
			}
		}
		
	}
	
	function UpgradeBlog(){
		global $wpdb;
		if (RC_CWP_DB_VERSION == 26){
			// Migrate database from previous versions after introducing models/panels
			// separation concept
			// The following code adds the field name to RC_CWP_TABLE_POST_META.
			
			$fieldMetaIDs = $wpdb->get_results("SELECT id FROM " . RC_CWP_TABLE_POST_META);
			foreach($fieldMetaIDs as $fieldMetaID){
				$metakey = $wpdb->get_var( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_id = '{$fieldMetaID->id}'" );
				$wpdb->query("UPDATE ". RC_CWP_TABLE_POST_META .
							 " SET field_name = '$metakey'".
							 " WHERE id = '{$fieldMetaID->id}'");
					
			}
		
		}
		
	}

	function UpgradeBlogSite(){
		global $wpdb;
		if (RC_CWP_DB_VERSION == 26){
			
			// Migrate database from previous versions after introducing models/panels
			// separation concept
			// The following code transfers fields/groups fomr modules to panels.
			
			require_once("RCCWP_CustomWritePanel.php");
			if (RCCWP_Application::IsWordpressMu()) {
				$RC_CWP_TABLE_PANEL_MODULES = $wpdb->base_prefix . 'rc_cwp_panel_modules';
			}
			else{
				$RC_CWP_TABLE_PANEL_MODULES = $wpdb->prefix . 'rc_cwp_panel_modules';
			}
			
			$writePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
			
			foreach($writePanels as $writePanel){
				$sql = "SELECT module_id FROM " . $RC_CWP_TABLE_PANEL_MODULES .
					" WHERE panel_id = " . $writePanel->id;
				$panelModules =$wpdb->get_results($sql);
				
				foreach($panelModules as $panelModule){
					$wpdb->query("UPDATE ". RC_CWP_TABLE_PANEL_GROUPS .
							 " SET panel_id = '{$writePanel->id}'".
							 " WHERE module_id = '{$panelModule->module_id}'");
				}
			}
		}
	}
	
	function Uninstall()
	{
 		global $wpdb;

		// Delete blog tables
		$sql = "DROP TABLE " . RC_CWP_TABLE_POST_META;
		$wpdb->query($sql);
		include_once "canvas-install.php";
		canvas_clean_deactivate();

		// Remove options
		delete_option(RC_CWP_OPTION_KEY);

		// Delete meta data
		$sql = "DELETE FROM $wpdb->postmeta WHERE meta_key = '" . RC_CWP_POST_WRITE_PANEL_ID_META_KEY . "'";
 		$wpdb->query($sql);

		if (get_option("Flutter_notTopAdmin")) return;


		
		RCCWP_Application::DeleteModulesFolders();	

		$sql = "DROP TABLE " . RC_CWP_TABLE_PANELS;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_GROUP_FIELDS;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_PANEL_CATEGORY;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_STANDARD_FIELDS;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_PANEL_STANDARD_FIELD;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES;
		$wpdb->query($sql);

		$sql = "DROP TABLE " . RC_CWP_TABLE_MODULES;
		$wpdb->query($sql);
		
		$sql = "DROP TABLE " . RC_CWP_TABLE_PANEL_GROUPS;
		$wpdb->query($sql);

		$sql = "DROP TABLE " . RC_CWP_TABLE_PANEL_HIDDEN_EXTERNAL_FIELD; 
		$wpdb->query($sql);

		$sql = "DROP TABLE " . RC_CWP_TABLE_PANEL_MODULES; 
		$wpdb->query($sql);
		
		global $canvas;
		$wpdb->query("DROP TABLE IF EXISTS ".$canvas->duplicates."");

		if (RCCWP_Application::is_mu_top_admin()){
			update_site_option('FLUTTER_fist_time', '');
		}
		else{
			update_option('FLUTTER_fist_time', '');
		}
	
		
	}

	function DeleteModulesFolders()
	{
		$customModules = RCCWP_CustomWriteModule::GetCustomModules();
		foreach($customModules as $customModule)
			RCCWP_CustomWriteModule::Delete($customModule->id);
	}
	
	function InCustomWritePanel()
	{
		return RCCWP_Application::InWritePostPanel() && isset($_REQUEST['custom-write-panel-id']);
	}
	
	function InWritePostPanel()
	{
		return (strstr($_SERVER['REQUEST_URI'], '/wp-admin/post-new.php') ||
			strstr($_SERVER['REQUEST_URI'], '/wp-admin/post.php') ||
			strstr($_SERVER['REQUEST_URI'], '/wp-admin/page-new.php') ||
			strstr($_SERVER['REQUEST_URI'], '/wp-admin/page.php'));
	}

	function IsWordpressMu(){
		global $is_wordpress_mu; //$wpdb, $wp_version, $wpmu_version;

		if  ($is_wordpress_mu){      // (isset($wpmu_version)) || (strpos($wp_version, 'wordpress-mu')) ) {
			return true;
		}

		return false;
	}

	function CheckInstallation(){
	
		if (stripos($_GET['page'], "flutter") === false && $_GET['page'] != "RCCWP_OptionsPage.php" && !isset($_GET['custom-write-panel-id'])) return;
		
		$dir_list = "";

		if (!is_writable(FLUTTER_IMAGES_CACHE_DIR)){
			$dir_list.= "<li>".FLUTTER_IMAGES_CACHE_DIR . "</li>";
		}

		if (!is_writable(FLUTTER_UPLOAD_FILES_DIR)){
			$dir_list.= "<li>".FLUTTER_UPLOAD_FILES_DIR . "</li>";
		}


		if (!is_writable(FLUTTER_MODULES_DIR)){
			$dir_list.= "<li>".FLUTTER_MODULES_DIR . "</li>";
		}

		if (!is_writable(FLUTTER_PURIFIER_CACHE_DIR)){
			$dir_list.= "<li>".FLUTTER_PURIFIER_CACHE_DIR . "</li>";
		}

		if ($dir_list != ""){
			echo "<div id='flutter-install-error-message' class='error'><p><strong>".__('Flutter is not ready yet.')."</strong> ".__('The following folders must be writable (usually chmod 777 is neccesary):')."</p><ul>";
			echo $dir_list;
			echo "</ul></div>";
		}

	}
	
	
	/**
	 * Checks for the existance of unzip
	 * 
	 * @access private 
	 */

	function CheckDecompressionProgramUnzip() {

		$return = exec("unzip -help", $output, $returnValue);
		if ( 0 != $returnValue ) return false;

		return true;
	}
	
	/*
	 * Checks for the existance of zip
	 */

	function CheckCompressionProgramZip() {

		$return = exec("zip -help", $output, $returnValue);
		if ( 0 != $returnValue ) return false;

		return true;
	}
	
	
}
?>
