-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdto.student.php
277 lines (257 loc) · 11.2 KB
/
dto.student.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/*
Copyright 2023 Eric Vyncke
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once "dbi.php" ;
if ($userId == 0) {
header("Location: https://www.spa-aviation.be/resa/mobile_login.php?cb=" . urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']) , TRUE, 307) ;
exit ;
}
require_once 'mobile_header5.php' ;
require_once 'dto.class.php' ;
if (isset($_REQUEST['student']) and is_numeric($_REQUEST['student']) and $_REQUEST['student'] != '') {
$student_id = $_REQUEST['student'] ;
$student = new Student() ;
$student->getById($student_id) ;
} else {
journalise($userId, 'F', "Invalid parameter student=$_REQUEST[student].") ;
}
if (! ($userIsAdmin or $userIsBoardMember or $userIsInstructor or $userId == $student_id))
journalise($userId, "F", "Vous devez être administrateur ou instructeur pour voir cette page.") ;
if ($userId == $student_id)
journalise($userId, "I", "Student looking his/her flights") ;
if (isset($_POST['action']) and $_POST['action'] == 'upload') {
if (!isset($_FILES['file']) or !isset($_FILES['file']['name']) or $_FILES['file']['size'] == 0)
die('Please select a file. <button onclick="window.history.back();">Try again</button>') ;
$source_file = $_FILES['file']['tmp_name'] ;
$path_info = pathinfo($_FILES['file']['name']) ;
$extension = $path_info['extension'] ;
$hashed_filename = sha1($source_file . $shared_secret) . ".$extension";
if (!move_uploaded_file($source_file, "dto_files/$hashed_filename")) {
journalise($userId, 'E', "Unable to move to dto_files/$hash_filename: $source_file") ;
}
$document = new StudentDocument() ;
$document->hashedFilename = $hashed_filename ;
$document->originalFilename = $_FILES['file']['name'] ;
$document->originalMIMEType = $_FILES['file']['type'] ;
$document->size = $_FILES['file']['size'] ;
$document->studentId = $student_id ;
$document->save() ;
journalise($userId, "I", "File $document->originalFilename uploaded") ;
}
?>
<h2>Details for <?=$student->lastName?> <?=$student->firstName?></h2>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" role="presentation" data-bs-toggle="tab" data-bs-target="#summary" aria-current="page" href="#summary">Summary</a>
</li>
<li class="nav-item">
<a class="nav-link" role="presentation" data-bs-toggle="tab" data-bs-target="#documents" aria-current="page" href="#documents">Documents</a>
</li>
<li class="nav-item">
<a class="nav-link" role="presentation" data-bs-toggle="tab" data-bs-target="#flights" aria-current="page" href="#flights">Flights</a>
</li>
<li class="nav-item">
<a class="nav-link" role="presentation" data-bs-toggle="tab" data-bs-target="#exercices" aria-current="page" href="#exercices">Exercices</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade" id="flights" role="tabpanel">
<div class="row">
<div class="col-sm-12 col-md-9 col-lg-7">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<th>Flight#</th><th>Date</th><th>Duration</th><th>Type</th><th>Plane</th><th>Instructor</th>
</thead>
<tbody class="table-group-divider">
<?php
$flights = new Flights($student_id) ;
$dc_minutes = 0 ;
$solo_minutes = 0 ;
$xcountry_minutes = 0 ;
$total_minutes = 0 ;
foreach($flights as $flight) {
switch ($flight->sessionGrade) {
case 'unsatisfactory': $session_grade_message = '<i class="bi bi-hand-thumbs-down-fill text-danger" title="Unsatisfactory flight"></i>' ; break ;
case 'verygood': $session_grade_message = '<i class="bi bi-hand-thumbs-up-fill text-success" title="Very good flight"></i>' ; break ;
default: $session_grade_message = '' ;
}
print("<tr><td>$flight->flightId $session_grade_message <a href=\"dto.flight.php?flight=$flight->id\">
<i class=\"bi bi-pencil-fill\" data-bs-toggle=\"tooltip\" title=\"See/edit the student flight report\"></i></a></td><td>$flight->date</td>
<td>$flight->flightDuration</td><td>$flight->flightType</td><td>$flight->plane</td><td>$flight->fiLastName $flight->fiFirstName</td></tr>\n") ;
// Sum up the duration
switch ($flight->flightType) {
case 'DC': $dc_minutes += $flight->flightDuration ; break ;
case 'solo': $solo_minutes += $flight->flightDuration ; break ;
case 'XCountry': $xcountry_minutes += $flight->flightDuration ; break ;
}
$total_minutes += $flight->flightDuration ;
}
?>
</tbody>
</table>
</div><!-- table responsive -->
</div><!-- col -->
</div><!-- row -->
</div><!-- tab-pane-->
<div class="tab-pane fade show active" id="summary" role="tabpanel">
<?php
// Let's convert minutes into hours
$dc_hours = intdiv($dc_minutes, 60) ;
$dc_minutes = $dc_minutes % 60 ;
$solo_hours = intdiv($solo_minutes, 60) ;
$solo_minutes = $solo_minutes % 60 ;
$xcountry_hours = intdiv($xcountry_minutes, 60) ;
$xcountry_minutes = $xcountry_minutes % 60 ;
$total_hours = intdiv($total_minutes, 60) ;
$total_minutes = $total_minutes % 60 ;
?>
<div class="row">
<div class="col-sm-12 col-md-4">
<p><ul>
<li>Flight count: <?=$flights->count?></li>
<li>DC: <?="$dc_hours H $dc_minutes min"?></li>
<li>Solo: <?="$solo_hours H $solo_minutes min"?></li>
<li>X-country: <?="$xcountry_hours H $xcountry_minutes min"?></li>
<li>Total: <?="$total_hours H $total_minutes min"?></li>
</ul>
</p>
</div><!-- col -->
<div class="col-sm-12 col-md-4">
<p>Placeholder for email, phone, postal address, picture.</p>
<?php
if ($student->blocked)
print("<p class=\"mt-2 p-4 bg-danger text-bg-danger rounded\">$student->blockedMessage</p>") ;
if (! $student->isStudent())
print("<p class=\"mt-2 p-4 bg-warning text-bg-warning rounded\">$student->lastName $student->firstName is no more registered as a student.</p>") ;
?>
<p><ul>
<li>Email: <a href="mailto:<?=$student->email?>" title="Send email"><?=$student->email?> <i class="bi bi-envelope-fill"></i></a></li>
<li>Mobile Phone: <a href="phone:<?=$student->mobilePhone?>" title="Call mobile phone"><?=$student->mobilePhone?> <i class="bi bi-telephone-fill"></i></a></li>
</ul>
</p>
<p>
<?=$student->address?><br/>
<?="$student->zipCode $student->city"?><br/>
<?="$student->country"?>
</p>
</div><!-- col -->
</div><!-- row -->
</div><!-- tab-pane -->
<div class="tab-pane fade" id="exercices" role="tabpanel">
<div class="row">
<p>The table below shows the aggregated evaluation for all exercices. It is read-only, to modify the evaluation of an exercice,
the FI must go to an individual flight report and change it there.
</p>
<div class="col-sm-12 col-md-9 col-lg-7">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr><th>Ref</th><th>Description</th><th>Demo</th><th>Trained</th><th>Acquired</th></tr>
</thead>
<tbody>
<?php
// Let's display the aggregated exercises
$exercices = new StudentExercices($student_id) ;
foreach ($exercices as $exercice) {
if ($exercice->grading) { // Multiple choice
?>
<tr><td><?=$exercice->reference?></td>
<td><?=$exercice->description?></td>
<td><div class="form-check form-switch">
<input class="form-check-input" type="checkbox" value="yes" disabled
onChange="gradeChanged(this, '<?=$exercice->reference?>', 'demo')"
<?=((isset($exercice->grade['demo']) and $exercice->grade['demo'] == 'demo') ? 'checked' : '')?>>
</div></td>
<td><div class="form-check form-switch">
<input class="form-check-input" type="checkbox" value="yes" disabled
onChange="gradeChanged(this, '<?=$exercice->reference?>', 'trained')"
<?=((isset($exercice->grade['trained']) and $exercice->grade['trained'] == 'trained') ? 'checked' : '')?>>
</div></td>
<td><div class="form-check form-switch">
<input class="form-check-input" type="checkbox" value="yes" disabled
onChange="gradeChanged(this, '<?=$exercice->reference?>', 'acquired')"
<?=((isset($exercice->grade['acquired']) and $exercice->grade['acquired'] == 'acquired') ? 'checked' : '')?>>
</div></td>
</tr>
<?php
} else { // Single choice
?>
<tr><td><b><?=$exercice->reference?></b></td>
<td><b><?=$exercice->description?></b></td>
<td colspan="3"><div class="form-check form-switch">
<input class="form-check-input" type="checkbox" value="yes" disabled
onChange="gradeChanged(this, '<?=$exercice->reference?>', 'yes')"
<?=((isset($exercice->grade['yes']) and $exercice->grade['yes'] == 'yes') ? 'checked' : '')?>>
<?=((isset($exercice->grade['yes']) and $exercice->grade['yes'] == 'yes') ? '<b>Successful</b>' : 'Sucessful')?>
</div></td>
</tr>
<?php
} // Grading
} // Foreach
?>
</tbody>
</table>
</div><!-- table responsive -->
</div><!-- col -->
</div><!-- row -->
</div><!-- tab-pane -->
<div class="tab-pane fade" id="documents" role="tabpanel">
<div class="row">
<p>Here are all documents linked to this student.
</p>
<div class="col-sm-12 col-md-9 col-lg-7">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr><th>Filename</th><th class="d-none d-lg-table-cell">Size</th><th class="d-none d-lg-table-cell">Date</th><th class="d-none d-lg-table-cell">Uploaded by</th></tr>
</thead>
<tbody class="table-group-divider">
<?php
$documents = new StudentDocuments($student_id) ;
foreach ($documents as $document) {
?>
<tr>
<td><?=$document->originalFilename?>
<a href="dto_files/<?=$document->hashedFilename?>" download="<?=$document->originalFilename?>" type="<?=$document->originalMIMEType?>">
<i class="bi bi-file-earmark-arrow-down-fill"></i></a>
<!-- should also use the dto.file.php to have the right MIME type and filename -->
<a href="dto.file.php?action=delete&file=<?=$document->hashedFilename?>" rel="noopener" target="_blank"><i class="bi bi-trash3-fill text-danger"></i></a></td>
<td class="d-none d-lg-table-cell"><?=$document->size?></td>
<td class="d-none d-lg-table-cell"><?=$document->when?></td>
<td class="d-none d-lg-table-cell"><?="<b>$document->whoLastName</b> $document->whoFirstName"?></td>
</tr>
<?php
} // Foreach
?>
</tbody>
</table>
</div><!-- table responsive -->
</div><!-- col -->
</div><!-- row -->
<div class="row">
<hr>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data" role="form" class="form-inline">
<input type="hidden" name="student" value="<?=$student->jom_id?>">
<input type="hidden" name="action" value="upload">
<div class="mb-3">
<label for="file" class="form-label">Add a new document</label>
<input class="form-control" type="file" id="file" name="file">
</div>
<button class="btn btn-primary" type="submit">Upload the file</button>
</form>
</div><!-- row -->
</div><!-- tab-pane -->
</div><!-- tab-content -->
</body>
</html>