Subversion Repositories taios

Compare Revisions

Ignore whitespace Rev 13 → Rev 75

/_taios.php
1,322 → 1,377
<?php
 
require '_config.php';
 
class Taios_Page
{
function __construct($title, $url = "")
{
$this->title = $title;
$this->url = $url;
$this->drawnHeader = false;
$this->drawnMiddle = false;
$this->drawnFooter = false;
$this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD);
if (!$this->db)
{
$this->drawError('Failed to connect to database: ' . mysql_error());
}
if (!mysql_select_db('Tim32'))
{
$this->drawError('Failed to select database: ' . mysql_error());
}
}
function drawHeader()
{
if (!$this->drawnHeader)
{
write('<!DOCTYPE html>');
write('<html>');
write('<head>');
write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">');
write('<title>Tim32 &middot; ' . $this->title . '</title>');
write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">');
write('</head>');
write('<body>');
write('<div class="sidebar">');
write('<div class="sidebar-header">');
write('<h1>Tim32</h1>');
write('</div>');
write('<div class="sidebar-menu">');
$this->drawMenuItem('Home', 'index.php');
$this->drawMenuItem('Blog', 'blog/');
$this->drawMenuItem('Projects', 'projects/');
$this->drawMenuItem('Forums', 'forums/');
$this->drawMenuItem('Wiki', 'wiki/');
$this->drawMenuItem('Photos', 'photos/');
write('<br />');
if ($this->isLoggedIn())
{
$this->drawMenuItem('Manage Account', 'admin/account.php?id=' . $this->getLoggedInUser()->ID);
$this->drawMenuItem('Logout', 'logout-do.php');
}
else
{
$this->drawMenuItem('Login', 'login.php');
$this->drawMenuItem('Register', 'register.php');
}
write('<br />');
$this->drawnHeader = true;
}
}
function drawMenuItem($t, $u)
{
write('<p><a href="' . $this->url . $u . '"</a>' . $t . '</a></p>');
}
function drawMiddle()
{
if (!$this->drawnMiddle)
{
write('<br />');
write('</div>');
write('</div>');
write('<div class="content">');
write('<h2>' . $this->title . '</h2>');
 
$this->drawnMiddle = true;
}
}
function drawFooter()
{
if (!$this->drawnFooter)
{
write('</div>');
write('</body>');
write('</html>');
$this->drawnFooter = true;
}
// die();
}
function drawError($text, $die = true)
{
$this->drawHeader();
$this->drawMiddle();
write('<h4 style="color: red;">Error: ' . $text . '</h4>');
if ($die)
{
$this->drawFooter();
die();
}
}
function redirect($url)
{
header('Location: ' . $url);
die();
}
function isLoggedIn()
{
$cookie = $_COOKIE['Tim32_Login'];
if (!empty($cookie))
{
$clist = explode('|~|', $cookie);
$user = $this->getUserByUsername($clist[0]);
if ($user)
{
if ($user->password == $clist[1])
{
return true;
}
}
}
return false;
}
function isUserAdmin()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 0)
{
return true;
}
}
return false;
}
function isUserGM()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 1)
{
return true;
}
}
return false;
}
function isUserNormal()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 2)
{
return true;
}
}
return false;
}
function checkLoggedIn()
{
if (!$this->isLoggedIn())
{
$this->drawError('You need to be logged in.');
}
}
function query($query)
{
$result = mysql_query($query);
if (!$result)
{
$this->drawError('MySQL Error: ' . mysql_error());
}
return $result;
}
function findIDs($table, $query = '')
{
$array = array();
$result = $this->query('SELECT ID FROM ' . $table . ' ' . $query);
while ($row = mysql_fetch_array($result))
{
array_push($array, $row['ID']);
}
return $array;
}
function getUserByID($id)
{
$result = $this->query('SELECT * FROM Users WHERE ID = ' . $id);
while ($row = mysql_fetch_array($result))
{
$user = new User;
$user->ID = $row['ID'];
$user->accessID = $row['AccessID'];
$user->username = $row['Username'];
$user->password = $row['Password'];
$user->emailAddress = $row['EmailAddress'];
$user->name = $row['Name'];
$user->challengeID = $row['ChallengeID'];
return $user;
}
return false;
}
function getUserByUsername($username)
{
$result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"');
while ($row = mysql_fetch_array($result))
{
return $this->getUserByID($row['ID']);
}
return false;
}
function getLoggedInUser()
{
if ($this->isLoggedIn())
{
$clist = explode('|~|', $_COOKIE['Tim32_Login']);
return $this->getUserByUsername($clist[0]);
}
return false;
}
function getBlogPost($id)
{
$result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id);
while ($row = mysql_fetch_array($result))
{
$post = new BlogPost;
$post->ID = $row['ID'];
$post->user = $this->getUserByID($row['AuthorID']);
$post->title = $row['Title'];
$post->content = $row['Content'];
$post->datePosted = strtotime($row['DatePosted']);
$post->category = $row['Category'];
return $post;
}
$this->drawError('Cannot find blog post, #' . $id);
}
function getGetID()
{
$id = $_GET['id'];
if (empty($id))
{
$id = 1;
}
return $id;
}
function getPostID()
{
$id = $_POSt['id'];
if (empty($id))
{
$id = 1;
}
return $id;
}
}
 
