/**
 * Display Administrative Menu for Projects.
 * @return menu
 */
function wpmanga_listProjects()
{
    global $wpdb;
    // Display Specified Category
    if (isset($_GET['view'])) {
        $projects = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects` WHERE `category` = '%d' ORDER BY `title` ASC", (int) $_GET['view']));
    } else {
        $projects = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}projects` ORDER BY `title` ASC");
    }
    if ($projects || isset($_GET['view'])) {
        ?>
		<div class="wrap">
			<?php 
        screen_icon('edit-pages');
        ?>
			<h2>Manga Projects <a href="?page=manga/project" class="add-new-h2">Add a New Project</a></h2>
			
			<ul class="subsubsub">
				<li class="all">
					<a href="admin.php?page=manga"<?php 
        if (!isset($_GET['view'])) {
            echo ' class="current"';
        }
        ?>
>All <span class="count">(<?php 
        echo count(get_sListProject());
        ?>
)</span></a>
				</li>
<?php 
        $categories = get_sListCategories();
        foreach ($categories as $category) {
            ?>
				 | 
				<li class="">
					<a href="admin.php?page=manga&view=<?php 
            echo $category->id;
            ?>
"<?php 
            if ($_GET['view'] == $category->id) {
                echo ' class="current"';
            }
            ?>
><?php 
            echo $category->name;
            ?>
 <span class="count">(<?php 
            echo get_sListCategory($category->id, false);
            ?>
)</span></a>
				</li>
<?php 
        }
        ?>
			</ul>
			
			<table class="wp-list-table widefat">
				<thead>
					<th scope="col" width="65px"></th>
					<th scope="col">Title</th>
				</thead>
				
				<tfoot>
					<th scope="col" width="65px"></th>
					<th scope="col">Title</th>
				</tfoot>
				
				<tbody id="the-list">
				<?php 
        $row = 1;
        ?>
				<?php 
        foreach ($projects as $project) {
            ?>
					<tr id="manga-<?php 
            echo $project->id;
            ?>
" <?php 
            if ($row % 2) {
                echo 'class="alternate" ';
            }
            $row++;
            ?>
valign="top">
						<td style="padding-bottom: 5px;">
							<img src="<?php 
            echo get_sThumbnail('60x60', empty($project->image_thumbnail) ? $project->image : $project->image_thumbnail);
            ?>
" style="padding: 1px; border: 1px double #878e98; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;" width="60" height="60" alt="<?php 
            the_title();
            ?>
" />
						</td>
						
						<td>
							<strong>
								<a href="admin.php?page=manga/project&action=edit&id=<?php 
            echo $project->id;
            ?>
" title="Edit &#8220;<?php 
            echo $project->title;
            ?>
&#8220;"><?php 
            echo $project->title;
            ?>
</a>
							</strong> <?php 
            if ($project->author) {
                echo 'by ' . $project->author;
            }
            ?>
<br>
							Status: <?php 
            echo get_sTitleCategory($project->category);
            ?>
; Genre(s): <?php 
            if ($project->genre) {
                echo $project->genre;
            } else {
                echo "N/A";
            }
            ?>
							<div class="row-actions">
								<span class="edit">
									<a href="admin.php?page=manga/project&action=edit&id=<?php 
            echo $project->id;
            ?>
" title="Edit this Project">Edit</a>
								</span>
								 | 
								<span class="trash">
									<a href="admin.php?page=manga/project&action=delete&id=<?php 
            echo $project->id;
            ?>
" title="Delete this Project">Delete</a>
								</span>
								 | 
								<span class="view">
									<a href="<?php 
            echo get_sPermalink($project);
            ?>
" title="View &#8220;<?php 
            echo $project->title;
            ?>
&#8221; Project Page">View</a>
								</span>
							</div>
						</td>						
					</tr>
				<?php 
        }
        ?>
				</tbody>
			</table>
		</div>
<?php 
    } else {
        ?>
		<script type="text/javascript">
			location.replace("admin.php?page=manga/project")
		</script>
<?php 
    }
}
function wpmanga_settings()
{
    global $wpdb;
    if (isset($_POST['settings_nonce'])) {
        if (!wp_verify_nonce($_POST['settings_nonce'], plugin_basename(plugin_sDIR() . '/wpmanga.php'))) {
            echo '<div class="error"><p>Error: Security Verification Failed.</p></div>';
        } else {
            $_POST = array_map('trim', $_POST);
            // Check Boxes Suck (Search for Alternative Method)
            if (!$_POST['wpmanga_releasebar_style']) {
                $_POST['wpmanga_releasebar_style'] = 0;
            }
            if (!$_POST['wpmanga_page_details_title']) {
                $_POST['wpmanga_page_details_title'] = 0;
            }
            if (!$_POST['wpmanga_page_details_header']) {
                $_POST['wpmanga_page_details_header'] = 0;
            }
            if (!$_POST['wpmanga_foolreader']) {
                $_POST['wpmanga_foolreader'] = 0;
            }
            if (!$_POST['wpmanga_widget_icons']) {
                $_POST['wpmanga_widget_icons'] = 0;
            }
            if (!$_POST['wpmanga_delay_megaupload']) {
                $_POST['wpmanga_delay_megaupload'] = 0;
            }
            if (!$_POST['wpmanga_delay_mediafire']) {
                $_POST['wpmanga_delay_mediafire'] = 0;
            }
            if (!$_POST['wpmanga_delay_depositfiles']) {
                $_POST['wpmanga_delay_depositfiles'] = 0;
            }
            if (!$_POST['wpmanga_delay_fileserve']) {
                $_POST['wpmanga_delay_fileserve'] = 0;
            }
            if (!$_POST['wpmanga_delay_filesonic']) {
                $_POST['wpmanga_delay_filesonic'] = 0;
            }
            if (!$_POST['wpmanga_delay_pdf']) {
                $_POST['wpmanga_delay_pdf'] = 0;
            }
            if (!$_POST['wpmanga_disable_megaupload']) {
                $_POST['wpmanga_disable_megaupload'] = 0;
            }
            if (!$_POST['wpmanga_disable_mediafire']) {
                $_POST['wpmanga_disable_mediafire'] = 0;
            }
            if (!$_POST['wpmanga_disable_depositfiles']) {
                $_POST['wpmanga_disable_depositfiles'] = 0;
            }
            if (!$_POST['wpmanga_disable_fileserve']) {
                $_POST['wpmanga_disable_fileserve'] = 0;
            }
            if (!$_POST['wpmanga_disable_filesonic']) {
                $_POST['wpmanga_disable_filesonic'] = 0;
            }
            if (!$_POST['wpmanga_disable_pdf']) {
                $_POST['wpmanga_disable_pdf'] = 0;
            }
            //Url and Title not empty
            if (!$_POST['wpmanga_projectslist_url']) {
                $_POST['wpmanga_projectslist_url'] = 'projects';
            } else {
                $_POST['wpmanga_projectslist_url'] = get_sSanitizedSlug($_POST['wpmanga_projectslist_url']);
            }
            if (!$_POST['wpmanga_projectslist_title']) {
                $_POST['wpmanga_projectslist_title'] = 'Projects';
            }
            // Filter $_POST and Update Setting
            $_DATA = array();
            foreach ($_POST as $key => $value) {
                if (preg_match("/wpmanga_(.*?)/i", $key)) {
                    $status = wpmanga_set($key, $value);
                    $_DATA[$key] = $status;
                }
            }
            // Update Thumbnails
            if ($_DATA['wpmanga_thumbnail_list_width'] || $_DATA['wpmanga_thumbnail_list_height']) {
                set_time_limit(0);
                $thumbnail = new WP_Http();
                foreach (get_sListProject() as $project) {
                    $thumbnail->request(plugin_sURL() . 'includes/generate_thumbnail.php?src=' . $project->image . '&w=' . wpmanga_get('wpmanga_thumbnail_list_width', 145) . '&h=' . wpmanga_get('wpmanga_thumbnail_list_height', 300));
                }
            }
            echo '<div class="updated"><p>Updated Settings.</p></div>';
        }
    }
    if (isset($_GET['generate'])) {
        if ($_GET['generate'] == 'thumbnails') {
            set_time_limit(0);
            $thumbnail = new WP_Http();
            foreach (get_sListProject() as $project) {
                $thumbnail->request(plugin_sURL() . 'includes/generate_thumbnail.php?src=' . $project->image . '&w=' . wpmanga_get('wpmanga_thumbnail_list_width', 145) . '&h=' . wpmanga_get('wpmanga_thumbnail_list_height', 300));
            }
            echo '<div class="updated"><p>Finished Generating Thumbnails.</p></div>';
        }
    }
    ?>
	<div class="wrap">
		<?php 
    screen_icon('options-general');
    ?>
		<h2>WP Manga Settings</h2>

		<p>WP Manga Project Manager has several options which affect the plugin behavior in different areas. The Frontend Options influence the output and features available in the pages, posts, or text-widgets. The Backend Options control the plugin's administrative area.</p>

		<div id="dashboard-widgets-wrap">
			<div id="dashboard-widgets" class="metabox-holder">
				<form method="post" action="admin.php?page=manga/settings">
					<div class="postbox">
						<h3 class='hndle'><span>Frontend Options</span></h3>
						<div class="inside">
							<table class="form-table fixed">
								<tr class="form-field">
									<td width="250px"><label for="wpmanga_thumbnail_list_width">Thumbnail Dimensions</label></td>
									<td>
										Width <input name="wpmanga_thumbnail_list_width" id="wpmanga_thumbnail_list_width" type="number" value="<?php 
    echo wpmanga_get('wpmanga_thumbnail_list_width', 145);
    ?>
" style="width: 10%;"> &nbsp;
										Height <input name="wpmanga_thumbnail_list_height" id="wpmanga_thumbnail_list_height" type="number" value="<?php 
    echo wpmanga_get('wpmanga_thumbnail_list_height', 300);
    ?>
" style="width: 10%;"> &nbsp; <a class="button-secondary" href="admin.php?page=manga/settings&generate=thumbnails">Force Generate Thumbnails</a>
									</td>
								</tr>

								<tr class="form">
									<td valign="top" width="250px"><label>Individual Project Page</label></td>
									<td>
										<input type="checkbox" name="wpmanga_page_details_title" id="wpmanga_page_details_title" value="1" <?php 
    if (wpmanga_get('wpmanga_page_details_title', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_page_details_title">Disable Title Filter <span class="description">(For Specific Themes)</span></label> <br>
										<input type="checkbox" name="wpmanga_page_details_header" id="wpmanga_page_details_header" value="1" <?php 
    if (wpmanga_get('wpmanga_page_details_header', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_page_details_header">Display Header <span class="description">(For Specific Themes)</span></label>
									</td>
								</tr>

								<tr class="form">
									<td valign="top" width="250px"><label>Online Reader Link Generator</label></td>
									<td>
										<input name="wpmanga_reader" id="reader_foolreader" type="radio" value="1"<?php 
    if (wpmanga_get('wpmanga_reader', 1) == 1) {
        echo ' checked="checked"';
    }
    ?>
> <label for="reader_foolreader">FoOlSlide</label> &nbsp;
										<input name="wpmanga_reader" id="reader_none" type="radio" value="0"<?php 
    if (!wpmanga_get('wpmanga_reader', 1) == 0) {
        echo ' checked="checked"';
    }
    ?>
> <label for="reader_none">None</label>
									</td>
								</tr>

								<tr class="form">
									<td valign="top" width="250px"><label for="wpmanga_releasebar_style">Release Bar Display Style</label></td>
									<td>
										<select name="wpmanga_releasebar_style" id="wpmanga_releasebar_style" style="width: 100%">
											<option value="1"<?php 
    if (wpmanga_get('wpmanga_releasebar_style', 1) == '1') {
        echo ' selected="selected"';
    }
    ?>
>Default Release Bar</option>
											<option value="2"<?php 
    if (wpmanga_get('wpmanga_releasebar_style', 1) == '2') {
        echo ' selected="selected"';
    }
    ?>
>Plain Release Bar</option>
										</select>
									</td>
								</tr>

								<tr class="form">
									<td width="250px"><label for="wpmanga_widget_icons">Latest Widget List</label></td>
									<td>
										<input type="checkbox" name="wpmanga_widget_icons" id="wpmanga_widget_icons" value="1" <?php 
    if (wpmanga_get('wpmanga_widget_icons', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_widget_icons">Show Release Icons</label>
									</td>
								</tr>

								<tr class="form">
									<td width="250px"><label for="wpmanga_channel">IRC Channel</label></td>
									<td>
										<input name="wpmanga_channel" id="wpmanga_channel" type="text" placeholder="irc://irc.irchighway.net/beta" value="<?php 
    echo wpmanga_get('wpmanga_channel', '');
    ?>
" style="width: 100%;">
									</td>
								</tr>

								<tr class="form">
									<td width="250px"><label for="wpmanga_projectslist_url">Projects List Url</label></td>
									<td>
										<input name="wpmanga_projectslist_url" id="wpmanga_projectslist_url" type="text" value="<?php 
    echo wpmanga_get('wpmanga_projectslist_url', 'projects');
    ?>
" style="width: 100%;">
									</td>
								</tr>

								<tr class="form">
									<td width="250px"><label for="wpmanga_projectslist_title">Projects List Title</label></td>
									<td>
										<input name="wpmanga_projectslist_title" id="wpmanga_projectslist_title" type="text" value="<?php 
    echo wpmanga_get('wpmanga_projectslist_title', 'Projects');
    ?>
" style="width: 100%;">
									</td>
								</tr>

								<tr class="form-field">
									<td valign="top" style="padding-top: 10px;" width="250px"><label for="wpmanga_delay">Delay Download Link</label></td>
									<td>
										<input name="wpmanga_delay" id="wpmanga_delay" type="number" value="<?php 
    echo wpmanga_get('wpmanga_delay', 0);
    ?>
" style="width: 10%;"> Hours <br>
										<input type="checkbox" name="wpmanga_delay_depositfiles" id="wpmanga_delay_depositfiles" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_depositfiles', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_depositfiles">Deposit Files</label> <br>
										<input type="checkbox" name="wpmanga_delay_fileserve" id="wpmanga_delay_fileserve" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_fileserve', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_fileserve">FileServe</label> <br>
										<input type="checkbox" name="wpmanga_delay_filesonic" id="wpmanga_delay_filesonic" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_filesonic', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_filesonic">FileSonic</label> <br>
										<input type="checkbox" name="wpmanga_delay_mediafire" id="wpmanga_delay_mediafire" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_mediafire', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_mediafire">MediaFire</label> <br>
										<input type="checkbox" name="wpmanga_delay_megaupload" id="wpmanga_delay_megaupload" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_megaupload', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_megaupload">MEGAUPLOAD</label> <br>
										<input type="checkbox" name="wpmanga_delay_pdf" id="wpmanga_delay_pdf" value="1" <?php 
    if (wpmanga_get('wpmanga_delay_pdf', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_delay_pdf">PDF</label>
									</td>
								</tr>
							</table>

							&nbsp; <input type="submit" class="button-primary" name="save" value="Save Settings"><br><br>
							<input type="hidden" name="settings_nonce" value="<?php 
    echo wp_create_nonce(plugin_basename(plugin_sDIR() . '/wpmanga.php'));
    ?>
">
						</div>
					</div>

					<div class="postbox" >
						<h3 class='hndle'><span>Backend Options</span></h3>
						<div class="inside">
							<table class="form-table fixed">
								<tr class="form-field">
									<td valign="top" style="padding-top: 10px;" width="250px"><label>Disable Download Links</label></td>
									<td>
										<input type="checkbox" name="wpmanga_disable_depositfiles" id="wpmanga_disable_depositfiles" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_depositfiles', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_depositfiles">Deposit Files</label> <br>
										<input type="checkbox" name="wpmanga_disable_fileserve" id="wpmanga_disable_fileserve" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_fileserve', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_fileserve">FileServe</label> <br>
										<input type="checkbox" name="wpmanga_disable_filesonic" id="wpmanga_disable_filesonic" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_filesonic', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_filesonic">FileSonic</label> <br>
										<input type="checkbox" name="wpmanga_disable_mediafire" id="wpmanga_disable_mediafire" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_mediafire', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_mediafire">MediaFire</label> <br>
										<input type="checkbox" name="wpmanga_disable_megaupload" id="wpmanga_disable_megaupload" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_megaupload', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_megaupload">MEGAUPLOAD</label> <br>
										<input type="checkbox" name="wpmanga_disable_pdf" id="wpmanga_disable_pdf" value="1" <?php 
    if (wpmanga_get('wpmanga_disable_pdf', 0)) {
        echo 'checked="checked"';
    }
    ?>
 style="width: 20px;"> <label for="wpmanga_disable_pdf">PDF</label>
									</td>
								</tr>

								<tr class="form">
									<td width="250px"><label for="wpmanga_release_statuspublished">Release publication status (0 for auto publish)</label></td>
									<td>
										<input name="wpmanga_release_statuspublished" id="wpmanga_release_statuspublished" type="text" value="<?php 
    echo wpmanga_get('wpmanga_release_statuspublished', '');
    ?>
" style="width: 100%;">
									</td>
								</tr>
							</table>

							&nbsp; <input type="submit" class="button-primary" name="save" value="Save Settings"><br><br>
							<input type="hidden" name="settings_nonce" value="<?php 
    echo wp_create_nonce(plugin_basename(plugin_sDIR() . '/wpmanga.php'));
    ?>
">
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
<?php 
}
			jQuery(this).parent().find('img').stop().animate({opacity:1}, 500);
			project_id = jQuery(this).parent().find('img').attr('id');
			project_information(true, project_id);
		});
		
		jQuery('.item img').mouseout(function() {
			jQuery(this).stop().animate({opacity: 0.7}, 500);
			project_information(false, 0);
		});
	});
	
	function project_information(status, id) {
		if (status) {
			var project = new Array();
			<?php 
$projects = get_sListProject();
foreach ($projects as $project) {
    $lastRelease = get_sLastRelease($project->id, true);
    if ($project->image) {
        $project->image = get_sThumbnail('60x60', $project->image);
    }
    unset($project->custom);
    unset($project->hit);
    if ($lastRelease) {
        if ($lastRelease->revision > 1) {
            $project->last_release_time = get_sDuration($lastRelease->unixtime_mod);
        } else {
            $project->last_release_time = get_sDuration($lastRelease->unixtime);
        }
        $project->last_release = get_sFormatRelease($project, $lastRelease);
        $project->last_release_title = $lastRelease->title;