<?php
$la = "a";
$z = "b";
include ("../config.php");
if (((($_GET['load'] == "help") or ($_GET['load'] == "chat") or ($_GET['load'] == "login") or ($_GET['load'] == "logout")))) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_header() . " <?php ");
}
} else {
eval (" ?>" . admin_header() . " <?php ");
echo '<SCRIPT LANGUAGE="JavaScript">var checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}</script>';
}
if ($ipbancheck3 == "0") {
if ($numv == "0"){
	if ($warn == $naum) {
	echo "You Do Not Have Access to the Admin Panel";
}
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$from = (($page * $setting[max_results]) - $setting[max_results]);
$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to the Plugins Manager. You are only a $level.";
} else {

echo "<center><a href='plugins.php?load=plugins&view=install'>Install Plugin</a> | <a href='plugins.php?load=plugins'>Manage Plugins</a> | <a href='plugins.php?load=plugins&view=search'>Search</a></center><br><br>";

if ($_GET['view'] == "search") {

	echo "<title>OneCMS - www.onecms.net > Plugins > Search</title><form action='plugins.php?load=plugins&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for module</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='plugins.php?load=plugins&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Plugin</b></td><td><b>Version</b></td><td><b>Status</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."plugins WHERE name LIKE '%" . $_POST['search'] . "%' AND readme = 1 ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name = stripslashes($row[name]);
		$url = stripslashes($row[url]);
    	echo "<tr><td><a href='plugins.php?load=plugins&view=load&plugin=".strtolower(str_replace(" ", "_", $r[name]))."'>".$name."</a></td><td>v".$row[version]."</td><td>";
		if (($row[status] == "") or ($row[status] == "Off")) {
		echo "<font color='red'>Off</font>";
		} else {
		echo "<font color='blue'>On</font>";
		}
		echo "</td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

echo "<tr><td><div align='right'><input type='submit' name='submit' value='Submit'></td><td><input type=button value='Check All' onClick='this.value=check(this.form)'></td></tr></form></table><br><br>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."plugins WHERE name LIKE '%" . $_POST['search'] . "%' AND readme = 1"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"plugins.php?load=plugins&view=search&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"plugins.php?load=plugins&view=search&page=$i\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"plugins.php?load=plugins&view=search&page=$next\">Next>></a>";
}
echo "</center>";
}
}

if ($_GET['view'] == "") {
	echo "<title>OneCMS - www.onecms.net > Manage Plugins</title><form action='plugins.php?load=plugins&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for module</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='plugins.php?load=plugins&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Plugin</b></td><td><b>Version</b></td><td><b>Status</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

$query="SELECT * FROM ".$pre."plugins WHERE readme = 1 ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name = stripslashes($row[name]);
		$url = stripslashes($row[url]);
    	echo "<tr><td><a href='plugins.php?load=plugins&view=load&plugin=".strtolower(str_replace(" ", "_", $r[name]))."'>".$name."</a></td><td>v".$row[version]."</td><td>";
		if (($row[status] == "") or ($row[status] == "Off")) {
		echo "<font color='red'>Off</font>";
		} else {
		echo "<font color='blue'>On</font>";
		}
		echo "</td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

echo "<tr><td><div align='right'><input type='submit' name='submit' value='Submit'></td><td><input type=button value='Check All' onClick='this.value=check(this.form)'></td></tr></form></table><br><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."plugins WHERE readme = 1"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"plugins.php?load=plugins&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"plugins.php?load=plugins&page=$i\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"plugins.php?load=plugins&page=$next\">Next>></a>";
}
echo "</center>";
}
}

if ($_GET['view'] == "load") {
$plugin = mysql_fetch_row(mysql_query("SELECT url,status FROM ".$pre."plugins WHERE name = '".strtolower(str_replace("_", " ", $_GET['plugin']))."'"));
if ($plugin[1] == "Off") {
echo "Sorry, but the <b>".ucwords($_GET['plugin'])."</b> Plugin is offline";
} else {
$module = $_GET['module'];
include ("../mods/".$plugin[0]);
}
}

