181 lines
6.6 KiB
PHP
181 lines
6.6 KiB
PHP
|
|
<?php
|
||
|
|
session_start();
|
||
|
|
error_reporting(E_ALL);
|
||
|
|
ini_set('display_errors', 'On');
|
||
|
|
|
||
|
|
if (isset($_SESSION['id']) && isset($_SESSION['user_name'])) {
|
||
|
|
?>
|
||
|
|
<?php
|
||
|
|
// Below is optional, remove if you have already connected to your database.
|
||
|
|
include_once "../src/PHP/connection3.php";
|
||
|
|
|
||
|
|
// For extra protection these are the columns of which the user can sort by (in your database table).
|
||
|
|
$columns = [
|
||
|
|
'mealname',
|
||
|
|
'mealadditive',
|
||
|
|
'mealsupplement1',
|
||
|
|
'mealsupplement2',
|
||
|
|
'mealsupplement3',
|
||
|
|
];
|
||
|
|
|
||
|
|
// Only get the column if it exists in the above columns array, if it doesn't exist the database table will be sorted by the first item in the columns array.
|
||
|
|
$column =
|
||
|
|
isset($_GET['column']) && in_array($_GET['column'], $columns)
|
||
|
|
? $_GET['column']
|
||
|
|
: $columns[0];
|
||
|
|
|
||
|
|
// Get the sort order for the column, ascending or descending, default is ascending.
|
||
|
|
$sort_order =
|
||
|
|
isset($_GET['order']) && strtolower($_GET['order']) == 'desc'
|
||
|
|
? 'DESC'
|
||
|
|
: 'ASC';
|
||
|
|
|
||
|
|
// Get the result...
|
||
|
|
|
||
|
|
if (
|
||
|
|
$result = $mysqli->query(
|
||
|
|
'SELECT COUNT(*) AS anzahl, mealname, mealadditive, mealsupplement1, mealsupplement2, mealsupplement3, mealdate FROM foody_main GROUP BY ' .
|
||
|
|
$column .
|
||
|
|
' ORDER BY ' .
|
||
|
|
$column . ' ' .
|
||
|
|
$sort_order
|
||
|
|
/* 'SELECT COUNT(*) AS anzahl, mealname, mealadditive, mealsupplement1, mealsupplement2, mealsupplement3, mealdate FROM foody_main GROUP BY ' .
|
||
|
|
$column .
|
||
|
|
' ' .
|
||
|
|
$sort_order*/
|
||
|
|
)
|
||
|
|
) {
|
||
|
|
|
||
|
|
// Some variables we need for the table.
|
||
|
|
$up_or_down = str_replace(['ASC', 'DESC'], ['up', 'down'], $sort_order);
|
||
|
|
$asc_or_desc = $sort_order == 'ASC' ? 'desc' : 'asc';
|
||
|
|
$add_class = ' class="highlight"';
|
||
|
|
?>
|
||
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<title>Foody-Infos</title>
|
||
|
|
<meta charset="utf-8" />
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
|
<title>Example</title>
|
||
|
|
<link rel="stylesheet" type="text/css" href="foody.css" />
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="grid-container">
|
||
|
|
<div class="item1">
|
||
|
|
<nav class="main-nav">
|
||
|
|
<ul>
|
||
|
|
<li><a href="../home.php">Kalender</a></li>
|
||
|
|
<li><a href="meallist.php">Essenübersicht</a></li>
|
||
|
|
</ul>
|
||
|
|
<form>
|
||
|
|
<input type="search" placeholder="Search" />
|
||
|
|
<button>Go</button>
|
||
|
|
</form>
|
||
|
|
</nav>
|
||
|
|
</div>
|
||
|
|
<div class="item2">
|
||
|
|
<table id="foody_main" cellspacing="1">
|
||
|
|
<thead>
|
||
|
|
<tr>
|
||
|
|
<th><button class="button" id="button_anzahl"><a href="meallist.php?column=anzahl&order=<?php echo $asc_or_desc; ?>">Häufigkeit<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'anzahl'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
<th><button class="button"><a href="meallist.php?column=mealname&order=<?php echo $asc_or_desc; ?>">Essen<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'mealname'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
<th><button class="button"><a href="meallist.php?column=mealadditive&order=<?php echo $asc_or_desc; ?>">Gerichtzusatz<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'mealadditive'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
<th><button class="button"><a href="meallist.php?column=mealsupplement1&order=<?php echo $asc_or_desc; ?>">Beilage-1<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'mealsupplement1'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
<th><button class="button"><a href="meallist.php?column=mealsupplement2&order=<?php echo $asc_or_desc; ?>">Beilage-2<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'mealsupplement2'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
<th><button class="button"><a href="meallist.php?column=mealsupplement3&order=<?php echo $asc_or_desc; ?>">Beilage-3<i class="fas fa-sort<?php echo $column ==
|
||
|
|
'mealsupplement3'
|
||
|
|
? '-' . $up_or_down
|
||
|
|
: ''; ?>"></i></a></button></th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody>
|
||
|
|
<?php while ($row = $result->fetch_assoc()): ?>
|
||
|
|
<tr>
|
||
|
|
<td<?php echo $column == 'anzahl'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['anzahl']; ?></td>
|
||
|
|
<td<?php echo $column == 'mealname'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['mealname']; ?></td>
|
||
|
|
<td<?php echo $column == 'mealadditive'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['mealadditive']; ?></td>
|
||
|
|
<td<?php echo $column == 'mealsupplement1'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['mealsupplement1']; ?></td>
|
||
|
|
<td<?php echo $column == 'mealsupplement2'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['mealsupplement2']; ?></td>
|
||
|
|
<td<?php echo $column == 'mealsupplement3'
|
||
|
|
? $add_class
|
||
|
|
: ''; ?>><?php echo $row['mealsupplement3']; ?></td>
|
||
|
|
</tr>
|
||
|
|
<?php endwhile; ?>
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
<div class="item3">Footer</div>
|
||
|
|
</div>
|
||
|
|
</body>
|
||
|
|
<script>
|
||
|
|
// Funktion zum Logout nach einer bestimmten Zeit
|
||
|
|
function delayedLogout() {
|
||
|
|
// Setze den Timeout auf 5 Minuten (300000 Millisekunden)
|
||
|
|
var timeout = 300000; // 5 Minuten in Millisekunden
|
||
|
|
|
||
|
|
// Timeout-Funktion zum Ausführen des Logouts
|
||
|
|
var logoutTimeout;
|
||
|
|
|
||
|
|
function startLogoutTimer() {
|
||
|
|
logoutTimeout = setTimeout(logout, timeout);
|
||
|
|
}
|
||
|
|
|
||
|
|
function resetLogoutTimer() {
|
||
|
|
clearTimeout(logoutTimeout); // Timer zurücksetzen
|
||
|
|
startLogoutTimer(); // Timer neu starten
|
||
|
|
}
|
||
|
|
|
||
|
|
function logout() {
|
||
|
|
// Weiterleitung auf die logout.php-Seite
|
||
|
|
window.location.href = "logout.php";
|
||
|
|
}
|
||
|
|
|
||
|
|
// Starte den Timer beim Laden der Seite
|
||
|
|
startLogoutTimer();
|
||
|
|
|
||
|
|
// Reagiere auf Benutzerinteraktionen
|
||
|
|
document.addEventListener("click", resetLogoutTimer);
|
||
|
|
//document.addEventListener("mousemove", resetLogoutTimer);
|
||
|
|
document.addEventListener("keypress", resetLogoutTimer);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Starte den Timer beim Laden der Seite
|
||
|
|
window.onload = delayedLogout;
|
||
|
|
</script>
|
||
|
|
</html>
|
||
|
|
<?php $result->free();
|
||
|
|
}
|
||
|
|
?>
|
||
|
|
<?php
|
||
|
|
} else {
|
||
|
|
header("Location: ../index.php");
|
||
|
|
exit();
|
||
|
|
}
|
||
|
|
?>
|