<?php
$la = "a";
$z = "b";
include ("config.php");

if ($ipbancheck2 == "0") {
if ($numvb == "0"){
	if ($warn == $naum) {
	echo "You are banned from the forums...now go away!";
} else {
echo "<link href='".$_SERVER['REQUEST_URI']."' rel='".$_SERVER['REQUEST_URI']."' />";
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><script language="javascript">
function awindow(towhere, newwinname, properties) {
window.open(towhere,newwinname,properties);
}
</script>';

if ($ip == "True") {
$resultID = mysql_query("INSERT INTO ".$pre."log VALUES ('null', '".$_SERVER['REQUEST_URI']."', '".$_SERVER['REMOTE_ADDR']."', '".date("F j, y - I:s A")."', '".$_COOKIE[username]."')") or die(mysql_error());
}

$result = loadTemplate("admin/templates/".$admintheme."/forum/header.php");

    $skin1[0] = "/{version}/";
	$skin1[1] = "/{menu1}/";
	$skin1[2] = "/{menu2}/";
	$skin1[3] = "/{menu3}/";
	$skin1[4] = "/{users}/"; // amount of users online
	$skin1[5] = "/{online}/"; // the users that are online
	$skin1[6] = "/{pms}/"; // amount of private messages
	$skin1[7] = "/{new}/"; // amount of new private messages
	$skin1[8] = "/{pm}/"; // display new private messages
	$skin1[9] = "/{welcome}/"; // Displays "Welcome username" if person is logged in, other wise "Welcome Guest" and a link to login
	$skin1[10] = "/{chooseskin}/";
	$skin1[11] = "/{skinname}/"; // the name of the current skin being used
	$skin2[12] = $version;

	$resultbab = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'admin'");
    $ojbab = mysql_num_rows($resultbab);

	$resultbab2 = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'global'");
    $ojbab2 = mysql_num_rows($resultbab2);

	$resultbab3 = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'mod'");
    $ojbab3 = mysql_num_rows($resultbab3);
    

$skin2[1] .= '- <a href="';
$skin2[1] .= $forumsurl;
$skin2[1] .= '">View Forum</a> / <a href="index.php">View Site</a><br>
- <a href="admin/admin.php?view=home">Admin CP</a><br>
- <a href="boardcp.php">CP Home</a><br><br>';

	if ($ojbab > "0") {

$skin2[2] .= '- <a href="boardcp.php?view=settings">Forum Settings</a><br>
- <a href="boardcp.php?view=cat">Categories</a><br>
- <a href="boardcp.php?view=forums">Forums</a><br>
- <a href="boardcp.php?view=sub">Sub-Forums</a><br>
- <a href="boardcp.php?view=users">Mods/Admins</a><br>
- <a href="boardcp.php?view=ranks">Ranks</a><br>
- <a href="boardcp.php?view=shop">Shop</a><br><br>';
	}
	if ($ojbab > 0 or $ojbab2 > 0 or $ojbab3 > 0) {

$skin2[3] .= '- <a href="boardcp.php?view=topics">Topics</a><br>
- <a href="boardcp.php?view=posts">Posts</a><br><br>';
}

     $skin2[4] = online();
	 $skin2[5] = usersonline();
	 $skin2[6] = totalpms();
	 $skin2[7] = newpms();
	 $skin2[8] = pms();
	 $skin2[9] = welcome();
	 $skin2[10] = skins();
	 $skin2[11] = skinname();
	 $skin2[12] = $version;

	 eval (" ?>" . preg_replace($skin1, $skin2, stripslashes($result)) . " <?php ");

	if ($ojbab > 0) {

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

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

			$sql = mysql_query("UPDATE ".$pre."shop SET name = '".addslashes($_POST["name_$i"])."', price = '".addslashes($_POST["price_$i"])."', instock = '".addslashes($_POST["instock_$i"])."', image = '".addslashes($_POST["image_$i"])."', pid = '', date = '".time()."' WHERE id = '".$i."'");
			}

			if ($_POST['del']) {
			while (list(, $i2) = each ($_POST['del'])) {

			$sql2 = mysql_query("DELETE FROM ".$pre."shop WHERE id = '".$i2."'");
			}
			}


            if (($sql == TRUE) or ($sql2 == TRUE)) {
			echo "The shop items have been updated/deleted! <a href='boardcp.php?view=shop'>Manage Shop</a>";
			}
		}

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

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

			$sql = mysql_query("INSERT INTO ".$pre."shop VALUES ('null', '".addslashes($_POST["name_$i"])."', '".addslashes($_POST["price_$i"])."', '".addslashes($_POST["instock_$i"])."', '".addslashes($_POST["image_$i"])."', '', '".time()."')");
			}


            if ($sql == TRUE) {
			echo "The shop items have been created! <a href='boardcp.php?view=shop'>Manage Shop</a>";
			}
		}

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

echo "<form action=\"boardcp.php?view=shop1\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many shop 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='boardcp.php?view=shop12' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Price *</b></td><td><b>In Stock **</b></td><td><b>Image</b></td></tr><input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

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

echo "<tr><td><input type='text' name='name_".$i."' size='12'></td><td><input type='text' name='price_".$i."' size='5'></td><td><input type='text' name='instock_".$i."' size='5'></td><td><input type='text' name='image_".$i."' size='20'></td></tr>";
}

echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td><td><input type='reset' name='reset' value='Reset'></td><td><small>* How many points required to buy this item</small></td><td><small>** How many of this item that you want in stock</small></td></tr>";
}
echo "</form></table>";
}

if ($_GET['view'] == "shop") {
echo "<form action='boardcp.php?view=shop2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Price</b></td><td><b>In Stock</b></td><td><b>Image</b></td><td><b>Delete?</b></td></tr>";

	$query="SELECT * FROM ".$pre."shop";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {
		echo "<tr><td><input type='hidden' name='id[]' value='".$r[id]."'><input type='text' name='name_".$r[id]."' value='".$r[name]."' size='16'></td><td><input type='text' name='price_".$r[id]."' value='".$r[price]."' size='5'></td><td><input type='text' name='instock_".$r[id]."' value='".$r[instock]."' size='4'></td><td><input type='text' name='image_".$r[id]."' value='".$r[image]."' size='12'></td><td><input type='checkbox' name='del[]' value='".$r[id]."'></td></tr>";
	}

	echo "<tr><td><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=\"boardcp.php?view=shop1\">Add Shop Item(s)</a></td></tr></form></table>";
	}


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

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

			$sql = mysql_query("INSERT INTO ".$pre."ranks VALUES ('null', '".addslashes($_POST["name_$i"])."', '".addslashes($_POST["color_$i"])."', '".addslashes($_POST["points_$i"])."', '".time()."')");
			}


            if ($sql == TRUE) {
			echo "The ranks have been created! <a href='boardcp.php?view=ranks'>Manage Ranks</a>";
			}
		}

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

