-
Notifications
You must be signed in to change notification settings - Fork 0
/
discussion.php
executable file
·118 lines (75 loc) · 3.51 KB
/
discussion.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
<?php
session_start();
include "./config/dbconnect.php";
include "./config/classes/Courses.php";
include "./config/classes/Insert.php";
$q = new Courses();
$i = new Insert();
// check GET request course_code param
if(isset($_GET['course_code'])){
$course_code = $_GET['course_code'];
// make sql
$questions = $q->getQuestionsBy($course_code);
}
else{
$questions = $q->getAllQuestions();
}
include "./templates/header.php"
?>
<title><?php echo htmlspecialchars($course_code). " Discussion"; ?>
</title>
</head>
<body>
<?php include "./templates/navigation.php" ?>
<section class="container">
<h1 class="text-center"><?php echo htmlspecialchars($questions['course_code'])?> Discussion Forum</h1>
<div class="discussion">
<!-- ask Question -->
<h3>Ask on the Forum</h3>
<?php
if(isset($_POST['submit'])){
unset($_POST['submit']);
$_POST['username'] = $_SESSION['username'];
$_POST['course_code'] = $course_code;
if($i->insertQuestion($_POST)){
echo "Question posted";
}
else{
echo "Error posting question";
}
}
?>
<form class="" action="" method="POST">
<div class="form-group my-2">
<label for="">Title</label>
<input class="form-control" type="text" name="question_title" id="">
<label for="floatingTextarea">Question Descriptin</label>
<textarea class="form-control" style="height: 100px" placeholder="Details here" id="floatingTextarea" name="question_body"></textarea>
</div>
<input class="btn btn-warning" type="submit" name="submit" value="Send">
</form>
<?php foreach ($questions as $question){ ?>
<?php $username = $question['username']; $posted = $question['created_at']; ?>
<div>
<h4><span class="text-danger">Q.</span><?php echo htmlspecialchars($question['question_title']); ?> <span class="" style="font-size:small; color:brown">(<?php echo $question['course_code'] ?>)</span> </h4>
<p>Asked by @<span><a href="user.php?username=<?php echo htmlspecialchars($username)?>"><?php echo htmlspecialchars($username)?></a></span> at <?php echo htmlspecialchars($question['created_at']); ?></p>
<p><span class="text-danger">Description : </span> <?php echo htmlspecialchars($question['question_body']); ?></p>
<a class="btn btn-primary" href="threads.php?question_id=<?php echo htmlspecialchars($question['question_id'])?>">Go to thread</a>
</div>
<?php } ?>
</div>
<div class="answers">
<ul>
<?php foreach($answers as $answer){ ?>
<div>
<p><?php echo htmlspecialchars($answer['answer-text']) ?></p>
<p>Answered by @<?php echo htmlspecialchars($answer['username']) ?>
</p>
</div>
<?php } ?>
</ul>
</div>
</section>
<?php include "./templates/footer.php" ?>
</body>
</html>