class User
{
public $ID;
public $accessID;
public $username;
public $password;
public $emailAddress;
public $name;
public $challengeID;
}
 
class BlogPost
{
public $ID;
public $author;
public $title;
public $content;
public $datePosted;
public $category;
}
 
function write($str)
{
echo $str;
echo "\n";
}
 
?>
<?php
 
require '_config.php';
 
class Taios_Page
{
function __construct($title, $url = "")
{
$this->title = $title;
$this->url = $url;
$this->drawnHeader = false;
$this->drawnMiddle = false;
$this->drawnFooter = false;
$this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD);
if (!$this->db)
{
$this->drawError('Failed to connect to database: ' . mysql_error());
}
if (!mysql_select_db('Tim32'))
{
$this->drawError('Failed to select database: ' . mysql_error());
}
}
function drawHeader()
{
if (!$this->drawnHeader)
{
write('<!DOCTYPE html>');
write('<html>');
write('<head>');
write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">');
write('<title>Tim32 &middot; ' . $this->title . '</title>');
write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">');
write('</head>');
write('<body>');
write('<div class="sidebar">');
write('<div class="sidebar-header">');
write('<h1>Tim32</h1>');
write('</div>');
write('<div class="sidebar-menu">');
$this->drawMenuItem('Home', 'index.php');
$this->drawMenuItem('Blog', 'blog/');
$this->drawMenuItem('Projects', 'projects/');
$this->drawMenuItem('Forums', 'forums/');
$this->drawMenuItem('Wiki', 'wiki/');
$this->drawMenuItem('Photos', 'photos/');
write('<br />');
if ($this->isLoggedIn())
{
$this->drawMenuItem('Administration', 'admin/';
$this->drawMenuItem('Logout', 'logout-do.php');
}
else
{
$this->drawMenuItem('Login', 'login.php');
$this->drawMenuItem('Register', 'register.php');
}
write('<br />');
$this->drawnHeader = true;
}
}
function drawMenuItem($t, $u)
{
write('<p><a href="' . $this->url . $u . '">' . $t . '</a></p>');
}
function drawMiddle()
{
if (!$this->drawnMiddle)
{
write('<br />');
write('</div>');
write('</div>');
write('<div class="content">');
write('<h2>' . $this->title . '</h2>');
 
$this->drawnMiddle = true;
}
}
function drawFooter()
{
if (!$this->drawnFooter)
{
write('</div>');
write('</body>');
write('</html>');
$this->drawnFooter = true;
}
die();
}
function drawError($text, $die = true)
{
$this->drawHeader();
$this->drawMiddle();
write('<h4 style="color: red;">Error: ' . $text . '</h4>');
if ($die)
{
$this->drawFooter();
die();
}
}
function drawBlogPostTree($id)
{
$post = $this->getBlogPost($id);
write('<a href="' . $this->url . 'blog/post.php?id=' . $id . '"><h3>' . $post->title. '</h3></a>');
write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>');
write('<p>' . $post->content . '</p>');
write('<br />');
if ($this->isUserNormal($this->getLoggedInUser()))
{
write('<p class="bold"><a href="add-commend.php?id="' . $id . '">Add Comment</a></p>');
write('<br />');
}
 
$ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id);
for ($i = 0; $i < count($ids); $i++)
{
write('<div class="indent">');
$this->drawBlogPostTree($ids[$i]);
write('</div>');
}
}
function drawBlogCategoriesMenu()
{
$cats = array();
$ids = $this->findIDs('BlogPosts', 'WHERE ParentID = -1');
for ($i = 0; $i < count($ids); $i++)
{
$cat = $this->getBlogPost($ids[$i])->category;
if (!in_array($cat, $cats))
{
array_push($cats, $cat);
}
}
write('<h3>Categories</h3>');
for ($i = 0; $i < count($cats); $i++)
{
$this->drawMenuItem($cats[$i], 'blog/index.php?cat=' . $cats[$i]);
}
}
 
