-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtopics.php
153 lines (147 loc) · 6.14 KB
/
topics.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
<?php require_once('include/top.php');
if (!isset($_SESSION['username'])) {
header('Location: login.php');
}
elseif (isset($_SESSION['username']) && $_SESSION['role'] =='student'){
header('Location: home.php');
}
?>
<?php require_once('server.php');?>
<?php
if ($_GET['submit_topic']) {
$sql = "INSERT INTO registration.topics (course_id,module_id,topic_name,topic_description,id_user) VALUES ('1','1','" . $_GET['topic_name'] . "','" . $_GET['topic_description'] . "','1')";
if ($db->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
}
# Delete Topic functionality
if (isset($_GET['delete'])) {
# Get the id of the Topic to be deleted
$delete_id = $_GET['delete'];
# Delete query to delete the Topic
$delete_query = "DELETE FROM `registration`.`topics` WHERE `id`= $delete_id;";
if (mysqli_query($db,$delete_query)) {
$msg = "Topic has been deleted";
}
else{
$error = "Topic has not been deleted";
}
}
?>
</head>
<body>
<div id="wrapper">
<?php require_once('include/header.php'); ?>
<div class="container-fluid body-section">
<div class="row">
<div class="col-md-3">
<?php require_once('include/left-sidebar.php'); ?>
</div>
<div class="col-md-9">
<h1><i class="fa fa-list" aria-hidden="true"></i> Topics <small>Different Topics</small></h1><hr>
<ol class="breadcrumb">
<li><a href="home.php"><i class="fa fa-tachometer"></i> Dashboard</a></li>
<li class="active"><i class="fa fa-folder-open"></i> Topics</li>
</ol>
<div class="row">
<div class="col-md-7">
<form action="">
<div class="form-group">
<label for="course">Course:</label>
<select name="course_name" id="course" class="form-control">
<?php
$query = "SELECT * FROM registration.courses";
if ($result = $db->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
print "<option value=\"$row[course_id]\">${row[course_name]}</option>";
}
/* free result set */
$result->free();
}
?>
</select>
</div>
<div class="form-group">
<label for="module">Module Name:</label>
<select name="module_name" id="module_name" class="form-control">
<?php
$query = "SELECT id, module_name from registration.modules";
if ($result = $db->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
print "<option value=\"$row[id]\">${row[module_name]}</option>";
}
/* free result set */
$result->free();
}
?>
</select>
</div>
<div class="form-group">
<label for="topic">Topic Name:</label>
<input type="text" name="topic_name" placeholder="Topic Name" class="form-control">
</div>
<div class="form-group">
<label for="topic">Topic Description:</label>
<textarea name="topic_description" placeholder="Topic Description" class="form-control"></textarea>
</div>
<input type="submit" value="Add New Topic" name="submit_topic" class="btn btn-primary">
</form>
</div>
<!-- Displaying message for the admin if the topic is deleted or not-->
<?php
if (isset($error)) {
echo "<span style='color:red;' class='pull-right'>$error</span>";
}
elseif (isset($msg)) {
echo "<span style='color:green;' class='pull-right'>$msg</span>";
}
?>
<div class="col-md-5">
<?php
$query = "SELECT id,topic_name FROM topics";
$run = mysqli_query($db,$query);
if (mysqli_num_rows($run) > 0) {
?>
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>Sr #</th>
<th>Topic</th>
<!--th>Edit</th-->
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$i =1;
while ($row = mysqli_fetch_array($run)) {
$id = $row['id'];
$course_id = $row['course_id'];
$module_id = $row['module_id'];
$topic_name = $row['topic_name'];
?>
<tr>
<td><?=$i++?></td>
<td><a href="view-topic.php?topic_id=<?php echo $id; ?>"><?php echo $topic_name;?></td>
<!--td><a href="edit-topic.php?edit=<?php echo $id;?>"><i class="fa fa-pencil"></i></a></td-->
<td><a href="topics.php?delete=<?php echo $id;?>"><i class="fa fa-times"></i></a></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
else{
echo "<center><h2> No Topics Avaliable </h2></center>";
}
?>
</div>
</div>
</div>
</div>
</div>
<?php require_once('include/footer.php'); ?>