echo "<form action=\"boardcp.php?view=ranks2\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many ranks 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='boardcp.php?view=ranks3' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Color</b></td><td><b>Points Required</b></td></tr><input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

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

echo "<tr><td><input type='text' name='name_".$i."'></td><td><input type='text' name='color_".$i."' size='16'></td><td><input type='text' name='points_".$i."' size='4'></td></tr>";
}

echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td><td><input type='reset' name='reset' value='Reset'></td></tr>";
}
echo "</form></table>";
}

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

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

			$sql = mysql_query("UPDATE ".$pre."ranks SET name = '".addslashes($_POST["name_$i"])."', color = '".addslashes($_POST["color_$i"])."', points = '".addslashes($_POST["points_$i"])."', date = '".time()."' WHERE id = '".$i."'");
			}
			}

            if ($_POST['delete']) {
			while (list(, $ia) = each ($_POST['delete'])) {
			$sql2 = mysql_query("DELETE FROM ".$pre."ranks WHERE id = '".$ia."'");
			}
			}


            if (($sql == TRUE) or ($sql2 == TRUE)) {
			echo "The ranks have been updated! <a href='boardcp.php?view=ranks'>Manage Ranks</a>";
			}
		}

	if ($_GET['view'] == "ranks") {
	echo "<form action='boardcp.php?view=ranks4' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Color</b></td><td><b>Points Required</b></td><td><b>Delete?</b></td></tr>";

	$query="SELECT * FROM ".$pre."ranks";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {
		echo "<tr><td><input type='hidden' name='id[]' value='".$r[id]."'><input type='text' name='name_".$r[id]."' value='".$r[name]."' size='16'></td><td><input type='text' name='color_".$r[id]."' value='".$r[color]."' size='12'></td><td><input type='text' name='points_".$r[id]."' value='".$r[points]."' size='4'></td><td><input type='checkbox' name='delete[]' value='".$r[id]."'></td></tr>";
	}

	echo "<tr><td><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=\"boardcp.php?view=ranks2\">Add Ranks</a></td></tr></form></table>";
	}

	if ($_GET['view'] == "sub") {
	echo "<form action='boardcp.php?view=sub1' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."forums WHERE type = 'sub'";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {
		$explode = explode("||", $r[name]);

    	echo "<tr><td>".$explode[0]."</td><td><input type=\"checkbox\" name=\"id[]\" value=\"".$r[id]."\"></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><td><a href=\"boardcp.php?view=sub2\">Add sub-forums</a></td></tr></form></table><br><br>";
}

if ((($_GET['view'] == "sub1") && ($_GET['add'] == "") && ($_GET['edit'] == ""))) {
if ($_POST['delete']) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion? All post(s) within these sub-forum(s) will be deleted.");
if (agree)
document.write("");
else
history.go(-1);

</SCRIPT>';

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

$delete2 = mysql_query("DELETE FROM ".$pre."posts WHERE fid = '$val'") or die(mysql_error());
$delete = mysql_query("DELETE FROM ".$pre."forums WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The sub-forum(s) have been deleted. <a href='boardcp.php?view=sub'>Manage Sub-Forums</a>";
}
}

if ($_POST['id']) {
	echo "<form action='boardcp.php?view=sub11' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

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

	$explode = explode("||", $row[name]);

	echo "<tr><td><b><center>Sub-Forum #".$i."</b></center><input type='hidden' name='id[]' value='".$i."'></td></tr><tr><td>Name</td><td><input type='text' name='name_".$i."' value='".$explode[0]."'><input type='hidden' name='name2_".$i."' value='".$explode[1]."'></td></tr><tr><td>Assign to Forum</td><td><select name='place_".$i."'>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'forum'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	if ($explode[1] == $row2[id]) {
	echo "<option value='".$row[id]."' selected>-- $row2[name] --</option>";
	} else {
	echo "<option value='".$row2[id]."'>$row2[name]</option>";
	}
	}
	echo "</select></td></tr><tr><td>Description</td><td><textarea name='des_".$i."' cols='30' rows='10'>".stripslashes($row[des])."</textarea></td></tr><tr><td>Order</td><td><input type='text' name='ord_".$i."' value='".$row['ord']."'></td></tr><tr><td>Locked?</td><td><input type='checkbox' name='lock_".$i."' value='yes'";
	
	if ($row[locked]) {
	echo " checked";
	}
	echo "></td></tr>";
	}
	echo "<tr><td>Post Requirement?</td><td><input type='text' name='prequire_".$i."' value='".$row[prequire]."'></td></tr><tr><td>Can visitors post?</td><td><select name='vpost_".$i."'><option value='".$row[vpost]."' selected>-- ".$row[vpost]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can visitors make a topic?</td><td><select name='vtopic_".$i."'><option value='".$row[vtopic]."' selected>-- ".$row[vtopic]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members edit there own posts/topics?</td><td><select name='epost_".$i."'><option value='".$row[epost]."' selected>-- ".$row[epost]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members delete there own posts/topics?</td><td><select name='dpost_".$i."'><option value='".$row[dpost]."' selected>-- ".$row[dpost]." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr>";
	
	echo "<tr><td>Rank Requirement?</td><td><select name='rankreq_".$i."'><option value=''>--------</option>";
	
	$rankname = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."userlevels WHERE level = '".$row[rankreq]."'"));
	
	echo "<option value='".$row[rankreq]."' selected>-- ".$rankname[0]." --</option>";
	
	$rankfetch = mysql_query("SELECT * from ".$pre."userlevels") or die(mysql_error());
	while($ranks = mysql_fetch_row($rankfetch)) {
	
	echo "<option value='".$ranks[2]."'>".$ranks[1]."</option>";
	}
	
	}

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

