<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
include_once("adminfunctions.inc");
$output = '';
$files = glob("plugins/" . "*");

//clean up plugins that are removed but still in db
$db->query("SELECT * from `plugin_menu`") ;
$resdb = $db->FetchAll();

	foreach($resdb as $value) {	
		if (!file_exists("plugins/".$value['menuclass'])) {
			$db->query("DELETE FROM plugin_menu WHERE menuclass = '".$value['menuclass']."' ") ;
		}
	}
	
	
	
foreach($files as $file) {
	if(is_dir($file)) {	
		if (file_exists($file."/settings.inc")) {
		require_once($file."/settings.inc");
		unset($status);
				$db->query("SELECT * from `plugin_menu` WHERE menuclass = '".$plug_menuclass."'") ;
				$res = $db->Fetch();
				if ($db->numRows() == 0) {
					$status = 'load';
					$db->query("INSERT INTO `plugin_menu` (menuname,menuclass,loaded) VALUES ('".$plug_name."','".$plug_menuclass."','0')") ;
				}
				if ($db->numRows() == 1) {
					if ($res['loaded'] == '1') {
						$status = 'unload';
					} else {
						$status = 'load';
					}
				}

			$output .= '<tr id="'.$plug_menuclass.'" class="plugintable">
			<th class="name">'.$plug_name.'<br />Version: '.$plug_version.'<br /><a href="'.$plug_website.'">Plugin Website</a></th>
			
			<th class="desc">'.$plug_description.'</th>
				<th class="info">
				Author: '.$plug_author.'<br />
				<a href="'.$plug_authorwebsite.'">Author Website</a></th>

			<th class="action">';
			
			if ($status == 'load') {
				$output .= '<input type="submit" class="submitbutton" id="Plugload_'.$plug_menuclass.'" title="Load" value="Load">';
			}
			if ($status == 'unload') {
				$output .= '<input type="submit" class="submitbutton" id="Plugunload_'.$plug_menuclass.'" title="unLoad" value="Unload">';
			}	
				
			$output .= '</th></tr>';
		}
	}
}



?>
<h2>Plugin manager</h2>

<h4>Want new plugins? go to <a href="http://www.justanothervideoscript.com/plugins">www.justanothervideoscript.com/plugins</a></h4>
<div class="settings">

	<fieldset>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
		<?php
		if ($output == '') {
			echo '<b>You have no plugins yet, go buy some...</b>';
		} else {
			echo '<tr><th>Plugin info</th><th>Description</th><th>Author Info</th><th>Actions</th></tr>';
			echo $output ;
		}
		?>		
			
		</table>
		</form>

	</fieldset>

</div>	