<?php
ob_start();
include "config.php";
switch ($_GET['frame']){
case 'addblock':
if (!$_POST['addblock']) {
echo ("You can add new blocks here, HTML <strong>IS</strong> allowed");
echo ("<form method=post>\n
Block Title: <input type=text name=title maxlength=50><br />\n
Content:<br /> <textarea class=\"inputarea\" rows=20 cols=70 name=content></textarea><br />\n
Hidden: <select name=hidden>\n
<option>No</option>\n
<option>Yes</option>
</select>\n <br />
<input type=submit name=addblock value=\"Add Block\">\n
</form>");
//if the form hasn't been submitted, present it
}else{
//we put the values from the form into variables
$title = strip_tags($_POST['title']);
$block = nl2br($_POST['content']);
$hidden = $_POST['hidden'];
//becaues this is a new block, we make it the last one to be displayed, order
//will be changed in the block manager, cause I'm too lazy to write something to
//find and update orders whenever blocks are added
$osql = "SELECT * FROM blocks";
$order = mysql_query($osql)
or die(mysql_error());
//we see how many blocks there are and set the order to 1 above
$numblocks = mysql_num_rows($order);
$order_value = ($numblocks + 1) * 10;
//add 1 to the number of rows, making the block displayed last
mysql_query("INSERT INTO blocks (name,content,hidden,position) VALUES('$title','$block','$hidden','$order_value')")
or die(mysql_error());
echo "Block added successfully, If you would like to reorder your blocks, please visted the block manager";
}
break;
case 'blockman':
echo "Welcome to the block manager<br />\n";
$sql = "SELECT * FROM blocks ORDER BY position";
$blocks = mysql_query($sql);
echo "<form method=post action=?frame=updateblocks>";
$countrows = mysql_num_rows($blocks);
$i = "1";
while($row = mysql_fetch_array($blocks)){
$title = $row['name'];
$bid = $row['bid'];
$position = $row['position'];
echo (" <a href=\"?frame=editblock&id=$bid\">$title</a> \n
<a href=\"?frame=delblock&id=$bid\">Delete?</a><br /><br />\n");
$i++;
} // while
echo "<center><input type=submit name=update value=Reorder></form></center>";
break;
case 'delblock':
if (!$_POST['confirm']) {//check to see if the form is submitted
$nid = $_GET['id'];
echo ("Are you sure you want to delete this block?\n
Block deletion is permenent and cannot be undone, there will be no other warning message\n
<br /><form method=post action=\"?frame=delblock&id=$bid\">\n
<div align=center><input type=submit name=confirm value=yes>\n
\n
<input type=submit name=confirm value=no></div></form>");
}elseif($_POST['confirm'] == "no"){
echo "This block will no longer be deleted, please continue your browsing";
}elseif($_POST['confirm'] == "yes"){
$bid = $_GET['id'];
$sql = "DELETE FROM site.blocks where bid='$bid'";
mysql_query($sql)
or die(mysql_error());
echo "block deleted successfully";
}
break;
case 'editblock':
if (!$_POST['update']) {//the form hasn't been submitted
$_GET['id'] = $bid;
$sql = "SELECT * FROM blocks WHERE bid=".$bid;
$getinfo = mysql_query($sql)
or die(mysql_error());//get the info from the database
if (mysql_num_rows($getinfo == "0")) {//no results
exit("sorry, we couldn't find a block with the id of $bid");
}
while($row = mysql_fetch_array($getinfo)){
$name = $row['name'];
$data = $row['content'];
$hidden = $row['hidden'];
$order = $row['position'];
//put our variables into smaller variables without quotes to avoid encapped white space error
echo ("<form method=post>\n
Block Title: <input type=text name=name value=$name><br />
Block data:<br />\n
<textarea rows=20 cols=65 name=data>$data</textarea><br />\n
Hidden: <select name=hidden>\n
<option>No</option>\n
<option>Yes</option>
</select>\n <br />
Position: <input type=text name=position maxlength=10 size=2 value=$order><br />\n
<input type=submit name=update value=\"Update Block\">\n
</form>");
}
}else{
$name = $_POST['name'];
$data = $_POST['data'];
$hidden = $_POST['hidden'];
$position = $_POST['position'];
$bid = $_GET['id'];
$update = mysql_query("Update blocks set name = '$name', content = '$data', hidden = '$hidden', position = '$position' WHERE bid = '$bid'")
or die(mysql_error());
echo "Block updated successfully";
}
break;
default:
echo "Welcome to the adminCP please select an option to the left";
;
} // switch
?>