summaryrefslogtreecommitdiff
path: root/create_thread.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-05-08 17:30:08 -0600
committerGitHub <noreply@github.com>2021-05-08 17:30:08 -0600
commit87b1dfd1f77b08915ee5e905da45e316ba2c0e7d (patch)
treef6c0f8d09454b6e887df0f66ca37c1ce9efb30d0 /create_thread.php
parent0b045d57b2164b5ce003955d79627ae506a153eb (diff)
parenta09d9f377f5c055e42e5f21b5cdea64c2e2ca896 (diff)
Merge pull request #14 from cflip/refactor
Huge refactor
Diffstat (limited to 'create_thread.php')
-rw-r--r--create_thread.php69
1 files changed, 33 insertions, 36 deletions
diff --git a/create_thread.php b/create_thread.php
index 4598ce2..6fb7df9 100644
--- a/create_thread.php
+++ b/create_thread.php
@@ -1,63 +1,60 @@
-<?php session_start()?>
+<?php session_start() ?>
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
- <title>Create a thread - cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
+ <title>Create a thread - cflip.net forum</title>
+ <link rel="stylesheet" href="styles/style.css">
</head>
<body>
-<?php include_once 'templates/header.php' ?>
+<?php include_once 'includes/templates/header.php' ?>
<h2>Create a new thread</h2>
<?php
-if (!isset($_SESSION['signed_in'])) {
- die('You must be <a href="signin.php">signed in</a> to create a thread.');
-}
+include_once 'includes/Session.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>
+<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/db_inc.php';
- include_once 'model/Category.php';
+ include_once './includes/functions_category.php';
+ include_once './includes/model/Category.php';
- $categories = get_all_categories($dbc);
+ $categories = get_all_categories();
- if (count($categories) == 0) {
- echo 'There are no categories to post to!';
- } else {
- echo '<select name="thread_cat">';
+ if (count($categories) == 0) {
+ echo '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>';
+ 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">
+ <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/db_inc.php';
-include_once 'includes/functions_insert.php';
+include_once 'includes/functions_post.php';
+include_once 'includes/functions_thread.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);
- $user_id = filter_var($_SESSION['user_id'], FILTER_SANITIZE_NUMBER_INT);
if (empty($thread_subject) or !$thread_subject) {
echo 'Thread subject cannot be empty';
} else {
- insert_thread($dbc, $thread_subject, $thread_cat, $user_id);
- $thread_id = mysqli_insert_id($dbc);
- insert_post($dbc, $post_content, $thread_id, $user_id, $thread_cat);
-
- $sql = "UPDATE categories SET `cat_thread_count` = `cat_thread_count` + '1' WHERE cat_id = " . $thread_cat . ";";
- mysqli_query($dbc, $sql);
+ $thread_id = create_thread($thread_subject, $thread_cat);
+ create_post($post_content, $thread_id, $thread_cat);
header("Location: viewthread.php?id=" . $thread_id);
}