<?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'] == "cat") {
$admin_page = "yes";
echo "<center><a href='cat.php?load=cat&view=add'>Add Categories</a> | <a href='cat.php?load=cat'>Manage Categories</a> | <a href='cat.php?load=cat&view=search'>Search</a></center><br><br>";

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

	echo "<title>{sitename} - OneCMS - www.onecms.net > Cat > Search</title>";

	echo "<form action='cat.php?load=cat&view=search' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for category</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='cat.php?load=cat&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."cat WHERE name LIKE '%" . $_POST[search] . "%' ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($query2)) {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$name = stripslashes($name2);
    	echo "<tr><td><a href='".$cpart1.$name.$cpart2."'>".$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=\"cat.php?load=cat&view=add\">Add category</a></td></tr></form></table><br><br>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."cat WHERE name 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=\"cat.php?load=cat&view=search&page=$prev\"><<Previous</a>&nbsp;";
}

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

if (($_GET['view'] == "") && ($_GET['load'] == "cat")) {

	echo "<title>OneCMS - www.onecms.net > Manage Categories</title>";

	echo "<form action='cat.php?load=cat&view=search' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for category</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='cat.php?load=cat&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."cat 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]";
		$name = stripslashes($name2);
    	echo "<tr><td><a href='".$cpart1.$name.$cpart2."'>".$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=\"cat.php?load=cat&view=add\">Add category</a></td></tr></form></table><br><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."cat"),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=\"cat.php?load=cat&page=$prev\"><<Previous</a>&nbsp;";
}

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

if (((($_GET['view'] == "manage") && ($_POST['delete'] == "") && ($_GET['edit'] == "") && ($_GET['load'] == "cat")))) {

	echo "<form action='cat.php?load=cat&view=manage&edit=2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

    while (list(, $val) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."cat WHERE id = '$val'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
		$namea = "$row2[name]";
	$query2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."content WHERE cat = '".$namea."'"));
	$query3 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."content"));

	echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\"><tr><td><b><center>Category #".$val."</b></center></td></tr><tr><td><b>Name</b></td><td><input type='hidden' name=\"name2_$val\" value=\"$namea\"><input type='text' name=\"name_$val\" value=\"$namea\"></td></tr>";
	echo "<tr><td><b>Number of $row2[name] in database:</b> ".$query2."</td>";
	echo "<tr><td><b>Overall content in database:</b> ".$query3."</td>";
	}
	}
			echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Submit Changes\"></td></tr></form></table>";
}

