-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditExercise.php
More file actions
109 lines (98 loc) · 4.34 KB
/
editExercise.php
File metadata and controls
109 lines (98 loc) · 4.34 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
<?php
exit("Do not have this function yet");
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;
}
// Only teacher can add exercise!
if ($_SESSION["type"] != "teacher") {
http_response_code(404);
exit;
}
// Connect to database
require_once "db_config.php";
// Get all info about this homework
$sql_query = "SELECT title, description, filePath, deadline FROM homework where id = ? and teacherId = ?";
if ($stmt = mysqli_prepare($db_connection, $sql_query)) {
// Bind variables to prepared SQL statement
mysqli_stmt_bind_param($stmt, "ii", $_GET["homeworkId"], $_SESSION["id"]);
// Execute SQL statement
if (mysqli_stmt_execute($stmt)) {
$homework_sql_result = $stmt->get_result();
if (!mysqli_num_rows($homework_sql_result)) {
// don't have right permission to access this edit page
exit("Don't exist");
}
else {
// access homeworkInfo['title] to access title of homework, ...
$homeworkInfo = $homework_sql_result -> fetch_assoc();
}
}
else {
echo "Cannot execute SQL homework query";
exit;
}
mysqli_stmt_close($stmt);
}
mysqli_close($db_connection);
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit homework</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">Add homework</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</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>Edit homework</h1>
</div>
<div class='container'>
<form action='' method='post' enctype='multipart/form-data'>
<div class='form-group'>
<label for='title'>Title:</label>
<input type='text' id='title' name='title' value="<?php echo $homeworkInfo['title']; ?>"><br>
</div>
<div class='form-group'>
<label for='description'>Description</label>
<textarea id='description' name='description'><?php echo $homeworkInfo['description']; ?></textarea><br>
</div>
<div class='form-group'>
<label for='deadline'>Deadline:</label>
<input type='datetime-local' id='deadline' name='deadline' placeholder="<?php echo $homeworkInfo['deadline']; ?>"> <br>
</div>
<div class='form-group'>
<label for='fileToUpload'>Select file to upload:</label>
<input type="file" name="fileToUpload" id="fileToUpload" required> <br>
</div>
<div class='form-group'>
<button type="submit" class="btn btn-success" value="Upload File" name="submit">Add new homework</button>
<button class='btn btn-warning' type='reset'>Reset</button>
<a class='btn btn-primary' href='listExercise.php'>Cancel</a>
</div>
<span class="form-text text-muted"><?php echo $upload_err; ?></span>
</form>
</div>
</body>
</html>