function redirect($u)
{
header('Location: ' . $u);
die();
}
function isLoggedIn()
{
$cookie = $_COOKIE['Tim32_Login'];
if (!empty($cookie))
{
$clist = explode('|~|', $cookie);
$user = $this->getUserByUsername($clist[0]);
if ($user)
{
if ($user->password == $clist[1])
{
return true;
}
}
}
return false;
}
function isUserAdmin()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 0)
{
return true;
}
}
return false;
}
function isUserGM()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 1)
{
return true;
}
}
return false;
}
function isUserNormal()
{
if ($this->isLoggedIn())
{
if ($this->getLoggedInUser()->accessID <= 2)
{
return true;
}
}
return false;
}
function checkLoggedIn()
{
if (!$this->isLoggedIn())
{
$this->drawError('You need to be logged in.');
}
}
function query($query)
{
$result = mysql_query($query);
if (!$result)
{
$this->drawError('MySQL Error: ' . mysql_error());
}
return $result;
}
function findIDs($table, $query = '')
{
$array = array();
$result = $this->query('SELECT ID FROM ' . $table . ' ' . $query);
while ($row = mysql_fetch_array($result))
{
array_push($array, $row['ID']);
}
return $array;
}
function getUserByID($id)
{
$result = $this->query('SELECT * FROM Users WHERE ID = ' . $id);
while ($row = mysql_fetch_array($result))
{
$user = new User;
$user->ID = $row['ID'];
$user->accessID = $row['AccessID'];
$user->username = $row['Username'];
$user->password = $row['Password'];
$user->emailAddress = $row['EmailAddress'];
$user->name = $row['Name'];
$user->challengeID = $row['ChallengeID'];
return $user;
}
return false;
}
function getUserByUsername($username)
{
$result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"');
while ($row = mysql_fetch_array($result))
{
return $this->getUserByID($row['ID']);
}
return false;
}
function getLoggedInUser()
{
if ($this->isLoggedIn())
{
$clist = explode('|~|', $_COOKIE['Tim32_Login']);
return $this->getUserByUsername($clist[0]);
}
return false;
}
function getBlogPost($id)
{
$result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id);
while ($row = mysql_fetch_array($result))
{
$post = new BlogPost;
$post->ID = $row['ID'];
if ($row['ParentID'] == -1)
{
$post->parent = -1;
}
else
{
$post->parent = $this->getBlogPost($row['ParentID']);
}
$post->user = $this->getUserByID($row['AuthorID']);
$post->title = $row['Title'];
$post->content = $row['Content'];
$post->datePosted = strtotime($row['DatePosted']);
$post->category = $row['Category'];
$post->spam = $row['Spam'];
return $post;
}
$this->drawError('Cannot find blog post, #' . $id);
}
function getGetID()
{
$id = $_GET['id'];
if (empty($id))
{
$id = 1;
}
return $id;
}
function getPostID()
{
$id = $_POST['id'];
if (empty($id))
{
$id = 1;
}
return $id;
}
 
}
 
class User
{
public $ID;
public $accessID;
public $username;
public $password;
public $emailAddress;
public $name;
public $challengeID;
}
 
class BlogPost
{
public $ID;
public $parent;
public $author;
public $title;
public $content;
public $datePosted;
public $category;
public $spam;
}
 
function write($str)
{
echo $str;
echo "\n";
}
 
?>
/admin/all-accounts.php
0,0 → 1,39
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Manage All Accounts', '../');
$page->drawHeader();
$page->drawMiddle();
 
$page->checkLoggedIn();
 
if ($page->isUserAdmin($page->getLoggedInUser())))
{
write('<table>');
 
$ids = $page->findIDs('Users');
for ($i = 0; $i < count($ids); $i++)
{
$user = $page->getUserByID($ids[$i]);
write('<tr>');
write('<td>' . $user->ID . '</td>');
write('<td>' . $user->accessID . '</td>');
write('<td>' . $user->username . '</td>');
write('<td>' . $user->password . '</td>');
write('<td>' . $user->name . '</td>');
write('<td>' . $user->email . '</td>');
write('</tr>');
}
write('</table>');
}
else
{
drawError('You do not have permission to access this page.');
}
 
