<?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 ");
if ($setting[wysiwyg] == "True") {
echo wysiwyg();
}
}
} else {
eval (" ?>" . admin_header() . " <?php ");
if ($setting[wysiwyg] == "True" && $_GET['load'] != "templates") {
echo wysiwyg();
}
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 ($setting[warn] == $naum) {
	echo $text_nopermission;
} else {

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

$from = (($page * $setting[max_results]) - $setting[max_results]);



if ($_GET['load'] == "elite") {
$admin_page = "yes";
if (($_GET['view'] == "") && ($_GET['load'] == "elite")) {
	echo "<form action='admin.php?load=elite&view=delete' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Username</b></td><td><b>Game/System</b></td><td><b>Type</b><?td><td><b>Delete</b></td></tr>";

$query="SELECT * FROM ".$pre."elite ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
$result=mysql_query($query);
while($r = mysql_fetch_array($result)) {

		$fetch = mysql_fetch_row(mysql_query("SELECT username FROM ".$pre."profile WHERE id = '".$r[pid]."'"));

		if ($r[type] == "systems") {
		$fetc1 = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."systems WHERE id = '".$r[game]."'"));
		$item = $fetc1[0];
		} else {
		$fetc2 = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."games WHERE id = '".$r[game]."'"));
		$item = $fetc2[0];
		}
echo "<tr><td><a href='".$elite1.$r[pid].$elite2."'>".$fetch[0]."</a></td><td>";
if ($r[type] == "systems") {
echo $item;
} else {
if ($r[type] == "topic") {
$tfetch = mysql_fetch_row(mysql_query("SELECT subject FROM ".$pre."posts WHERE id = '".$r[game]."'"));
echo "<a href='".$f2part1.$r[id].$f2part2."'>".stripslashes($tfetch[0])."</a>";
} else {
echo "<a href='".$gamepart1.intval($r[id]).$gamepart2."'>".$item."</a>";
}
}
echo "</td><td>".$r[type]."</td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$r[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."elite"),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=\"admin.php?load=elite&page=$prev\"><<Previous</a>&nbsp;";
}

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

if (($_GET['view'] == "delete") && ($_GET['load'] == "elite")) {
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."elite 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", "admin.php?load=elite");
echo "The elite data have been deleted. <a href='admin.php?load=elite'>Manage Elite Data</a>";
}
}
}

if (($userlevel == "2") or ($userlevel == "3")) {
	echo "Sorry ".$_COOKIE[$pre."username"].", but you do not have permission to manage fields. You are only a $level.";
} else {

if ($_GET['load'] == "fields") {
$admin_page = "yes";
echo "<center><a href='admin.php?load=fields&view=add'>Add Fields</a> | <a href='admin.php?load=fields'>Manage Fields</a> | <a href='admin.php?load=fields&view=search'>Search</a></center><br><br>";

echo '<SCRIPT LANGUAGE="JavaScript">
function info () {
alert ("Games - If you select the type games, then when posting content for this category, the user will be able to select a game to assign from the games database.\n\nSystems - If you select the type systems, then when posting content for this category, the user will be able to select a system to assign from the systems database.\n\nAlbums - If you select the type albums, then when posting content for this category, the user will be able to select a album to assign from the albums database. Recommended for a media or movies category.");
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function info2 () {
alert ("User Profiles - If you select this `category`, then this field will be added to user profiles...allowing users to enter info for that field, viewable in there profile.");
}
</SCRIPT>';
}

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

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

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

	$query="SELECT * FROM ".$pre."fields WHERE name 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]";
		$name = stripslashes($name2);

		if ($row[cat] == "") {
		$cat = "global";
		} else {
		$cat = $row[cat];
		}

    	echo "<tr><td>$name</td><td>$cat</td><td>$row[type]</td>";
		if ((($name == "games") or ($name == "systems") or ($name == "albums"))) {
		echo "<td>-</td><td>-</td></tr>";
		} else {
		echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$id\" readonly></td><td><input type=\"checkbox\" readonly 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=\"admin.php?load=fields&view=add\">Add field</a></td></tr></form></table><br><br>";

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

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

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

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

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

$query="SELECT * FROM ".$pre."fields 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);

		if ($row[cat] == "") {
		$cat = "global";
		} else {
		$cat = $row[cat];
		}

    	echo "<tr><td>$name</td><td>$cat</td><td>$row[type]</td>";
		if ((($name == "games") or ($name == "systems") or ($name == "albums"))) {
		echo "<td>-</td><td>-</td></tr>";
		} else {
		echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$id\" readonly></td><td><input type=\"checkbox\" readonly 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=\"admin.php?load=fields&view=add\">Add field</a></td></tr></form></table><br><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."fields"),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=\"admin.php?load=fields&page=$prev\"><<Previous</a>&nbsp;";
}

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

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

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'])) {

$sql = @mysql_fetch_row(mysql_query("SELECT name,cat FROM ".$pre."fields WHERE id = '".$val."'"));
$name = $sql[0];
$cat = $sql[1];

if ($cat == "users") {
$delete2 = mysql_query("ALTER TABLE ".$pre."profile DROP `$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());
} else {
$delete2 = mysql_query("DELETE FROM ".$pre."fielddata WHERE name = '".$name."' AND cat = '".$cat."'") 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());
}
$delete = mysql_query("DELETE FROM ".$pre."fields 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) && ($delete2 == TRUE)) {
echo re_direct("1500", "admin.php?load=fields");
echo "The field(s) has been deleted. <a href=\"admin.php?load=fields\">Return to Manage Fields Home</a>";
}
}

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

	echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\">";
	echo "<tr><td><b><center>Field #".$val."</b></center></td></tr><tr><td>Name</td><td><input type=\"hidden\" name='name2_".$val."' value=\"$namea\"><input type=\"text\" name='name_".$val."' value=\"$namea\"></td></tr><tr><td>Help Info</td><td><textarea name='".$val."' cols='30' rows='12'>".$des."</textarea></td></tr><tr><td>Category <a href='javascript:info2()'><b>[Help]</b></a></td><td><select name='cat_".$val."'>";

		if ((!$cat == "games") or (!$cat == "users")) {
			echo "<option value='games'>Games</option><option value='users'>User Profiles</option>";
		}

		if ($cat == "") {
			echo "<option value=''>-- Global --</option>";
		} else {
			echo "<option value='".$cat."' selected>-- ".$cat." --</option>";
		}

	$query="SELECT * FROM ".$pre."cat";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
		if ($name == $cat) {
		} else {
		echo "<option value=\"$name\">$name</option>";
		}
	}

	echo "</select></td></tr><tr><td>Type <a href='javascript:info()'><b>[Help]</b></a></td><td><select name='type_".$val."'><option value=\"$type\" selected>-- $type --</option><option value='textarea'>Text Box</option><option value='textfield'>Text Field</option></select></td></tr>";
	}
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Submit Changes\"></td></tr></form></table>";
}

if ((($_GET['view'] == "manage") && ($_GET['edit'] == "2") && ($_GET['load'] == "fields"))) {
   while (list(, $val) = each ($_POST['id'])) {
   $r = mysql_query("UPDATE ".$pre."fields SET des = '".addslashes($_POST["$val"])."', name = '".$_POST["name_$val"]."', type = '".$_POST["type_$val"]."', cat = '".$_POST["cat_$val"]."' WHERE id = '$val'") 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 ($_POST["cat_$val"] == "users") {
   $r2 = mysql_query("ALTER TABLE ".$pre."profile CHANGE `".$_POST["name2_$val"]."` `".$_POST["name_$val"]."` TEXT DEFAULT '' NOT NULL") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   } else {
   $r2 = mysql_query("UPDATE ".$pre."fielddata 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> ".$r2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
   }
if (($r2 == TRUE) && ($r == TRUE)) {
echo re_direct("1500", "admin.php?load=fields");
echo "The field(s) have been updated. <a href=\"admin.php?load=fields\">Return to Fields Manager Home</a>";
}
}

if (($_GET['view'] == "add") && ($_GET['load'] == "fields")) {
		echo "<form action=\"admin.php?load=fields&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='admin.php?load=fields&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>Field #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Help Info</td><td><textarea name='help_".$i."' cols='30' rows='12'></textarea></td></tr><tr><td>Category</td><td><select name='cat_".$i."'><option value=''>-------</option><option value='global'>Global Field</option><option value='games'>Games</option><option value='users'>User Profiles</option></select><select name='cat2_".$i."'><option value='' selected>------</option>";

	$query = mysql_query("SELECT * FROM ".$pre."cat");
	while($r = mysql_fetch_array($query)) {
		$name = "$r[name]";
		echo "<option value=\"$name\">$name</option>";
	}

	echo "</select></td></tr><tr><td>Type <a href='javascript:info()'><b>[Help]</b></a></td><td><select name='type_".$i."'><option value='textarea'>Text Box</option><option value='textfield'>Text Field</option></select></td></tr>";
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
	}
	echo "</form></table>";
	}

if (($_GET['view'] == "add2") && ($_GET['load'] == "fields")) {
   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   if ($_POST["cat2_$i"]) {
   $cat = $_POST["cat2_$i"];
   } else {
   $cat = $_POST["cat_$i"];
   }
   $upd1 = mysql_query("INSERT INTO ".$pre."fields VALUES (null, '".addslashes($_POST["name_$i"])."', '".$cat."', '".addslashes($_POST["type_$i"])."', '".addslashes($_POST["help_$i"])."')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$upd1."<br><b>Error:</b> (".mysql_errno().")".mysql_error());

if ($_POST["cat_$i"] == "users") {
$upd2 = mysql_query("ALTER TABLE ".$pre."profile ADD `".$_POST["name_$i"]."` TEXT DEFAULT '' NOT NULL") 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());
}
}
if ($upd1 == TRUE) {
echo re_direct("1500", "admin.php?load=fields");
echo "The field(s) have been updated. <a href=\"admin.php?load=fields\">Manage Fields</a>";
}
}
}