if ($_GET['view'] == "sub11") {
	
    while (list(, $i) = each ($_POST['id'])) {

	$fin1 = mysql_query("SELECT cat FROM ".$pre."forums WHERE id = '".$_POST["name2_$i"]."'");
	$fin2 = mysql_fetch_row($fin1);

	$update = mysql_query("UPDATE ".$pre."forums SET name = '".$_POST["name_$i"]."||".$_POST["name2_$i"]."', ord = '".$_POST["ord_$i"]."', des = '".addslashes($_POST["des_$i"])."', cat = '".$fin2[0]."', locked = '".$_POST["lock_$i"]."', prequire = '".$_POST["prequire_$i"]."', vpost = '".$_POST["vpost_$i"]."', vtopic = '".$_POST["vtopic_$i"]."', epost = '".$_POST["epost_$i"]."', dpost = '".$_POST["dpost_$i"]."', '".$_POST["rankreq_$i"]."' WHERE id = '".$i."'");
	}

	if ($update == TRUE) {
	echo "The sub-forum(s) have been updated. <a href='boardcp.php?view=sub'>Manage Sub-Forums</a>";
	}
}

if ($_GET['view'] == "sub2") {
		echo "<form action=\"boardcp.php?view=sub2\" name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many sub-forums 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='boardcp.php?view=sub21' 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>Sub-Forum #".$i."</b></center></td></tr><tr><td>Name</td><td><input type='text' name='name_".$i."'></td></tr><tr><td>Assign to Forum</td><td><select name='place_".$i."'>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'forum'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	echo "<option value='".$row2[id]."'>$row2[name]</option>";
	}
	
	echo "</select></td></tr><tr><td>Description</td><td><textarea name='des_".$i."' cols='30' rows='10'></textarea></td></tr><tr><td>Order</td><td><input type='text' name='ord_".$i."'></td></tr><tr><td>Locked?</td><td><input type='checkbox' name='lock_".$i."' value='yes'></td></tr><tr><td>Post Requirement?</td><td><input type='text' name='prequire_".$i."'></td></tr><tr><td>Can visitors post?</td><td><select name='vpost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can visitors make a topic?</td><td><select name='vtopic_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members edit there own posts/topics?</td><td><select name='epost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members delete there own posts/topics?</td><td><select name='dpost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr>";
	

	
	echo "<tr><td>Rank Requirement?</td><td><select name='rankreq_".$i."'><option value=''>--------</option>";
	
	$rankfetch = mysql_query("SELECT * from ".$pre."userlevels") or die(mysql_error());
	while($ranks = mysql_fetch_row($rankfetch)) {
	
	echo "<option value='".$ranks[2]."'>".$ranks[1]."</option>";
	
	}
		
	echo "</select></td></tr>";	
	}

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

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

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

	$sql = mysql_query("SELECT cat FROM ".$pre."forums WHERE id = '".$_POST["place_$i"]."' AND type = 'forum'");
	$here = mysql_fetch_row($sql);

	$create = mysql_query("INSERT INTO ".$pre."forums VALUES ('null', '".$_POST["name_$i"]."||".$_POST["place_$i"]."', '".addslashes($_POST["des_$i"])."', 'sub', '".$here[0]."', '".$_POST["ord_$i"]."', '".$_POST["lock_$i"]."', '".$_POST["prequire_$i"]."', '".$_POST["vpost_$i"]."', '".$_POST["vtopic_$i"]."', '".$_POST["epost_$i"]."', '".$_POST["dpost_$i"]."', '".$_POST["rankreq_$i"]."')");
	}

	if ($create == TRUE) {
	echo "The sub-forum(s) have been created. <a href='boardcp.php?view=sub'>Manage Sub-Forums</a>";
	} else {
	echo mysql_error();
	}
}

if ($_GET['view'] == "settings") {
echo "<form action='boardcp.php?view=settings2' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b> Name</b></td><td><b>Data</b></td><td><b>Description</b></td><td><b>Delete</b></tr>";
$query = mysql_query("SELECT * FROM ".$pre."settings WHERE type = 'setting' AND parent = 'Forum' ORDER BY `name` ASC");
while($row = mysql_fetch_array($query)) {
echo "<tr><td><input type='text' name='name_".$row[id]."' value='".stripslashes($row[name])."'></td><td>
<textarea name='data_".$row[id]."'>".stripslashes($row[data])."</textarea>
<input type='hidden' name='id[]' value='".$row[id]."'></td><td>".wordwrap(stripslashes($row[description]), 20, "<br />\n")."</td><td><input type='checkbox' name='delete_".$row[id]."' value='delete'></td></tr>";
}

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

echo "<center><a href='boardcp.php?view=settings&type=add'>Add Settings</a></center>";

}

if (($_GET['view'] == "settings") && ($_GET['type'] == "add")) {
	echo "<form action='boardcp.php?view=settings&type=add2' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

	echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"></td></tr>";
	echo "<tr><td>Data</td><td><textarea name=\"data\"></textarea></td></tr>";
	echo "<tr><td>Description</td><td><textarea name=\"description\"></textarea></td></tr>";
	
	echo "<tr><td><input type=\"submit\" name=\"submit\" value=\"Submit\"></td></tr></table></form>";

}

if (($_GET['view'] == "settings") && ($_GET['type'] == "add2")) {
$sql = mysql_query("INSERT INTO ".$pre."settings VALUES (null, '".addslashes($_POST["name"])."', '".addslashes($_POST["description"])."', '".addslashes($_POST["data"])."', 'setting', 'Forum')");

if ($sql == TRUE) {
echo "Setting ".$_POST["name"]." added. <a href='boardcp.php?view=settings'>Forum Settings Home</a>";
}
}

if ($_GET['view'] == "settings2") {
while (list(, $i) = @each ($_POST['id'])) {
if ($_POST["delete_$i"]) {
$sql = mysql_query("DELETE FROM ".$pre."settings WHERE id = '".$i."'");
} else {
$sql = mysql_query("UPDATE ".$pre."settings SET name = '".addslashes($_POST["name_$i"])."', data = '".addslashes($_POST["data_$i"])."' WHERE id = '".$i."'");
}
}
if ($sql == TRUE) {
echo "Forum settings updated. <a href='boardcp.php?view=settings'>Forum settings Home</a>";
}
}

if ((($_GET['view'] == "cat") && ($_GET['edit'] == "") && ($_GET['add'] == ""))) {
	echo "<form action='boardcp.php?view=cat2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."forums WHERE type = 'cat'";
	$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><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=\"boardcp.php?view=cat&add=1\">Add category</a></td></tr></form></table><br><br>";
}

