-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgd.php
More file actions
237 lines (197 loc) · 8.3 KB
/
cgd.php
File metadata and controls
237 lines (197 loc) · 8.3 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
$stid = $_GET['stid'];
$ccode = $_GET['ccode'];
$checkgrades = $mysqli->prepare("SELECT cw1,cw2,cw3,cw4,exam from gradestring where course_code = '$ccode' and student_id = '$stid'");
$checkgrades->execute();
$checkgrades->bind_result($cw1,$cw2,$cw3,$cw4,$exam);
while ($checkgrades->fetch()) {
$grades = array($cw1,$cw2,$cw3,$cw4,$exam);
}
$checkgrades->close();
require_once("models/header.php");
if(!empty($_POST))
{
if (isset($grades) && !is_null($grades)) {
$cw1 = htmlspecialchars(stripcslashes(trim($_POST["cw1"])));
$cw2 = htmlspecialchars(stripcslashes(trim($_POST["cw2"])));
$cw3 = htmlspecialchars(stripcslashes(trim($_POST["cw3"])));
$cw4 = htmlspecialchars(stripcslashes(trim($_POST["cw4"])));
$exam = htmlspecialchars(stripcslashes(trim($_POST["exam"])));
$ccode = htmlspecialchars(stripcslashes(trim($_POST["ccode"])));
$stid = htmlspecialchars(stripcslashes(trim($_POST["stid"])));
$today = date("Y-m-d");
if (!is_numeric($cw1) or !is_numeric($cw2) or !is_numeric($cw3) or !is_numeric($cw4) or !is_numeric($exam)) {
$errors[] = lang("WRONG_DATA");
} elseif ($cw1>0 and $cw1<101 and $cw2>0 and $cw2<101 and $cw3>0 and $cw3<101 and $cw4>0 and $cw4<101 and $exam>0 and $exam<101){
$updaterecord = $mysqli->prepare("UPDATE `gradestring` SET `cw1`='$cw1', `cw2`='$cw2', `cw3`='$cw3', `cw4`='$cw4', `exam`='$exam', `timestamp`='$today' WHERE course_code = '$ccode' and student_id = '$stid';");
$updaterecord->execute();
$updaterecord->close();
$successes[] = lang("GRADES_RECORDED");
} else {
$errors[] = lang("WRONG_DATA");
}
} else {
$cw1 = htmlspecialchars(stripcslashes(trim($_POST["cw1"])));
$cw2 = htmlspecialchars(stripcslashes(trim($_POST["cw2"])));
$cw3 = htmlspecialchars(stripcslashes(trim($_POST["cw3"])));
$cw4 = htmlspecialchars(stripcslashes(trim($_POST["cw4"])));
$exam = htmlspecialchars(stripcslashes(trim($_POST["exam"])));
$ccode = htmlspecialchars(stripcslashes(trim($_POST["ccode"])));
$stid = htmlspecialchars(stripcslashes(trim($_POST["stid"])));
$today = date("Y-m-d");
if (!is_numeric($cw1) or !is_numeric($cw2) or !is_numeric($cw3) or !is_numeric($cw4) or !is_numeric($exam)) {
$errors[] = lang("WRONG_DATA");
} elseif ($cw1>0 and $cw1<101 and $cw2>0 and $cw2<101 and $cw3>0 and $cw3<101 and $cw4>0 and $cw4<101 and $exam>0 and $exam<101) {
$createrecord = $mysqli->prepare("INSERT INTO `gradestring` (`course_code`, `student_id`, `cw1`, `cw2`, `cw3`, `cw4`, `exam`,`timestamp`) VALUES ('$ccode', '$stid', '$cw1', '$cw2', '$cw3', '$cw4', '$exam','$today');");
$createrecord->execute();
$createrecord->close();
$successes[] = lang("GRADES_RECORDED");
} else {
$errors[] = lang("WRONG_DATA");
}
}
}
echo "
</div>
<div id='main' class='col-md-10'>
<div id='regbox'><h1>Grade distribution for $ccode:</h1>";
echo resultBlock($errors,$successes);
if (isset($grades) && !is_null($grades[0])) {
echo "<form class='form-horizontal' action='".$_SERVER['PHP_SELF']."?stid=$stid&ccode=$ccode' method='post'>
<fieldset>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='course_id'>Course code:</label>
<div class='col-md-3'>
<input id='course_id' name='course_id' value='$ccode' disabled class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='student_id'>Student ID:</label>
<div class='col-md-3'>
<input id='student_id' name='student_id' value='$stid' disabled class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw1'>Coursework 1:</label>
<div class='col-md-2'>
<input id='cw1' name='cw1' value='$cw1' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw2'>Coursework 2:</label>
<div class='col-md-2'>
<input id='cw2' name='cw2' value='$cw2' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw3'>Coursework 3:</label>
<div class='col-md-2'>
<input id='cw3' name='cw3' value='$cw3' class='form-control input-md' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw4'>Coursework 4:</label>
<div class='col-md-2'>
<input id='cw4' name='cw4' value='$cw4' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='exam'>Examination:</label>
<div class='col-md-2'>
<input id='exam' name='exam' value='$exam' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<input type='hidden' name='ccode' value='".$ccode."' />
<input type='hidden' name='stid' value='".$stid."' />
<!-- Button -->
<div class='form-group'>
<label class='col-md-2 control-label' for='submit'></label>
<div class='col-md-2'>
<button id='submit' name='submit' class='btn btn-default'>Update</button>
</div>
</div>
</fieldset>
</form>"
;
} else {
echo "<form class='form-horizontal' action='".$_SERVER['PHP_SELF']."?stid=$stid&ccode=$ccode' method='post'>
<fieldset>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='course_id'>Course code:</label>
<div class='col-md-3'>
<input id='course_id' name='course_id' value='$ccode' disabled class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='student_id'>Student ID:</label>
<div class='col-md-3'>
<input id='student_id' name='student_id' value='$stid' disabled class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw1'>Coursework 1:</label>
<div class='col-md-2'>
<input id='cw1' name='cw1' value='$cw1' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw2'>Coursework 2:</label>
<div class='col-md-2'>
<input id='cw2' name='cw2' value='$cw2' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw3'>Coursework 3:</label>
<div class='col-md-2'>
<input id='cw3' name='cw3' value='$cw3' class='form-control input-md' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='cw4'>Coursework 4:</label>
<div class='col-md-2'>
<input id='cw4' name='cw4' value='$cw4' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<!-- Text input-->
<div class='form-group'>
<label class='col-md-2 control-label' for='exam'>Examination:</label>
<div class='col-md-2'>
<input id='exam' name='exam' value='$exam' class='form-control input-md' required onClick='this.select();' type='text'>
</div>
</div>
<input type='hidden' name='ccode' value='".$ccode."' />
<input type='hidden' name='stid' value='".$stid."' />
<!-- Button -->
<div class='form-group'>
<label class='col-md-2 control-label' for='submit'></label>
<div class='col-md-2'>
<button id='submit' name='submit' class='btn btn-default'>Submit</button>
</div>
</div>
</fieldset>
</form>";
}
echo"
</div>
</div>
</div>
<div id='bottom'></div>
</div>
</body>
</html>";
?>