-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodifyQuestion.php
More file actions
145 lines (119 loc) · 5.89 KB
/
modifyQuestion.php
File metadata and controls
145 lines (119 loc) · 5.89 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
<?php
$page_title = 'Modify Question';
$page_title = 'Quiz Master > Modify Questions';
require 'bin/functions.php';
require 'db_configuration.php';
include('header.php');
$page = "questions_list.php";
verifyLogin($page);
?>
<div class="container">
<style>#title {text-align: center; color: darkgoldenrod;}</style>
<?php
include_once 'db_configuration.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
$sql = "SELECT * FROM questions
WHERE id = '$id'";
if (!$result = $db->query($sql)) {
die ('There was an error running query[' . $connection->error . ']');
} //end if
} //end if
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
if (isset($_GET['modifyQuestion'])) {
if ($_GET["modifyQuestion"] == "fileRealFailed") {
echo '<br><h3 align="center" class="bg-danger">FAILURE - Your image is not real, Please Try Again!</h3>';
}
}
if (isset($_GET['modifyQuestion'])) {
if ($_GET["modifyQuestion"] == "answerFailed") {
echo '<br><h3 align="center" class="bg-danger">FAILURE - Your answer was not one of the choices, Please Try Again!</h3>';
}
}
if (isset($_GET['modifyQuestion'])) {
if ($_GET["modifyQuestion"] == "fileTypeFailed") {
echo '<br><h3 align="center" class="bg-danger">FAILURE - Your image is not a valid image type (jpg,jpeg,png,gif), Please Try Again!</h3>';
}
}
if (isset($_GET['modifyQuestion'])) {
if ($_GET["modifyQuestion"] == "fileExistFailed") {
echo '<br><h3 align="center" class="bg-danger">FAILURE - Your image does not exist, Please Try Again!</h3>';
}
}
$questionID = $row['id'];
// Fetch keywords linked to the question
$keywordQuery = "SELECT k.keyword
FROM keywords k
JOIN question_keywords qk ON k.id = qk.keyword_id
WHERE qk.question_id = '$questionID'";
$keywordResult = mysqli_query($db, $keywordQuery);
$keywords = '';
while ($keywordRow = mysqli_fetch_assoc($keywordResult)) {
$keywords .= $keywordRow['keyword'] . ', ';
}
$keywords = rtrim($keywords, ', ');
echo '<h2 id="title">Modify Question</h2><br>';
echo '<form action="modifyTheQuestion.php" method="POST" enctype="multipart/form-data">
<br>
<h3>' . $row["topic"] . ' - ' . $row["question"] . '? </h3> <br>
<div>
<label for="id">Id</label>
<input type="text" class="form-control" name="id" value="' . $row["id"] . '" maxlength="5" style=width:400px readonly><br>
</div>
<div>
<label for="name">Topic</label>
<input type="text" class="form-control" name="topic" value="' . $row["topic"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="category">Question</label>
<input type="text" class="form-control" name="question" value="' . $row["question"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="level">Choice 1</label>
<input type="text" class="form-control" name="choice_1" value="' . $row["choice_1"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="facilitator">Choice 2</label>
<input type="text" class="form-control" name="choice_2" value="' . $row["choice_2"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="description">Choice 3</label>
<input type="text" class="form-control" name="choice_3" value="' . $row["choice_3"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="required">Choice 4</label>
<input type="text" class="form-control" name="choice_4" value="' . $row["choice_4"] . '" maxlength="255" style=width:400px required><br>
</div>
<div>
<label for="optional">Answer</label>
<input type="text" class="form-control" name="answer" value="' . $row["answer"] . '" maxlength="255" style=width:400px required><br>
</div>
<!-- Add the updated dropdown for multiple keyword selection here -->
<div>
<label for="keywords">Keywords</label><br>
<select name="keywords[]" class="form-control" multiple="multiple" style="width: 400px;">';
$keywordQuery = "SELECT id, keyword FROM keywords";
$keywordResult = mysqli_query($db, $keywordQuery);
$keywordsArray = array();
while ($keywordRow = mysqli_fetch_assoc($keywordResult)) {
$selected = in_array($keywordRow['keyword'], explode(", ", $keywords)) ? 'selected="selected"' : '';
echo '<option value="' . $keywordRow['id'] . '" ' . $selected . '>' . $keywordRow['keyword'] . '</option>';
}
echo '</select>
</div>
<br>
<div class="text-left">
<a href="questions_list.php" class="btn btn-secondary btn-md align-items-center">Cancel</a>
<button type="submit" name="submit" class="btn btn-primary btn-md align-items-center">Modify Question</button>
</div>
<br> <br>
</form>';
} //end while
} //end if
else {
echo "0 results";
} //
?>
</div>