if ($_GET['view'] == "cat2") {
	if ($_POST['id']) {
	echo "<form action='boardcp.php?view=cat&edit=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

		while (list(, $val) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."forums WHERE id = '$val'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = "$row[name]";
		$order = "$row[ord]";

		echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\"><input type=\"hidden\" name=\"name2_".$val."\" value=\"".$name."\"><tr><td><b><center>Category # ".$val."</b></center></td></tr><tr><td><b>Name</b></td><td><input type='text' name='name_".$val."' value='".$name."'></td></tr><tr><td><b>Order</b></td><td><input type='text' name='order_".$val."' value='".$order."'></td></tr><tr><td>Locked?</td><td><input type='checkbox' name='lock_".$val."' value='yes'";
	
	if ($row[locked]) {
		echo " checked";
	}
	echo "></td></tr>";
	}
	}

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

if (($_GET['view'] == "cat") && ($_GET['edit'] == "yes")) {
while (list(, $val) = each ($_POST['id'])) {
	$update = mysql_query("UPDATE ".$pre."forums SET name = '".$_POST["name_$val"]."', cat = '".$_POST["name_$val"]."', ord = '".$_POST["order_$val"]."', locked = '".$_POST["locked_$val"]."' WHERE id = '".$val."'") or die(mysql_error());
	$update2 = mysql_query("UPDATE ".$pre."forums SET cat = '".$_POST["name_$val"]."' WHERE cat = '".$_POST["name2_$val"]."'");
}   
	if ($update == TRUE) {
		echo "Categories have been updated. <a href='boardcp.php?view=cat'>Manage Categories</a>";
	}
}

if ($_GET['view'] == "cat2") {
	if ($_POST['delete']) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion? All Forums within these category(s) will be deleted.");
if (agree)
document.write("");
else
history.go(-1);

</SCRIPT>';

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

$select = mysql_query("SELECT * FROM ".$pre."forums WHERE id = '".$val."'");
while($row = mysql_fetch_array($select)) {
	$cat = "$row[name]";
}
$delete2 = mysql_query("DELETE FROM ".$pre."forums WHERE cat = '".$cat."'") or die(mysql_error());
$delete = mysql_query("DELETE FROM ".$pre."forums WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The categories have been deleted. <a href='boardcp.php?view=cat'>Manage Categories</a>";
}
}
}

// END CAT, BEGIN FORUMS

if ((($_GET['view'] == "forums") && ($_GET['edit'] == "") && ($_GET['add'] == ""))) {
	echo "<form action='boardcp.php?view=forums2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."forums WHERE type = 'forum'";
	$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><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=\"boardcp.php?view=forums&add=1\">Add forums</a></td></tr></form></table><br><br>";
}

if ($_GET['view'] == "forums2") {
if ($_POST['id']) {
	echo "<form action='boardcp.php?view=forums&edit=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

	while (list(, $val) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."forums WHERE id = '$val'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$name = $row[name];
		$order = $row['ord'];
		$cat = $row[cat];
		$lock = $row[locked];
		$preq = $row[prequire];
		$vpost = $row[vpost];
		$vtopic = $row[vtopic];
		$epost = $row[epost];
		$dpost = $row[dpost];
		$des = stripslashes($row[des]);
		$rankreq = $row[rankreq];

		echo "<input type=\"hidden\" name=\"id[]\" value=\"$val\"><input type=\"hidden\" name=\"name2_".$val."\" value=\"".$name."\"><tr><td><b><center>Forum # ".$val."</b></center></td></tr><tr><td>Name</td><td><input type='text' name='name_".$val."' value='".$name."'></td></tr><tr><td>Order</td><td><input type='text' name='order_".$val."' value='".$order."'></td></tr><tr><td>Category</td><td><select name='cat_".$val."'><option value='".$row[cat]."' selected>-- ".$row[cat]." --</option>";
    $catsql = mysql_query("SELECT * FROM ".$pre."forums WHERE type = 'cat' ORDER BY `ord` ASC");
	while($r = mysql_fetch_array($catsql)) {
	if ($r[name] == $cat) {
	} else {
	echo "<option value='".$r[name]."'>".$r[name]."</option>";
	}
	}
	echo "</select></td></tr><tr><td>Description</td><td><textarea name='des_".$val."' cols='36' rows='12'>".$des."</textarea></td></tr><tr><td>Locked?</td><td><input type='checkbox' name='lock_".$val."' value='yes'";
	
	if ($lock) {
	echo " checked";
	}
	echo "></td></tr>";
	}
	echo "<tr><td>Post Requirement?</td><td><input type='text' name='prequire_".$val."' value='".$preq."'></td></tr><tr><td>Can visitors post?</td><td><select name='vpost_".$val."'><option value='".$vpost."' selected>-- ".$vpost." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can visitors make a topic?</td><td><select name='vtopic_".$val."'><option value='".$vtopic."' selected>-- ".$vtopic." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members edit there own posts/topics?</td><td><select name='epost_".$val."'><option value='".$epost."' selected>-- ".$epost." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members delete there own posts/topics?</td><td><select name='dpost_".$val."'><option value='".$dpost."' selected>-- ".$dpost." --</option><option value='Yes'>Yes</option><option value='No'>No</option></td></tr>";
	
	echo "<tr><td>Rank Requirement?</td><td><select name='rankreq_".$val."'><option value=''>--------</option>";
	
	$rankname = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."userlevels WHERE level = '".$rankreq."'"));
	
	echo "<option value='".$rankreq."' selected>-- ".$rankname[0]." --</option>";
	
	$rankfetch = mysql_query("SELECT * from ".$pre."userlevels") or die(mysql_error());
	while($ranks = mysql_fetch_row($rankfetch)) {
	
	echo "<option value='".$ranks[2]."'>".$ranks[1]."</option>";
	
	}
		
	echo "</select></td></tr>";	
	
	}

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

if (($_GET['view'] == "forums") && ($_GET['edit'] == "yes")) {
while (list(, $val) = each ($_POST['id'])) {
	$update = mysql_query("UPDATE ".$pre."forums SET name = '".$_POST["name_$val"]."', ord = '".$_POST["order_$val"]."', des = '".addslashes($_POST["des_$val"])."', cat = '".$_POST["cat_$val"]."', locked = '".$_POST["lock_$val"]."', prequire = '".$_POST["prequire_$val"]."', vpost = '".$_POST["vpost_$val"]."', vtopic = '".$_POST["vtopic_$val"]."', epost = '".$_POST["epost_$val"]."', dpost = '".$_POST["dpost_$val"]."', rankreq = '".$_POST["rankreq_$val"]."' WHERE id = '".$val."'") or die(mysql_error());
}
	if ($update == TRUE) {
		echo "The Forum(s) have been updated. <a href='boardcp.php?view=forums'>Manage Forums</a>";
	}
}