if ($_GET['load'] == "pm") {
$admin_page = "yes";
$result2 = mysql_query("SELECT * FROM ".$pre."pm WHERE jo = '".$_COOKIE[$pre."username"]."'") or die(mysql_error());
$num2 = mysql_num_rows($result2);

$per = $num2/$setting[max_pm];

echo '<script language="javascript">
function awindow(towhere, newwinname, properties) {
window.open(towhere,newwinname,properties);
}
</script>';

	echo "<center><a href=\"admin.php?load=pm&box=sent\">Sentbox</a> | <a href=\"admin.php?load=pm&new=msg\">Compose a Message</a></center><br><br>";

if (($_GET['box'] == "in") && ($_GET['del'] == "") && ($_GET['msg'] == "") && ($_GET['confirm'] == "")) {

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

	echo "<center><b>$num2</b> Messages/<b>$pm</b> Allowed | $per%</center><br><form action='admin.php?load=pm&del=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject</b></td><td><b>From</b></td><td><b>Date</b></td><td><b>Delete?</b></td></tr>";

$query="SELECT * FROM ".$pre."pm WHERE jo = '".$_COOKIE[$pre."username"]."' ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		 $id = "$row[id]";
		 $viewed = "$row[viewed]";
		 $subject = "$row[subject]";
		 $date = date($dformat, $row[date]);
		 $to = "$row[jo]";
		 $userguy = "$row[who]";

		 echo "<tr><td><a href=\"admin.php?load=pm&msg=$id\">";
		 if ($viewed == "0") {
			 echo "$subject";
		 } else {
			 echo "<b><i>$subject</b></i>";
		 }
		 echo "</a></td><td>$userguy</td><td>$date</td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
	}
echo "<tr><td><input type='submit' value='Delete'></td><td><input type=button value='Check All' onClick='this.value=check(this.form)'></td></tr></table>";
}
if (($_GET['box'] == "") && ($_GET['del'] == "") && ($_GET['confirm'] == "") && ($_GET['new'] == "")) {

	$query="SELECT * FROM ".$pre."pm WHERE id = '" . $_GET['msg'] . "'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$from = "$row[who]";
		$message2 = "$row[message]";
		$date = date($dformat, $row[date]);
		$subject = "$row[subject]";
		$jo = "$row[jo]";

		$message = stripslashes($message2);
	}

		echo "<title>OneCMS - www.onecms.net > Inbox > $subject</title>";

		echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject:</b></td><td>$subject</td></tr>
		<tr><td><b>";
	$query="SELECT * FROM ".$pre."pm WHERE id = '$id'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$jo = "$row[jo]";
	}
	if ($jo == $_COOKIE[$pre."username"]) {
		$resultID = mysql_query("UPDATE ".$pre."pm SET viewed = '0' WHERE id = '" . $_GET['msg'] . "'") or die(mysql_error());
		echo "From:</b></td><td>$from";
	} else {
		echo "To:</b></td><td>$jo";
	}

		echo " at $date</td></tr><tr><td><b>Message:</b></td><td>$message</td></tr><tr>";

	if ($jo == $_COOKIE[$pre."username"]) {
	  echo "<td><a href=\"admin.php?load=pm&del=" . $_GET['msg'] . "\">Delete Message?</a></td>
			<td><a href=\"admin.php?load=pm&new=reply&id=" . $_GET['msg'] . "\">Reply to this Message</a></td><td><a href=\"admin.php?load=pm&box=in\">Return to Inbox</a></td><td><a href=\"admin.php?load=pm&box=sent\">Go to Sentbox</a></td></tr></table>";
	} else {

	  echo "<td><a href=\"admin.php?load=pm&box=sent\">Return to Sentbox</a></td>
		    <td><a href=\"admin.php?load=pm&box=in\">Go to Inbox</a></td></tr></table>";
	}
}
if ((((($_GET['del'] == "yes") && ($_GET['msg'] == "") && ($_GET['box'] == "") && ($_GET['confirm'] == "") && ($_GET['new'] == ""))))) {

		echo "<title>OneCMS - www.onecms.net > Inbox > Delete Message (s)</title>";

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."pm WHERE id = '$val'") or die(mysql_error());
}
if ($delete == TRUE) {
	echo "Message(s) have been deleted. <a href='admin.php?load=pm&box=in'>Return to Inbox</a>";
}
}

if (((($_GET['msg'] == "") && ($_GET['box'] == "") && ($_GET['confirm'] == "") && ($_GET['new'] == "")))) {
if ($_GET['del'] == "yes") {
} else {
		echo "<title>OneCMS - www.onecms.net > Inbox > Delete Message</title>";

echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion?");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</SCRIPT>';

$delete = mysql_query("DELETE FROM ".$pre."pm WHERE id = '".$_GET['del']."'") or die(mysql_error());

if ($delete == TRUE) {
	echo "Message has been deleted. <a href='admin.php?load=pm&box=in'>Return to Inbox</a>";
}
}
}
if (($_GET['box'] == "sent") && ($_GET['del'] == "") && ($_GET['msg'] == "") && ($_GET['confirm'] == "") && ($_GET['new'] == "")) {

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

	echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject</b></td><td><b>To</b></td><td><b>Date</b></td></tr>";

$query="SELECT * FROM ".$pre."pm WHERE who = '".$_COOKIE[$pre."username"]."' ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		 $id = "$row[id]";
		 $viewed = "$row[viewed]";
		 $subject = "$row[subject]";
		 $date = date($dformat, $row[date]);
		 $to = "$row[jo]";
		 $userguy = "$row[jo]";

		 echo "<tr><td><a href=\"admin.php?load=pm&msg=$id\">$subject</a></td><td>$userguy</td><td>$date</td></tr>";
	}

echo "<tr><td><a href=\"admin.php?load=pm&box=in\">Inbox</a></td><td><a href=\"admin.php?load=pm&new=msg\">Compose a Message</a></td></tr></table>";
}

if (($_GET['box'] == "") && ($_GET['msg'] == "") && ($_GET['del'] == "") && ($_GET['confirm'] == "") && ($_GET['new'] == "reply") && ($_GET['sent'] == "")) {

	$query="SELECT * FROM ".$pre."pm WHERE id = '" . intval($_GET['id']) . "'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		 $subject = "$row[subject]";
		 $jo = "$row[who]";
		 $message2 = "$row[message]";
		 $message = stripslashes($message2);
	}

		echo "<title>OneCMS - www.onecms.net > Inbox > Reply > $subject</title>";

if (!$_POST['submit']) {
if ($pm-$num2 > 1) {

		echo "<form action=\"admin.php?load=pm&new=reply&id=$id\" method=\"post\"><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject:</b></td><td><input type=\"text\" name=\"subject2\" value=\"Re: $subject\"></td></tr>
		<tr><td>To:</td><td><input type=\"hidden\" name=\"tto\" value=\"$jo\">$jo</td></tr><tr><td><b>Message:</b></td><td>
<textarea name=\"messagea2\" cols=\"36\" rows=\"10\">

-- Original Message: $message --</textarea></td></tr><tr><td><input type=\"submit\" name=\"submit\" value=\"Send Reply\"></td><td><a href=\"admin.php?load=pm&box=in\">Return to Inbox</a></td></tr></table></form>";
} else {

echo "Sorry ".$_COOKIE[$pre."username"].", but you have used up all the allotted messages. Please delete at least (1) message before replying to '$subject'.";
}
}

if ($_POST['submit']) {

$messageaa2 = addslashes($_POST['messagea2']);

$sent = mysql_query("INSERT INTO ".$pre."pm VALUES (null, '1', '".$_POST['subject2']."', '$messageaa2', '".$_COOKIE[$pre."username"]."', '".$_POST['tto']."', '".time()."', 'inbox')") or die(mysql_error());

if ($sent == TRUE) {
	echo "The reply has been sent to ".$_POST['tto'].". <a href=\"admin.php?load=pm&box=in\">Return to Inbox</a>";
} else {
	echo "The reply could not be sent to ".$_POST['tto'].". Please click 'Back' on your browser and try again";
}
}
}

if (($_GET['msg'] == "") && ($_GET['new'] == "msg") && ($_GET['box'] == "") && ($_GET['del'] == "") && ($_GET['confirm'] == "") && ($_GET['sent'] == "")) {

		echo "<title>OneCMS - www.onecms.net > Inbox > Compose Message</title>";

if (!$_POST['submit']) {

		echo "<form action=\"admin.php?load=pm&new=msg\" method=\"post\"><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject:</b></td><td><input type=\"text\" name=\"subject\"></td></tr>
		<tr><td>To:</td><td><select name=\"jo\">";

	$query="SELECT * FROM ".$pre."users";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$userguyr = "$row[username]";

		echo "<option value=\"$userguyr\">$userguyr</option>";
	}
	   echo "</select></td></tr><tr><td><b>Message:</b></td><td><textarea name=\"message\" cols=\"36\" rows=\"10\"></textarea></td></tr><tr><td><input type=\"submit\" name=\"submit\" value=\"Send Message\"></td><td><a href=\"admin.php?load=pm&box=in\">Return to Inbox</a></td></tr></table></form>";
}
	if ($pm-$num2 > 1) {

if ($_POST['submit']) {

$message2 = addslashes($_POST['message']);

$sent = mysql_query("INSERT INTO ".$pre."pm VALUES (null, '1', '".$_POST['subject']."', '$message2', '".$_COOKIE[$pre."username"]."', '".$_POST['jo']."', '".time()."', 'inbox')") or die(mysql_error());

if ($sent == TRUE) {
	echo "Message has been sent. <a href=\"admin.php?load=pm&box=in\">Return to Inbox</a>";
} else {
	echo "Message could not be sent. Please click 'Back' on your browser and try again";
}
}
} else {

echo "Sorry ".$_COOKIE[$pre."username"].", but ".$_POST['jo']." has used up all there allotted messages. Please tell them to delete at least (1) message.";
}
}
}

if ($_GET['load'] == "") {
$admin_page = "yes";
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

if (($_GET['cat'] == "") && ($_GET['view'] == "add")) {
$fetch = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."cat ORDER BY `id` ASC"));
header("location: admin.php?view=add&cat=".$fetch[0]);
}

$from = (($page * $setting[max_results]) - $setting[max_results]);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>';

echo '<script language="javascript">
function awindow(towhere, newwinname, properties) {
window.open(towhere,newwinname,properties);
}
</script>';

if ($_GET['view'] == "home") {
} else {
if ($_GET['cat']) {
$cat = $_GET['cat'];
} else {
$fetch = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."cat ORDER BY `id` ASC"));
$cat = $fetch[0];
}
echo "<center><a href='admin.php?view=add&cat=".$cat."'>Add ".$cat."</a> | <a href='admin.php?view=ver'>Verify ".$cat."</a> | <a href='admin.php?view=postpone'>Delay ".$cat."</a> | <a href='admin.php'>Manage ".$cat."</a>";

echo "</center><br>";
}

if ($_GET['view'] == "massemail2") {
$sub = stripslashes($_POST['subject']);
$msg = stripslashes($_POST['message']);
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$sitename." <".$email.">"."\r\n";
$headers .= "Reply-To: ".$email."\r\n";

$query = mysql_query("SELECT * FROM ".$pre."users ORDER BY `id` DESC");
while($r = mysql_fetch_array($query)) {
mail($r[email], $sub, $msg, $headers);
}
echo "E-Mail submitted. <a href='admin.php?view=home'>Return to main admin panel</a>";
}

if ($_GET['view'] == "massemail") {
echo "<form action='admin.php?view=massemail2' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\"><tr><td><b>Subject</b></td><td><input type='text' name='subject'></td></tr><tr><td><b>Message</b></td><td><textarea name='message' cols='50' rows='12'></textarea></td></tr><tr><td><input type='submit' value='Submit E-Mail'></td><td><input type='reset' value='Reset E-Mail'></td></tr></table></form>";
}

