-
Notifications
You must be signed in to change notification settings - Fork 0
/
question-detail.php
227 lines (181 loc) · 6.48 KB
/
question-detail.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
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Question Detail</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- Favicon and touch icons -->
<link rel="shortcut icon" href="assets/ico/favicon.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="stylesheet" type="text/css" href="mystyle.css">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,300italic' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<header id="fixed-header">
<a href="./index.php"> <img id="logo" src="logo1.png" /></a>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<?php
session_start();
$loggedin = isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true;
if($loggedin) : ?>
<a href="./logout.php" id="header-login">Logout</a>
<?php else : ?>
<a href="./form-login.php" id="header-login">Login</a>
<?php endif; ?>
</header>
<?php if($loggedin) : ?>
<a href="./form-question.php"><img src="FAB.png" alt="Submit a question" title="Submit a question" id="FAB" /></a>
<?php endif; ?>
<div id="user-question">
<?php
require_once('mysqli-connect.php');
$qid = $_GET["qid"];
$sql = "SELECT * FROM Questions WHERE id=" . $qid;
$response = $conn->query($sql);
if($response) {
if(mysqli_num_rows($response) > 0) {
while($row = mysqli_fetch_array($response)){
$avatarpath = "./avatars/avatar-" . $row["user_id"] . ".png";
if(!file_exists($avatarpath)) {
$avatarpath = "avatar.png";
}
$sql2 = "SELECT * FROM Users WHERE id=" . $row["user_id"];
$response2 = $conn->query($sql2);
$user = mysqli_fetch_array($response2);
?>
<img src=<?php echo $avatarpath; ?> alt="Avatar" id="qd-avatar" />
<p id="qd-username"><?php echo $user["username"]; ?></p>
<br />
<p id="qd-question"><?php echo $row["question_text"]; ?></p>
<?php if($loggedin) { ?>
<br /> <hr />
<a href=<?php echo "./form-answer.php?qid=" . $row["id"]; ?> class="answer-button">Answer!</a>
<?php } //end if
} //end while
?>
</div>
<div id="answer-list">
<?php
$sql = "SELECT * FROM Answers WHERE question_id=" . $qid . " ORDER BY upvotes-downvotes DESC";
$response = $conn->query($sql);
if($response) {
if(mysqli_num_rows($response) > 0) {
while($row = mysqli_fetch_array($response)) {
$user_id = $row["user_id"];
$sql = "SELECT * FROM Users WHERE id=" . $user_id;
$result = $conn->query($sql);
if($user = mysqli_fetch_array($result)) {}
?>
<div class="qd-answer">
<?php
if($loggedin){
$sql = "SELECT value FROM Votes WHERE user_id=" . $_SESSION["id"] . " AND answer_id=" . $row["id"];
$result = $conn->query($sql);
}
?>
<aside class="votes">
<img src="upvote-grey.png" alt=<?php echo "\"" . $row["id"] . "\""; ?> class="upvote-arrow
<?php
if($result) {
$vote = mysqli_fetch_array($result);
if($vote["value"] == 1) { echo "upvote-highlight"; }
else { echo "upvote-unhighlight"; }
} else { echo "upvote-unhighlight"; }
?>" />
<label class="upvote-count"><?php echo $row["upvotes"]; ?> Upvotes</label>
<br />
<img src="downvote-grey.png" alt=<?php echo "\"" . $row["id"] . "\""; ?> class="downvote-arrow
<?php
if($result) {
if($vote["value"] == -1) { echo "downvote-highlight"; }
else { echo "downvote-unhighlight"; }
} else { echo "downvote-unhighlight"; }
?>" />
<label class="downvote-count"><?php echo $row["downvotes"]; ?> Downvotes</label>
</aside>
<aside class="answerer-info">
<label class="answer-username"><?php echo $user["username"] ?></label>
</aside>
<hr />
<label class="answer-text"><?php echo $row["answer_text"]; ?></label>
</div>
<?php } //end while loop
} //end if(rows > 0)
else {
?>
<div class="qd-answer post-display no-answers">There are no answers yet.<br />Be the first!</div>
<?php
} //end else(no answers)
mysqli_free_result($response);
} //end if(response)
} //end if(question id exists)
} //end if (response)
else {
echo "Error.</div>";
}
?>
</div>
<?php if($loggedin) { ?>
<script type="text/javascript" src="script-qd.js"></script>
<?php } ?>
</body>
</html>
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/scripts.js"></script>
<style type="text/css">
#logo
{
border:1px solid white;
border-radius: 50%;
margin-left:45px;
margin-bottom:20px;
}
#form-title
{
background-color: #379683;
}
button
{
background-color: #379683;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 20px 10px;
cursor: pointer;
font-size: 40px;
}
button:hover
{
opacity:0.5;
}
text-area
{
display: inline-block;
border: solid 2px blue;
}
</style>