if ($_GET['view'] == "forums2") {
	if ($_POST['delete']) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion? All post(s) within these forum(s) will be deleted.");
if (agree)
document.write("");
else
history.go(-1);

</SCRIPT>';

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

$delete2 = mysql_query("DELETE FROM ".$pre."posts WHERE fid = '$val'") or die(mysql_error());
$delete = mysql_query("DELETE FROM ".$pre."forums WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The forum(s) have been deleted. <a href='boardcp.php?view=forums'>Manage Forums</a>";
}
}
}

// END FORUMS, START CAT ADD

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

    if ($_POST['search']) {

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

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

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

   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   $upd[0] = mysql_query("INSERT INTO ".$pre."forums VALUES ('null', '".$_POST["name_$i"]."', '', 'cat', '".$_POST["name_$i"]."', '".$_POST["ord_$i"]."', '".$_POST["locked_$i"]."', '', '', '', '', '', '')") or die(mysql_error());
   }
if ($upd == TRUE) {
	echo "The category(s) have been created. <a href=\"boardcp.php?view=cat\">Manage Categories</a>";
}
	}

// END CAT ADD, START FORUM ADD

if (($_GET['view'] == "forums") && ($_GET['add'] == "1")) {
		echo "<form action=\"boardcp.php?view=forums&add=1\" name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many forums 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='boardcp.php?view=forums&add=2' 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>Forum #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Order</td><td><input type='text' name='ord_".$i."'></td></tr><tr><tr><td>Description</td><td><textarea name='des_".$i."' cols='25' rows='7'></textarea></td></tr><tr><td>Category</td><td><select name='cat_".$i."'>";
        $query="SELECT * FROM ".$pre."forums WHERE type = 'cat' ORDER BY `ord` ASC";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	echo "<option value='".$row[name]."'>$row[name]</option>";
	}
	echo "</select></td></tr><tr><td>Locked?</td><td><input type='checkbox' name='lock_".$i."' value='yes'></td></tr><tr><td>Post Requirement?</td><td><input type='text' name='prequire_".$i."'></td></tr><tr><td>Can visitors post?</td><td><select name='vpost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can visitors make a topic?</td><td><select name='vtopic_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members edit there own posts/topics?</td><td><select name='epost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr><tr><td>Can members delete there own posts/topics?</td><td><select name='dpost_".$i."'><option value='Yes'>Yes</option><option value='No'>No</option></td></tr>";
	
	echo "<tr><td>Rank Requirement?</td><td><select name='rankreq_".$i."'><option value=''>--------</option>";
	
	$rankfetch = mysql_query("SELECT * from ".$pre."userlevels") or die(mysql_error());
	while($ranks = mysql_fetch_row($rankfetch)) {
	
	echo "<option value='".$ranks[2]."'>".$ranks[1]."</option>";
	
	}
	
	}
	echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form></table>";
	}
}

if (($_GET['view'] == "users3") && ($_GET['act'] == "edit")) {
if (!$_POST['submitt']) {
echo "<SCRIPT LANGUAGE='JavaScript'>function smiles(which) {document.form1.text1.value = document.form1.text1.value + which;}</SCRIPT><script language='javascript'>function awindow(towhere, newwinname, properties) {window.open(towhere,newwinname,properties);}</script><table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\"><form name='form1' method='post' action='".$HTTP_SERVER_VARS['REQUEST_URI']."'><tr><td><b>Username</b></td><td><input type='hidden' name='username' value='".$_COOKIE[username]."'>".$_COOKIE[username]."</td>";

$smilies = mysql_query("SELECT * FROM ".$pre."posts WHERE id = '".$_GET['id']."'");
while($row = mysql_fetch_array($smilies)) {
	$topic = stripslashes($row[subject]);
	$msg = stripslashes($row[message]);
	$tid = "$row[tid]";
	$fid = "$row[fid]";
}

echo "<input type='hidden' name='id' value='".$_GET['id']."'><input type='hidden' name='tid' value='".$tid."'></tr><tr><td><b>Subject</b></td><td><input type='text' name='subject' value='Re: ".$topic."'></td></tr><tr><td><b>Message</b></td><td><textarea name=\"text1\" cols='18' rows='7'>".$msg."

</textarea></td><td width='75'><b><center>Smilies</center></b><center><input type='hidden' name='fid' value='".$fid."'>";

$query2 = mysql_query("SELECT * FROM ".$pre."comments1 WHERE type = 'smiley'");
$limit = mysql_num_rows($query2);

$smilies = mysql_query("SELECT * FROM ".$pre."comments1 WHERE type = 'smiley' LIMIT 9");
while($row = mysql_fetch_array($smilies)) {
$tag = "$row[field]";
$name = "$row[name]";

list($width, $height, $type, $attr) = getimagesize("".$images."/".$tag."");
echo "<a href=\"javascript:smiles(' ".$name." ')\"><img src='".$images."/".$tag."' border='0' width='";
if ($width > "20") {
echo "20";
} else {
echo "$width";
}
echo "'></a>";
if (($limit/3) == (int)($limit/3)) {
	echo "<br>";
}
}
echo "<br><br><a href='javascript:awindow(\"comments.php?view=smilies\", \"\", \"width=200,height=200,scroll=yes\")'>View All</a>";
echo "</center></td></tr><tr><td><input type='submit' name='submit' value='Submit Post'></td><td><input type='reset' name='reset' value='Reset'></td></tr></table></form>";
}
}
	}

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

   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   $upd[0] = mysql_query("INSERT INTO ".$pre."forums VALUES ('null', '".$_POST["name_$i"]."', '".addslashes($_POST["des_$i"])."', 'forum', '".$_POST["cat_$i"]."', '".$_POST["ord_$i"]."', '".$_POST["lock_$i"]."', '".$_POST["prequire_$i"]."', '".$_POST["vpost_$i"]."', '".$_POST["vtopic_$i"]."', '".$_POST["epost_$i"]."', '".$_POST["dpost_$i"]."', '".$_POST["rankreq_$i"]."')") or die(mysql_error());
   }
if ($upd == TRUE) 
	{
	echo "The forum(s) have been created. <a href=\"boardcp.php?view=forums\">Manage Forums</a>";
	}
}

