-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export csv time entries and api changes timeentries
- Loading branch information
1 parent
338b8ad
commit 3176787
Showing
9 changed files
with
607 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
require_once 'config.php'; | ||
require_once 'functions.php'; | ||
|
||
// Ensure user is logged in | ||
session_start(); | ||
if (!isset($_SESSION['user_id'])) { | ||
die('Not authorized'); | ||
} | ||
|
||
try { | ||
// Set headers for CSV download with UTF-8 encoding | ||
header('Content-Type: text/csv; charset=UTF-8'); | ||
header('Content-Disposition: attachment; filename="Arbeitszeiterfassung_' . date('Y-m-d') . '.csv"'); | ||
|
||
// Create output stream with UTF-8 encoding | ||
$output = fopen('php://temp', 'w+'); | ||
fprintf($output, "\xEF\xBB\xBF"); // UTF-8 BOM | ||
|
||
// Add headers | ||
fputcsv($output, [ | ||
'Datum', | ||
'Start', | ||
'Ende', | ||
'Pause (Min)', | ||
'Arbeitszeit', | ||
'Standort', | ||
'Beschreibung' | ||
], ';'); | ||
|
||
// Fetch records | ||
$stmt = $conn->prepare(' | ||
SELECT | ||
startzeit, | ||
endzeit, | ||
pause, | ||
standort, | ||
beschreibung | ||
FROM zeiterfassung | ||
WHERE user_id = :user_id | ||
ORDER BY startzeit DESC | ||
'); | ||
$stmt->execute(['user_id' => $_SESSION['user_id']]); | ||
|
||
while ($record = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$startzeit = new DateTime($record['startzeit']); | ||
$endzeit = $record['endzeit'] ? new DateTime($record['endzeit']) : null; | ||
|
||
fputcsv($output, [ | ||
$startzeit->format('d.m.Y'), | ||
$startzeit->format('H:i'), | ||
$endzeit ? $endzeit->format('H:i') : '', | ||
$record['pause'] ?: '', | ||
calculateDuration($record['startzeit'], $record['endzeit'], $record['pause']), | ||
$record['standort'], | ||
$record['beschreibung'] | ||
], ';'); | ||
} | ||
|
||
// Output the file with UTF-8 encoding | ||
rewind($output); | ||
echo mb_convert_encoding(stream_get_contents($output), 'UTF-8', 'UTF-8'); | ||
fclose($output); | ||
exit; | ||
|
||
} catch (Exception $e) { | ||
die('Error exporting data: ' . $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.