-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignments.php
182 lines (172 loc) · 8.75 KB
/
assignments.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php if (!isset($_SESSION)) {
session_start();
} ?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="/images/home-icon.png">
<?php include("php_templates/HeadContents.php"); ?>
<title>Assignments</title>
<script defer src="/js/assignment-modal.js"></script>
</head>
<body>
<?php include("php_templates/DefaultMenu.php");
include_once("php_helpers/Database.php");
include_once("php_helpers/loginStatus.php");
include_once("php_helpers/removeAssignment.php");
include_once("php_helpers/Functions.php");?>
<?php
if (isset($_POST['SubmitAssignment'])) {
$con = Database::open();
$Professor = $_SESSION['id'];
$Course = $_REQUEST['Course'];
$Assignment = $_REQUEST['Assignment'];
$AssignmentLink = $_REQUEST['AssignmentLink'];
$DueDate = $_REQUEST['AssignmentDate'];
$semesterId = getSemesterID();
$query = "INSERT INTO assignment(professor_id, course_id, assignment_name, assignment_link, due_date, semester_id)
VALUES($1, $2, $3, $4, $5, $6)";
pg_prepare($con, "", $query);
pg_execute($con, "", array($Professor, $Course, $Assignment, $AssignmentLink, $DueDate, $semesterId))
or die("Query failed: " . pg_last_error());
$_POST = array();
}
?>
<div class="ui main container">
<div class="ui segment middle aligned center aligned">
<h1>Assignments</h1>
<?php if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'Professor') {
?>
<button class="ui button" id="assignment-button">Add an assignment</button>
<?php
}
} ?>
<div class="ui divider"></div>
<div class="ui grid centered">
<table style="width:80%;" class="ui celled collapsing table">
<thead>
<tr>
<th class="center aligned two wide">Professor</th>
<th class="center aligned two wide">Course</th>
<th class="center aligned two wide">Assignment</th>
<th class="center aligned one wide">Link</th>
<th class="center aligned one wide">Due Date</th>
<?php if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'Professor') {
?>
<th class="center aligned one wide">Remove</th>
<?php
}
} ?>
</tr>
</thead>
<tbody>
<?php
$con = Database::open();
$sql = 'SELECT last_name, number, assignment_name, assignment_link, due_date, assignment.id
FROM assignment JOIN course ON course_id = course.id
JOIN person ON professor_id = person.id
ORDER BY due_date';
pg_prepare($con, "", $sql);
$rs = pg_execute($con, "", [])
or die("Query failed: " . pg_last_error());
pg_close($con);
while ($row = pg_fetch_row($rs)) {
?>
<tr>
<td>
<h4 class="ui image header">
<div class="content">
<?php echo $row[0] ?>
</div>
</h4>
</td>
<td>
<?php echo $row[1] ?>
</td>
<td>
<?php echo $row[2] ?>
</td>
<td>
<a href="<?php echo $row[3] ?>"><?php echo $row[3] ?></a>
</td>
<td>
<?php echo $row[4] ?>
</td>
<?php if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'Professor') {
?>
<td>
<?php
echo '<a class="ui button" href="../php_helpers/removeAssignment.php?assignmentId=' . $row[5] . '"><i class="ui trash icon"></i></a>';
?>
</td>
<?php
}
} ?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="ui modal" id="assignment-modal">
<i class="close icon"></i>
<div class="description">
<form class="ui large form" id="assignment-form" action="assignments.php" method="post">
<div class="ui stacked segment">
<div class="field">
<div class="ui left icon input">
<i class="user icon"></i>
<input type="text" name="Name" placeholder="Name" id="name" value="<?php echo $_SESSION['user_id'] ?>" readonly="readonly" required>
</div>
</div>
<div class="field">
<!-- <div class="ui left icon input"> -->
<div class="ui selection dropdown">
<i class="grey book icon"></i>
<input type="hidden" name="Course">
<i class="dropdown icon"></i>
<div class="default text">Course</div>
<div class="menu">
<?php
$con = Database::open();
$sql = 'SELECT id, subject, number FROM course;';
pg_prepare($con, "", $sql);
$rs = pg_execute($con, "", [])
or die("Query failed: " . pg_last_error());
pg_close($con);
while ($row = pg_fetch_row($rs)) {
?>
<div class="item" data-value="<?php echo $row[0] ?>">
<?php echo $row[1] . " " . $row[2] ?></div>
<?php
}
?>
<!-- <div class="item" data-value="0">Female</div> -->
</div>
</div>
<!-- <input type="text" name="Course" placeholder="Course" id="course" required> -->
<!-- </div> -->
</div>
<div class="field">
<input type="text" name="Assignment" placeholder="Assignment Name" id="assignment" required>
</div>
<div class="field">
<input type="text" name="AssignmentLink" placeholder="Assignment Link" id="assignmentLink" required>
</div>
<div class="field">
<input type="date" name="AssignmentDate" id="assignmentDate" required>
<div class="ui pointing label">
Please enter a due date
</div>
</div>
<input class="ui fluid jmuPurple submit button" id="assignment-submit" type="submit" value="Submit" name="SubmitAssignment">
<div class="ui error message"></div>
</form>
</div>
</div>
</body>
</html>