if ($_GET['view'] == "home") {
echo "<iframe src='http://www.onecms.net/onecms-updates.php?version=".$version."&siteurl=".$_SERVER['HTTP_HOST']."&sitename=".$sitename."' width='100%' height='100' frameborder='0'></iframe><table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" width=\"95%\" align=\"center\"><tr>";
	
$query = mysql_query("SELECT * FROM ".$pre."cat ORDER BY `id` DESC LIMIT 10");
while($r = mysql_fetch_array($query)) {
$cat = $r[name];
$lchar = substr($cat, -1);
if ($lchar == "s") {
$cat = substr_replace($cat, "", -1);
}
$cat = ucfirst($cat);

echo "<td><a href='admin.php?view=add&cat=".$r[name]."'>Add ".$cat."</a></td>";
}

echo "<td><a href='admin.php?view=massemail'><b>Mass E-Mail</b></a></td></tr></table><iframe src='admin.php?load=chat' width='100%' frameborder='0' scrolling='yes'></iframe><br><br><form action='admin.php?view=manage' name='form1' method='post'><table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" align=\"center\"><tr><td valign='top'><center><u>Latest Content</u></center><table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Views</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr>";
$sql = mysql_query("SELECT * FROM ".$pre."content ORDER BY `id` DESC LIMIT 12");
while($row = mysql_fetch_array($sql)) {
	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."'>".stripslashes($row[name])."</a></td><td>".$row[stats]."</td>";
	if ($userlevel < "3") {
	echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$row[id]\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$row[id]\"></td>";
	} else {
	if ($row[username] == $_COOKIE[$pre."username"]) {
	echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$row[id]\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$row[id]\"></td>";	
	} else {
	echo "<td>&nbsp;</td><td>&nbsp;</td>";
	}
	}
	echo "</tr>";
}
echo "<tr><td><div align='right'><input type='submit' name='submit' value='Submit'></td></tr></table></form></td><td valign='top'><form action='admin.php?load=games&view=manage' name='form1' method='post'><center><u>Latest Games</u></center><table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Game</b></td><td><b>Views</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr>";

$sql = mysql_query("SELECT * FROM ".$pre."games ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_array($sql)) {
	echo "<tr><td><a href='".$gamepart1.$row[id].fthrough($row[name], "").$gamepart2."'>".stripslashes($row[name])."</a></td><td>".$row[stats]."</td>";
	if ($userlevel < "3") {
	echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$row[id]\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$row[id]\"></td>";
	} else {
	if ($row[username] == $_COOKIE[$pre."username"]) {
	echo "<td><input type=\"checkbox\" name=\"id[]\" value=\"$row[id]\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$row[id]\"></td>";	
	} else {
	echo "<td>&nbsp;</td><td>&nbsp;</td>";
	}
	}
	echo "</tr>";
}
echo "<tr><td><input type='submit' name='submit' value='Submit'></td></tr></table></form>";

echo "</td></tr><tr><td><center><u>Latest Users</u></center><table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Profile</b></td><td><b><b>Rank</b></td><td><b># of Posts</b></td></tr>";

$sql = mysql_query("SELECT * FROM ".$pre."users ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_array($sql)) {
$posts = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE uid = '".$row[id]."'"));
$color = mysql_fetch_row(mysql_query("SELECT color FROM ".$pre."ranks WHERE name = '".$row[rank]."'"));
echo "<tr><td><a href='".$elite1.$row[username].$elite2."'>".stripslashes($row[username])."</a></td><td><font color='".$color[0]."'>".ucwords($row[rank])."</font></td><td>".$posts."</td></tr>";
}

echo "</table></td><td><center><u>Latest Posts</u></center><table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject</b></td><td><b>Views</b></td><td><b><b>Poster</b></td><td><b>Replies</b></td></tr>";

$sql = mysql_query("SELECT * FROM ".$pre."posts ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_array($sql)) {

$row2 = mysql_fetch_row(mysql_query("SELECT username,id FROM ".$pre."profile WHERE id = '".$row[uid]."'"));
$replies = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE tid = '".$row[id]."' AND type = 'post'"));

    if ($row[type] == "topic") {
	echo "<tr><td><a href='".$f2part1.$row[id].$f2part2."'>";
	} else {
	echo "<tr><td><a href='".$f2part1.$row[tid].$f2part2."#".$row[id]."'>";
	}
	
	echo stripslashes($row[subject])."</a></td><td>".$row[stats]."</td><td>";
	
	if ($row[uid] == "") {
	echo "Guest";
	} else {	
	echo "<a href='".$elite1.$row2[1].$elite2."'>";
	
	$r = mysql_fetch_row(mysql_query("SELECT rank FROM ".$pre."users WHERE username = '".$row2[0]."'"));
    $color = mysql_fetch_row(mysql_query("SELECT color FROM ".$pre."ranks WHERE name = '".$r[0]."'"));
	if ($color[0]) {
		echo "<font color='".$color[0]."'>".$row2[0]."</font>";
	} else {
		echo $row2[0];
	}
	}

	echo "</a></td><td>".$replies."</td></tr>";
}

echo "</table></td></tr></table>";
}

if ($_GET['view'] == "search") {
echo "<title>OneCMS Admin > Search</title>";

if ($_GET['cat'] == "") {
echo "<form action='admin.php?view=search' name='form1' method='post'>";
} else {
echo "<form action='admin.php?view=search&cat=".$_GET['cat']."' name='form1' method='post'>";
}

echo '<script language="JavaScript"> 
function openDir(form) { 
var newIndex = form.fieldname.selectedIndex; 
if ( newIndex == 0 ) { 
alert( "Please select a location!"); 
} else { 
cururl = form.fieldname.options[ newIndex ].value; 
window.location.assign( cururl ); 
} 
} 
</script>';

	echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option>";

if ($_GET['cat']) {
echo "<option value='".$_GET['cat']."'>".$_GET['cat']."</option>";
}
	
	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";

		if ($_GET['cat'] == "") {
		} else {
		if ($name == $_GET['cat']) {
		} else {
    	echo "<option value=\"$name\">$name</option>";
	}
		}
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

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

	if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
    if ($cat2 == "") {

	$query="SELECT * FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND username = '".$_COOKIE[$pre."username"]."' 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]";
		$cat5 = "$row[cat]";
		$name = stripslashes($name2);
		$systems = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

	} else {

$query="SELECT * FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND cat = '$cat2' AND username = '".$_COOKIE[$pre."username"]."' 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);
		$systems = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }
	}
	
} else {

	if ($cat2 == "") {

	$query="SELECT * FROM ".$pre."content WHERE name 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]";
		$cat5 = "$row[cat]";
		$name = stripslashes($name2);
		$systems = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td>$systems[0]</td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

	} else {

$query="SELECT * FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND cat = '$cat2' 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);
		$systems = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td>$systems[0]</td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</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><select name='fieldname' size='1' onChange='openDir(this.form)'><option selected>- Add Content -</option>";

$sql = mysql_query("SELECT * FROM ".$pre."cat");
while($r = mysql_fetch_array($sql)) {
echo "<option value='admin.php?view=add&cat=".stripslashes($r[name])."'>".stripslashes($r[name])."</option>";
}

echo "</select></td></tr></form></table><br><br>";

if ($cat2 == "") {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%'"),0);
} else {
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND cat = '$cat2'"),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=\"admin.php?cat=".$_GET['cat']."&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
			
            echo "<a href=\"admin.php?cat=".$_GET['cat']."&page=$i\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"admin.php?cat=".$_GET['cat']."&page=$next\">Next>></a>";
}
echo "</center>";
}
}

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

	echo "<title>OneCMS Admin > Manage Content</title>";

echo '<script language="JavaScript"> 
function openDir(form) { 
var newIndex = form.fieldname.selectedIndex; 
if ( newIndex == 0 ) { 
alert( "Please select a location!"); 
} else { 
cururl = form.fieldname.options[ newIndex ].value; 
window.location.assign( cururl ); 
} 
} 
</script>';

	echo "<form action='admin.php?view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option>";
	
	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
    	echo "<option value=\"$name\">$name</option>";
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<table cellspacing=\"0\" cellpadding=\"3\" width=\"550\" border=\"0\" align=\"center\"><form action='admin.php?view=manage' name='form1' method='post'><tr><td><b>Name</b></td><td><b>System</b></td><td><b>Category</b></td><td><b><b>Edit</b></td><td width=\"15\"><b>Delete</b></td></tr><center><div align=\"center\">";

	if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {

	$query="SELECT * FROM ".$pre."content WHERE username = '".$_COOKIE[$pre."username"]."' 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]";
		$cat2 = "$row[cat]";
		$name = stripslashes($name2);
		$systems = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

} else {

$query="SELECT * FROM ".$pre."content 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]";
		$cat2 = "$row[cat]";
		$name = stripslashes($name2);
		$systems = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><a href='".$cpart1.$row[cat].$cpart2."'>".$row[cat]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }
	}

echo "<tr><td><center><input type='submit' name='submit' value='Submit'><select name='fieldname' size='1' onChange='openDir(this.form)'><option selected>- Add Content -</option>";

$sql = mysql_query("SELECT * FROM ".$pre."cat");
while($r = mysql_fetch_array($sql)) {
echo "<option value='admin.php?view=add&cat=".stripslashes($r[name])."'>".stripslashes($r[name])."</option>";
}

echo "</select></td></td></tr></center></form></table><br><br>";


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

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

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

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

	echo "<title>OneCMS Admin > Manage ".$_GET['cat']."</title>";

	echo "<form action='admin.php?view=search&cat=".$_GET['cat']."' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" width=\"550\" align=\"center\"><tr><td>Search for content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option><option value='".$_GET['cat']."'>".$_GET['cat']."</option>";

		$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
		if ($name == $_GET['cat']) {
		} else {
    	echo "<option value=\"$name\">$name</option>";
	}
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

echo "<form action='admin.php?view=manage&cat=".$_GET['cat']."' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" width=\"550\" align=\"center\"><tr><td><b>Name</b></td><td><b>System</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
$query="SELECT * FROM ".$pre."content WHERE cat = '".$_GET['cat']."' AND username = '".$_COOKIE[$pre."username"]."' 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);
		$system = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
}
} else {

$query="SELECT * FROM ".$pre."content WHERE cat = '".$_GET['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);
		$system = mysql_fetch_row(mysql_query("SELECT abr,name FROM ".$pre."systems WHERE id = '".$row[systems]."'"));

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td><a href='".$system1.$systems[0].$system2."'>".$systems[1]."</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
}
}

echo "<tr><td><center><input type='submit' name='submit' value='Submit'></form></table><br><br>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE cat = '".$_GET['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=\"admin.php?page=$prev&cat=".$_GET['cat']."\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"admin.php?page=$i&cat=".$_GET['cat']."\">$i</a>&nbsp;";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"admin.php?page=$next&cat=".$_GET['cat']."\">Next>></a>";
}
echo "</center>";
}
}

if (($_GET['view'] == "manage") && ($_POST['id'] == "")) {
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to delte posts. You are only a $level. Please see an editor for futher information.";
} else {

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."content 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());
$delete2 = mysql_query("DELETE FROM ".$pre."fielddata WHERE id = '$val' AND cat = 'content'") 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());
}
if (($delete == TRUE) && ($delete2 == TRUE)) {
echo re_direct("1500", "admin.php");
echo "The content has been deleted. <a href=\"admin.php\">Return to Manage Content Home</a>";
}
}
}
if ($_GET['view'] == "add") {
$cat_check = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."permissions WHERE username = '".$_COOKIE[$pre."username"]."' AND ".$_GET['cat']." = 'yes'"));

