<?php
$z = "b";
include ("../config.php");
if (((($_GET['load'] == "help") or ($_GET['load'] == "chat") or ($_GET['load'] == "login") or ($_GET['load'] == "logout")))) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_header() . " <?php ");
}
} else {
eval (" ?>" . admin_header() . " <?php ");
echo '<SCRIPT LANGUAGE="JavaScript">var checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}</script>';
}
if ($ipbancheck3 == "0") {if ($numv == "0"){
	if ($warn == $naum) {
	echo "Looks Like Everything Checks Out, Go Ahea....Wait, You Don't Have Access to the Admin Panel!";
} else {

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
}
}
}
$from = (($page * $setting[max_results]) - $setting[max_results]);
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to access this page. You are only a $level.";
} else {
$admin_page = "yes";
	echo "<title>OneCMS - www.insanevisions.com/onecms > Comments Manager</title><form action='comments.php?load=comments&view=search' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for comments</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

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

$query="SELECT * FROM ".$pre."comments 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[subject]</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."comments"),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=\"comments.php?load=comments&page=$prev\"><<Previous</a>&nbsp;";
}

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

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

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

     echo "<input type='hidden' name='id[]' value='".$i."'>";
    
	if ($row[name] == "") {
	$name = "Visitor";
	} else {
	$name = $row[name];
	}

    echo "<tr><td><b><center>Comment #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."' value='".$name."'></td></tr><tr><td>Subject</td><td><input type='text' name='sub_".$i."' value='".$row2[subject]."'></td></tr>";
    echo "<tr><td>Comment</td><td><textarea name='mes_".$i."' cols='34' rows='10'>".stripslashes($row2[comment])."</textarea></td></tr>";
    }
	}
	echo "<tr><td><input type=\"submit\" name=\"Modify\" value=\"Modify\"></td></tr></form></table>";
    }

if ((($_GET['view'] == "manage") && ($_GET['edit'] == "2") && ($_GET['load'] == "comments"))) {
   while (list(, $i) = each ($_POST['id'])) {
   $r = mysql_query("UPDATE ".$pre."comments SET name = '".$_POST["name_$i"]."', subject = '".$_POST["sub_$i"]."', message = '".addslashes($_POST["mes_$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", "comments.php?load=comments");
echo "The comment(s) have been updated. <a href='comments.php?load=comments'>Manage Comments</a>";
}
}

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

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

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

	$query="SELECT * FROM ".$pre."comments 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);
    	echo "<tr><td>$name</td><td>$row[subject]</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."comments 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=\"comments.php?load=comments&view=search&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"comments.php?load=comments&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=\"comments.php?load=comments&view=search&page=$next\">Next>></a>";
}
echo "</center>";
}
}
if (($_GET['load'] == "help") or ($_GET['load'] == "chat")) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_footer() . " <?php ");
}
} else {
eval (" ?>" . admin_footer() . " <?php ");
}
?>