$page->drawFooter();
 
?>
 
/admin/account-do.php
0,0 → 1,53
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Update Account', '../');
$userID = $page->getPostID();
 
$page->checkLoggedIn();
 
$accessID = $_POST['accessID'];
$password = $_POST['password'];
$email = $_POST['email'];
$name = $_POST['name'];
 
$user = $page->getUserByID($userID);
if (($page->getLoggedInUser()->ID == $userID || $page->isUserAdmin($page->getLoggedInUser())) && $user)
{
if (isset($accessID) && $page->isUserAdmin($page->getLoggedInUser()))
{
$page->query('UPDATE Users SET AccessID = "' . $accessID . '" WHERE ID = ' . $userID);
}
if (!empty($password))
{
$page->query('UPDATE Users SET Password = "' . sha1($password) . '" WHERE ID = ' . $userID);
}
if (!empty($email))
{
$page->query('UPDATE Users SET EmailAddress = "' . $email . '" WHERE ID = ' . $userID);
}
if (!empty($name))
{
$page->query('UPDATE Users SET Name = "' . $name . '" WHERE ID = ' . $userID);
}
}
else
{
if (!$user)
{
drawError('No such user, #' . $userID);
}
else
{
drawError('You do not have permission to access this page.');
}
}
 
$page->redirect('account.php?id=' . $userID);
 
?>
 
/admin/account.php
0,0 → 1,60
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Manage Account', '../');
$page->drawHeader();
$page->drawMiddle();
 
$page->checkLoggedIn();
 
$userID = $page->getGetID();
$user = $page->getUserByID($userID);
 
if (($page->getLoggedInUser()->ID == $userID || $page->isUserAdmin($page->getLoggedInUser())) && $user)
{
?>
 
<p class="bold">Here you can edit your account.</p>
<p>Only change the password value if you want to change your password.</p>
<br />
 
<form action="account-do.php" method="POST">
<table>
<tr><td class="bold">ID: </td><td><?php echo $user->ID; ?></td></tr>
<?php
if ($page->isUserAdmin($page->getLoggedInUser()))
{
write('<tr><td class="bold">AccessID: </td><td><input type="text" name="accessID" value="' . $user->accessID . '" /></td></tr>');
}
else
{
write('<tr><td class="bold">AccessID: </td><td>' . $user->accessID . '</td></tr>');
}
?>
<tr><td class="bold">Username: </td><td><?php echo $user->username; ?></td></tr>
<tr><td class="bold">Password: </td><td><input type="password" name="password" /></td></tr>
<tr><td class="bold">Email Address: </td><td><input type="text" name="email" value="<?php echo $user->emailAddress; ?>" /></td></tr>
<tr><td class="bold">Name: </td><td><input type="text" name="name" value="<?php echo $user->name; ?>" /></td></tr>
<tr><td></td><td><input type="submit" value="Update Account" /></td></tr>
</table>
</form>
 
<?php
}
else
{
if (!$user)
{
drawError('No such user, #' . $userID);
}
else
{
drawError('You do not have permission to access this page.');
}
}
 
$page->drawFooter();
 
?>
 
/admin/index.php
9,18 → 9,19
$page->checkLoggedIn();
$user = $page->getLoggedInUser();
 
write('<h3><a href="account.php?id=' . $user->ID. '">Manage Account</a></h3>');
write('<h4><a href="account.php?id=' . $user->ID. '">Manage Account</a></h4>');
 
if ($page->isUserAdmin($user))
{
write('<h3><a href="all-accounts.php">Manage All Accounts</a></h3>');
write('<h3><a href="all-blog-posts.php">Manage All Blog Posts</a></h3>');
write('<h3><a href="all-blog-comments.php">Manage All Blog Comments</a></h3>');
write('<h3><a href="all-forum-categories.php">Manage All Forum Categories</a></h3>');
write('<h3><a href="all-forum-topics.php">Manage All Forum Topics</a></h3>');
write('<h3><a href="all-forum-posts.php">Manage All Forum Posts</a></h3>');
write('<h4><a href="all-accounts.php">Manage All Accounts</a></h4>');
write('<h4><a href="all-blog-posts.php">Manage All Blog Posts</a></h4>');
write('<h4><a href="all-blog-comments.php">Manage All Blog Comments</a></h4>');
write('<h4><a href="all-forum-categories.php">Manage All Forum Categories</a></h4>');
write('<h4><a href="all-forum-topics.php">Manage All Forum Topics</a></h4>');
write('<h4><a href="all-forum-posts.php">Manage All Forum Posts</a></h4>');
}
 
