xxxxxxxxxx
1
<?php
2
require('../header.php');
3
require('pdo.php');
4
5
// alle leerlingen inladen
6
if ($_SESSION["Rol"] == "leerling") {
7
header("Location: ../index.php");
8
exit;
9
}
10
11
$query = "SELECT * FROM `LLN` WHERE LLActief = 1 ORDER BY LLKlascode ASC, LLNaam ASC";
12
try {
13
$res = $pdo->prepare($query);
14
$res->execute();
15
} catch (PDOException $e) {
16
echo 'Query error<br>' . $e;
17
die();
18
}
19
20
$rows = [];
21
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
22
$voornaam = $row["LLVoornaam"];
23
$naam = $row["LLNaam"];
24
$klas = $row["LLKlascode"];
25
$id = $row["LLnr"];
26
// button toevoegen aan elk record
27
$button = '<button onclick="goToTimeline(\''.$id.'\',\''.$voornaam.'\',\''.$klas.'\',\''.$naam.'\')"
28
class="bg-success text-white border-0 rounded " name="path" value="tijdlijn">Tijdlijn</button> ';
29
30
31
$array = [$voornaam, $naam, $klas, $button];
32
$rows[] = $array;
33
}
34
35
// php rows omzetten naar json rows om te gebruiken in javascript
36
$rows_json = json_encode($rows);
37
?>
38
39
<?php
40
require('../startHTML.php');
41
?>
42
43
<style>
44
/* Add any additional styling here */
45
</style>
46
47
<?php
48
require('../navbar.php');
49
?>
50
51
<div class="container-fluid mt-5" id="top">
52
<div class="d-flex justify-content-center align-items-center">
53
<div class="card mt-3" style="width: 80%">
54
<div class="card-header text-center bg-danger text-white">
55
<h2>Overzicht leerlingen</h2>
56
</div>
57
<div class="card-body">
58
<div data-mdb-input-init class="form-outline mb-4">
59
<input type="text" class="form-control" id="datatable-search-input" />
60
<label class="form-label" for="datatable-search-input">Zoek een leerling</label>
61
</div>
62
<div data-mdb-datatable-init class="datatable" id="datatable"></div>
63
</div>
64
</div>
65
</div>
66
</div>
67
68
<br>
69
70
<?php
71
require('../footer1.php');
72
?>
73
74
<!-- Custom scripts -->
75
<script type="text/javascript">
76
const data = {
77
columns: [
78
{
79
label: 'Voornaam',
80
field: 'voornaam'
81
},
82
'Achternaam',
83
'Klas',
84
'Actie', // Changed column label to 'Actie' for the button
85
],
86
// json rows terug omzetten naar php rows
87
rows: <?php echo $rows_json; ?>,
88
};
89
90
const instance = new mdb.Datatable(document.getElementById('datatable'), data)
91
92
document.getElementById('datatable-search-input').addEventListener('input', (e) => {
93
instance.search(e.target.value);
94
});
95
96
function goToTimeline(id, voornaam, klas, naam){
97
let ajx = new XMLHttpRequest();
98
ajx.onreadystatechange = function() {
99
if(ajx.readyState == 4 && ajx.status ==200){
100
//console.log(ajx.responseText);
101
//location.reload();
102
window.location.href = "tijdlijn.php";
103
}
104
};
105
ajx.open("POST", "tijdlijn.php", true);
106
ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
107
108
// data voor de post in tijdlijn.php
109
var postData = "leerlingID=" + encodeURIComponent(id) +
110
"&voornaam=" + encodeURIComponent(voornaam) +
111
"&klas=" + encodeURIComponent(klas) +
112
"&naam=" + encodeURIComponent(naam);
113
114
ajx.send(postData);
115
}
116
117
</script>
118
119
<?php
120
require('../footer2.php');
121
?>
122
1
1
1
1
Console errors: 0