forked from heyhellomila/SOEN341
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost Table.php
More file actions
108 lines (94 loc) · 3.08 KB
/
Copy pathPost Table.php
File metadata and controls
108 lines (94 loc) · 3.08 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require_once("action/postTableAction.php");
$action = new postTableAction();
$action->execute();
if (isset($_POST['liked'])) {
$postid = $_POST['postid'];
$n = $action->getPostByID($postid);
$action->updateLike($postid, $n["post_nb_likes"]);
echo $n["post_nb_likes"]+1;
exit(); }
if (isset($_POST['disliked'])) {
$postid = $_POST['postid'];
$n = $action->getPostByID($postid);
$action->updateDislike($postid, $n["post_nb_likes"]);
echo $n["post_nb_likes"]-1;
exit(); }
?>
<div class="my-3">
<?php
foreach ($action->posts as $index=>$post) {
$postCreator = $action->getUserByID($post["post_creator"]);
?>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="container">
<div>
<!-- Single post starts here -->
<form name="title" action="index.php" method="post">
<input type="hidden" name="post_id" value="<?=$post["post_id"]?>">
<button type="submit" class="notButton"><?=$post["post_title"]?></button>
</form>
<div class="media text-muted pt-0 mb-3 border-bottom border-gray">
<table>
<tr>
<td>
<strong class="d-block text-gray-dark">From:<form name="name" action="profilePage.php" method="post">
<input type="hidden" name="post_creator" value="<?=$post["post_creator"]?>">
<button type="submit" name="submit" class="notButton"><?=$postCreator["user_name"]?></button>
</form></strong>
<strong class="d-block text-gray-dark">Posted: <?=$post["post_creation_time"]?></strong>
<strong class="d-block">Answers: <?=$post["post_nb_answers"]?></strong>
<strong id="likes" class="d-block"><span class="likes_count">Likes: <?=$post["post_nb_likes"]?></span></strong>
<span class="like fa fa-thumbs-up" data-id="<?=$post["post_id"]?>"></span>
<span class="dislike fa fa-thumbs-down" data-id="<?=$post["post_id"]?>"></span>
</td>
<td style="padding: 5px;"><?=$post["post_content"]?></td>
</tr>
</table>
<!-- End of single post -->
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.like').on('click', function(){
var postid = $(this).data('id');
$post = $(this);
$.ajax({
url: 'Post Table.php',
type: 'post',
data: {
'liked': 1,
'postid': postid
},
success: function(response){
$post.parent().find('span.likes_count').text("Likes: " + response);
}
});
});
$('.dislike').on('click', function(){
var postid = $(this).data('id');
$post = $(this);
$.ajax({
url: 'Post Table.php',
type: 'post',
data: {
'disliked': 1,
'postid': postid
},
success: function(response){
$post.parent().find('span.likes_count').text("Likes: " + response);
}
});
});
});
</script>