DH_Alumni/overview.php

122 lines
4.4 KiB
PHP

<?php
require_once 'general.php';
require_once 'vendor/autoload.php';
session_start();
if(!isset($_SESSION['user'])) {
echo "Nicht angemeldet";
http_response_code(401);
exit;
}
$statement = getDatabase()->prepare("SELECT * from entries WHERE verify = 1");
if(!$statement->execute()) {
echo "database Error";
}
$entries = $statement->fetchAll(PDO::FETCH_ASSOC);
if($_GET['export'] != null) {
if($statement->rowCount() > 0){
$delimiter = ";";
$filename = "ehemalige_" . date('Y-m-d') . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array("ID", "Name", "E-Mail", "Telefon", "Wohnort", "Abschlussjahrgang", "Geburtstag", "Email validiert", "Tätigkeit", "Eintragungsdatum");
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
foreach ($entries as $entry) {
$lineData = array($entry['id'], $entry['name'], $entry['mail'], $entry['phone'], $entry['location'], $entry['year'], $entry['birthday'], $entry['verify'], $entry['vocation'], $entry['creation']);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
}
exit;
}
returnHeader();
?>
<div class="flex flex-col">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg relative space-y-32">
<div class="md:mt-6 top-0 right-0 absolute">
<a href="overview.php?export=true" class="bg-blue-500 px-2 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">als CSV exportieren</a>
<a href="logout.php" class="bg-blue-500 px-4 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">ausloggen</a>
</div>
<table id="overviewTable" class="display">
<thead>
<tr>
<th>Name</th>
<th>Tätigkeit</th>
<th>E-Mail Adresse & Telefon</th>
<th>Wohnort</th>
<th>Jahrgang</th>
<th>Alter</th>
<th>Eintragung</th>
</tr>
</thead>
<tbody>
<?php
foreach ($entries as $entry) {
$age = date_diff(date_create($entry['birthday']), date_create('now'))->y;
$creationDate = date_create($entry["creation"]);
?>
<tr>
<td><?php echo $entry["name"] ?></td>
<td><?php echo $entry["vocation"] ?></td>
<td><?php echo $entry["mail"] . " "; echo (isset($entry['phone'])) ? $entry['phone'] : "" ?></td>
<td><?php echo (isset($entry['location'])) ? $entry['location'] : "" ?></td>
<td><?php echo $entry["year"] ?></td>
<td><?php echo $age ?></td>
<td><?php echo date_format($creationDate, "d.m.Y") ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#overviewTable').DataTable({
language: {
url: 'https://cdn.datatables.net/plug-ins/1.10.24/i18n/German.json'
}
});
});
</script>
<?php
returnFooter();