<?
//WriteBlogEntry.php
include("common.inc");
include("common_db.inc");
include("viewblog.inc");
global $author;
checkAuthor();
displayPage();
function displayPage()
{
global $author;
displayHeader("$author's blog - Write a blog entry");
parseInput();
print "<h1>$author's blog</h1>\n";
displayForm();
//Display the last three entries you wrote
print " <h3>Latest entries</h3>\n";
global $author;
displayEntries($author,3);
displayFooter();
}
function displayForm()
{
global $author;
$PHP_SELF = $_SERVER['PHP_SELF'];
print " <h3>Write a new entry</h3>\n";
print " <form title=$PHP_SELF action=\"$PHP_SELF?author=$author\" method=POST>\n";
print " <b>Title:</b><br><input type=text name=title size=60 maxlength=60 value=\"\"><br><br>\n";
print " <b>Entry:</b><br> <textarea name=blogEntry cols=80 rows=20></textarea><br><br>\n";
print " <b>Password:</b><br><input type=password name=password value=\"\"><br><br>\n";
print " <input type=submit name=submit value=Submit!>\n";
print " <input type=hidden name=added value=\"added\">\n";
print " </form>\n";
print " <br>\n";
}
function parseInput(){
global $author;
global $secretpassword;
$added = $_POST['added'];
$title = $_POST['title'];
$blogEntry = $_POST['blogEntry'];
$getpassword = $_POST['password'];
if( IsSet($added) )
{
if($getpassword != $secretpassword){
die("Forbidden to access this page! Go back <a href=\"/\">home</a>.");
}
$date = strftime("%Y-%m-%d %H:%M:%S", time());
$title = addslashes($title);
$blogEntry = addslashes($blogEntry);
$connection = db_connect();
$query = "INSERT INTO $author (title, date, blogEntry) VALUES ('$title', '$date', '$blogEntry')";
$result = db_query($query) or die("Error updating the blog for author [$author]");
UnSet($added);
}
}
function checkAuthor(){
global $yourAuthorVar;
$author = $_GET['author'];
if( IsSet($author) && $author == $yourAuthorVar){
}
// Support multiple authors by uncommenting and replicating this else-if block
// else if( IsSet($author) && $author == "SomeOtherAuthor){
// }
else{
die("Forbidden to access this page! Go back to <a href=\"/\">home</a>.");
}
}
?>