$page->drawFooter();
 
?>
 
/styles.css
1,111 → 1,120
body {
background-color: #FFFFFF;
color: #000000;
font-family: Droid Sans, Tahoma, sans-serif;
font-size: 11pt;
}
 
h1 {
font-size: 28pt;
margin: 6px;
margin-top: 0px;
color: #000089;
border-bottom: 1px solid #000000;
}
 
h2 {
font-size: 20pt;
margin: 6px;
margin-left: 8px;
color: #00004B;
}
 
h3 {
font-size: 16pt;
margin: 6px;
margin-left: 10px;
color: #000055;
}
 
h4 {
font-size: 12pt;
margin: 6px;
margin-left: 12px;
color: #00005F;
}
 
h5 {
font-size: 10pt;
margin: 6px;
margin-left: 14px;
color: #000069;
}
 
p, table, span {
font-size: 11pt;
margin: 6px;
margin-left: 16px;
}
 
a {
text-decoration: none;
color: #000050;
}
 
a:hover {
text-decoration: underline;
}
 
input {
border: 1px solid #000000;
color: #000000;
background-color: #B5D7FF;
}
 
.sidebar {
left: 0px;
top: 0px;
position: fixed;
padding: 0px;
padding-left: 32px;
border-right: 1px solid #000089;
background-color: #FFFF73;
background-image: url('data/sidebar-gradient.png');
background-repeat: repeat-x;
background-position: center bottom;
}
 
.sidebar-header {
left: 0px;
width: 140px;
padding: 6px;
text-align: right;
}
 
.sidebar-menu {
text-align: right;
padding: 6px;
}
 
.sidebar-menu h3 {
margin: 6px;
}
 
.sidebar-menu p {
font-size: 12pt;
margin: 4px;
}
 
.content {
left: 200px;
top: 0px;
position: absolute;
width: 720px;
margin-right: 32px;
}
 
.bold {
font-weight: bold;
}
body {
background-color: #FFFFFF;
color: #000000;
font-family: Droid Sans, Tahoma, sans-serif;
font-size: 11pt;
}
 
h1 {
font-size: 28pt;
margin: 6px;
margin-top: 0px;
color: #000089;
border-bottom: 1px solid #000000;
}
 
h2 {
font-size: 20pt;
margin: 6px;
margin-left: 8px;
color: #00004B;
}
 
h3 {
font-size: 16pt;
margin: 6px;
margin-left: 10px;
color: #000055;
}
 
h4 {
font-size: 12pt;
margin: 6px;
margin-left: 12px;
color: #00005F;
}
 
h5 {
font-size: 10pt;
margin: 6px;
margin-left: 14px;
color: #000069;
}
 
p, table, span {
font-size: 11pt;
margin: 6px;
margin-left: 16px;
}
 
a {
text-decoration: none;
color: #000050;
}
 
a:hover {
text-decoration: underline;
}
 
input {
border: 1px solid #000000;
color: #000000;
background-color: #B5D7FF;
}
 
table, td {
border: 1px solid #222222;
}
 
.sidebar {
left: 0px;
top: 0px;
position: fixed;
padding: 0px;
padding-left: 32px;
border-right: 1px solid #000089;
background-color: #FFFF73;
background-image: url('data/sidebar-gradient.png');
background-repeat: repeat-x;
background-position: center bottom;
}
 
.sidebar-header {
left: 0px;
width: 140px;
padding: 6px;
text-align: right;
}
 
.sidebar-menu {
text-align: right;
padding: 6px;
}
 
.sidebar-menu h3 {
margin: 6px;
}
 
.sidebar-menu p {
font-size: 12pt;
margin: 4px;
}
 
.content {
left: 200px;
top: 0px;
position: absolute;
width: 720px;
margin-right: 32px;
}
 
.bold {
font-weight: bold;
}
 
.indent {
margin-left: 14px;
border-left: 1px solid #BBBBBB;
}
/index.php
34,12 → 34,6
write('<br />');
}
 
if ($page->isLoggedIn())
{
write('<h3>Actions</h3>');
write('<h4><a href="admin/account.php?id=' . $page->getLoggedInUser()->ID . '">Manage Account</a></h4>');
}
 
