-
Notifications
You must be signed in to change notification settings - Fork 154
/
hub.php
214 lines (167 loc) · 7.97 KB
/
hub.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
session_start();
require 'includes/dbh.inc.php';
define('TITLE',"Hub | KLiK");
if(!isset($_SESSION['userId']))
{
header("Location: login.php");
exit();
}
include 'includes/HTML-head.php';
include 'includes/navbar.php';
?>
<link rel="stylesheet" type="text/css" href="css/list-page.css">
</head>
<body style="background: #f1f1f1">
<main role="main" class="container">
<div class="d-flex align-items-center p-3 my-3 text-white-50 bg-purple rounded shadow-sm">
<img class="mr-3" src="img/200.png" alt="" width="48" height="48">
<div class="lh-100">
<h1 class="mb-0 text-white lh-100">KLiK Hub</h1>
<small>Spreading Ideas</small>
</div>
</div>
<div class="my-3 p-3 bg-white rounded shadow-sm">
<h5 class="border-bottom border-gray pb-2 mb-0">Top Blogs</h5>
<?php
$sql = "select blog_id, blog_img, blog_date, blog_votes, blog_title, blog_content, uidUsers
from blogs, users
where blogs.blog_by = users.idUsers
order by blog_votes desc
LIMIT 5 ";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('SQL error');
}
else
{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result))
{
echo '<a href="blog-page.php?id='.$row['blog_id'].'">
<div class="media text-muted pt-3">
<img src="uploads/'.$row['blog_img'].'" alt="" class="mr-2 rounded div-img ">
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray ">
<strong class="d-block text-gray-dark">'.ucwords($row['blog_title']).'</strong></a>
<br>'.substr($row['blog_content'],0,50).'...
</p>
<span class="text-right text-primary"><i class="fa fa-thumbs-up" aria-hidden="true"></i>
'.$row['blog_votes'].'<br>';
if ($_SESSION['userLevel'] == 1 || $_SESSION['userLevel'] == $row['blog_by'])
{
echo '<a href="includes/delete-blog.php?id='.$row['blog_id'].'&page=forum" >
<i class="fa fa-trash" aria-hidden="true" style="color: red;"></i>
</a>
</span>';
}
else
{
echo '</span>';
}
echo '</div>';
}
}
?>
<small class="d-block text-right mt-3">
<a href="create-blog.php" class="btn btn-primary">Create a Blog</a>
<a href="blogs.php" class="btn btn-primary">All Blogs</a>
</small>
</div>
<div class="my-3 p-3 bg-white rounded shadow-sm">
<h5 class="border-bottom border-gray pb-2 mb-0">Upcoming Events</h5>
<?php
$sql = "select event_id, event_by, title, event_date, event_image
from events
where event_date > now()
order by event_date
LIMIT 5";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('SQL error');
}
else
{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result))
{
$earlier = new DateTime(date("Y-m-d"));
$later = new DateTime($row['event_date']);
$diff = $later->diff($earlier)->format("%a");
echo '<a href="event-page.php?id='.$row['event_id'].'">
<div class="media text-muted pt-3">
<img src="uploads/'.$row['event_image'].'" alt="" class="mr-2 rounded div-img">
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">'.ucwords($row['title']).'</strong></a>
'.date("F jS, Y", strtotime($row['event_date'])).'<br>
<span class="text-primary" >'.$diff.' days remaining </span>
</p>
<span class="text-primary text-right">';
if ($_SESSION['userLevel'] == 1 || $_SESSION['userId'] == $row['event_by'])
{
echo '<a href="includes/delete-event.php?id='.$row['event_id'].'&page=forum" >
<i class="fa fa-trash" aria-hidden="true" style="color: red;"></i>
</a>
</span>';
}
else
{
echo '</span>';
}
echo '</span>
</div>';
}
}
?>
<small class="d-block text-right mt-3">
<a href="create-event.php" class="btn btn-primary">Create An Event</a>
<a href="events.php" class="btn btn-primary">All Events</a>
</small>
</div>
<div class="my-3 p-3 bg-white rounded shadow-sm">
<h5 class="border-bottom border-gray pb-2 mb-0">Latest Polls</h5>
<?php
$sql = "select p.id, p.subject, p.created_by, p.locked, uidUsers, (
select count(*)
from poll_votes pv
where pv.poll_id = p.id
) as voters
from polls p, users u
where p.created_by = u.idUsers
order by voters desc, created asc
LIMIT 5";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('SQL error');
}
else
{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result))
{
echo '<a href="poll.php?poll='.$row['id'].'">
<div class="media text-muted pt-3">
<img src="img/poll-cover.png" alt="" class="mr-2 rounded div-img">
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">'.ucwords($row['subject']).'</strong></a>
<span class="text-muted">Created By'.ucwords($row['uidUsers']).'</span><br>
<span class="text-primary">'.$row['voters'].' user(s) voted</span>
</p>
</div>';
echo '';
}
}
?>
<small class="d-block text-right mt-3">
<a href="create-poll.php" class="btn btn-primary">Create A Poll</a>
<a href="polls.php" class="btn btn-primary">All Polls</a>
</small>
</div>
</main>
<?php include 'includes/footer.php'; ?>
<?php include 'includes/HTML-footer.php'; ?>