if ($cat_check == "0") {
echo "Sorry, but you do not have permission to add content to the ".$_GET['cat']." category.";
} else {

echo "<form action=\"admin.php?view=add&cat=".$_GET['cat']."\" 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>";

if ($_POST['search']) {

echo "<form action='admin.php?view=add2' 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 "<input type=\"hidden\" name='cat_".$i."' value='".$_GET['cat']."'><tr><td><b><center>Item #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Require membership to view?</td><td><select name='lev".$i."' multiple><option value='Yes'>Yes</option><option value='No' selected>No</option></select></td></tr>";
	$query = mysql_query("SELECT * FROM ".$pre."fields WHERE cat = '" . $_GET['cat'] . "' OR cat = '' OR cat = 'global' ORDER BY `id` DESC") or die(mysql_error());
	while($row = mysql_fetch_array($query)) {
		$name = "$row[name]";
		$type = "$row[type]";

		if ($type == "textarea") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><textarea name='$name".$i."' cols=\"45\" rows=\"12\"></textarea></td></tr>";
		}
		if ($type == "textfield") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><input type=\"text\" name='$name".$i."' id='$name".$i."'></td></tr>";
		}
		if ($type == "image") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><input type=\"text\" name='$name".$i."'></td></tr>";
		}
		if ($type == "games") {
				echo "<link rel=\"stylesheet\" href=\"../includes/js/css/common.css\" type=\"text/css\" />
	<link type=\"text/css\" rel=\"stylesheet\" href=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/ui.all.css\" />
	<link type=\"text/css\" href=\"../includes/js/css/ui.multiselect.css\" rel=\"stylesheet\" />
	<script type=\"text/javascript\" src=\"../includes/js/jquery-1.4.2.min.js\"></script>
	<script type=\"text/javascript\" src=\"../includes/js/jquery-ui-1.8.custom.min.js\"></script>
	<script type=\"text/javascript\" src=\"../includes/js/plugins/localisation/jquery.localisation-min.js\"></script>
	<script type=\"text/javascript\" src=\"../includes/js/plugins/scrollTo/jquery.scrollTo-min.js\"></script>
	<script type=\"text/javascript\" src=\"../includes/js/ui.multiselect.js\"></script>
	<script type=\"text/javascript\">
		$(function(){
			$.localise('ui-multiselect', {/*language: 'en',*/ path: '../js/locale/'});
			$(\".multiselect\").multiselect();
			$('#switcher').themeswitcher();
		});
	</script>";
			
	echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."[]' multiple='multiple' class = 'multiselect'><option value='' selected>--------</option>";

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

		if ($type == "system") {
	echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."[]' multiple class = 'multiselect'><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>";
		}
		
	if ($type == "company") {
		echo "<tr><td>".$name." <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><select name='".$name."_".$i."[]' multiple class = 'multiselect'><option value='' selected>--------</option>";

	$sqlc = mysql_query("SELECT * FROM ".$pre."pr ORDER BY `name` ASC") or die(mysql_error());
	
	while($row2c = mysql_fetch_array($sqlc)) {
			echo "<option value='".$row2c[id]."'>".$row2c[name]."</option>";
	}

	}
	if ($setting[wysiwyg] == "False") {
	echo "<tr><td>Automatically Break lines?</td><td><input type='checkbox' name='autobr_".$i."' value='yes' checked></td></tr>";
	}
	}
	echo "<tr><td>Save Post</td><td><select name = 'save".$i."'><option value = '0'>No</option><option value = '1'>Yes</option>";
	
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td><td><input type='reset' name='reset' value='Reset'></td></tr></form></table>";
	
	
	}
}
}
}

//Just submitting the post
if ($_GET['view'] == "add2") {

   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   if ($_POST["name_$i"]) {

   $upd = "INSERT INTO ".$pre."content VALUES (null, '".addslashes($_POST["name_$i"])."', '".$_POST["cat_$i"]."', '".$_COOKIE[$pre."username"]."', '".time()."'";

   if ($ver == "yes") {
   $upd .= ", '1', '', '0', '".$_POST["lev$i"]."'";
   } else {
   $upd .= ", '0', '', '0', '".$_POST["lev$i"]."'";
   }
     $upd .= ",'".$_POST["save$i"]."' ";
   $upd .= " '".$val."')";

$r = mysql_query($upd) 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());

$fetch = mysql_fetch_row(mysql_query("SELECT id,name,cat FROM ".$pre."content WHERE cat = '".$_POST["cat_$i"]."' AND username = '".$_COOKIE[$pre."username"]."' ORDER BY `id` DESC LIMIT 1"));

   $tcount = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."elite WHERE type = 'tracked' AND game = '".addslashes($_POST["games_$i"])."'"));

   if ($tcount > "0") {
   $qr = mysql_query("SELECT * FROM ".$pre."elite WHERE type = 'tracked' AND game = '".addslashes($_POST["games_$i"])."' ORDER BY `id`") or die(mysql_error());
   while($ra = mysql_fetch_array($qr)) {
   mysql_query("INSERT INTO ".$pre."pm VALUES (null, '1', 'Tracked: ".addslashes($_POST["games_$i"])."', '<small>You are receiving this Private Message because you are tracking the game ".addslashes($_POST["games_$i"])."</small><br><br>There has been new content posted for the game <b>".addslashes($_POST["games_$i"])."</b> which you can view below:<br><br><a href=\"".$part1.$fetch[0].fthrough($fetch[1], $fetch[2]).$part2."\">View the ".$_POST["cat_$i"]."</a><br><br>Enjoy', '', '".userid($ra[pid])."', '".time()."', 'tracked')");
   }
   }
   	
$query = mysql_query("SELECT * FROM ".$pre."fields WHERE cat = '' OR cat = '".$_POST["cat_$i"]."' ORDER BY `id`") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
$name = "$row[name]";

if ($row[type] == "system") {
while(list($a, $ia) = each ($_POST["systems_$i"])) {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$ia."', '".$fetch[0]."', 'content')");
}
}

if ($row[type] == "games") {
while(list($b, $ib) = each ($_POST["games_$i"])) {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$ib."', '".$fetch[0]."', 'content')");
}
}

if ($row[type] == "company") {
while(list($c, $ic) = each ($_POST["company_$i"])) {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'company', '".$ic."', '".$fetch[0]."', 'content')");
}
}
   
if (($_POST["autobr_$i"]) && ($row[type] == "textarea")) {
$autobr = preg_replace("/<br>\n/","\n",addslashes($_POST["$name$i"]));
$autobr = preg_replace("/<br \/>\n/","\n",addslashes($_POST["$name$i"]));
$autobr = preg_replace("/(\015\012)|(\015)|(\012)/","<br>\n",addslashes($_POST["$name$i"]));
} else {
$autobr = addslashes($_POST["$name$i"]);
}
   if (($row[name] == "albums") && ($_POST["albums_$i"])) {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, '".$name."', '".addslashes($_POST["albums_$i"])."', '".$fetch[0]."', 'content')");
   } else {
   if ($autobr) {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, '".$name."', '".$autobr."', '".$fetch[0]."', 'content')");
   }
   }
   }


   }
   }
if ($r == TRUE) {
echo re_direct("1500", "admin.php");
echo "The content has been created. <a href=\"admin.php\">Return to Manage Content Home</a>";
}
}

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

	echo "<form action='admin.php?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."content WHERE id = '$val'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
		$nameav = "$row2[name]";
		$cat = "$row2[cat]";
		$namea = htmlspecialchars(stripslashes($nameav));

	echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\"><input type=\"hidden\" name=\"cat_$val\" value=\"$cat\"><tr><td><b><center>Item #".$val."</b></center></td></tr><tr><td><b>Name</b></td><td><input type='text' name=\"name_$val\" value=\"$namea\"></td></tr><tr><td>Require membership to view?</td><td><select name='lev_".$val."' multiple><option value='".$row2[lev]."' selected>-- ".$row2[lev]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr>";

	$query = mysql_query("SELECT * FROM ".$pre."fields WHERE cat = '".$cat."' OR cat = '' OR cat = 'global' ORDER BY `id` DESC") or die(mysql_error());
	while($row = mysql_fetch_array($query)) {
		$name = "$row[name]";
		$type = "$row[type]";

		$dataa = mysql_fetch_row(mysql_query("SELECT data FROM ".$pre."fielddata WHERE name = '".$name."' AND id2 = '".$row2[id]."' AND cat = 'content'"));
		$data = stripslashes($dataa[0]);

		if ($type == "textarea") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><textarea name='".$name.$val."' cols=\"45\" rows=\"12\">".$data."</textarea></td></tr>";
		}
		if ($type == "textfield") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><input type=\"text\" name='".$name.$val."' value='".$data."'></td></tr>";
		}
		if ($type == "image") {
			echo "<tr><td>$name <a href='javascript:awindow(\"admin.php?load=help&id=$row[id]\", \"\", \"width=200,height=200,scroll=yes\")'><b>[Help]</b></a></td><td><input type=\"text\" name='".$name.$val."' value='".$data."'></td></tr>";
		}
		
		if ($type == "games") {
			$queryb  = "SELECT * FROM ".$pre."fielddata WHERE id2 = '".$row2[id]."' AND name = 'games'";
			$resultb = mysql_query($queryb);
			while($rowb = mysql_fetch_array($resultb)) {
			$sql2 = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."games WHERE id = '".$rowb[data]."'"));

			echo "<tr><td>".$name."</td><td><li>".$sql2[name]."</li></tr>";
			}
			echo "</td>";
		}

		if ($type == "system") {
			$queryb  = "SELECT * FROM ".$pre."fielddata WHERE id2 = '".$row2[id]."' AND name = 'systems'";
			$resultb = mysql_query($queryb);
			while($rowb = mysql_fetch_array($resultb)) {
			$sql2 = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."systems WHERE id = '".$rowb[data]."'"));

			echo "<tr><td>".$name."</td><td><li>".$sql2[name]."</li></tr>";
			}
			echo "</td>";
		}
	
		if ($type == "company") {
			$queryb  = "SELECT * FROM ".$pre."fielddata WHERE id2 = '".$row2[id]."' AND name = 'company'";
			$resultb = mysql_query($queryb);
			while($rowb = mysql_fetch_array($resultb)) {
			$sql2 = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."pr WHERE id = '".$rowb[data]."'"));

			echo "<tr><td>".$name."</td><td><li>".$sql2[name]."</li></tr>";
			}
			echo "</td>";
		}

	}
	
		if ($row2['save'] == 0) {
		$savestate = "No";
		} else {
		$savestate = "Yes";
		}
		
		echo "<tr><td>Save Post</td><td><select name = 'save_".$val."'><option value='".$row2['save']."' selected>".$savestate."</option><option value = '0'>No</option><option value = '1'>Yes</option>";
		
	if ($setting[wysiwyg] == "False") {
	echo "<tr><td>Automatically Break lines?</td><td><input type='checkbox' name='autobr_".$val."' value='yes'></td></tr>";
	}
	}
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Submit Changes\"></td></tr></form></table>";
}

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

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

   $r = mysql_query("UPDATE ".$pre."content SET name = '".addslashes($_POST["name_$val"])."', lev = '".$_POST["lev_$val"]."', save = '".$_POST["save_$val"]."' WHERE id = '".$val."'") 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());

   $result = mysql_query("SELECT * FROM ".$pre."fields WHERE cat = '".$_POST["cat_$val"]."' OR cat = 'global' OR cat = '' ORDER BY `id` DESC");
   while ($row = mysql_fetch_array($result)) {
   $name = "$row[name]";
   
   //Not working yet
  /*if ($name == "games") {
	while(list($anum, $ianumbers) = each ($_POST["games$val"])) 
	{
	print_r($ianum);
	   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$ianumbers."', '".$val."', 'content')");
	}
	}
	
if ($name == "systems") {
	while(list($anum, $ibnumbers) = each ($_POST["systems$val"])) 
	{
	   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$ibnumbers."', '".$val."', 'content')");
	}
	}

	if ($name == "company") {
		while(list(, $i251) = each ($_POST["company$val"])) 
		{
			mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'company', '".$i251."', '".$val."', 'content')");
		}
	}*/


   if (($name == "games") && ($name == "systems") && ($name == "company")) {
   } else {

   if (($_POST["autobr_$val"]) && ($row[type] == "textarea")) {
   $autobr = preg_replace("/<br>\n/","\n",addslashes($_POST["$name$val"]));
   $autobr = preg_replace("/<br \/>\n/","\n",addslashes($_POST["$name$val"]));
   $autobr = preg_replace("/(\015\012)|(\015)|(\012)/","<br>\n",addslashes($_POST["$name$val"]));
   } else {
   $autobr = addslashes($_POST["$name$val"]);
   }
    
   $thefcheck = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."fielddata WHERE id2 = '".$val."' AND cat = 'content' AND name = '".$name."'"));

   if ($autobr) {
   if ($thefcheck > "0") {
   mysql_query("UPDATE ".$pre."fielddata SET data = '".$autobr."' WHERE id2 = '".$val."' AND cat = 'content' AND name = '".$name."'");
   } else {
   mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, '".$name."', '".$autobr."', '".$val."', 'content')");
   }
   }
   }
   }

   }