// END FORUM ADD, PERMISSION ADD START

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

		echo "<form action='boardcp.php?view=users&add=2' 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>User #".$i."</b></center></td></tr><tr><td>Username</td><td><select name='user_".$i."'><option value=''>-------</option>";
	
	$query="SELECT * FROM ".$pre."profile";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	echo "<option value='".$row[id]."'>$row[username]</option>";
	}
	echo "</select></td></tr><tr><td>Type</td><td><select name='type_".$i."'><option value=''>-------</option><option value='admin'>Admin</option><option value='global'>Global Mod</option><option value='mod'>Moderator</option></select></td></tr>";
	echo "<tr><td>Assign to Forum (only select a forum if your assigning this user as a moderator)</td><td><select name='place_".$i."'><option value=''>-------</option>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'forum' OR type = 'sub'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	if ($row2[type] == "sub") {
	$explode = explode("||", $row2[name]);
	echo "<option value='".$row2[id]."'>".$explode[0]."</option>";
	} else {
	echo "<option value='".$row2[id]."'>$row2[name]</option>";
	}
	}
	echo "</select></td></tr>";

	echo "<tr><td>Assign to Category (only select a category if your assigning this user as a moderator...do not select both a forum and category)</td><td><select name='place2_".$i."'><option value=''>-------</option>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'cat'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	echo "<option value='".$row[id]."'>$row[name]</option>";
	}
	echo "</select></td></tr>";
	}
			echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr></form></table>";
	}
}

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

   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   if ($_POST["place_$i"]) {
   $type = "forum";
   $place = "".$_POST["place_$i"]."";
   } else {
   $type = "cat";
   $place = "".$_POST["place2_$i"]."";
   }
   $upd[0] = mysql_query("INSERT INTO ".$pre."boardcp VALUES ('null', '".$_POST["user_$i"]."', '".$place."', '".$type."', '".$_POST["type_$i"]."')") or die(mysql_error());
   }
if ($upd == TRUE) {
	echo "The permission(s) have been assigned. <a href=\"boardcp.php?view=users\">Manage Levels</a>";
}
	}

// END PERMISSION ADD, START MANAGE PERMISSIONS

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

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

</SCRIPT>';

$delete = mysql_query("DELETE FROM ".$pre."posts WHERE id = '".$_GET['id']."'");

if ($delete == TRUE) {
	echo "Congratulations, the post has been deleted.";
}
}

if ($_GET['act'] == "update") {

echo "<SCRIPT LANGUAGE='JavaScript'>
  function smiles(which) {
  document.form1.text1.value = document.form1.text1.value + which;
  }
</SCRIPT>
<script language='javascript'>
function awindow(towhere, newwinname, properties) {
window.open(towhere,newwinname,properties);
}
</script><form action='boardcp.php?view=users3&act=update2&id=".$_GET['id']."' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

$sql = mysql_query("SELECT subject,message FROM ".$pre."posts WHERE id = '".$_GET['id']."'");
$row = mysql_fetch_row($sql);

	echo "<tr><td>Subject</td><td><input type='text' name='subject' value='".stripslashes($row[0])."'></td></tr><tr><td>Message</td><td><textarea name='text1' cols='30' rows='10'>".stripslashes($row[1])."</textarea></td><td width='75'><b><center>Smilies</center></b><center>";

$query2 = mysql_query("SELECT * FROM ".$pre."comments1 WHERE type = 'smiley'");
$limit = mysql_num_rows($query2);

$smilies = mysql_query("SELECT * FROM ".$pre."comments1 WHERE type = 'smiley' LIMIT 9");
while($row = mysql_fetch_array($smilies)) {
$tag = "$row[field]";
$name = "$row[name]";

list($width, $height, $type, $attr) = getimagesize("".$images."/".$tag."");
echo "<a href=\"javascript:smiles(' ".$name." ')\"><img src='".$images."/".$tag."' border='0' width='";
if ($width > "20") {
echo "20";
} else {
echo "$width";
}
echo "'></a>";
if (($limit/3) == (int)($limit/3)) {
	echo "<br>";
}
}
echo "<br><br><a href='javascript:awindow(\"comments.php?view=smilies\", \"\", \"width=200,height=200,scroll=yes\")'>View All</a></center></td></tr><tr><td><input type='submit' name='submit' value='Submit Post'></td><td><input type='reset' name='reset' value='Reset'></td></tr></table></form>";
}

if ($_GET['act'] == "update2") {
$sql = mysql_query("UPDATE ".$pre."posts SET subject = '".addslashes($_POST['subject'])."', message = '".addslashes($_POST['text1'])."', date = '".time()."' WHERE id = '".$_GET['id']."'");

if ($sql == TRUE) {
	echo "The post has been updated.";
}
}
}

if ($_GET['view'] == "users2") {
if ($_POST['id']) {
		echo "<form action='boardcp.php?view=users&edit=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

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

	echo "<tr><td><b><center>User #".$i."</b></center></td></tr><tr><td>Username</td><td><select name='user_".$i."'>";
	
	$query="SELECT * FROM ".$pre."profile";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	if ($row[uid] == $row2[id]) {
    echo "<option value=''>-------</option><option value='".$row[uid]."' selected>-- $row2[username] --</option>";
	} else {
	echo "<option value='".$row2[id]."'>$row2[username]</option>";
	}
	}
	echo "</select></td></tr><tr><td>Type</td><td><select name='type_".$i."'><option value='".$row[level]."' selected>-- $row[level] --</option><option value=''>-------</option><option value='admin'>Admin</option><option value='global'>Global Mod</option><option value='mod'>Moderator</option></select></td></tr>";
	echo "<tr><td>Assign to Forum (only select a forum if your assigning this user as a moderator)</td><td><select name='place_".$i."'><option value=''>-------</option>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'forum' OR type = 'sub'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	if ($row[id] == $row2[id]) {
	if ($row2[type] == "sub") {
	$explode = explode("||", $row2[name]);
	echo "<option value='".$row[id]."' selected>-- ".$explode[0]." --</option>";
	} else {
	echo "<option value='".$row[id]."' selected>-- $row2[name] --</option>";
	}
	} else {
	if ($row2[type] == "sub") {
	$explode = explode("||", $row2[name]);
	echo "<option value='".$row2[id]."'>".$explode[0]."</option>";
	} else {
	echo "<option value='".$row2[id]."'>$row2[name]</option>";
	}
	}
	}
	echo "</select></td></tr>";

	echo "<tr><td>Assign to Category (only select a category if your assigning this user as a moderator...do not select both a forum and category)</td><td><select name='place2_".$i."'><option value=''>-------</option>";
	
	$query="SELECT * FROM ".$pre."forums WHERE type = 'cat'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
	if ($row[id] == $row2[id]) {
	echo "<option value='".$row[id]."' selected>-- $row2[name] --</option>";
	} else {
	echo "<option value='".$row2[id]."'>$row2[name]</option>";
	}
	}
	echo "</select></td></tr>";
	}
		}

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

