-
Notifications
You must be signed in to change notification settings - Fork 3
/
training.php
470 lines (425 loc) · 19.1 KB
/
training.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<?php
require "config.php";
if ($_SESSION['loggedin'] != TRUE) {
Header("Location: login.php?returnpage=training");
}
if ($_SESSION['role'] == "anwb") {
Header("Location: index");
}
$getTrainerStatus = $con->query("SELECT * FROM users WHERE id = '".$_SESSION['id']."' AND trainer = 1");
if ($getTrainerStatus->num_rows == 1) {
$_SESSION['trainer'] = true;
}
if (@$_SESSION['trainer'] != true) {
//Header("Location:index");
//exit;
}
$getOwnRang = $con->query("SELECT rang FROM users WHERE id = '".$_SESSION['id']."' LIMIT 1");
$row = $getOwnRang->fetch_assoc();
$_SESSION['rang'] = $row['rang'];
$getAllFinishedTrainingsByShort = $con->query("SELECT specialisaties FROM users WHERE id = '".$_SESSION['id']."' LIMIT 1");
$rr = $getAllFinishedTrainingsByShort->fetch_assoc();
$allFinishedTrainingsByShort = explode(", ",$rr['specialisaties']);
$getAllTraining = $con->query("SELECT * FROM specialisaties ORDER BY id ASC");
$getAllTraining2 = $con->query("SELECT * FROM specialisaties ORDER BY id ASC");
//$getAllTraining2 = $con->query("SELECT * FROM specialisaties as s WHERE s.id not in (select table1_id from table2)");
//$getAllTraining2 = $con->query("SELECT s.id FROM specialisaties as s LEFT JOIN specialisatie_aanmeldingen as a ON s.id = a.specialisatie WHERE a.user = '".$_SESSION['id']."'");
$getAllTrainingRegistered = $con->query("SELECT * FROM specialisatie_aanmeldingen WHERE user = '".$_SESSION['id']."'");
if ($getAllTrainingRegistered->num_rows == 0) {
$registredAtTrainings = null;
}
while ($row = $getAllTrainingRegistered->fetch_assoc()) {
$registredAtTrainings[] = $row['specialisatie'];
}
if (isset($_GET['registeer'])) {
$con->query("INSERT INTO specialisatie_aanmeldingen (specialisatie,user) VALUES ('".$_GET['registeer']."','".$_SESSION['id']."')");
$specialisatieNaamQ = $con->query("SELECT name FROM specialisaties WHERE id = '".$_GET['registeer']."'");
$snrow = $specialisatieNaamQ->fetch_assoc();
$message = "Zojuist heeft ".$_SESSION['name']." zich aangemeld voor ".$snrow['name']."\n\n";
$data = array("username" => "Trainingen en specialisaties", "content" => $message);
$data_string = json_encode($data);
$ch = curl_init('https://discordapp.com/api/webhooks/672866292012941334/RDxQWj3A7szUv6aUey6NJsIqrNRSLvd5msZZgS_MRxKd0Sd3tRJ5mlN5PFIIVMzrYGjG');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
Header("Location: training");
}
if (isset($_GET['action'])) {
if ($_GET['action'] == "verwijderaanmelding") {
$nameq = $con->query("SELECT u.name as name, u.username as username FROM specialisatie_aanmeldingen as a INNER JOIN users as u ON a.user = u.id WHERE a.id = '".$_GET['kandidaatid']."'");
$name = $nameq->fetch_assoc();
$specq = $con->query("SELECT s.name as name, s.short as short FROM specialisatie_aanmeldingen as sa INNER JOIN specialisaties as s ON sa.specialisatie = s.id WHERE sa.id= '".$_GET['kandidaatid']."'");
$spec = $specq->fetch_assoc();
$username = $name['username']." (".$name['name'].")";
$specialisatie = $spec['name'];
$message = "Datum: ".date("d-m-Y")."\n";
$message .= "Kandidaat: ". $username . "\n";
$message .= "Instructeur: ". $_SESSION['name'] . "\n";
$message .= "Beoordeling: Onvoldoende\n";
$message .= "Opleidingsonderdeel: ".$spec['name']." (".$spec['short'].")\n";
$data = array("username" => "Trainingen en specialisaties", "content" => $message);
$data_string = json_encode($data);
$ch = curl_init('https://discordapp.com/api/webhooks/652500330491150357/mPm5TIvlz_SHpUw9IbLHYtxG3Bnj6OJyKNah3Jm9DubwMuXZP0QFsUtPmzNq5BkKVf1X');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
$con->query("DELETE FROM specialisatie_aanmeldingen WHERE id = '".$_GET['kandidaatid']."'");
Header("Location: training");
}
if ($_GET['action'] == "specialisatieafgerond") {
$a = $con->query("SELECT s.name as spec, s.short as short, s.beloningspromotie as beloningspromotie, a.user as user FROM specialisaties as s INNER JOIN specialisatie_aanmeldingen as a ON s.id=a.specialisatie WHERE a.id = '".$_GET['kandidaatid']."' LIMIT 1");
$row = $a->fetch_assoc(); //Short,beloningspromotie,user
$b = $con->query("SELECT specialisaties FROM users WHERE id = '".$row['user']."'");
$r2 = $b->fetch_assoc(); //Huidige specialisaties
//echo "<pre>";
//var_dump($row);
//exit;
if ($r2['specialisaties'] == NULL) {
$r2['specialisaties'] = $row['short'];
} else {
$r2['specialisaties'] = $r2['specialisaties'].", ".$row['short'];
}
$con->query("UPDATE users SET specialisaties = '".$r2['specialisaties']."' WHERE id='".$row['user']."'");
//echo $row['beloningspromotie'];
if (strlen($row['beloningspromotie']) > 1) {
//echo "RANK";
$con->query("UPDATE users SET rang = '".$row['beloningspromotie']."' WHERE id='".$row['user']."'");
}
//exit;
//I want to have the username
$userQuery = $con->query("SELECT username, name FROM users WHERE id='".$row['user']."'");
$rowUser = $userQuery->fetch_assoc();
$username = $rowUser['username']." (".$rowUser['name'].")";
$specialisatie = $row['spec'];
$message = "Datum: ".date("d-m-Y")."\n";
$message .= "Kandidaat: ". $username . "\n";
$message .= "Instructeur: ". $_SESSION['name'] . "\n";
$message .= "Beoordeling: Voldoende\n";
$message .= "Opleidingsonderdeel: ".$row['spec']." (".$row['short'].")\n";
$data = array("username" => "Trainingen en specialisaties", "content" => $message);
$data_string = json_encode($data);
$ch = curl_init('https://discordapp.com/api/webhooks/652500330491150357/mPm5TIvlz_SHpUw9IbLHYtxG3Bnj6OJyKNah3Jm9DubwMuXZP0QFsUtPmzNq5BkKVf1X');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
if ($rowUser != "") {
$result = curl_exec($ch);
}
$con->query("DELETE FROM specialisatie_aanmeldingen WHERE id = '".$_GET['kandidaatid']."'");
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if ($_POST['form'] == "create") {
$rang = implode(",",$_POST['rang']);
$beloning_rang = implode(",",$_POST['beloning_rang']);
$con->query("INSERT INTO specialisaties
(
id,
name,
short,
docent,
toelatingsrangen,
beloningspromotie,
created_by,
ip
) VALUES
(
'',
'".$con->real_escape_string($_POST['name'])."',
'".$con->real_escape_string($_POST['afkorting'])."',
'".$con->real_escape_string($_POST['teacher'])."',
'".$con->real_escape_string($rang)."',
'".$con->real_escape_string($beloning_rang)."',
'".$con->real_escape_string($_SESSION['id'])."',
'".$con->real_escape_string($_SERVER['REMOTE_ADDR'])."'
)");
Header("Location:training");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Specialisatietraining | MEOS</title>
<!-- Bootstrap core CSS-->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template-->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- Page level plugin CSS-->
<link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- datatables -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js"></script>
<link rel="icon" type="image/png" href="favicon.ico" />
<meta name="theme-color" content="<?php echo $browser_color; ?>">
</head>
<body class="fixed-nav sticky-footer bg-dark" id="page-top">
<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
<a class="navbar-brand" href="/">Specialisatietraining | MEOS</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav navbar-sidenav" id="exampleAccordion">
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Dashboard">
<a class="nav-link" href="index">
<i class="fa fa-fw fa-home"></i>
<span class="nav-link-text">Homepagina</span>
</a>
</li>
<?php if ($_SESSION['role'] != "anwb") { ?>
<?php } ?>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="basisadministratie">
<i class="fa fa-fw fa-area-chart"></i>
<span class="nav-link-text">Basisadministratie</span>
</a>
</li>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="voertuigregistratie">
<i class="fa fa-fw fa-area-chart"></i>
<span class="nav-link-text">Voertuigregistratie</span>
</a>
</li>
<?php if (@$_SESSION['cjib'] == 1) { ?>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="cjib">
<i class="fa fa-fw fa-list"></i>
<span class="nav-link-text">CJIB</span>
</a>
</li>
<?php } ?>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="/intranet">
<i class="fa fa-folder"></i>
<span class="nav-link-text">Intranet</span>
</a>
</li>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="training">
<i class="fa fa-fw fa-book"></i>
<span class="nav-link-text"><u>Training</u></span>
</a>
</li>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="aangiftes">
<i class="fa fa-fw fa-area-chart"></i>
<span class="nav-link-text">Aangifteadministratie</span>
</a>
</li>
<?php if ($_SESSION['role'] == "admin") { ?>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="gebruikers">
<i class="fa fa-fw fa-user-circle"></i>
<span class="nav-link-text">Gebruikersadministratie</span>
</a>
</li>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="jaillog">
<i class="fa fa-fw fa-history"></i>
<span class="nav-link-text">Logboeken</span>
</a>
</li>
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
<a class="nav-link" href="exit.php">
<i class="fa fa-sign-out"></i>
<span class="nav-link-text">Uitloggen</span>
</a>
</li>
<?php } ?>
</ul>
</div>
</nav>
<div class="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="index">Dashboard</a>
</li>
<li class="breadcrumb-item active">Training</li>
</ol>
<?php if (@$_SESSION['trainer'] == true) { ?>
<button onclick="$('#createModal').modal();" class="btn btn-success">Creëer specialisatie</button>
<?php } ?>
<?php if (@$_SESSION['trainer'] == true) { ?>
<h1>Kandidaten en aanmeldingen:</h1>
<form id="getSpecialisatieForm" method="get">
<em><b>Selecteer training</b></em>
<select id="specialisatieSelector" onchange="document.location.href='?getSpecialisatieFormgetSpecialisatie='+document.getElementById('specialisatieSelector').value;" class="form-control" name="getSpecialisatie">
<option disabled <?php if (!isset($_GET['getSpecialisatieFormgetSpecialisatie'])) { ?> selected <?php } ?>>Maak een keuze...</option>
<?php
while ($row = $getAllTraining->fetch_assoc()) {
?>
<option <?php if (@$_GET['getSpecialisatieFormgetSpecialisatie'] == $row['id']) { echo "selected"; } ?> value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?> (<?php echo $row['short']; ?>) - <?php echo str_replace("<br>"," - ",$row['docent']); ?>
<?php
}
?>
</select>
<?php } ?>
</form>
<?php if (@$_SESSION['trainer'] == true AND isset($_GET['getSpecialisatieFormgetSpecialisatie'])) { ?>
<?php
$q = $con->query("SELECT specialisatie_aanmeldingen.id as id,users.name as name, users.username as username FROM specialisatie_aanmeldingen INNER JOIN users ON users.id=specialisatie_aanmeldingen.user WHERE specialisatie = '".$con->real_escape_string($_GET['getSpecialisatieFormgetSpecialisatie'])."'");
if ($q->num_rows == 0) {
echo "Geen kandidaten gevonden";
} else {
?><br>
<table class="table">
<tr>
<th>Nummer</th>
<th>Kandidaatnaam</th>
<th> </th>
</tr>
<?php
while ($row = $q->fetch_assoc()) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?> (<?php echo $row['username']; ?>)</td>
<td>
<a class="btn btn-success" href="?action=specialisatieafgerond&kandidaatid=<?php echo $row['id']; ?>">Afgerond</a>
<a class="btn btn-danger" href="?action=verwijderaanmelding&kandidaatid=<?php echo $row['id']; ?>">Verwijderen</a>
</td>
</tr>
<?php } ?>
</table>
<?php
}
} echo "<hr>"; ?>
<h1>Inschrijven training</h1>
<table class="table">
<tr>
<th>Nummer</th>
<th>Specialisatie</th>
<th>Toelatingsrangen</th>
<th> </th>
</tr>
<?php
while ($row = $getAllTraining2->fetch_assoc()) { ?>
<?php
$explode = explode(",",$row['toelatingsrangen']);
if (!in_array($_SESSION['rang'],$explode) OR @in_array($row['id'],$registredAtTrainings) OR @in_array($row['short'],$allFinishedTrainingsByShort)) {
$toelaatbaar = false;
} else {
$toelaatbaar = true;
}
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo str_replace(",",", ",$row['toelatingsrangen']); ?></td>
<td>
<a <?php if ($toelaatbaar == true) { ?> class="btn btn-success" href="?registeer=<?php echo $row['id']; ?>" <?php } else { ?> class="btn btn-danger" href="" <?php } ?> ><?php if ($toelaatbaar == false) { echo "Niet (meer) beschikbaar"; } else { echo "Inschrijven"; }?></a>
</td>
</tr>
<?php } ?>
</table>
</div>
<!-- /.container-fluid-->
<!-- /.content-wrapper-->
<footer class="sticky-footer">
<div class="container">
<div class="text-center">
<small>Copyright © Zoutelande</small>
</div>
</div>
</footer>
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fa fa-angle-up"></i>
</a>
<!-- BEGIN Create Modal-->
<div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Creëer specialisatie</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST">
<input type="hidden" name="form" value="create">
<em><b>Specialisatienaam:</b></em>
<input class="form-control" type="text" name="name" required>
<em><b>Specialisatieafkorting:</b></em>
<input class="form-control" pattern="[A-Za-z0-9\-\_]+" type="text" name="afkorting" required>
<em><b>Docent:</b></em>
<input class="form-control" type="text" name="teacher" value="<?php echo $_SESSION['name']; ?>" required>
<em><b>Toelatingsrangen:</b></em>
<select multiple style="height: 100%;" size="10" name="rang[]" class="form-control" required>
<option value="Aspirant">Aspirant</option>
<option value="Surveillant">Surveillant</option>
<option value="Agent">Agent</option>
<option value="Hoofd Agent">Hoofd Agent</option>
<option value="Brigadier">Brigadier</option>
<option value="Inspecteur">Inspecteur</option>
<option value="Hoofd Inspecteur">Hoofd Inspecteur</option>
<option value="Commissaris">Commissaris</option>
<option value="Hoofd Commissaris">Hoofd Commissaris</option>
<option value="1e Hoofd Commissaris">1e Hoofd Commissaris</option>
</select>
<em><b>Beloningspromotie:</b></em>
<select style="height: 100%;" size="11" name="beloning_rang[]" class="form-control" required>
<option selected value="0">Geen</option>
<option value="Aspirant">Aspirant</option>
<option value="Surveillant">Surveillant</option>
<option value="Agent">Agent</option>
<option value="Hoofd Agent">Hoofd Agent</option>
<option value="Brigadier">Brigadier</option>
<option value="Inspecteur">Inspecteur</option>
<option value="Hoofd Inspecteur">Hoofd Inspecteur</option>
<option value="Commissaris">Commissaris</option>
<option value="Hoofd Commissaris">Hoofd Commissaris</option>
<option value="1e Hoofd Commissaris">1e Hoofd Commissaris</option>
</select>
<input type="submit" class="btn btn-primary" value="Bewaren">
</form>
</div>
</div>
</div>
</div>
<!-- END Create Modal-->
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Page level plugin JavaScript-->
<script src="vendor/chart.js/Chart.min.js"></script>
<script src="vendor/datatables/jquery.dataTables.js"></script>
<script src="vendor/datatables/dataTables.bootstrap4.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin.min.js"></script>
<!-- Custom scripts for this page-->
<script src="js/sb-admin-datatables.min.js"></script>
<script src="js/sb-admin-charts.min.js"></script>
</div>
<script>
</script>
</body>
</html>