if ($r == TRUE) {
echo re_direct("1500", "admin.php");
echo "The content has been updated. <a href=\"admin.php\">Return to Content Manager Home</a>";
}
}
}

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

	if ($ver == "yes") {
	echo "Sorry, but your not allowed to verify content.";
} else {

			echo "<title>OneCMS Admin > Verify Content</title>";

				echo "<form action='admin.php?view=search2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option>";
	
	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
    	echo "<option value=\"$name\">$name</option>";
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

			echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><form action='admin.php?view=ver2' name='form1' method='post'><tr><td><b>Name</b></td><td><b>Category</b></td><td><b><b>Verify</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";


$query="SELECT * FROM ".$pre."content WHERE ver = '1' ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		if ($row[postpone] == "") {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$cat2 = "$row[cat]";
		$name = stripslashes($name2);

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td>$cat2</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."content WHERE ver = '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=\"admin.php?view=ver&page=$prev\"><<Previous</a>&nbsp;";
}

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

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

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

if ($_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."content WHERE id = '$val'") or die(mysql_error());
$delete2 = mysql_query("DELETE FROM ".$pre."fielddata WHERE id2 = '$val' AND cat = 'content'") or die(mysql_error());
}
}

if ($_POST['id']) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Are you sure you want to verify this content?");
if (agree)
document.write("");
else
history.go(-1);
</SCRIPT>';

while (list(, $val) = each ($_POST['id'])) {
$r = mysql_query("UPDATE ".$pre."content SET ver = '0' WHERE id = '$val'") 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", "admin.php");
echo "Content has been verified/deleted";
}
}

if ($_GET['view'] == "search2") {
echo "<title>OneCMS Admin > Verify Content > Search</title>";

if ($_GET['cat'] == "") {
echo "<form action='admin.php?view=search2' name='form1' method='post'>";
} else {
echo "<form action='admin.php?view=search2&cat=".$_GET['cat']."' name='form1' method='post'>";
}
echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for unverified content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option>";

if ($_GET['cat'] == "") {
} else {
echo "<option value='".$_GET['cat']."'>".$_GET['cat']."</option>";
}
	
	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";

		if ($_GET['cat'] == "") {
		} else {
		if ($name == $_GET['cat']) {
		} else {
    	echo "<option value=\"$name\">$name</option>";
	}
	}
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='admin.php?view=ver' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Category</b></td><td><b><b>Verify</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND ver = '1' 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]";
		$cat5 = "$row[cat]";
		$name = stripslashes($name2);

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td>$cat5</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>";

if ($cat2 == "") {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND ver = '1'"),0);
} else {
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE name LIKE '%" . $_POST['search'] . "%' AND cat = '$cat2' AND ver = '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=\"admin.php?view=search2&page=$prev\"><<Previous</a>&nbsp;";
}

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

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

if (($_GET['view'] == "postpone") && ($_GET['edit'] == "1")) {

	echo "<form action='admin.php?view=postpone&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."content WHERE id = '$val'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
		$nameav = "$row2[name]";
		$namea = stripslashes($nameav);

	echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\"><tr><td><b><center>Item #".$val."</b></center></td></tr>";
	echo "<tr><td>Day:</td><td><select name='day_".$val."'>";
for ($i = 01; $i <= 31; $i++) {
	echo "<option value=\"$i\">$i</option>";
}
echo "</select></td></tr>";

echo "<tr><td>Month:</td><td><select name='month_".$val."'>";
for ($i = 01; $i <= 12; $i++) {
	echo "<option value=\"$i\">$i</option>";
}
echo "</select></td></tr>";
echo "<tr><td>Year:</td><td><select name='year_".$val."'>";
for ($i = 2005; $i <= 2012; $i++) {
	echo "<option value=\"$i\">$i</option>";
}
echo "</select></td></tr><tr><td>Hour:</td><td><select name='hour_".$val."'>";
for ($i = 00; $i <= 24; $i++) {
	echo "<option value=\"$i\">$i</option>";
}
echo "</select></td></tr><tr><td>Minutes:</td><td><select name='minutes_".$val."'>";
for ($i = 00; $i <= 59; $i++) {
	echo "<option value=\"$i\">$i</option>";
}
echo "</select></td></tr>";
	}
	}
			echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Submit Changes\"></td></tr></form></table>";
}

if (($_GET['view'] == "postpone") && ($_GET['edit'] == "2")) {

   while (list(, $val) = each ($_POST['id'])) {
   $postponeok = $_POST["year_$val"];

   if ($_POST["month_$val"] < "10") {
	   $postponeok4 = "0".$_POST["month_$val"];
   } else {
	   $postponeok4 = $_POST["month_$val"];
   }

   if ($_POST["day_$val"] < "10") {
	   $postponeok5 = "0".$_POST["day_$val"];
   } else {
	   $postponeok5 = $_POST["day_$val"];
   }
   
   if ($_POST["hour_$val"] < "10") {
	   $postponeok2 = "0".$_POST["hour_$val"];
   } else {
	   $postponeok2 = $_POST["hour_$val"];
   }
   
   if ($_POST["minutes_$val"] < "10") {
	   $postponeok3 = "0".$_POST["minutes_$val"];
   } else {
	   $postponeok3 = $_POST["minutes_$val"];
   }
   $upd = "UPDATE ".$pre."content SET postpone = '".$postponeok.$postponeok4.$postponeok5.$postponeok2.$postponeok3."', ver = '1' WHERE id = '$val'";
   $r = mysql_query($upd) 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());
   }
if ($r == TRUE) {
echo re_direct("1500", "admin.php");
echo "The content has been postponed. <a href=\"admin.php?view=postpone\">Return to Postpone Manager Home</a>";
}
}

if (($_GET['view'] == "postpone") && ($_GET['edit'] == "")) {
			echo "<title>OneCMS Admin > Postpone Content</title>";

				echo "<form action='admin.php?view=search3' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for content</td><td><input type='text' name='search'></td><td><select name='cat2'><option value=\"\">---------</option>";
	
	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
    	echo "<option value=\"$name\">$name</option>";
	}
	
	echo "</select></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

			echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><form action='admin.php?view=postpone&edit=1' name='form1' method='post'><tr><td><b>Name</b></td><td><b>Category</b></td><td><b><b>Update</b></td></tr><center><div align=\"center\">";


$query="SELECT * FROM ".$pre."content 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]";
		$cat2 = "$row[cat]";
		$name = stripslashes($name2);

    	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."' target='popup'>$name</a></td><td>$cat2</td><td><input type=\"checkbox\" name=\"id[]\" 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."content"),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=\"admin.php?view=postpone&page=$prev\"><<Previous</a>&nbsp;";
}

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

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

if ($_GET['load'] == "ipban") {
$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to manage systems. You are only a $level.";
} else {

	echo "<center><a href='admin.php?load=ipban'>Manage Banned IP's</a> | <a href='admin.php?load=ipban&view=add'>Ban IP's</a></center><br><br>";

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

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

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

$query="SELECT * FROM ".$pre."ipban ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name2 = "$row[ip]";
		$name = stripslashes($name2);

    	echo "<tr><td>$name</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."ipban"),0);

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

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

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

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

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

echo "<form action=\"admin.php?load=ipban&view=add\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many ip's to ban?</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='admin.php?load=ipban&view=add&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>IP #".$i."</b></center></td></tr><tr><td>IP</td><td><input type=\"text\" name='ip_".$i."'></td></tr><tr><td>Ban from Forums?</td><td><select name='forums_".$i."' multiple><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr><tr><td>Ban from Site?</td><td><select name='site_".$i."' multiple><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr><tr><td>Ban from Admin CP?</td><td><select name='cp_".$i."' multiple><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr>";
}
	}
echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form></table>";
}

if (($_GET['view'] == "add") && ($_GET['add'] == "yes")) {

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

   $r = mysql_query("INSERT INTO ".$pre."ipban VALUES (null, '".$_POST["ip_$i"]."', '".$_POST["forums_$i"]."', '".$_POST["site_$i"]."', '".$_POST["cp_$i"]."', '".time()."')") 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", "admin.php?load=ipban");
echo "The ip(s) have been banned. <a href=\"admin.php?load=ipban\">Manage Banned IP's</a>";
}
}

if (($_GET['view'] == "manage") && ($_POST['id'] == "")) {
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."ipban 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", "admin.php?load=ipban");
echo "The banned ip(s) have been deleted. <a href=\"admin.php?load=ipban\">Manage Banned </a>";
}
}

