function DeleteModulesFolders()
 {
     $customModules = RCCWP_CustomWriteModule::GetCustomModules();
     foreach ($customModules as $customModule) {
         RCCWP_CustomWriteModule::Delete($customModule->id);
     }
 }
    function Main()
    {
        global $flutter_domain;
        $modules = RCCWP_CustomWriteModule::GetCustomModules();
        if (isset($_GET['custom-write-panel-id']) && !empty($_GET['custom-write-panel-id'])) {
            $customWritePanelId = (int) $_GET['custom-write-panel-id'];
        }
        if (isset($_POST['custom-write-panel-id']) && !empty($_POST['custom-write-panel-id'])) {
            $customWritePanelId = (int) $_POST['custom-write-panel-id'];
        }
        ?>

		<div class="wrap">

		<h2><?php 
        _e('Add Module', $flutter_domain);
        ?>
</h2>
		
		<form action="" method="post" id="add-new-module-form">
		
		<table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
		<tbody>

		<tr valign="top">
			<th scope="row"  align="right"><?php 
        _e('Name', $flutter_domain);
        ?>
:</th>
			<td>
		
				<input type="hidden" name="custom-write-panel-id" value="<?php 
        echo $customWritePanelId;
        ?>
" />
				<select tabindex="3" name="custom-write-module-id"  id="custom-write-module-id">
					<?php 
        foreach ($modules as $module) {
            ?>
					
						<option value="<?php 
            echo $module->id;
            ?>
"><?php 
            echo $module->name;
            ?>
</option>
					
					<?php 
        }
        ?>
				</select>
			</td>
		</tr>
		</tbody>
		</table>
		
		<p class="submit" >
			<input name="cancel-add-module" type="submit" id="cancel-add-module" value="<?php 
        _e('Cancel', $flutter_domain);
        ?>
" /> 
			<input name="finish-add-module" type="submit" id="finish-add-module" value="<?php 
        _e('Finish', $flutter_domain);
        ?>
" />
		</p>
		
		</form>

		</div>

		<?php 
    }
 function UpdateAllModulesSettings()
 {
     global $wpdb;
     $customModules = RCCWP_CustomWriteModule::GetCustomModules();
     $currDuplicates = $wpdb->get_results("SELECT * FROM " . FLUTTER_TABLE_MODULES_DUPLICATES);
     $currModules = $wpdb->get_results("SELECT * FROM " . FLUTTER_TABLE_LAYOUT_MODULES);
     foreach ($currModules as $currModule) {
         // -- Delete obselete modules
         if ($currModule->module_id > -1) {
             $found = false;
             foreach ($customModules as $customModule) {
                 if ($customModule->id == $currModule->module_id) {
                     $found = true;
                 }
             }
             if (!$found) {
                 FlutterLayoutBlock::DeleteModule($currModule->module_id);
             }
         }
         // -- Delete obselete duplicates
         $found = false;
         foreach ($currDuplicates as $currDuplicate) {
             if ($currDuplicate->duplicate_id == $currModule->duplicate_id) {
                 $found = true;
             }
         }
         if (!$found && $currModule->duplicate_id != 0) {
             FlutterLayoutBlock::DeleteDuplicate($currModule->duplicate_id);
         }
     }
     // -- Insert/Update modules in the Layout table
     foreach ($customModules as $customModule) {
         $filename = FLUTTER_MODULES_DIR . $customModule->name . "/configure.xml";
         FlutterLayoutBlock::UpdateModuleSettings($filename, $customModule->id);
         //Insert duplicates
         $currDuplicates = $wpdb->get_results("SELECT * FROM " . FLUTTER_TABLE_MODULES_DUPLICATES . " WHERE module_id = '{$customModule->id}'");
         foreach ($currDuplicates as $currDuplicate) {
             FlutterLayoutBlock::UpdateModuleSettings($filename, $customModule->id, false, false, $currDuplicate->duplicate_id);
         }
     }
 }
    function ViewModules()
    {
        global $flutter_domain;
        $customWriteModules = RCCWP_CustomWriteModule::GetCustomModules();
        ?>
<script type='text/javascript' src='../../wp-includes/js/thickbox/thickbox.js'></script>
<link rel='stylesheet' href='../../wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />



		<div class="wrap">
		
		<form action="<?php 
        echo RCCWP_ManagementPage::GetCustomWriteModuleGenericUrl('import-module');
        ?>
" method="post"  id="posts-filter" name="ImportModuleForm" enctype="multipart/form-data">
			<h2><?php 
        _e('Modules');
        ?>
</h2>
			<p id="post-search">					
				<input id="import-module-file" name="import-module-file" type="file" /> 
				<a href="#none" class="button-secondary" style="display:inline" onclick="document.ImportModuleForm.submit();"><?php 
        _e('Import a Module', $flutter_domain);
        ?>
</a>
				<a href="<?php 
        echo RCCWP_ManagementPage::GetCustomWriteModuleGenericUrl('create-custom-write-module');
        ?>
" class="button-secondary" style="display:inline">+ <?php 
        _e('Create a Module', $flutter_domain);
        ?>
</a>
			</p>	
		</form>

		<br class="clear"/>
		<table cellpadding="3" cellspacing="3" width="100%" class="widefat">
		<thead>
		<tr>
			<th scope="col" width="70%"><?php 
        _e('Name');
        ?>
</th>
			<th scope="col" colspan="2" ><?php 
        _e('Actions');
        ?>
</th>
		</tr>
		</thead>
		<tbody>
		<?php 
        foreach ($customWriteModules as $module) {
            $class = $class == '' ? 'alternate' : '';
            ?>
		<tr class="<?php 
            echo $class;
            ?>
">
			<td><?php 
            echo $module->name;
            ?>
</td>
			<td><a href="<?php 
            echo RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($module->id);
            ?>
" class="edit"><?php 
            _e('Edit');
            ?>
</a></td>
			<td><a href="<?php 
            echo FLUTTER_URI . "RCCWP_ExportModule.php?custom-write-module-id={$module->id}";
            ?>
&amp;TB_iframe=true&amp;height=500&amp;width=700" class="thickbox" title='Export Module'><?php 
            _e('Export', $flutter_domain);
            ?>
</a></td>
		</tr>
		<?php 
        }
        ?>
		</tbody>
		</table>

		<form style="display:none" id="do_export" name="do_export" action="<?php 
        echo FLUTTER_URI . "RCCWP_ExportModule.php";
        ?>
" method="post" >
			<input type="text" name="write_panels"/>
			<input type="text" name="custom-write-module-id"/>
		</form>	
		
		</div>
		<?php 
    }