This repository has been archived by the owner on May 17, 2023. It is now read-only.
forked from if-itb/IF3110-2015-T1
/
question.php
125 lines (115 loc) · 3.76 KB
/
question.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
<!DOCTYPE HTML>
<html>
<head>
<title>Question Topic</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="/style/master.css" >
</head>
<body>
<?php
require 'query.php';
?>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if($_POST['type']=='question') {
$question['name']=test_input($_POST['name']);
$question['email']=test_input($_POST['email']);
$question['topic']=test_input($_POST['topic']);
$question['content']=test_input($_POST['content']);
$question['q_id']=$_POST['q_id'];
updateQuestion($question);
} else{
$answer['q_id']=$_GET['q_id'];
$answer['name']=test_input($_POST['name']);
$answer['email']=test_input($_POST['email']);
$answer['content']=test_input($_POST['content']);
addAnswer($answer);
}
}
?>
<?php
$q_id=$_GET['q_id'];
$question=getQuestion($q_id);
$tabAnswer=getAnswers($q_id);
$nAnswer=mysqli_num_rows($tabAnswer);
?>
<div class="view">
<h1>Simple Stack Exchange</h1><br>
<h2 id="title"><?php echo $question['topic']; ?></h2>
<hr>
<div class="row">
<div class="vote-col-1">
<div><img src="/assets/up.png" onclick="vote('question', <?php echo $q_id; ?>, 'up')"></div>
<div id="questionVote"><?php echo $question['vote']; ?></div>
<div><img src="/assets/down.png" onclick="vote('question', <?php echo $q_id; ?>, 'down')"></div>
</div>
<div class="content-col">
<p><?php echo $question['content']; ?></p>
<div></div>
</div>
<div class="other">
<div>asked by</div>
<div class="name"><?php echo $question['name']; ?></div>
<div>at </div><div><?php echo $question['date_posted']; ?></div>
<div> |</div>
<div class="edit"><a href="ask.php?q_id=<?php echo $question['q_id'].'&address=question';?>">edit</a></div><div> |</div>
<div class="delete"><a href="delete.php?q_id=<?php echo $question['q_id'];?>" onclick="return confirmDeletion()">delete</a></div>
</div>
</div>
<br>
<div class="answer">
<h3><?php echo countAnswer($q_id); ?></h2>
<h3>answer</h2>
</div>
<hr>
<?php
if($nAnswer==0) {
} else{
while($answer=mysqli_fetch_assoc($tabAnswer)){
?>
<div class="row">
<div class="vote-col-1">
<div><img src="/assets/up.png" onclick="vote('answer', <?php echo $answer['a_id']; ?>, 'up')"></div>
<div id="answerVote-<?php echo $answer['a_id'];?>"><?php echo $answer['vote']; ?></div>
<div><img src="/assets/down.png" onclick="vote('answer', <?php echo $answer['a_id']; ?>, 'down')"></div>
</div>
<div class="content-col">
<p><?php echo $answer['content'];?></p>
<div></div>
</div>
<div class="other">
<div>answered by</div>
<div class="name"><?php echo $answer['name'];?></div>
<div>at </div><div><?php echo $answer['date_posted'];?></div>
</div>
</div>
<br>
<hr>
<?php
}
}
?>
<div>
<h2>Your Answer<h2>
<form name="answerForm" method="post" onsubmit="return validateAnswer()"
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"])."?q_id=".$question['q_id'];?>">
<input type="text" id="name" name="name" value="" placeholder="Name"><br>
<input type="text" id="email" name="email" value="" placeholder="Email"><br>
<textarea rows="4" cols="50" id="content" name="content" placeholder="Content"></textarea><br>
<input type="submit" value="Post">
<input type="hidden" name="type" value="answer">
</form>
</div>
</div>
<script src="/script/master.js"></script>
<?php
mysqli_close($conn);
?>
</body>
</html>