if ((($_GET['view'] == "manage") && ($_GET['edit'] == "2") && ($_GET['load'] == "cat"))) {

   while (list(, $val) = each ($_POST['id'])) {

   if ((((((((((((((((((((((((((((((($_POST["name_$i"] == "id") or ($_POST["name_$i"] == "games") or ($_POST["name_$i"] == "users") or ($_POST["name_$i"] == "ver") or ($_POST["name_$i"] == "username") or ($_POST["name_$i"] == "Global")  or ($_POST["name_$i"] == "type") or ($_POST["name_$i"] == "contest") or ($_POST["name_$i"] == "album") or ($_POST["name_$i"] == "ad") or ($_POST["name_$i"] == "smilies") or ($_POST["name_$i"] == "badwords") or ($_POST["name_$i"] == "comments") or ($_POST["name_$i"] == "poll") or ($_POST["name_$i"] == "page") or ($_POST["name_$i"] == "file") or ($_POST["name_$i"] == "af") or ($_POST["name_$i"] == "pr") or ($_POST["name_$i"] == "settings") or ($_POST["name_$i"] == "users") or ($_POST["name_$i"] == "ip") or ($_POST["name_$i"] == "content") or ($_POST["name_$i"] == "systems") or ($_POST["name_$i"] == "cat") or ($_POST["name_$i"] == "fields") or ($_POST["name_$i"] == "stats") or ($_POST["name_$i"] == "templates") or ($_POST["name_$i"] == "posts") or ($_POST["name_$i"] == "topics") or ($_POST["name_$i"] == "stickies") or ($_POST["name_$i"] == "announcements") or ($_POST["name_$i"] == "elite") or ($_POST["name_$i"] == "userreviews"))))))))))))))))))))))))))))))) {
	   echo "Sorry, but the category name <b>".$_POST["name_$i"]."</b> is already in use. Go back and choose another name.";
   } else {

   $sql = mysql_query("SELECT * FROM ".$pre."cat WHERE name = '".$_POST["name_$i"]."'");
   $num = mysql_num_rows($sql);

   if ($num > "0") {
	   echo "Sorry, but the category name <b>".$_POST["name_$i"]."</b> is already in use. Go back and choose another name.";
   } else {

   $upd = "UPDATE ".$pre."cat SET name = '".$_POST["name_$val"]."', date = '".time()."' WHERE id = '$val'";
   $upd2 = mysql_query("UPDATE ".$pre."templates SET name = '".$_POST["name_$val"]."' WHERE name = '".$_POST["name2_$val"]."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $upd3 = mysql_query("ALTER TABLE ".$pre."permissions CHANGE `".$_POST["name2_$val"]."` `".$_POST["name_$val"]."` TEXT") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd3."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $r = mysql_query($upd) 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", "cat.php?load=cat");
echo "The category(s) has been updated. <a href=\"cat.php?load=cat\">Manage Categories</a>";
}
}	
	
if (((($_GET['view'] == "manage") && ($_GET['confirm'] == "") && ($_POST['delete']) && ($_GET['load'] == "cat")))) {

while (list(, $val) = each ($_POST['delete'])) {
	$row = @mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."cat WHERE id = '$val'"));
	$name = $row[0];

	if ($val == "media") {
	} else {

	$delete2 = mysql_query("DELETE FROM ".$pre."templates WHERE name = '$name'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());

	$delete3 = mysql_query("ALTER TABLE ".$pre."permissions DROP `$name`") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete3."<br><b>Error:</b> (".mysql_errno().")".mysql_error());

	$delete4 = mysql_query("DELETE FROM ".$pre."content WHERE cat = '".$name."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete4."<br><b>Error:</b> (".mysql_errno().")".mysql_error());

	$delete5 = mysql_query("DELETE FROM ".$pre."content WHERE cat = '$name'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete5."<br><b>Error:</b> (".mysql_errno().")".mysql_error());

	$delete = mysql_query("DELETE FROM ".$pre."cat 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", "cat.php?load=cat");
echo "The category has been deleted. <a href=\"cat.php?load=cat\">Manage Categories</a>";
}
}

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

		echo "<form action='cat.php?load=cat&view=add2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

    if ($_POST['search']) {

echo "<input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

    for($i = 0; $i < $_POST['search']; $i = $i+1) {
	echo "<tr><td><b><center>Category #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr>";
	}
			echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
	}
	echo "</form></table>";
}

if (($_GET['view'] == "add2") && ($_GET['load'] == "cat")) {

   $time = date("Ymd");
   for($i = 0; $i < $_POST['s']; $i = $i+1) {

   if ((((((((((((((((((((((((((((((($_POST["name_$i"] == "id") or ($_POST["name_$i"] == "games") or ($_POST["name_$i"] == "users") or ($_POST["name_$i"] == "ver") or ($_POST["name_$i"] == "username") or ($_POST["name_$i"] == "Global")  or ($_POST["name_$i"] == "type") or ($_POST["name_$i"] == "contest") or ($_POST["name_$i"] == "album") or ($_POST["name_$i"] == "ad") or ($_POST["name_$i"] == "smilies") or ($_POST["name_$i"] == "badwords") or ($_POST["name_$i"] == "comments") or ($_POST["name_$i"] == "poll") or ($_POST["name_$i"] == "page") or ($_POST["name_$i"] == "file") or ($_POST["name_$i"] == "af") or ($_POST["name_$i"] == "pr") or ($_POST["name_$i"] == "settings") or ($_POST["name_$i"] == "users") or ($_POST["name_$i"] == "ip") or ($_POST["name_$i"] == "content") or ($_POST["name_$i"] == "systems") or ($_POST["name_$i"] == "cat") or ($_POST["name_$i"] == "fields") or ($_POST["name_$i"] == "stats") or ($_POST["name_$i"] == "templates") or ($_POST["name_$i"] == "posts") or ($_POST["name_$i"] == "topics") or ($_POST["name_$i"] == "stickies") or ($_POST["name_$i"] == "announcements") or ($_POST["name_$i"] == "elite") or ($_POST["name_$i"] == "userreviews"))))))))))))))))))))))))))))))) {

	   echo "Sorry, but the category name <b>".$_POST["name_$i"]."</b> is already in use. Go back and choose another name.<br><br>";
   } else {

   $sql = mysql_query("SELECT * FROM ".$pre."cat WHERE name = '".$_POST["name_$i"]."'");
   $num = mysql_num_rows($sql);

   if ($num > "0") {
	   echo "Sorry, but the category name <b>".$_POST["name_$i"]."</b> is already in use. Go back and choose another name.<br><br>";
   } else {

   $upd = mysql_query("INSERT INTO ".$pre."cat VALUES ('null', '".$_POST["name_$i"]."', '".time()."')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $upd2 = mysql_query("INSERT INTO ".$pre."templates VALUES ('null', '".$_POST["name_$i"]."', '', '')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $upd3 = mysql_query("ALTER TABLE ".$pre."permissions ADD `".$_POST["name_$i"]."` varchar(10) NOT NULL default 'no'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd3."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $upd4 = mysql_query("UPDATE ".$pre."permissions SET ".$_POST["name_$i"]." = 'no' WHERE ".$_POST["name_$i"]." = ''") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd4."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
if (((($upd2 == TRUE) && ($upd == TRUE) && ($upd3 == TRUE) && ($upd4 == TRUE)))) {
echo re_direct("1500", "cat.php?load=cat");
echo "The category(s) have been created. <a href=\"cat.php?load=cat\">Manage Categories</a>";
}
}
}
}
}
}
if (($_GET['load'] == "help") or ($_GET['load'] == "chat")) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_footer() . " <?php ");
}
} else {
eval (" ?>" . admin_footer() . " <?php ");
}
?>