if (($_GET['view'] == "manage") && ($_POST['delete'])) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion?");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</SCRIPT>';

while (list(, $val) = each ($_POST['delete'])) {
$delete = mysql_query("DELETE FROM ".$pre."plugins WHERE id = '$val'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
}
if ($delete == TRUE) {
echo re_direct("1500", "plugins.php?load=plugins");
echo "The plugin(s) have been deleted. <a href=\"plugins.php?load=plugins\">Manage Plugins</a>";
}
}

if ((($_GET['view'] == "manage") && ($_POST['delete'] == "") && ($_GET['edit'] == ""))) {
	echo "<form action='plugins.php?load=plugins&view=manage&edit=2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

    while (list(, $i) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."plugins WHERE id = '$i'";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {

	echo "<input type=\"hidden\" name=\"id[]\" value=\"$i\"><tr><td><b><center>Plugin #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."' value='".$r[name]."'></td></tr><tr><td>URL</td><td><input type=\"text\" name='url_".$i."' value='".$r[url]."'></td></tr><tr><td>Version</td><td><input type='text' name='version_".$i."' value='".$r[version]."'></td></tr><tr><td>Status?</td><td><select name='status_".$i."'><option value='".$r[status]."' selected>-- ".$r[status]." --</option><option value='On'>On</option><option value='Off'>Off</option></select></td></tr>";
	}
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Submit Changes\"></td></tr></form></table>";
}

if (($_GET['view'] == "manage") AND ($_GET['edit'] == "2")) 
{
    while (list(, $val) = each($_POST['id'])) 
    { 
        $r = mysql_query(" 
            UPDATE ".$pre."plugins 
            SET  
                name      = '" . mysql_real_escape_string($_POST["name_$val"]) . "',  
                url       = '" . mysql_real_escape_string($_POST["url_$val"]) . "',   
                status    = '" . mysql_real_escape_string($_POST["status_$val"]) . "',  
                version   = '" . mysql_real_escape_string($_POST["version_$val"]) . "'
            WHERE id = '" . mysql_real_escape_string($val) . "' 
        ") or die("<b style='color: red;'>A fatal MySQL error occured</b>.<br /><br /><b>Query:</b> " . htmlspecialchars($r) . "<br /><b>Error:</b> (" . mysql_errno() . ")" . mysql_error()); 
    } 

    if ($r == TRUE) 
    { 
        echo re_direct("1500", "plugins.php?load=plugins"); 
        echo "The plugin has been updated. <a href=\"plugins.php?load=plugins\">Manage Plugins</a>"; 
    } 
}  	

if ($_GET['view'] == "install" && !$_GET['url']) {

echo "<table cellpadding='5' cellspacing='0' border='0' width='480' style='padding-left:5px' align='left'><tr><td><b>Plugin Name</b></td><td><b>Size</b></td></tr>";

function size($size) {
  $i=0;
  $iec = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  while (($size/1024)>1) {
   $size=$size/1024;
   $i++;
  }
  return substr($size,0,strpos($size,'.')+4)." ".$iec[$i];
}

if ($handle = @opendir("../mods")) {
while (false !== ($file = @readdir($handle))) {
if ($file != '.' and $file != '..' and $file != 'index.html') {
if (preg_match("/functions/", $file)) {
} else {
$plg_check = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."plugins WHERE url = '".$file."'"));
if ($plg_check == 0) {
$ex = explode(".", $file);
$check = file_get_contents($siteurl."mods/".$file."?check=status");
if ($check == 1) {
echo "<tr><td><a href='plugins.php?load=plugins&view=install&url=".$file."'>".ucwords($ex[0])."</a></td><td>".size(filesize("../mods/".$file))."</td></tr>";
}
}
}
}
}
@closedir($handle);
}
echo "</table><br clear='all'>";


}

}
}
}
if (($_GET['load'] == "help") or ($_GET['load'] == "chat")) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_footer() . " <?php ");
}
} else {
eval (" ?>" . admin_footer() . " <?php ");
}
?>