-
Notifications
You must be signed in to change notification settings - Fork 0
/
showPostList.php
135 lines (113 loc) · 3.94 KB
/
showPostList.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php require_once 'controllers/crudController.php';
require_once 'controllers/loginSessionController.php';?>
<?php
$rq = $_GET['key'];
$posts;
if($rq=="approved"){
$posts = getApprovedPosts();
}
else if($rq=="pending"){
$posts = getPendingPosts();
}
else if($rq=="mine"){
$posts = getMyPosts($user_id);
}
else if($rq=="mypending"){
$posts = getMyPendingPosts($user_id);
}
else if($rq=="myapproved"){
$posts = getMyApprovedPosts($user_id);
}
else $posts = getAllPosts();
if($rq == "mine" || $rq=="myapproved" || $rq=="mypending")echo '<th class = "userHeader"> </th>';
if($type=="admin")echo '<th class = "userHeader"> </th> <th class = "userHeader"> </th>';//For approve/disapprove button and remove button
else if($rq == "mine" || $rq=="myapproved" || $rq=="mypending"){//Users can delete their own post
echo '<th class = "userHeader"> </th>';
}
echo ' <th class = "userHeader"> </th>
<th class = "userHeader">Title</th>
<th class = "userHeader">Content preview</th>
<th class = "userHeader">Tag(s)</th>
<th class = "userHeader">Status</th>
<th class = "userHeader">Posted by</th>
<th class = "userHeader">Posted on</th>
';
foreach($posts as $post){
$posterName = getUserName($post['posterid']);
$postTitle = $post['title'];
$postContent = $post['txt'];
$postTag = $post['tag'];
$color = "yellow";
$postid = $post['id'];
if($post['status']=='pending')$color = "red";
if(strlen($postContent)>31){
$postContent = substr($postContent, 0, 30);
$postContent = $postContent.'...';
}
if(strlen($postTag)>31){
$postTag = substr($postTag, 0, 30);
$postTag = $postTag.'...';
}
if(strlen($postTitle)>31){
$postTitle = substr($postTitle, 0, 30);
$postTitle = $postTitle.'...';
}
echo '<tr >
<td>
<input class = "btnView" onClick = "location.href = '."'view_post.php?id=$postid'".'" type = "button" value = "View"> </button>
</td>';
if($rq == "mine" || $rq=="myapproved" || $rq=="mypending"){
echo '<td>
<input class = "btnView" onClick = "location.href = '."'edit_post.php?id=$postid'".'" type = "button" value = "Edit"> </button>
</td>';
}
if($type=="admin"){//Adds "approve" and "disapprove" buttons if user is admin
if($post['status']=='pending'){
echo '<td>
<input class = "btnView" onClick = "postAction('.$post["id"].','."'approve'".','."'$rq'".')" type = "button" style = "background-color:lightgreen; width:122px" value = "Approve"> </button>
</td>';
}
else{
echo '<td>
<input class = "btnView" onClick = "postAction('.$post["id"].','."'disapprove'".','."'$rq'".')" type = "button" style = "background-color:pink; width:122px" value = "Disapprove"> </button>
</td>';
}
}
if($type=="admin" || $rq == "mine" || $rq=="myapproved" || $rq=="mypending"){
echo '<td>
<input class = "btnView" onClick = "postAction('.$post["id"].','."'remove'".','."'$rq'".')" type = "button" style = "background-color:red; width:100px" value = "Remove"> </button>
</td>';
}
echo '<td>
<div class="post1">
<p >'.$postTitle.'</p>
</div>
</td>
<td>
<div class="post1">
<p >'.$postContent.'</p>
</div>
</td>
<td>
<div class="post1">
<p >'.$postTag.'</p>
</div>
</td>
<td>
<div class="poststatus" style = "background-color:'.$color.'">
<p >'.$post['status'].'</p>
</div>
</td>
<td>
<div class="postedby">
<p >'.$posterName.'</p>
</div>
</td>
<td>
<div class="postedon">
<p >'.$post["date"].'</p>
</div>
</td>
</tr>';
}
?>