Exam detailid
Exam detailid
ID |
Exam aeg |
Koht |
Eksamineerija nimi |
Opilane nimi |
Kestvus (tunnid) |
Email |
1 |
2025-08-25 14:30 |
30087 Garrison Street |
Jordanna Sherbrook |
Emelyne Posselt |
2 |
jordanna.sherbrook@example.com |
2 |
2025-07-25 09:15 |
35451 Schurz Trail |
Elli Harwood |
Rickard Giabuzzi |
1 |
elli.harwood@example.com |
3 |
2025-05-04 10:45 |
43665 Fairfield Circle |
Julietta Duffett |
Arda Shaddick |
3 |
julietta.duffett@example.com |
4 |
2025-05-14 12:00 |
4 Bashford Avenue |
Hewett Canty |
Nissa Barnwell |
1 |
hewett.canty@example.com |
5 |
2025-01-14 08:00 |
7 Jackson Way |
Pietra Clew |
Yorgos Elrick |
2 |
pietra.clew@example.com |
6 |
2025-09-15 11:30 |
77257 Meadow Valley Parkway |
Xenos Kilbourne |
Myrvyn Beatens |
3 |
xenos.kilbourne@example.com |
7 |
2025-01-21 07:45 |
50389 Kim Center |
Connie Sutherden |
Margarethe Jans |
1 |
connie.sutherden@example.com |
8 |
2025-08-19 13:00 |
2281 Clarendon Trail |
Tiffi Cherrison |
Susanne Pariso |
4 |
tiffi.cherrison@example.com |
9 |
2025-05-31 16:00 |
820 Sunnyside Court |
Davon Gronaver |
Clotilda Clowley |
4 |
davon.gronaver@example.com |
10 |
2025-05-28 14:00 |
4067 Briar Crest Junction |
Florida Sibson |
Marena Vasler |
3 |
florida.sibson@example.com |
<?php
// Load XML data
$xml = new DOMDocument;
$xml->load('XML/eksamid.xml');
// Search and fiters
$searchName = isset($_POST['name']) ? $_POST['name'] : '';
$filterDate = isset($_POST['date']) ? $_POST['date'] : '';
$sortColumn = isset($_GET['sort']) ? $_GET['sort'] : 'id'; // Default sort by ID
$sortOrder = isset($_GET['order']) ? $_GET['order'] : 'asc'; // Default sort order
$filteredXml = new DOMDocument;
$filteredXml->appendChild($filteredXml->createElement('eksamid'));
foreach ($xml->getElementsByTagName('eksam') as $eksam) {
$examinerNode = $eksam->getElementsByTagName('eksamineerijanimi')->item(0);
$studentNode = $eksam->getElementsByTagName('opilanenimi')->item(0);
$dateNode = $eksam->getElementsByTagName('eksamiaeg')->item(0);
$examinerName = $examinerNode ? $examinerNode->nodeValue : '';
$studentName = $studentNode ? $studentNode->nodeValue : '';
$examDate = $dateNode ? $dateNode->nodeValue : '';
// Checks does the name and filers matces
if ((empty($searchName) || stripos($examinerName, $searchName) !== false || stripos($studentName, $searchName) !== false) &&
(empty($filterDate) || strpos($examDate, $filterDate) !== false)) {
$filteredXml->documentElement->appendChild($filteredXml->importNode($eksam, true));
}
}
$xpath = new DOMXPath($filteredXml);
$sortedXml = new DOMDocument;
$sortedXml->appendChild($sortedXml->createElement('eksamid'));
$nodes = $xpath->query('/eksamid/eksam');
$sortedArray = [];
foreach ($nodes as $node) {
$sortedArray[] = $node;
}
// Sorting
usort($sortedArray, function ($a, $b) use ($sortColumn, $sortOrder) {
$aNode = $a->getElementsByTagName($sortColumn)->item(0);
$bNode = $b->getElementsByTagName($sortColumn)->item(0);
$aValue = $aNode ? $aNode->nodeValue : '';
$bValue = $bNode ? $bNode->nodeValue : '';
if ($aValue == $bValue) {
return 0; // Equal
}
if ($sortOrder === 'asc') {
return ($aValue < $bValue) ? -1 : 1; // Ascending order
} else {
return ($aValue > $bValue) ? -1 : 1; // Descending order
}
});
foreach ($sortedArray as $node) {
$sortedXml->documentElement->appendChild($sortedXml->importNode($node, true));
}
// XSLT load
$xslt = new DOMDocument;
$xslt->load('XML/eksamid.xslt');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStylesheet($xslt); // Stylesheet
$html = $proc->transformToXML($sortedXml);
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Exam Details</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function() {
$("#date").datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
<script>
$(document).ready(function(){
$("#codeshowbut").click(function(){
$("#codeshow").slideToggle("slow");
});
});
</script>
<style>
#codeshowbut{
bgcolor="Red"
}
</style>
</head>
<body>
<h1>Exam detailid</h1>
<form method="POST">
<label for="name">Otsi nime järgi:</label>
<input type="text" id="name" name="name" value="<?php echo htmlspecialchars($searchName); ?>" placeholder="Sisestage nimi...">
<label for="date">Filtreeri kuupäeva järgi:</label>
<input type="text" id="date" name="date" value="<?php echo htmlspecialchars($filterDate); ?>" placeholder="Valige kuupäev...">
<button type="submit">Otsi</button>
</form>
<div>
<table>
<thead>
</thead>
<tbody>
<?php
if ($html) {
echo $html;
} else {
echo "<p>Tulemusi ei leitud.</p>";
}
?>
</tbody>
</table>
</div>
<button id="codeshowbut">Näita koodi</button>
<pre id="codeshow" class="brush: php">
<?php
highlight_string(file_get_contents(__FILE__));
?>
</pre>
</body>
</html>