$page->drawFooter();
 
?>
/blog/post.php
0,0 → 1,19
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Blog Posts', '../');
 
if (!isset($_GET['id']))
$page->redirect("index.php");
 
$page->drawHeader();
$page->drawBlogCategoriesMenu();
$page->drawMiddle();
 
$page->drawBlogPostTree($_GET['id']);
 
$page->drawFooter();
 
?>
 
/blog/index.php
1,30 → 1,37
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Blog Posts', '../');
$page->drawHeader();
write('<h3>Blog</h3>');
$page->drawMenuItem('Computing', 'index.php?cat=Computing');
$page->drawMiddle();
 
if ($page->isUserGM($page->getLoggedInUser()))
{
write('<p class="bold"><a href="add-post.php">Add Post</a></p>');
write('<br />');
}
 
$ids = $page->findIDs('BlogPosts', 'WHERE ParentID = -1');
for ($i = 0; $i < count($ids); $i++)
{
$id = $ids[$i];
$post = $page->getBlogPost($id);
write('<h3>' . $post->title. '</h3>');
write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>');
write('<p>' . $post->content . '</p>');
}
 
$page->drawFooter();
 
?>
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Blog Posts', '../');
$page->drawHeader();
$page->drawBlogCategoriesMenu();
$page->drawMiddle();
 
if ($page->isUserGM($page->getLoggedInUser()))
{
write('<p class="bold"><a href="add-post.php?id=-1">Add Post</a></p>');
write('<br />');
}
 
$query = 'WHERE ParentID = -1';
 
if (isset($_GET['cat']))
{
$query = $query . ' AND Category = "' . $_GET['cat'] . '"';
write('<p>Only showing blog posts from the ' . $_GET['cat'] . ' category. <a href="index.php">Reset Filtering</a></p><br />');
}
 
$ids = $page->findIDs('BlogPosts', $query);
for ($i = 0; $i < count($ids); $i++)
{
$id = $ids[$i];
$post = $page->getBlogPost($id);
write('<a href="post.php?id=' . $ids[$i] . '"><h3>' . $post->title. '</h3></a>');
write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>');
write('<p>' . $post->content . '</p>');
}
 
 
$page->drawFooter();
 
?>
/blog/post-add.php
0,0 → 1,55
<?php
 
require '../_taios.php';
 
$page = new Taios_Page('Blog Posts', '../');
 
if (isset($_POST['title']) && isset($_POST['content']) && isset($_POST['catagory']) && isset($_POST['parentID']))
{
$page->query('insert into BlogPosts VALUES(0, ' . $_POST['parentID'] . ', "' . $page->getLoggedInUser()->ID . '", "' . $_POST['title'] . '", "' . $_POST['content'] . '", NOW(), "' . $_POST['catagory'] . '", 0)');
$page->redirect('index.php');
}
 
$page->drawHeader();
$page->drawBlogCategoriesMenu();
$page->drawMiddle();
 
if ($page->isUserGM($page->getLoggedInUser()))
{
write('<p class="bold"><a href="add-post.php">Add Post</a></p>');
write('<br />');
}
 
?>
 
<form action="post-add.php" method="post">
<table>
<tr>
<td class="bold">Title: </td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td class="bold">Content: </td>
<td><input type="text" name="content" /></td>
</tr>
<tr>
<td class="bold">Catagory: </td>
<td><input type="text" name="catagory" /></td>
</tr>
 
<?php
write('<input type="hidden" name="parentID" value="' . $_GET['id'] . '"/>');
?>
 
<tr>
<td class="bold"></td>
<td><input type="submit" value="Post" /></td>
</tr>
</table>
</form>
 
<?php
 
$page->drawFooter();
 
?>
/install.sql
72,4 → 72,4
);
 
INSERT INTO Users VALUES (1, 0, "admin", SHA1("password"), "admins@tim32.org", "Tim32 Admin", 0);
INSERT INTO BlogPosts VALUES(1, 1, "Welcome to Tim32!", "Welcome to the new Tim32 website! It has had a complete design re-think to make it simpler and easier to use!", NOW(), "Tim32");
INSERT INTO BlogPosts VALUES(1, -1, 1, "Welcome to Tim32!", "Welcome to the new Tim32 website! It has had a complete design re-think to make it simpler and easier to use!", NOW(), "Tim32", FALSE);