153 lines
5.7 KiB
PHP
153 lines
5.7 KiB
PHP
<?php
|
|
|
|
//Since this page writes to a session, initialise it here
|
|
session_start();
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Überprüfen, welcher Button geklickt wurde
|
|
if ($_POST["action"] == "PDF anzeigen") {
|
|
// Weiterleitung zur createPDF.php mit den Parametern
|
|
$userId = $_POST["user"];
|
|
$selectedMonth = $_POST["month"];
|
|
$monthYear = explode("/", $selectedMonth);
|
|
$month = $monthYear[0];
|
|
$year = $monthYear[1];
|
|
// Weiterleitung zur createPDF.php mit den Parametern
|
|
# echo "Location: createPDF.php?id=$userId&month=$month&year=$year";
|
|
header("Location: createPDF.php?id=$userId&month=$month&year=$year");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
require_once("inc/config.inc.php");
|
|
require_once("inc/functions.inc.php");
|
|
//Überprüfe, dass der User eingeloggt ist
|
|
//Der Aufruf von check_user() muss in alle internen Seiten eingebaut sein
|
|
$user = check_user();
|
|
?>
|
|
<?php include 'header.php'; ?>
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
|
|
<?php
|
|
// Starten der Session, falls noch nicht geschehen
|
|
if(session_status() === PHP_SESSION_NONE) session_start();
|
|
|
|
// Überprüfen, ob eine Benutzer-ID in der Session vorhanden ist
|
|
if (!isset($_SESSION['userid'])) {
|
|
die("Kein Benutzer angemeldet.");
|
|
}
|
|
|
|
$user_id = $_SESSION['userid'];
|
|
|
|
// Benutzer aus der Datenbank erhalten
|
|
try {
|
|
$users_stmt = $pdo->prepare("SELECT id,vorname, nachname FROM users WHERE zeiterfassung='1' ORDER BY nachname ASC");
|
|
$users_stmt->execute();
|
|
$users = $users_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
// Monate für den Dropdown-Menü erhalten
|
|
try {
|
|
// Hier sollte die Abfrage angepasst werden, um auf den ausgewählten Benutzer zu filtern
|
|
$months_stmt = $pdo->prepare("SELECT DISTINCT MONTH(timestamp_datetime) as month, YEAR(timestamp_datetime) as year FROM timestamps ORDER BY timestamp_datetime DESC");
|
|
#$months_stmt->bindParam(1, $user_id);
|
|
$months_stmt->execute();
|
|
$months = $months_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
$selectedUser = $_POST['user'] ?? $user_id; // Standardmäßig der angemeldete Benutzer
|
|
$selectedMonth = $_POST['month'] ?? '';
|
|
|
|
// Zeiten für den ausgewählten Monat und Benutzer erhalten
|
|
if ($selectedMonth && $selectedUser) {
|
|
try {
|
|
$selectedYear = explode('/',$selectedMonth)[1];
|
|
$times_stmt = $pdo->prepare("SELECT timestamp_datetime, timestamp_type FROM timestamps WHERE employee_id = ? AND MONTH(timestamp_datetime) = ? AND YEAR(timestamp_datetime) = ? ORDER BY timestamp_datetime ASC");
|
|
$times_stmt->bindParam(1, $selectedUser);
|
|
$times_stmt->bindParam(2, explode('/', $selectedMonth)[0]); // Monat extrahieren
|
|
$times_stmt->bindParam(3, $selectedYear);
|
|
$times_stmt->execute();
|
|
$times = $times_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
// Gruppieren der Zeiten nach Tagen
|
|
$groupedTimes = [];
|
|
foreach ($times as $time) {
|
|
$date = date('Y-m-d', strtotime($time['timestamp_datetime']));
|
|
$groupedTimes[$date][] = $time;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
<h2>Zeitenübersicht</h2>
|
|
|
|
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
|
|
<div class="form-group">
|
|
<label for="user">Benutzer auswählen:</label>
|
|
<select name="user" id="user" class="form-control">
|
|
<?php foreach ($users as $user): ?>
|
|
<option value="<?php echo $user['id']; ?>" <?php if ($user['id'] == $selectedUser) echo 'selected'; ?>>
|
|
<?php echo htmlspecialchars($user['vorname']); ?> <?php echo htmlspecialchars($user['nachname']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="month">Monat auswählen:</label>
|
|
<select name="month" id="month" class="form-control">
|
|
<?php foreach ($months as $month): ?>
|
|
<option value="<?php echo $month['month'] . '/' . $month['year']; ?>" <?php if ($month['month'] . '/' . $month['year'] == $selectedMonth) echo 'selected'; ?>>
|
|
<?php echo $month['month'] . '/' . $month['year']; ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<br>
|
|
<input type="submit" value="Zeiten anzeigen" class="btn btn-primary btn-lg">
|
|
<!-- Button zum Anzeigen der PDF -->
|
|
<input type="submit" name="action" value="PDF anzeigen" class="btn btn-primary btn-lg" formtarget="_blank">
|
|
|
|
</form>
|
|
|
|
<?php if ($selectedMonth && $selectedUser): ?>
|
|
<table class="table table-striped table-hover">
|
|
<tr>
|
|
<th>Datum</th>
|
|
<th>Typ</th>
|
|
<th>Aktionen</th>
|
|
</tr>
|
|
<?php foreach ($groupedTimes as $date => $times): ?>
|
|
<tr>
|
|
<td><?php echo date('d.m.Y', strtotime($date)); ?></td>
|
|
<td>
|
|
<?php foreach ($times as $time): ?>
|
|
<div><?php echo date('H:i:s', strtotime($time['timestamp_datetime'])) . ' - ' . $time['timestamp_type']; ?></div>
|
|
<?php endforeach; ?>
|
|
</td>
|
|
<td>
|
|
<a href="editDayEntries.php?employee_id=<?php echo $selectedUser; ?>&datum=<?php echo date('Y-m-d', strtotime($time['timestamp_datetime'])); ?>" class="btn btn-primary">Anpassen</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</table>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|