forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
106 lines (103 loc) · 4.04 KB
/
view.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
<?php
include_once("header.php");
include_once("functions.php");
$error = "";
if(empty($_GET["q"])){
include_once("not_found.php");
} else {
$id = $_GET["q"];
}
if(isQuestionExist($id)){
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = (!(empty($_POST["name"])))?$_POST["name"]:'';
$email = (!(empty($_POST["email"])))?$_POST["email"]:'';
$content = (!(empty($_POST["content"])))?$_POST["content"]:'';
$error = postAnswer($id,$name,$email,$content);
}
$row = getQuestionRow($id);
?>
<div class="container" id="view-question">
<span id="question-topic"><?php echo $row['topic'];?></span>
<hr>
<div class="question-details">
<table>
<tr>
<td width="50px">
<center>
<a onclick="vote('up','q',<?php echo $row['id'];?>)" class="vote vote-up"><img src="images/vote-up.png" width="30px"></a></br>
<div class="vote-number" id="q-<?php echo $row['id'];?>">
<?php
echo getVoteNumber('q',$id);
?>
</div>
</br><a onclick="vote('down','q',<?php echo $row['id'];?>)" class="vote vote-down"><img src="images/vote-down.png" width="30px"></a>
</center>
</td>
<td>
<span class="question-content"><?php echo $row['content'];?></span></br></br>
<div class="question-asked">Asked by <span class='question-item-name'><?php echo $row['name'];?></span> on <?php echo date("m/d/Y H:i", strtotime($row['create_date']));?> | <a href='edit.php?q=<?php echo $row['id'];?>'>edit</a> | <a class=''><span onclick='delQuestion(<?php echo $row['id'];?>,false)' class='question-item-delete'>delete</span></a></div>
</br>
</td>
</table>
</div>
<div class="answers">
<?php
$answers = countAnswers($id);
if ($answers > 0){
if($answers == 1){
echo "<span id='answers-number'>".$answers." Answer</span><hr>";
} else {
echo "<span id='answers-number'>".$answers." Answers</span><hr>";
}
echo "<div class='answers-list'>";
$result = getAnswers($id);
while($row = $result->fetch_assoc()) {
$q_id = $row['id'];
?>
<div class="answer-details">
<table width=100%>
<tr>
<td width="50px">
<center>
<a onclick="vote('up','a',<?php echo $q_id;?>)" class="vote vote-up"><img src="images/vote-up.png" width="30px"></a></br>
<div class="vote-number" id="a-<?php echo $q_id;?>">
<?php
include_once ('functions.php');
echo getVoteNumber('a',$q_id);
?>
</div>
</br><a onclick="vote('down','a',<?php echo $q_id;?>)" class="vote vote-down"><img src="images/vote-down.png" width="30px"></a>
</center>
</td>
<td>
<span class="answer-content"><?php echo $row['content'];?></span></br></br>
<div class="answer-answered">Answered by <span class='question-item-name'><?php echo $row['name'];?></span> on <?php echo date("m/d/Y H:i", strtotime($row['create_date']));?></div></br>
</td>
</tr>
</table>
<hr>
</div>
<?php
}
echo "</div>";
} else {
echo "<span class='answers-number'>0 Answer</span><hr>";
}
?>
<h2>Your Answer</h2>
<?php if (strlen($error)>0){echo '<span class="error">'.$error.'</span></br>';}?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]).'?q='.$id;?>"onsubmit="return chkValidityAnswer();" id="form-ask">
<input type="text" name="name" id="name" placeholder="Name"></br><span class="error">
<input type="text" name="email" id="email" placeholder="Email"></br><span class="error">
<textarea rows=10 type="text" name="content" id="content" placeholder="Content"></textarea>
<input required type="submit" name="researcher-submit" id="ask-submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
<?php
} else {
include_once("not_found.php");
}
?>