if (($_GET['view'] == "users") && ($_GET['edit'] == "yes")) {
while (list(, $val) = each ($_POST['id'])) {
   if ($_POST["place_$i"]) {
   $type = "forum";
   $place = "".$_POST["place_$i"]."";
   } else {
   $type = "cat";
   $place = "".$_POST["place2_$i"]."";
   }
   $update = mysql_query("UPDATE ".$pre."boardcp SET uid = '".$_POST["user_$val"]."', place = '$place', type = '".$_POST["type_$i"]."', level = '$type' WHERE id = '".$val."'") or die(mysql_error());
}
	if ($update == TRUE) {
		echo "The Permission(s) have been updated. <a href='boardcp.php?view=users'>Manage Users</a>";
	}
}

	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."boardcp WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The mods/admins have been deleted.";
}
}

}

if ($_GET['view'] == "forums2") {
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."boardcp WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
echo "The permission(s) have been deleted. <a href='boardcp.php?view=users'>Manage Users</a>";
}
}
}

// END MANAGE PERMISSIONS, START USERS INDEX

if ((($_GET['view'] == "users") && ($_GET['edit'] == "") && ($_GET['add'] == ""))) {
	echo "<form action='boardcp.php?view=users2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Level</b></td><td><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."boardcp";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$uidr = "$row[uid]";
	$querye = "SELECT * FROM ".$pre."profile WHERE id = '".$uidr."'";
	$resulte = mysql_query($querye);
	while($row2 = mysql_fetch_array($resulte)) {
		$user = "$row2[username]";
	}
    	echo "<tr><td>$user</td><td>$row[level]</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=\"boardcp.php?view=users&add=1\">Add Users</a></td></tr></form></table><br><br>";
}

// END USERS INDEX, END BOARD CP ADMIN, BEGIN MOD BOARD CP

	}

	if ($ojbab > 0 or $ojbab2 > 0 or $ojbab3 > 0) {

if (((($_GET['view'] == "topics") && ($_GET['edit'] == "") && ($_GET['move'] == "") && ($_GET['add'] == "")))) {
	echo "<form action='boardcp.php?view=topics2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Topic Name</b></td><td><b>Forum</b></td><td><b>Edit</b></td><td><b>Delete</b></td><td><b>Move</b></td></tr><center><div align=\"center\">";

	$result2ok790 = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'admin' OR level = 'global'");
        $yee4 = mysql_num_rows($result2ok790);
		if ($yee4 > "0") {
	$query="SELECT * FROM ".$pre."posts WHERE type = 'topic'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$id = "$row[id]";
	$forumid = "$row[fid]";
	$name = "$row[subject]";

	$querye = "SELECT * FROM ".$pre."forums WHERE id = '$forumid'";
	$resulte = mysql_query($querye);
	while($row2 = mysql_fetch_array($resulte)) {
		$forum = "$row2[name]";
	}
    	echo "<tr><td>$name</td><td>$forum</td><td><input type='checkbox' name='id[]' value='".$id."'></td><td><input type='checkbox' name='delete[]' value='".$id."'></td><td><input type='checkbox' name='move[]' value='".$id."'></td></tr>";
	}
		} else {

	$query="SELECT * FROM ".$pre."posts WHERE type = 'topic'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$forumid = "$row[fid]";
	$id = "$row[id]";
	$name = "$row[subject]";

	$q = mysql_query("SELECT * FROM ".$pre."boardcp WHERE place = '".$forumid."' AND uid = '".$useridn."'");
	$for = mysql_num_rows($q);

	if ($for > "0") {

	$querye = "SELECT * FROM ".$pre."forums WHERE id = '$forumid'";
	$resulte = mysql_query($querye);
	while($row2 = mysql_fetch_array($resulte)) {
		$forum = "$row2[name]";
	}
    	echo "<tr><td>$name</td><td>$forum</td><td><input type='checkbox' name='id[]' value='".$id."'></td><td><input type='checkbox' name='delete[]' value='".$id."'></td><td><input type='checkbox' name='move[]' value='".$id."'></td></tr>";
	}
	}
		}

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

if ((($_GET['view'] == "topics2") && ($_GET['edit'] == "") && ($_GET['move'] == ""))) {
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."posts WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The topic(s) have been deleted. <a href='boardcp.php?view=topics'>Manage Topics</a>";
}
}

if ($_POST['id']) {

		echo "<form action='boardcp.php?view=topics2&edit=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

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

		echo "<input type=\"hidden\" name=\"ida[]\" value=\"$val\"><tr><td><b><center>Topic # ".$val."</b></center></td></tr><tr><td>Subject</td><td><input type='text' name='sub_".$val."' value='".$row[subject]."'></td></tr><tr><td>Message</td><td><textarea name='mes_".$val."' cols='36' rows='12'>".stripslashes($row[message])."</textarea></td></tr>";
}
		}

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

if ($_POST['move']) {

		echo "<form action='boardcp.php?view=topics2&move=yes' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

	while (list(, $val) = each ($_POST['move'])) {
	$query="SELECT * FROM ".$pre."posts WHERE id = '$val'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	
	$me = mysql_query("SELECT * FROM ".$pre."forums WHERE id = '".$row[fid]."'");
	while($n = mysql_fetch_array($me)) {
	$forum = "$n[name]";
	}

		echo "<input type=\"hidden\" name=\"ida[]\" value=\"$val\"><tr><td><b><center>Topic # ".$val."</b></center></td></tr><tr><td>Topic Name</td><td>$row[subject]</td></tr><tr><td>Forum</td><td>".$forum."</td></tr><tr><td>New Forum</td><td><select name='f2_".$val."'>";
		
	$my = mysql_query("SELECT * FROM ".$pre."forums WHERE type = 'forum'");
	while($w = mysql_fetch_array($my)) {
	$myu = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND place = '".$w[id]."'");
	if (mysql_num_rows($myu) > "0") {
	if ($w[id] == $row[fid]) {
	} else {
	echo "<option value='".$w[id]."'>$w[name]</option>";
	}
	}
	}
	echo "</select></td></tr>";
}
		}
}

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

if ((($_GET['view'] == "topics2") && ($_GET['edit'] == "yes") && ($_GET['move'] == ""))) {

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

   $update = mysql_query("UPDATE ".$pre."posts SET subject = '".$_POST["sub_$val"]."', message = '".addslashes($_POST["mes_$val"])."' WHERE id = '$val'") or die(mysql_error());
   }
