-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistExercise.php
More file actions
144 lines (126 loc) · 5.08 KB
/
listExercise.php
File metadata and controls
144 lines (126 loc) · 5.08 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
<?php
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
// Connect to database
require_once "db_config.php";
// If teacher display homework he/she gives, if student display all homework
if ($_SESSION["type"] == "teacher") $sql_query = "SELECT id, title, description, filePath, modified_time, deadline FROM homework where teacherId = ?";
else if ($_SESSION["type"] == "student") $sql_query = "SELECT id, title, description, filePath, modified_time, deadline FROM homework";
else {
http_response_code(404);
exit;
}
if ($stmt = mysqli_prepare($db_connection, $sql_query)) {
// Bind variables to prepared SQL statement
if ($_SESSION["type"] == "teacher") mysqli_stmt_bind_param($stmt, "i", $_SESSION["id"]);
// Execute SQL statement
if (mysqli_stmt_execute($stmt)) {
// All homework should display to this user
$homework_sql_result = $stmt->get_result();
}
else {
echo "Cannot execute SQL homework query";
exit;
}
mysqli_stmt_close($stmt);
}
// If student try to get all submit homework of this student
if ($_SESSION["type"] == "student") {
$sql_query = "SELECT homeworkId FROM submitHomework WHERE studentId = ?";
if ($stmt = mysqli_prepare($db_connection, $sql_query)) {
// Bind variables to prepared SQL statement
mysqli_stmt_bind_param($stmt, "i", $_SESSION["id"]);
// Execute SQL statement
if (mysqli_stmt_execute($stmt)) {
// All homework should display to this user
$submitStatus = array();
$submit_sql_result = $stmt->get_result();
while ($row = $submit_sql_result -> fetch_assoc()) {
$submitStatus[$row['homeworkId']] = true;
}
}
else {
echo "Cannot execute SQL submitHomework query";
exit;
}
mysqli_stmt_close($stmt);
}
}
mysqli_close($db_connection);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>List exercise</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel='stylesheet' href='styles/mycss.css'>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.php"><img src='img/cat-logo.jpg' alt='Cute cat' width='30' height='30'></a>
</div>
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li class='active'><a href="listExercise.php"><?php if ($_SESSION["type"] == "teacher") echo "Add homework"; else echo "Homework" ?></a></li>
<li><a href="listChallenge.php"><?php if ($_SESSION["type"] == "teacher") echo "Add challenge"; else echo "Challenge" ?></a></li>
<li><a href="listUser.php">List user</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="profile.php?username=<?php echo $_SESSION['username']?>"><span class="glyphicon glyphicon-user"></span> Profile</a></li>
<li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</div>
</nav>
<div class="page-header">
<h1>All exercises</h1>
</div>
<?php
if ($_SESSION["type"] == "teacher") {
echo "
<div class='container'>
<a class='btn btn-success' href='addExercise.php'>Add new homework</a>
</div>
<br>
";
}
?>
<!--List of homework -->
<div class="container panel-group">
<?php
while ($row = $homework_sql_result ->fetch_assoc()) {
echo "
<div class='panel panel-primary'>
<div class='panel-heading'>{$row['title']}</div>
<div class='panel-body'>Deadline: {$row['deadline']}</div>
";
if ($_SESSION["type"] == "student") {
$status = isset($submitStatus[$row['id']]) ?'Submitted':'Not done';
echo "<div class='panel-body'>Status: $status</div>";
echo "<div class='panel-body'><a class='btn btn-success' href='submitHomework.php?homeworkId={$row['id']}'>Submit</a></div>";
}
if ($_SESSION["type"] == 'teacher') {
echo "
<div class='panel-body'>
<form class='form-inline'>
<a class='btn btn-info btn-inline' href='seeSubmission.php?homeworkId={$row['id']}'>See submissions</a>
<a class='btn btn-danger btn-inline' href='deleteExercise.php?homeworkId={$row['id']}' onclick=\"return confirm('Are you sure you want to delete this homework?')\">Delete exercise</a>
</form>
</div>
";
}
echo "
</div>
";
}
?>
</div>
</body>
</html>