-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.php
61 lines (54 loc) · 1.95 KB
/
thread.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
include("./includes/header.php");
$thread_id = "";
if(isset($_GET["thread_id"])){
$thread_id = mysql_real_escape_string($_GET["thread_id"]); //remember to check for sql injection
}else{
$thread_id = mysql_real_escape_string($_POST["thread_id"]);
}
$thread = Thread::getThreadFromID($thread_id);
if(isset($_POST['newPost'])){
$post_text = mysql_real_escape_string($_POST["post_text"]);
$board_id = mysql_real_escape_string($_POST["board_id"]);
Post::CreatePost($userid, $user->getUsername(), $board_id, $thread, $post_text);
}
if(isset($_POST['editPost'])){
$post_id = mysql_real_escape_string($_POST["post_id"]);
$edited_text = mysql_real_escape_string($_POST["edited_text"]);
Post::UpdatePostText($post_id, $edited_text);
}
$thread->LoadPosts();
$posts = $thread->GetPostList();
$post_list_size = count($posts);
echo "<table border='1'><tr><th>Post </th><th>Posted By</th><th> Last edited </th></tr>";
for($i=0;$i<$post_list_size; $i++){
$curr_post = $posts[$i];?>
<tr>
<td><?php echo $curr_post->GetPostText();?></td>
<td><?php echo $curr_post->GetPosterName()?></td>
<td><?php echo $curr_post->GetEditTime()?></td>
<td><?php
if($curr_post->GetPosterID() == $userid){ ?>
<form action="editPost.php" method="post">
<input type="hidden" name="post_id" value="<?php echo $curr_post->GetID(); ?>"/>
<input type="hidden" name="thread_id" value="<?php echo $thread->GetID(); ?>"/>
<input type="hidden" name="poster_id" value="<?php echo $user->getID(); ?>"/>
<input type="submit" value="Edit" name="editPost"/>
</form>
<?php } ?>
</td>
</tr>
<?php
}
echo "</table>";
if($loggedin){ ?>
<br><h2> Create Post </h2></br>
<form action="" method="post">
<br>Text: </br><br><textarea name="post_text" rows="10" cols="40"></textarea></br>
<input type="hidden" name="board_id" value="<?php echo $thread->GetBoardID();?>"/>
<br><input type="submit" name="newPost" value="Post"/></br>
</form>
<?php
}
include("./includes/footer.php");
?>