<?php
$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]);
//if ($_GET['load'] == "featured") {
$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to manage featured. You are only a $level.";
} else {

	echo "<center><a href=\"featured.php?load=featured&view=add1\">Add featured</a> | <a href='featured.php?load=featured'>Manage featured</a></center><br><br>";

	if ($_GET['view'] == "") {
	echo "<title>That Gaming Site  - Make Magic Happen! > Featured Content Manager</title><form action='featured.php?load=featured&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for slides</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

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

$query="SELECT * FROM ".$pre."featured ORDER BY `rank` ASC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$url = "$row[url]";
		$name = stripslashes($name2);
		if ($row[type] == "backend") {
    	echo "<tr><td><a href='".$pagepart1.$url.$pagepart2."' target='popup'>$name</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
		} else {
		echo "<tr><td><a href='featured.php?id=".$id."' target='popup'>$name</a></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."featured"),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=\"featured.php?load=featured&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"featured.php?load=featured&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=\"featured.php?load=featured&page=$next\">Next>></a>";
}
echo "</center>";
}
	}

if (($_GET['view'] == "add1") && ($_GET['add'] == "")) {
echo "<form action=\"featured.php?load=featured&view=add1\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many featured to add?</td><td><input type='text' name='search'></td><td><input type='submit' name='addd' value='Submit'></td></tr></table></form>";

    if ($_POST['search']) {

echo "<form action='featured.php?load=featured&view=add1&add=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\"><input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

    for($i = 0; $i < $_POST['search']; $i = $i+1) {
    echo "<tr><td><b><center>Featured Slide #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Order</td><td><input type=\"text\" name='rank_".$i."'></td></tr><tr><td>Description</td><td><textarea name='description_".$i."' cols='45' rows='12'></textarea></td></tr><tr><td>Image</td><td><input type=\"text\" name='image_".$i."'></td></tr><tr><td>URL</td><td><input type=\"text\" name='url_".$i."'></td></tr>";
	echo "<tr><td>System</td><td><select name='system_".$i."'><option value='' selected>--------</option>";

	$sqlb = mysql_query("SELECT * FROM ".$pre."systems ORDER BY `name` ASC") or die(mysql_error());
	while($row2b = mysql_fetch_array($sqlb)) {
			echo "<option value='".$row2b[id]."'>".$row2b[name]."</option>";
	}
	echo "</select></td></tr>";
	}
echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form></table>";
}
}

}

if (($_GET['view'] == "add1") && ($_GET['add'] == "yes")) {
   for($i = 0; $i < $_POST['s']; $i = $i+1) {

   $r = mysql_query("INSERT INTO ".$pre."featured VALUES (null, '".addslashes($_POST["name_$i"])."', '".addslashes($_POST["description_$i"])."', '".addslashes($_POST["image_$i"])."', '".addslashes($_POST["url_$i"])."', '".$_POST["system_$i"]."', '".$_POST["rank_$i"]."', '".$useridn."')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
if ($r == TRUE) {
echo re_direct("1500", "featured.php?load=featured");
echo "The slides have been created. <a href=\"featured.php?load=featured\">Return to Featured Manager Home</a>";
}
}

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

while (list(, $val) = each ($_POST['delete'])) {
	$delete = mysql_query("DELETE FROM ".$pre."featured 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", "featured.php?load=featured");
echo "The slide(s) have been deleted. <a href=\"featured.php?load=featured\">Return to Featured Manager Home</a>";
}
}

if ((($_GET['view'] == "manage") && ($_POST['delete'] == "") && ($_GET['edit'] == ""))) {
	echo "<form action='featured.php?load=featured&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."featured WHERE id = '$i'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {

 echo "<input type='hidden' name='id[]' value='".$row2[id]."'><tr><td><b><center>Featured Slide #".$i."</b></center></td></tr>";
 echo "<tr><td>Name</td><td><input type=\"text\" name='name_".$i."' value='".stripslashes($row2[name])."'></td></tr><tr><td>Order</td><td><input type=\"text\" name='rank_".$i."' value='".$row2[rank]."'></td></tr><tr><td>Description</td><td><textarea name='description_".$i."' cols='45' rows='12'>".stripslashes($row2[description])."</textarea></td></tr><tr><td>Image</td><td><input type=\"text\" name='image_".$i."' value='".stripslashes($row2[image])."'></td></tr><tr><td>URL</td><td><input type=\"text\" name='url_".$i."' value='".stripslashes($row2[url])."'></td></tr>";
 
	echo "<tr><td>System</td><td><select name='system_".$i."'><option value='' selected>--------</option>";

	$sqlb = mysql_query("SELECT * FROM ".$pre."systems ORDER BY `name` ASC") or die(mysql_error());
	while($row2b = mysql_fetch_array($sqlb)) {
			echo "<option value='".$row2b[id]."'>".$row2b[name]."</option>";
	}
	echo "</select></td></tr>";

}
}
echo "<tr><td><input type=\"submit\" name=\"Modify\" value=\"Modify\"></td></tr></form></table>";
}

if ($_GET['view'] == "search") {
	echo "<title>That Gaming Site  - Make Magic Happen! > Featured Manager > Search</title><form action='featured.php?load=featured&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for slides</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

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

	$query="SELECT * FROM ".$pre."featured WHERE name LIKE '%" . $_POST['search'] . "%' OR url LIKE '%" . $_POST['search'] . "%' ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$url = "$row[url]";
		$name = stripslashes($name2);
		if ($row[type] == "backend") {
    	echo "<tr><td><a href='".$pagepart1.$url.$pagepart2."' target='popup'>$name</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
		} else {
		echo "<tr><td><a href='featured.php?id=".$id."' target='popup'>$name</a></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><td><a href=\"featured.php?load=featured&view=add1\">Add Slides</a></td></tr></form></table><br><br>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."featured WHERE name LIKE '%" . $_POST['search'] . "%' OR url LIKE '%" . $_POST['search'] . "%'"),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=\"featured.php?load=featured&view=search&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"featured.php?load=featured&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=\"featured.php?load=featured&view=search&page=$next\">Next>></a>";
}
echo "</center>";
}
}

if (($_GET['view'] == "manage") && ($_GET['edit'] == "2")) {
   while (list(, $i) = each ($_POST['id'])) {

   $r = mysql_query("UPDATE ".$pre."featured SET name = '".$_POST["name_$i"]."', description = '".addslashes($_POST["description_$i"])."', image = '".addslashes($_POST["image_$i"])."', url = '".addslashes($_POST["url_$i"])."', system = '".$_POST["system_$i"]."', rank = '".$_POST["rank_$i"]."' WHERE id = '".$i."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
if ($r == TRUE) {
echo re_direct("1500", "featured.php?load=featured");
echo "The slide(s) have been updated. <a href='featured.php?load=featured'>Return to Featured Manager Home</a>";
}
}
}
//}
}
?>