summaryrefslogtreecommitdiff
path: root/create_thread.php
diff options
context:
space:
mode:
Diffstat (limited to 'create_thread.php')
-rwxr-xr-x[-rw-r--r--]create_thread.php156
1 files changed, 78 insertions, 78 deletions
diff --git a/create_thread.php b/create_thread.php
index 3d1c530..d01eb26 100644..100755
--- a/create_thread.php
+++ b/create_thread.php
@@ -1,78 +1,78 @@
-<?php session_start() ?>
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <title>Create a thread - cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
-</head>
-<body>
-<?php include_once 'includes/templates/header.php' ?>
-<h2>Create a new thread</h2>
-<?php
-include_once 'includes/Session.php';
-include_once 'includes/error.php';
-if (!Session::get()->is_signed_in()) {
- trigger_error('You must be <a href="signin.php">signed in</a> to create a thread.');
- exit();
-}
-?>
-<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
- <label for="thread_subject">Subject: </label><br>
- <input type="text" name="thread_subject"><br>
- <label for="thread_cat">Category: </label><br>
- <?php
- include_once './includes/model/Category.php';
-
- $categories = Category::get_all_categories();
-
- if (count($categories) == 0) {
- trigger_error('There are no categories to post to!');
- } else {
- echo '<select name="thread_cat">';
-
- foreach ($categories as $category) {
- echo '<option value="' . $category->id . '">' . $category->name . '</option>';
- }
-
- echo '</select><br>';
- }
- ?>
- <label for="post_content">Write your post: </label><br>
- <textarea name="post_content"></textarea><br>
- <input type="submit" name="submit">
-</form>
-<?php
-include_once './includes/model/Post.php';
-include_once './includes/model/Thread.php';
-include_once './includes/error.php';
-
-if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING);
- $thread_subject = filter_input(INPUT_POST, 'thread_subject', FILTER_SANITIZE_STRING);
- $thread_cat = filter_input(INPUT_POST, 'thread_cat', FILTER_SANITIZE_NUMBER_INT);
-
- $errors = array();
- if (empty($thread_subject) or !$thread_subject) {
- $errors[] = 'Thread subject cannot be empty';
- }
- if (empty($post_content) or !$post_content) {
- $errors[] = 'Thread body cannot be empty';
- }
-
- if (!empty($errors)) {
- $errstr = 'Please check the following problems: <ul>';
- foreach ($errors as $err) {
- $errstr .= '<li>' . $err . '</li>';
- }
- $errstr .= '</ul>';
- trigger_error($errstr);
- } else {
- $thread_id = Thread::create($thread_subject, $thread_cat);
- Post::create($post_content, $thread_id, $thread_cat);
-
- header("Location: viewthread.php?id=" . $thread_id);
- }
-}
-?>
-</body>
-</html>
+<?php session_start() ?>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Create a thread - cflip.net forum</title>
+<?php include_once 'includes/templates/head.php'; ?>
+</head>
+<body>
+<?php include_once 'includes/templates/header.php' ?>
+ <h2>Create a new thread</h2>
+<?php
+include_once 'includes/Session.php';
+include_once 'includes/error.php';
+if (!Session::get()->is_signed_in()) {
+ trigger_error('You must be <a href="signin.php">signed in</a> to create a thread.');
+ exit();
+}
+?>
+ <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
+ <label for="thread_subject">Subject: </label><br>
+ <input type="text" name="thread_subject"><br>
+ <label for="thread_cat">Category: </label><br>
+ <?php
+ include_once './includes/model/Category.php';
+
+ $categories = Category::get_all_categories();
+
+ if (count($categories) == 0) {
+ trigger_error('There are no categories to post to!');
+ } else {
+ echo '<select name="thread_cat">';
+
+ foreach ($categories as $category) {
+ echo '<option value="' . $category->id . '">' . $category->name . '</option>';
+ }
+
+ echo '</select><br>';
+ }
+ ?>
+ <label for="post_content">Write your post: </label><br>
+ <textarea name="post_content"></textarea><br>
+ <input type="submit" name="submit">
+ </form>
+<?php
+include_once './includes/model/Post.php';
+include_once './includes/model/Thread.php';
+include_once './includes/error.php';
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING);
+ $thread_subject = filter_input(INPUT_POST, 'thread_subject', FILTER_SANITIZE_STRING);
+ $thread_cat = filter_input(INPUT_POST, 'thread_cat', FILTER_SANITIZE_NUMBER_INT);
+
+ $errors = array();
+ if (empty($thread_subject) or !$thread_subject) {
+ $errors[] = 'Thread subject cannot be empty';
+ }
+ if (empty($post_content) or !$post_content) {
+ $errors[] = 'Thread body cannot be empty';
+ }
+
+ if (!empty($errors)) {
+ $errstr = 'Please check the following problems: <ul>';
+ foreach ($errors as $err) {
+ $errstr .= '<li>' . $err . '</li>';
+ }
+ $errstr .= '</ul>';
+ trigger_error($errstr);
+ } else {
+ $thread_id = Thread::create($thread_subject, $thread_cat);
+ Post::create($post_content, $thread_id, $thread_cat);
+
+ header("Location: viewthread.php?id=" . $thread_id);
+ }
+}
+?>
+</body>
+</html>