if (($_GET['view'] == "add") && ($_GET['add'] == "no")) {

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

   $r = mysql_query("UPDATE ".$pre."ipban SET ip = '".$_POST["ip_$i"]."', site = '".$_POST["site_$i"]."', forums = '".$_POST["forums_$i"]."', cp = '".$_POST["cp_$i"]."', date = '".time()."' 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", "admin.php?load=ipban");
echo "The banned ip(s) have been updated. <a href='admin.php?load=ipban'>Mange Banned IP's</a>";
}
}

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

    while (list(, $i) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."ipban 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>IP #".$i."</b></center></td></tr><tr><td>IP</td><td><input type=\"text\" name='ip_".$i."' value='".$row2[ip]."'></td></tr><tr><td>Ban from Forums?</td><td><select name='forums_".$i."' multiple><option value='".$row2[forums]."' selected>-- ".$row2[forums]." --</option><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr><tr><td>Ban from Site?</td><td><select name='site_".$i."' multiple><option value='".$row2[site]."' selected>-- ".$row2[site]." --</option><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr><tr><td>Ban from Admin CP?</td><td><select name='cp_".$i."' multiple><option value='".$row2[cp]."' selected>-- ".$row2[cp]." --</option><option value='yes'>Yes</option><option value='no'>No</option></select></td></tr>";
	
}
}

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

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

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

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

	$query="SELECT * FROM ".$pre."ipban WHERE name 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[ip]";
		$name = stripslashes($name2);

    	echo "<tr><td>$name</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=\"admin.php?load=ipban&view=add\">Add Company</a></td></tr></form></table><br><br>";

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

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

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

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

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

if ($_GET['load'] == "login") {
$admin_page = "yes";
if ($_GET['login'] == "yes") {
$usernameb = check(stripcslashes($_POST['username']));
$passwordc = check($_POST['password']); 
$passwordb = md5($salt.$passwordc);

$sql = mysql_query("SELECT * FROM ".$pre."users WHERE username = '".$usernameb."' AND password = '".$passwordb."' LIMIT 1");
$login_check = mysql_num_rows($sql);

$sql3 = mysql_query("SELECT * FROM ".$pre."userlevels WHERE name = '".$levely."'");
while($row = mysql_fetch_array($sql3)) {
	$leveltr = "$row[level]";
}

if (($login_check == "1") && ($leveltr < "6")) {
if ($dcheck == "yes") {
setcookie($pre."username", $usernameb, time()+24*3600*30, "/", ".".$domain);
setcookie($pre."password", $passwordb, time()+24*3600*30, "/", ".".$domain);
setcookie($pre."login_date", time(), time()+24*3600*30, "/", ".".$domain);
} else {
setcookie($pre."username", $usernameb, time()+24*3600*30);
setcookie($pre."password", $passwordb, time()+24*3600*30);
setcookie($pre."login_date", time(), time()+24*3600*30);
}

mysql_query("UPDATE ".$pre."users SET logged = '$timelogin' WHERE username = '".$usernameb."'") or die(mysql_error());
echo re_direct("1000", "admin.php?view=home");     

echo '<style>
body { font-family: tahoma;
font-size: 11px;
color: black;  }

td {
font-family: tahoma;
font-size: 11px;
color: black;
}

TABLE.text1 {
font-family: tahoma;
border:1px solid black;
font-size: 11px;
color: black;
}

TD.nay {
font-family: tahoma;
font-size: 11px;
color: white;
}

.quote {
	font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #444444; line-height: 125%;
	background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
a:link {color: #000000;  font-family: tahoma; text-decoration: none}
a:visited {color: #000000;  font-family: tahoma; text-decoration: none} 
a:active {color: #000000;  font-family: tahoma; text-decoration: none} 
a:hover {color: #2EA8F3;  font-family: tahoma; text-decoration: none}
a:visited:hover {text-decoration: none; color: #2EA8F3}
</style>';

echo "<title>OneCMS Admin Panel :: Login</title>
<body bgcolor='#DCDCDC'>
<br /><br /><br /><br />
<center><img src='templates/main/images/banner.gif'>
<table width='800' border='0' cellpadding='0' cellspacing='0'><tr><td height='21' align='center' valign='middle' bgcolor='#2EA8F3'><strong>Login Successful at <b>".$domain."</b>!</strong></td>
</tr>
<tr bgcolor='#F2F2F2'><td height='43' valign='top'>Welcome back ".$usernameb.". Continue onto admin CP home...<br><a href='admin.php?view=home'>Continue</a></table></form></center></td></tr></table>";
} else {
mysql_query("UPDATE ".$pre."users SET logged = '0' WHERE id = '".$row[id]."'") or die(mysql_error());
echo "Sorry, but your login info is incorrect. Please <a href='admin.php?load=login'>go back</a> and try again.";
}
}

if ($_GET['login'] == "no") {
echo "You are only a $level, you do not have permission to access the admin panel.";
}

if ($_GET['login'] == "no2") {
echo "It seems you are logged in but with incorrect info. This could be because your password was changed, try to logout and then <a href='admin.php?load=login'>re-login</a>.";
}

if ($_GET['login'] == "") {
if (($_COOKIE[$pre."username"]) && ($leveltr < "6")) {
header ('location: admin.php?view=home');
} else {
echo '<style>
body { font-family: tahoma;
font-size: 11px;
color: black;  }

td {
font-family: tahoma;
font-size: 11px;
color: black;
}

TABLE.text1 {
font-family: tahoma;
border:1px solid black;
font-size: 11px;
color: black;
}

TD.nay {
font-family: tahoma;
font-size: 11px;
color: white;
}

.quote {
	font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #444444; line-height: 125%;
	background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
a:link {color: #000000;  font-family: tahoma; text-decoration: none}
a:visited {color: #000000;  font-family: tahoma; text-decoration: none} 
a:active {color: #000000;  font-family: tahoma; text-decoration: none} 
a:hover {color: #2EA8F3;  font-family: tahoma; text-decoration: none}
a:visited:hover {text-decoration: none; color: #2EA8F3}
</style>
<title>OneCMS Admin Panel :: Login</title>
<body bgcolor="#DCDCDC">
<br /><br /><br /><br />
<center><img src="templates/main/images/banner.gif">
<table width="800" border="0" cellpadding="0" cellspacing="0"><tr><td height="21" align="center" valign="middle" bgcolor="#2EA8F3"><strong>Login</strong></td>
</tr>
<tr bgcolor="#F2F2F2"><td height="43" valign="top"><center><form action="admin.php?load=login&login=yes" method="post">
<table cellpadding=2 cellspacing=0 border=0>
<td>Username:</td><td><input type="text" name="username" value="" size=10></td><tr>
<td>Password:</td><td><input type="password" name="password" value="" size=10></td><tr>
<td></td><td><input type="submit" name="submit" value="Log In"></td>
</table></form></center></td></tr></table>';
}
}
}

if ($_GET['load'] == "logout") {
$admin_page = "yes";
if ($dcheck == "yes") {
setcookie($pre."username", "", ""-24*3600*30, "/", ".".$domain);
setcookie($pre."password", "", ""-24*3600*30, "/", ".".$domain);
setcookie($pre."login_date", "", ""-24*3600*30, "/", ".".$domain);
} else {
setcookie($pre."username", "", ""-24*3600*30);
setcookie($pre."password", "", ""-24*3600*30);
setcookie($pre."login_date", "", ""-24*3600*30);
}

$upd = mysql_query("UPDATE ".$pre."users SET logged = '0' WHERE username = '".$_COOKIE[$pre."username"]."'") or die(mysql_error());
eval (" ?>" . admin_header() . " <?php ");
echo re_direct("1000", "../index.php");  
echo "You are now logged out. Taking you to main site";
eval (" ?>" . admin_footer() . " <?php ");
}

if ($_GET['load'] == "modules") {
$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to the Module Manager. You are only a $level.";
} else {

echo "<center><a href='admin.php?load=modules&view=add'>Add Modules</a> | <a href='admin.php?load=modules'>Manage Modules</a> | <a href='admin.php?load=modules&view=search'>Search</a></center><br><br>";

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

	echo "<title>OneCMS - www.onecms.net > Modules > Search</title><form action='admin.php?load=modules&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='admin.php?load=modules&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Module Name</b></td><td><b>URL</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."mods WHERE name LIKE '%" . $_POST['search'] . "%' AND readme = '' 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>".$name."</td><td><a href='".$url."' target='popup'>".$url."</a></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."mods WHERE name LIKE '%" . $_POST['search'] . "%' AND readme = ''"),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=\"admin.php?load=modules&view=search&page=$prev\"><<Previous</a>&nbsp;";
}

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

if ($_GET['view'] == "") {
	echo "<title>OneCMS - www.onecms.net > Manage Modules</title><form action='admin.php?load=modules&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='admin.php?load=modules&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Module Name</b></td><td><b>URL</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."mods WHERE readme = '' 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>".$name."</td><td><a href='".$url."' target='popup'>".$url."</a></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."mods WHERE readme = ''"),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=\"admin.php?load=modules&page=$prev\"><<Previous</a>&nbsp;";
}

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

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."mods 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", "admin.php?load=modules");
echo "The module(s) have been deleted. <a href=\"admin.php?load=modules\">Manage Modules</a>";
}
}

if ((($_GET['view'] == "manage") && ($_POST['delete'] == "") && ($_GET['edit'] == ""))) {
	echo "<form action='admin.php?load=modules&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."mods 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>Module #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."' value='".$r[name]."'></td></tr><tr><td>URL (to module backend, only put in the filename and extension...ex.a_top10.php)</td><td><input type=\"text\" name='url_".$i."' value='".$r[url]."'></td></tr><tr><td>Installed?</td><td><select name='installed_".$i."'><option value='".$r[installed]."' selected>-- ".$r[installed]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr><tr><td>Version</td><td><input type='text' name='version_".$i."' value='".$r[version]."'></td></tr><tr><td>URL (to module frontend, only put in the filename and extension...ex.top10.php)</td><td><input type='text' name='url2_".$i."' value='".$r[sql]."'></td></tr><tr><td>Module 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."mods 
            SET  
                name      = '" . mysql_real_escape_string($_POST["name_$val"]) . "',  
                url       = '" . mysql_real_escape_string($_POST["url_$val"]) . "',  
                installed = '" . mysql_real_escape_string($_POST["installed_$val"]) . "',  
                status    = '" . mysql_real_escape_string($_POST["status_$val"]) . "',  
                version   = '" . mysql_real_escape_string($_POST["version_$val"]) . "',  
                sqla      = '" . mysql_real_escape_string($_POST["url2_$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", "admin.php?load=modules"); 
        echo "The modules has been updated. <a href=\"admin.php?load=modules\">Manage Modules</a>"; 
    } 
}  	

if ($_GET['view'] == "add") {
	echo "<form action=\"admin.php?load=modules&view=add\" name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many modules 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='admin.php?load=modules&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>Module #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>URL (to module backend, only put in the filename and extension...ex.a_top10.php)</td><td><input type=\"text\" name='url_".$i."'></td></tr><tr><td>Installed?</td><td><select name='installed_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr><tr><td>Version</td><td><input type='text' name='version_".$i."'></td></tr><tr><td>URL to readme file</td><td><input type='text' name='readme_".$i."'></td></tr><tr><td>URL (to module frontend, only put in the filename and extension...ex.top10.php)</td><td><input type='text' name='url2_".$i."'></td></tr><tr><td>Module status?</td><td><select name='status_".$i."'><option value='On'>On</option><option value='Off'>Off</option></select></td></tr>";
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form>";
	}
	echo "</table>";
}

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

for($i = 0; $i < $_POST['s']; $i = $i+1) {
$r = mysql_query("INSERT INTO ".$pre."mods VALUES (null, '".$_POST["name_$i"]."', '".$_POST["url_$i"]."', '".$_POST["installed_$i"]."', '".$_POST["version_$i"]."', '".$_POST["readme_$i"]."', '".$_POST["url2_$i"]."', '".$_POST["status_$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", "admin.php?load=modules");
echo "The module(s) have been created. <a href=\"admin.php?load=modules\">Manage Modules</a>";
}
}
}
}


if ($_GET['load'] == "pages") {
$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to manage pages. You are only a $level.";
} else {

	echo "<center><a href=\"admin.php?load=pages&view=add1\">Add pages</a> | <a href=\"admin.php?load=pages&view=add2\">Add pages (to content)</a> | <a href='admin.php?load=pages'>Manage Pages</a></center><br><br>";

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

	echo "<form action='admin.php?load=pages&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."pages 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='pages.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."pages WHERE type = 'backend'"),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=\"admin.php?load=pages&page=$prev\"><<Previous</a>&nbsp;";
}

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

if (($_GET['view'] == "add1") && ($_GET['add'] == "")) {
echo "<form action=\"admin.php?load=pages&view=add1\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many pages 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='admin.php?load=pages&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>Page #".$i."</b></center></td></tr><tr><td>Page Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Coding</td><td><textarea name='content_".$i."' cols='45' rows='12'></textarea></td></tr>";
    echo "<tr><td>Page Online?</td><td><select name='online_".$i."' multiple><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr><tr><td>URL (ex. contact)</td><td><input type='text' name='url_".$i."'></td></tr>";
}
echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form></table>";
}
}

if (($_GET['view'] == "add2") && ($_GET['add'] == "")) {
echo "<form action=\"admin.php?load=pages&view=add2\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many pages 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='admin.php?load=pages&view=add2&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>Page #".$i."</b></center></td></tr>";
	echo "<tr><td>Content</td><td><textarea name='content_".$i."' cols='45' rows='12'></textarea></td></tr>";
    echo "<tr><td>Page Online?</td><td><select name='online_".$i."' multiple><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr><tr><td>Content for this page to be linked to</td><td><select name='url_".$i."'>";
	
	$sql = mysql_query("SELECT * FROM ".$pre."content ORDER BY `id` DESC");
	while($row = mysql_fetch_array($sql)) {

	$check1 = mysql_query("SELECT * FROM ".$pre."cat WHERE name = '".$row[cat]."'");
	$check2 = mysql_num_rows($check1);

	if ($check2 == "1") {

	$perm = mysql_query("SELECT * FROM ".$pre."permissions WHERE username = '".$_COOKIE[$pre."username"]."' AND ".$row[cat]." = 'yes'") or die(mysql_error());
	$numper = mysql_num_rows($perm);

	if ($numper > "0") {
		echo "<option value=\"".$row[id]."\">".$row[name]."</option>";
	}
	}
	}

	echo "</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."pages VALUES (null, '".$_POST["name_$i"]."', '".$_POST["url_$i"]."', '".addslashes($_POST["content_$i"])."', '".$_POST["online_$i"]."', 'backend')") 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", "admin.php?load=pages");
echo "The page(s) have been created. <a href=\"admin.php?load=pages\">Return to Page Manager Home</a>";
}
}

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

   $findea = mysql_query("SELECT * FROM ".$pre."pages WHERE url = '".$_POST["url_$i"]."' AND type = 'frontend'");
   $page = mysql_num_rows($findea);
   
   $pagename = $page + 2;

   $r = mysql_query("INSERT INTO ".$pre."pages VALUES (null, '".$pagename."', '".$_POST["url_$i"]."', '".addslashes($_POST["content_$i"])."', '".$_POST["online_$i"]."', 'frontend')") 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", "admin.php?load=pages");
