-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·301 lines (261 loc) · 8 KB
/
index.php
File metadata and controls
executable file
·301 lines (261 loc) · 8 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
session_start();
include("./conn.php");
if (isset($_SESSION['UserID'])) {
$userID = $_SESSION['UserID'];
$name = $_SESSION['Name'];
$loggedInBtn = '<button onclick="window.location.href=\'./logout.php\'"><small> <i class="fa fa-power-off"></i></small><small> Logout</small></button>';
$askBtn = ' <div class="askbtn"><a class="link" href="./pages/ask.php">Ask a question</a></div>';
$loginBtn = '';
$phoneauth = ' <div class="login-btnnav">
<a href="./logout.php">Logout</a>
</div>';
} else {
$loggedInBtn = '<button onclick="window.location.href=\'./pages/signup.php\'">Signup</button>';
$loginBtn = '<button onclick="window.location.href=\'./pages/login.php\'">Login</button>';
$askBtn = '';
$phoneauth = ' <div class="login-btnnav">
<a href="./pages/login.php">Login</a>
</div>
<div class="signup-btnnav">
<a href="./pages/signup.php">Signup</a>
</div>';
$name = "<a style='color:white;' href='./pages/login.php'> Login<a/>";
}
// Retrieve data from the qna table
$sql = "SELECT qna.id, qna.UserID, qna.questionTitle, qna.problemDetails, qna.answerExpectations, qna.tags, qna.askedTime, qna.updatedTime, qna.upvote, qna.downvote,
Users.Name AS UserName
FROM qna
JOIN Users ON qna.UserID = Users.UserID
ORDER BY qna.id DESC
LIMIT 10";
$result = mysqli_query($conn, $sql);
$questionLoop = ''; // Initialize the variable outside the loop
// Check if any rows are returned
if (mysqli_num_rows($result) > 0) {
// Loop through each row
while ($row = mysqli_fetch_assoc($result)) {
// Retrieve the question details
$id = $row['id'];
$userID = $row['UserID'];
$qname = $row['UserName'];
$questionTitle = $row['questionTitle'];
$problemDetails = $row['problemDetails'];
$answerExpectations = $row['answerExpectations'];
$tags = $row['tags'];
$askedTime = $row['askedTime'];
$updatedTime = $row['updatedTime'];
// Query to retrieve the number of answers for the current question
$answerCountQuery = "SELECT COUNT(*) AS answerCount, upvote, downvote FROM answers WHERE questionID = '$id'";
$answerCountResult = mysqli_query($conn, $answerCountQuery);
$answerCountRow = mysqli_fetch_assoc($answerCountResult);
$answerCount = $answerCountRow['answerCount'];
$upvote = $answerCountRow['upvote'];
$downvote = $answerCountRow['downvote'];
$votes = $upvote + $downvote;
// Append the question HTML to the $questionLoop variable
$questionLoop .= '
<div class="middle-nav">
<div class="questions">
<div class="que">
<div class="name">' . $qname . '</div>
<div class="q">' . $questionTitle . '</div>
<div class="statement">' . $problemDetails . '</div>
<div class="cont">
<div class="answer">' . $answerCount . ' Answers</div>
<div class="views">' . $votes . ' Votes</div>
<div class="answer-btn">
<a href="./pages/answer.php?id=' . $id . '">Answers</a>
</div>
</div>
</div>
</div>
</div>
<hr />';
}
} else {
$questionLoop = "No Questions found.";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DEVCOM - Developers Community</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Poppins:600&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/a81368914c.js"></script>
<link rel="stylesheet" href="./style.css" />
<body>
<!-- header nav start -->
<div class="navbar">
<div class="logo">
<img src="./images/logo.png" alt="logo failed to load" height="100" />
</div>
<div class="nav">
<ul>
<li>
<a class="link " href="#">Home</a>
</li>
<li>
<a class="link" href="/about">About</a>
</li>
<li>
<a class="link" href="/contact">Contact Us</a>
</li>
<li>
<!-- Rendered conditionally based on localStorage token -->
<a class="link" href="./pages/profile.php">
<i class="fa fa-user"></i> <?php echo $name ?>
</a>
</li>
</ul>
</div>
<div class="search">
<input type="text" placeholder="Search" />
</div>
<div class="search-btn">
<button>
<i class="fa fa-search"></i>
</button>
</div>
<div class="login-btn">
<?php echo $loginBtn; ?>
</div>
<div class="signup-btn">
<?php echo $loggedInBtn; ?>
</div>
</div>
<!-- header nav close -->
<!-- motto start -->
<div class="content">
</div>
<!-- motto end -->
<!-- side nav start -->
<div onclick="openNav()" class="menu-bars">
<i class="fa fa-bars"></i>
</div>
<div id="navPhone" class="navside">
<div onclick="closeNav()" class="cancelbtn">X</div>
<ul>
<li>
<a class="sidelink active_side" href="#">
<i class="fa fa-home"></i> Home
</a>
</li>
<li>
<a class="sidelink" href="./pages/questions.php">
<i class="fa fa-book"></i> Questions
</a>
</li>
<li>
<a class="sidelink" href="./pages/community.php">
<i class="fa fa-users"></i> Community
</a>
</li>
<li>
<i class="fa fa-user"></i> Admins
</li>
<li>
<i class="fa fa-tags"></i> Tags
</li>
<li>
<i class="fa fa-file-code-o">..</i> Docs
</li>
</ul>
<div class="auth-btns">
<?php echo $phoneauth; ?>
</div>
<div class="estra">
<ul>
<li>
<a class="linkli" href="">About</a>
</li>
<li>
<a class="linkli" href="">Contact Us</a>
</li>
</ul>
</div>
</div>
<!-- side nav close -->
<!-- questions start -->
<div class="middle-nav-menu">
<ul>
<li>
<a href="" class="menu-link active">Recent Questions</a>
</li>
<li>
<a href="./most_vote.php" class="menu-link">Most Voted</a>
</li>
<li>
<a href="./most_ans.php" class="menu-link">Most Answered</a>
</li>
</ul>
</div>
<?php
echo $questionLoop;
?>
<!-- questions end -->
<!-- footer start -->
<div class="footer">
<div class="logof">
<img src="./images/logo.png" alt="" />
<p>
DEVCOM is a social questions and Answer Engine. Which will help you
to solve your problem and connect with other people.
</p>
</div>
<div class="column">
<h1>About Us</h1>
<a href="">Meet the Team</a>
<a href="">Blog</a>
<a href="">About Us</a>
<a href="">Contact Us</a>
</div>
<div class="column">
<h1>Legal Stuff</h1>
<a href="">Terms of Use</a>
<a href="">Privacy Policy</a>
<a href="">Cookie Policy</a>
</div>
<div class="column">
<h1>Help</h1>
<a href="">Knowledge Base</a>
<a href="">Support</a>
</div>
<div class="column">
<h1>Follow</h1>
<div class="row">
<a href="">
<i class="fa fa-instagram"></i>
</a>
<a href="">
<i class="fa fa-instagram"></i>
</a>
<a href="">
<i class="fa fa-instagram"></i>
</a>
</div>
</div>
</div>
<div class="copyright">
<p>© DEVCOM. All rights Reserved</p>
<p>with love by PACE</p>
</div>
<!-- footer end -->
<?php echo $askBtn; ?>
<script>
function openNav() {
document.getElementById('navPhone').style.width = "100vw";
}
function closeNav() {
document.getElementById('navPhone').style.width = "0";
}
</script>
</body>
</html>