if ($update == TRUE) {
    echo "The topic(s) has been updated. <a href=\"boardcp.php?view=topics\">Manage Topics</a>";
}
	}

	if ((($_GET['view'] == "topics2") && ($_GET['move'] == "yes") && ($_GET['edit'] == ""))) {
   while (list(, $val) = each ($_POST['ida'])) {
   $move = mysql_query("UPDATE ".$pre."posts SET fid = '".$_POST["f2_$val"]."' WHERE id = '$val'") or die(mysql_error());

   $move2 = mysql_query("UPDATE ".$pre."posts SET fid = '".$_POST["f2_$val"]."' WHERE tid = '$val'") or die(mysql_error());
   }
if (($move2 == TRUE) && ($move == TRUE)) {
    echo "The topic(s) has been moved. <a href=\"boardcp.php?view=topics\">Manage Topics</a>";
}
	}

	// END MANAGE TOPICS, BEGIN MANAGE POSTS

if (((($_GET['view'] == "posts") && ($_GET['edit'] == "") && ($_GET['move'] == "") && ($_GET['add'] == "")))) {
	echo "<form action='boardcp.php?view=posts2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Topic Name</b></td><td><b>Topic</b></td><td><b>Forum</b></td><td><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."posts WHERE type = 'post'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$forumid = "$row[fid]";
	$topicid = "$row[tid]";
	$name = "$row[subject]";

	$querye = "SELECT * FROM ".$pre."forums WHERE id = '$forumid'";
	$resulte = mysql_query($querye);
	while($row2 = mysql_fetch_array($resulte)) {
		$forum = "$row2[name]";
	}

	$querye = "SELECT * FROM ".$pre."posts WHERE id = '$topicid' AND type = 'topic'";
	$resulte = mysql_query($querye);
	while($row2b = mysql_fetch_array($resulte)) {
		$topic = "$row2b[subject]";
	}
    	echo "<tr><td>";
		if ($name == "") {
			echo "<i>No Subject</i>";
		} else {
			print $name;
		}
		echo "</td><td>$topic</td><td>$forum</td><td><input type='checkbox' value='".$row[id]."' name='id[]'></td><td><input type='checkbox' value='".$row[id]."' name='delete[]'></td></tr>";
	}

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

if ((($_GET['view'] == "posts2") && ($_GET['edit'] == "") && ($_GET['move'] == ""))) {
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."posts WHERE id = '$val'") or die(mysql_error());
}

if ($delete == TRUE) {
	echo "The post(s) have been deleted. <a href='boardcp.php?view=posts'>Manage Posts</a>";
}
}
}

if (($_GET['view'] == "posts2") && ($_GET['move'] == "")) {
if ($_POST['id']) {

		echo "<form action='boardcp.php?view=posts2&edit=yes' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\">";

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

		echo "<input type=\"hidden\" name=\"ida[]\" value=\"$val\"><tr><td><b><center>Post # ".$val."</b></center></td></tr><tr><td>Subject</td><td><input type='text' name='sub_".$val."' value='".$row[subject]."'></td></tr><tr><td>Message</td><td><textarea name='mes_".$val."' cols='36' rows='12'>".stripslashes($row[message])."</textarea></td></tr>";
}
		}

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

if ((($_GET['view'] == "posts2") && ($_GET['edit'] == "yes") && ($_GET['move'] == ""))) {

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

   $update = mysql_query("UPDATE ".$pre."posts SET subject = '".$_POST["sub_$val"]."', message = '".addslashes($_POST["mes_$val"])."' WHERE id = '$val'") or die(mysql_error());
   }
if ($update == TRUE) {
    echo "The post(s) have been updated. <a href=\"boardcp.php?view=posts\">Manage Posts</a>";
}
}

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

$result = loadTemplate("admin/templates/".$admintheme."/forum/footer.php");

    $skin1[0] = "/{version}/";
	$skin1[1] = "/{menu1}/";
	$skin1[2] = "/{menu2}/";
	$skin1[3] = "/{menu3}/";
	$skin1[4] = "/{users}/"; // amount of users online
	$skin1[5] = "/{online}/"; // the users that are online
	$skin1[6] = "/{pms}/"; // amount of private messages
	$skin1[7] = "/{new}/"; // amount of new private messages
	$skin1[8] = "/{pm}/"; // display new private messages
	$skin1[9] = "/{welcome}/"; // Displays "Welcome username" if person is logged in, other wise "Welcome Guest" and a link to login
	$skin1[10] = "/{chooseskin}/";
	$skin1[11] = "/{skinname}/"; // the name of the current skin being used
	$skin2[12] = $version;

	$resultbab = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'admin'");
    $ojbab = mysql_num_rows($resultbab);

	$resultbab2 = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'global'");
    $ojbab2 = mysql_num_rows($resultbab2);

	$resultbab3 = mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'mod'");
    $ojbab3 = mysql_num_rows($resultbab3);

$skin2[1] .= '- <a href="';
$skin2[1] .= $forumsurl;
$skin2[1] .= '">View Forum</a><br>
- <a href="admin/admin.php?view=home">Admin CP</a><br>
- <a href="boardcp.php">CP Home</a><br><br>';

	$oj = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'admin'"));
	if ((($oj > "0") && ($_COOKIE[username]) && (is_numeric($useridn)))) {

$skin2[2] .= '- <a href="boardcp.php?view=settings">Forum Settings</a><br>
- <a href="boardcp.php?view=cat">Categories</a><br>
- <a href="boardcp.php?view=forums">Forums</a><br>
- <a href="boardcp.php?view=sub">Sub-Forums</a><br>
- <a href="boardcp.php?view=users">Mods/Admins</a><br>
- <a href="boardcp.php?view=ranks">Ranks</a><br>
- <a href="boardcp.php?view=shop">Shop</a><br><br>';
	}
	if (($_COOKIE[username]) && (is_numeric($useridn))) {
	$ou = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'global'"));
	$ou2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'admin'"));
	$ou3 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."boardcp WHERE uid = '".$useridn."' AND level = 'mod'"));
	if ((($ou > "0") or ($ou2 > "0") or ($ou3 > "0"))) {

$skin2[3] .= '- <a href="boardcp.php?view=topics">Topics</a><br>
- <a href="boardcp.php?view=posts">Posts</a><br><br>';
}
}

     $skin2[4] = online();
	 $skin2[5] = usersonline();
	 $skin2[6] = totalpms();
	 $skin2[7] = newpms();
	 $skin2[8] = pms();
	 $skin2[9] = welcome();
	 $skin2[10] = skins();
	 $skin2[11] = skinname();
	 $skin2[12] = $version;

	 eval (" ?>" . preg_replace($skin1, $skin2, stripslashes($result)) . " <?php ");
?>