echo "The page(s) have been created. <a href=\"admin.php?load=pages\">Return to Page 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."pages 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", "admin.php?load=pages");
echo "The page(s) have been deleted. <a href=\"admin.php?load=pages\">Return to Page Manager Home</a>";
}
}

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

	$row1 = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."content WHERE id = '".$row2[url]."'"));

 echo "<input type='hidden' name='id[]' value='".$row2[id]."'><tr><td><b><center>Page #".$i."</b></center></td></tr>";
 echo "<tr><td>Page Name</td><td><input type=\"text\" name='name_".$i."' value='".$row2[name]."'></td></tr><tr><td>Content</td><td><textarea name='content_".$i."' cols='45' rows='12'>".stripslashes($row2[content])."</textarea></td></tr><tr><td>Page Online?</td><td><select name='online_".$i."' multiple><option value='".$row2[online]."' selected>-- ".$row2[online]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></select></td></tr>";
  if ($row2['type'] == "frontend") {
 echo "<tr><td>Content for this page to be linked to</td><td><select name='url_".$i."'><option value='".$row2[url]."' selected>-- ".$row1[0]." --</option>";
	
	$query="SELECT * FROM ".$pre."content";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$cat = "$row[cat]";
	$name = "$row[name]";
	$id = "$row[id]";

	$queryy = mysql_query("SELECT * FROM ".$pre."permissions WHERE username = '$username' AND ".$cat." = 'yes'") or die(mysql_error());
	$numb = mysql_num_rows($queryy);

	if ($numb == "0") {
		echo "";
	} else {
		echo "<option value=\"$id\">$name</option>";
	}
	}

	echo "</td></tr>";
	} else {
	echo "</tr><tr><td>URL (ex. contact)</td><td><input type='text' name='url_".$i."' value='".$row2[url]."'></td></tr>";
	}
}
}
echo "<tr><td><input type=\"submit\" name=\"Modify\" value=\"Modify\"></td></tr></form></table>";
}

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

	echo "<form action='admin.php?load=pages&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."pages 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='pages.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=\"admin.php?load=pages&view=add\">Add Company</a></td></tr></form></table><br><br>";

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

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"admin.php?load=pages&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=\"admin.php?load=pages&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."pages SET name = '".$_POST["name_$i"]."', url = '".$_POST["url_$i"]."', content = '".addslashes($_POST["content_$i"])."', online = '".$_POST["online_$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", "admin.php?load=pages");
echo "The page(s) have been updated. <a href='admin.php?load=pages'>Return to Page Manager Home</a>";
}
}
}
}

if ($_GET['load'] == "polls") {
$admin_page = "yes";
echo "<center><a href=\"admin.php?load=polls&view=add1\">Add poll</a> | <a href='admin.php?load=polls&view=add2'>Add options</a> | <a href='admin.php?load=polls'>Manage Polls/Options</a></center><br><br>";

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

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

$query="SELECT * FROM ".$pre."polls WHERE type = 'pollname' OR type = 'option' 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>$name</td><td>$row[type]</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."polls WHERE type = 'pollname' OR type = 'option'"),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=\"admin.php?load=polls&page=$prev\"><<Previous</a>&nbsp;";
}

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

if (($_GET['view'] == "add1") && ($_GET['add'] == "")) {
echo "<form action=\"admin.php?load=polls&view=add1\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many polls 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='admin.php?load=polls&view=add1&add=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

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

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

if (($_GET['view'] == "add2") && ($_GET['add'] == "")) {
echo "<form action=\"admin.php?load=polls&view=add2\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many options 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='admin.php?load=polls&view=add2&add=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

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

    for($i = 0; $i < $_POST['search']; $i = $i+1) {
    echo "<tr><td><b><center>Option #".$i."</b></center></td></tr><tr><td>Option Name</td><td><input type=\"text\" name='name_".$i."'></td></tr>";
    echo "<tr><td>Assign to poll</td><td><select name='poll_".$i."'>";
    	$query="SELECT * FROM ".$pre."polls WHERE type = 'pollname' ORDER BY `id` DESC";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	echo "<option value=\"$row2[name]\">$row2[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."polls VALUES (null, '".$_POST["name_$i"]."', 'pollname', '".$_POST["name_$i"]."', '0')") 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());

   $r2 = mysql_query("INSERT INTO ".$pre."polls VALUES (null, '".addslashes($_POST["q_$i"])."', 'question', '".$_POST["name_$i"]."', '0')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
if (($r2 == TRUE) && ($r == TRUE)) {
echo re_direct("1500", "admin.php?load=polls");
echo "The poll(s) have been created. <a href=\"admin.php?load=polls\">Return to Poll Manager Home</a>";
}
}

if (($_GET['view'] == "add2") && ($_GET['add'] == "yes")) {
   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   $r = mysql_query("INSERT INTO ".$pre."polls VALUES (null, '".$_POST["name_$i"]."', 'option', '".$_POST["poll_$i"]."', '0')") 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", "admin.php?load=polls");
echo "The option(s) have been created. <a href=\"admin.php?load=polls\">Return to Poll Manager Home</a>";
}
}

if (($_GET['view'] == "manage") && ($_GET['edit'] == "")) {
if ($_POST['delete']) {
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."polls 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", "admin.php?load=polls");
echo "The poll(s)/option(s) have been deleted. <a href=\"admin.php?load=polls\">Return to Poll Manager Home</a>";
}
}

if ($_POST['id']) {
	echo "<form action='admin.php?load=polls&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."polls WHERE id = '$i'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
    $name = stripslashes($row2['name']);

    if ($row2['type'] == "option") {
    echo "<input type='hidden' name='id[]' value='".$i."'><tr><td><b><center>Option #".$i."</b></center></td></tr><tr><td>Option Name</td><td><input type=\"text\" name='name_".$i."' value='".$name."'></td></tr><tr><td>Assign to poll</td><td><select name='poll_".$i."'><option value='".$row2['pname']."' selected>-- ".$row2['pname']." --</option>";
    $query="SELECT * FROM ".$pre."polls WHERE type = 'pollname'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	echo "<option value=\"$row2[name]\">$row2[name]</option>";
	}
	echo "</select></td></tr>";
} else {
	$query="SELECT name FROM ".$pre."polls WHERE type = 'question' AND pname = '".$row2[pname]."'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$q = "$row[name]";
	}
echo "<input type='hidden' name='id[]' value='".$i."'><input type='hidden' name='type_".$i."' value='".$row2['type']."'><input type='hidden' name='pname2_".$i."' value='".$name."'><tr><td><b><center>Poll #".$i."</b></center></td></tr><tr><td>Poll Name</td><td><input type=\"text\" name='pname_".$i."' value='".$name."'></td></tr><tr><td>Poll Question</td><td><input type=\"text\" name='question_".$i."' value=\"$q\"></td></tr>";
}
}
}
echo "<tr><td><input type=\"submit\" value=\"Modify\"></td></tr></form></table>";
}
}

