-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-classes.php
119 lines (84 loc) · 4.22 KB
/
update-classes.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
<?php
//initialize modules on start
require 'php/auth-mods/auth-login.php';
require ("php/mod_conn.php");
$class_id = $_GET['id'];
//query corresponding entry by class ID
$class_entry = mysqli_query($conn,
"SELECT * FROM class WHERE class_ID = '$class_id'"
) or die(mysqli_error($conn));
$class_query_result = mysqli_fetch_assoc($class_entry);
?>
<html>
<header>
<title>Class Update Information</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="css/global-style.css" rel="stylesheet" type="text/css"/>
<link href="css/register.css" rel="stylesheet" type="text/css"/>
<script src = "js/jquery.js"></script>
<script src = "js/functions.js"></script>
</header>
<body class="container-fluid fill-height">
<div id = "divContainer" style = "height: 100%;" class="col-lg-6 col-lg-offset-3">
<center>
<h1>Class Registration</h1>
<br>
<form method = "post">
<h6 align = "left" id = "elementLabel"><span><strong>Teacher Assigned</strong></span></h6>
<select style = "text-align-last: center; width: 80%; padding-top: 15px; padding-bottom: 15px;" required = "required" name="classStaff">
<?php
// list all staffs and select the one currently assigned
$q_staffs = mysqli_query(
$conn,
"SELECT * FROM staffs ORDER BY staff_lname ASC
"
) or die ("<script>Something went wrong retreiving the list of Staff accounts!</script>");
while($r_staffs = mysqli_fetch_assoc($q_staffs)){
$account_lvl = "";
$currentStaff = "";
if($r_staffs['staff_accountLevel'] == 1){
$account_lvl = "Administrator";
}else{
$account_lvl = "Teacher";
}
if($r_staffs['staff_ID'] == $class_query_result['class_staff']){
$currentStaff = "selected";
}
echo "<option value = \"".$r_staffs['staff_ID']."\" $currentStaff>".$r_staffs['staff_lname'].", ".$r_staffs['staff_fname']." ".$r_staffs['staff_mname']." - (".$account_lvl.")</option>";
}
?>
</select>
<h6 align = "left" id = "elementLabel"><span><strong>Class Grade</strong></span></h6>
<input onkeyup = "numericOnly(this)" value = "<?php echo $class_query_result['class_grade']; ?>" required = "required" name="classGrade" type="text" placeholder="Class Grade"/><br>
<h6 align = "left" id = "elementLabel"><span><strong>Class Section</strong></span></h6>
<input onkeyup = "textOnly(this)" value = "<?php echo $class_query_result['class_section']; ?>" required = "required" name="classSection" type="text" placeholder="Class Section"/><br>
<hr>
<input onclick = "return confirm('Confirm updating the selected class?')" name="register" type="submit" value="Update Class Information"><br>
</form>
<a href="class-search.php"><button>Cancel</button></a>
</center>
</div>
</body>
</html>
<?php
if(isset($_POST['register'])){
$staff = mysqli_real_escape_string($conn, $_POST['classStaff']);
$grade = mysqli_real_escape_string($conn, $_POST['classGrade']);
$section = mysqli_real_escape_string($conn, $_POST['classSection']);
$query = mysqli_query($conn,
"UPDATE `class`
SET
`class_staff`='$staff',
`class_grade`='$grade',
`class_section`='$section'
WHERE class_ID = $class_id
") or die(mysqli_error($conn));
if($query){
echo
"<script>
alert('Class has been updated successfully!');
window.location.href='class-search.php';
</script>";
}
}
?>