<?php
session_start();
include('classes/auth.php');
include("classes/header.php");
require_once('classes/conf.php');
require_once('classes/threads.php');
require_once('classes/comments.php');
$threads = new threads(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$comments = new comments("comments" ,DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

if($_POST){
	if($_POST['comment'])
		$id = $_POST['comment'];
	else
		$id = $threads->file_thread($_POST['title'],$_SESSION['username'], date("g:iA M d, Y"));
	$comments->write($id, $_POST['title'], $_POST['bodytext']);
	echo  $threads->display_thread($id);
} else {
	if($_REQUEST['deletepost'])
		echo $comments->delete_comment($_REQUEST['deletepost'], $_REQUEST['thread']);
	if($_REQUEST['thread'])
		echo $threads->display_thread($_REQUEST['thread']);
	else {
		if($_REQUEST['delete'])
			echo $threads->delete_thread($_REQUEST['delete']);
		
		echo '<h2 align="center"> Forum </h2>';
		echo $threads->display_report_list();
		echo <<<NEW_THREAD
<h2>New Thread</h2>
<form action="forum.php" method="post">
<div class="clearfix">
	<label for="title">Title</label><br />
    <div class="input">
    	<input name="title" id="title" type="text" maxlength="55"  class="xlarge" required/>
    </div>
</div>
    
<div class="clearfix">
	<label for="bodytext">Body Text</label><br />
    <div class="input">
    	<textarea name="bodytext" id="bodytext" rows=10 cols=56 class="xxlarge" required></textarea>
    </div>
</div>
      
<div class="actions">
	<button type="submit" class="btn primary" >Create This Thread</button>
    <button type="reset" class="btn">Cancel</button>
</div>
</form>
NEW_THREAD;

	}
}
include("classes/footer.php");
?>