if (($_GET['view'] == "manage") && ($_GET['edit'] == "2")) {
   while (list(, $i) = each ($_POST['id'])) {
   if ($_POST["type_$i"] == "option") {
   $r = mysql_query("UPDATE ".$pre."polls SET name = '".$_POST["question_$i"]."', pname = '".$_POST["pname_$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());
   } else {
   $r = mysql_query("UPDATE ".$pre."polls SET pname = '".$_POST["pname_$i"]."' WHERE pname = '".$_POST["pname2_$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());
   $r2 = mysql_query("UPDATE ".$pre."polls SET name = '".$_POST["question_$i"]."' WHERE type = 'Question' AND pname = '".$_POST["pname_$i"]."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r2."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   $r3 = mysql_query("UPDATE ".$pre."polls SET name = '".$_POST["pname_$i"]."' WHERE name = '".$_POST["pname2_$i"]."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r3."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
   }
if ($r == TRUE) {
//echo re_direct("1500", "admin.php?load=polls");
echo "The poll(s) have been updated. <a href='admin.php?load=polls'>Return to Poll Manager Home</a>";
}
}

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

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

	$query="SELECT * FROM ".$pre."polls WHERE name LIKE '%" . $_POST['search'] . "%' OR pname 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]";
		$name = stripslashes($name2);
    	echo "<tr><td>$name</td><td>$row[type]</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=\"admin.php?load=polls&view=add\">Add Company</a></td></tr></form></table><br><br>";

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

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

if ($_GET['load'] == "search") {
$admin_page = "yes";
if ($_GET['view'] == "types") {
echo "<SCRIPT LANGUAGE='JavaScript'>
function file(text) {
	text = '' + text + '';
	opener.document.form1.".intval($_GET['id']).".value  += text;
	opener.document.form1.".intval($_GET['id']).".focus();
  }
function file2(text) {
	text = '' + text + '';
	opener.document.form1.".$_GET['id2'].".value  += text;
	opener.document.form1.".$_GET['id2'].".focus();
  }
</SCRIPT>";
		echo "<LINK REL='stylesheet' HREF='ta3.css' TYPE='text/css'><form action='admin.php?load=search&view=types' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for ".$_GET['type']."</td><td><input type='text' name='keyword'></td><td><input type='submit' name='submit' value='Search'></td></tr></table></form>";

		echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>".$_GET['type']." Name</b></td><td>ID</td></tr>";

	$queryed="SELECT * FROM ".$pre.$_GET['type'];
	if ($_GET['type'] == "albums") {
		$queryed .= " WHERE type = 'album'";
	}
	$resulted=mysql_query($queryed);
	while($row2 = mysql_fetch_array($resulted)) {
		echo "<tr><td><a href=\"javascript:file2('".$row2[id]."')\" onClick=\"javascript:file('".$row2[name]."')\">".$row2[name]."</a></td><td>".$row2[id]."</td></tr>";
	}

	echo "</table><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><br><br><center><a href='javascript:window.close();'><b>Close Window</b></a></center></td></tr></table>";

if ($_POST['submit']) {
	echo "<SCRIPT LANGUAGE='JavaScript'>
function file(text) {
	text = '' + text + '';
	opener.document.form1.".intval($_GET['id']).".value  += text;
	opener.document.form1.".intval($_GET['id']).".focus();
  }
function file2(text) {
	text = '' + text + '';
	opener.document.form1.".$_GET['id2'].".value  += text;
	opener.document.form1.".$_GET['id2'].".focus();
  }
</SCRIPT>";

echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>".$_GET['type']." Name</b></td><td>ID</td></tr>";

	$queryed="SELECT * FROM ".$pre.$_GET['type']." WHERE name LIKE '%".$_POST["keyword"]."%'";
	if ($_GET['type'] == "albums") {
		$queryed .= " AND type = 'album'";
	}
	$resulted=mysql_query($queryed);
	while($row2 = mysql_fetch_array($resulted)) {
		$a = "/".$_POST['keyword']."/";
		$b = "<b>".$_POST['keyword']."</b>";
		$key = preg_replace($a, $b, $row2[name]);
		echo "<tr><td><a href=\"javascript:file2('".$row2[id]."')\" onClick=\"javascript:file('".$row2[name]."')\">".$key."</a></td><td>".$row2[id]."</td></tr>";
	}

	echo "</table><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><br><br><center><a href='javascript:window.close();'><b>Close Window</b></a></center></td></tr></table>";
}
}
/////////////////////////////////////////////////////
if ($_GET['view'] == "files") {
	echo "<LINK REL='stylesheet' HREF='ta3.css' TYPE='text/css'><form action='admin.php?load=search&view=files' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for file</td><td><input type='text' name='keyword'></td><td><input type='submit' name='submit' value='Search'></td></tr></table></form>";

if ($_POST['submit']) {
	echo "<SCRIPT LANGUAGE='JavaScript'>
function file(text) {
	text = '' + text + '';
	opener.document.form1.file_".intval($_GET['id']).".value  += text;
	opener.document.form1.file_".intval($_GET['id']).".focus();
  }
function file2(text) {
	text = '' + text + '';
	opener.document.form1.file2_".intval($_GET['id']).".value  += text;
	opener.document.form1.file2_".intval($_GET['id']).".focus();
  }
</SCRIPT>";

echo "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>File Name</b></td><td><b>Date</b></td></tr>";

	$queryed="SELECT * FROM ".$pre."images WHERE name LIKE '%".$_POST["keyword"]."%'";
	$resulted=mysql_query($queryed);
	while($row2 = mysql_fetch_array($resulted)) {
		$a = "/".$_POST['keyword']."/";
		$b = "<b>".$_POST['keyword']."</b>";
		$key = preg_replace($a, $b, $row2[name]);
		echo "<tr><td><a href=\"javascript:file('".$row2[name]."')\" onClick=\"javascript:file2('".$row2[id]."')\">".$key."</a></td><td>".date($dformat, $row2[date])."</td></tr>";
	}

	echo "</table><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><br><br><center><a href='javascript:window.close();'><b>Close Window</b></a></center></td></tr></table>";
}
}
}


if ($_GET['load'] == "help") {
$admin_page = "yes";
echo '<link rel="stylesheet" href="v3_2.css" type="text/css">';

if (!is_numeric($_GET['id'])) {
if ($_GET['id'] == "list3") {
echo "More than likely you came from the 'List' help tutorial and want to find out the id of a system. Below all systems, along with there ID, are listed.<br><br><table cellspacing='0' cellpadding='2' border='0' align='center'><tr><td><b>System Name</b></td><td><b>ID</b></td></tr>";

$sql = mysql_query("SELECT * FROM ".$pre."systems ORDER BY `id` DESC");
while($r = mysql_fetch_array($sql)) {
echo "<tr><td>".$r[name]."</td><td><i>".$r[id]."</i></td></tr>";
}

echo "</table>";
}
} else {
$des = mysql_fetch_row(mysql_query("SELECT name,des FROM ".$pre."fields WHERE id = '".$_GET['id']."'"));

echo "<title>Help :: $des[0] field</title><b><center><font size='1' face='verdana'>Help for field: </b><i>$des[0]</i><br><br>$des[1]<br><br><a href=\"javascript:self.close()\">Close Window</a>";
}
}

if ($_GET['load'] == "chat") {
$admin_page = "yes";

if ($_GET['view'] == "chat2") {
echo "<SCRIPT LANGUAGE='JavaScript'>
  function smiles(which) {
  document.form1.text1.value = document.form1.text1.value + which;
  }
</SCRIPT>";
echo wysiwyg();
echo "<link rel='stylesheet' type='text/css' href='ta3.css'><form action='admin.php?load=chat&view=chat3' method='post' name='form1'><table cellspacing=\"5\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Message Subject:</td><td><input type='text' name='subject'></td></tr><tr><td>Message:</td><td><textarea name='text1' cols='25' rows='7'></textarea></td>";
echo "<td width='65' align='center'><b>Smilies</b><br>";
$samount = "0";
if ($handle = opendir("../smilies")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$samount = $samount + 1;
if (($samount == "9") or ($samount < "9")) {
$file2 = explode(".", $file);
echo "<a href=\"javascript:smiles(' :".strtolower($file2[0]).": ')\"><img src='../smilies/".$file."' border='0'></a>&nbsp;";
}
}
}
}
echo "<br><br><a href='javascript:awindow(\"comments.php?view=smilies\", \"\", \"width=200,height=200,scroll=yes\")'>View All</a>";
echo "</td></tr><tr><td><input type='submit' value='Submit Message'></td></tr></table></form>";
}

if ($_GET['view'] == "chatdelete") {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm deletion of chat message?");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</SCRIPT>';
if (is_numeric($_GET['id'])) {
$delete = mysql_query("DELETE FROM ".$pre."chat WHERE id = '".$_GET['id']."'") or die(mysql_error());

if ($delete == TRUE) {
echo "<link rel='stylesheet' type='text/css' href='ta3.css'>Chat message deleted. <a href='admin.php?load=chat'>Go back to the chat</a>";
}
} else {
echo "Invalid ID number, go back";
}
}

if ($chat2[$userlevel] == "Yes") {
if ($_GET['view'] == "chat3") {
$chatmessage = mysql_query("INSERT INTO ".$pre."chat VALUES (null, '".$useridn."', '".$_POST['subject']."', '".addslashes($_POST['text1'])."', '".time()."')") or die(mysql_error());

if ($chatmessage == TRUE) {
echo "<link rel='stylesheet' type='text/css' href='ta.css'>Message posted. <a href='admin.php?load=chat'>View it</a>";
}
}

if ($_GET['view'] == "") {
include ("../forum_functions.php");
echo "<link rel='stylesheet' type='text/css' href='ta3.css'><table cellspacing=\"5\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Refresh Chat <input type=checkbox onclick=\"window.location='admin.php?load=chat'; return true;\"></td><td><a href='admin.php?load=chat&view=chat2'>Post Message</a><br><br></td></tr>";

$sql = mysql_query("SELECT * FROM ".$pre."chat ORDER BY `date` DESC LIMIT ".$chat."");
while($row = mysql_fetch_array($sql)) {

$rowr = mysql_fetch_row(mysql_query("SELECT username FROM ".$pre."profile WHERE id = '".$row[uid]."'"));
$r = mysql_fetch_row(mysql_query("SELECT rank FROM ".$pre."users WHERE username = '".$rowr[0]."'"));
$color = mysql_fetch_row(mysql_query("SELECT color FROM ".$pre."ranks WHERE name = '".$r[0]."'"));

if ($handlea = opendir("../smilies")) {
while (false !== ($fileb = readdir($handlea))) {
if ($fileb != "." && $fileb != "..") {
$file2e = explode(".", $fileb);
$tr1[] = ":".$file2e[0].":";
$tr2[] = "[img]smilies/".$fileb."[/img]";
}
}
}

$message = str_replace($tr1, $tr2, stripslashes($row[message]));
$subject = str_replace($tr1, $tr2, stripslashes($row[subject]));
$message = alinks($message);
$message = bbcode($message);

	echo "<tr><td><b>".$subject."</b> posted by <a href='".$elite1.$row[uid].$elite2."'>";
	
	if ($color[0]) {
		echo "<font color='".$color[0]."'>".$rowr[0]."</font>";
	} else {
		echo $rowr[0];
	}

	echo "</a> at <i>".date($dformat, $row[date])."</i>";
	if (($userlevel == "1") or ($userlevel == "2")) {
	echo "&nbsp;&nbsp;<a href='admin.php?load=chat&view=chatdelete&id=".$row[id]."'><b>Delete</b></a>";
	}
	echo "</td></tr><tr><td><p>".$message."</p></td></tr>";
}
echo "</table>";
}
}
}

if ($admin_page == "") {
echo "Sorry but this admin page does not exist.";
}

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