mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:32:44 +01:00
448 lines
20 KiB
HTML
448 lines
20 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Speiseplan Generator</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 20px;
|
|
background: #f0f0f0;
|
|
font-family: 'Fira Sans', sans-serif;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1000px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.week-controls {
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.week-controls button {
|
|
padding: 8px 16px;
|
|
margin: 0 10px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
#currentWeek {
|
|
display: inline-block;
|
|
min-width: 250px;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.day-controls {
|
|
text-align: center;
|
|
margin: 10px 0 20px 0;
|
|
}
|
|
|
|
.day-controls button {
|
|
padding: 6px 12px;
|
|
margin: 0 10px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
#currentDay {
|
|
display: inline-block;
|
|
min-width: 150px;
|
|
font-size: 14px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.template-container {
|
|
position: relative;
|
|
background: white;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.template-page {
|
|
position: relative;
|
|
height: 0;
|
|
padding-bottom: 60%;
|
|
background: url('/assets/speiseplan_vorlage_Seite_1.png') no-repeat center;
|
|
background-size: contain;
|
|
}
|
|
|
|
.form-overlay {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.input-field-14 {
|
|
position: absolute;
|
|
background: transparent;
|
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
padding: 2px 4px;
|
|
font-size: 20px;
|
|
color: rgb(159, 28, 12);
|
|
font-weight: bold;
|
|
width: 400px;
|
|
}
|
|
|
|
.input-field-13 {
|
|
position: absolute;
|
|
background: transparent;
|
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
padding: 2px 4px;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.input-field-12 {
|
|
position: absolute;
|
|
background: transparent;
|
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
padding: 2px 4px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.input-field-10 {
|
|
position: absolute;
|
|
background: transparent;
|
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
padding: 2px 4px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.bottom-controls {
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.day-form {
|
|
display: none;
|
|
}
|
|
|
|
.day-form.active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="week-controls">
|
|
<button onclick="previousWeek()">< Vorherige Woche</button>
|
|
<span id="currentWeek"></span>
|
|
<button onclick="nextWeek()">Nächste Woche ></button>
|
|
</div>
|
|
|
|
<div class="day-controls">
|
|
<button onclick="previousDay()">< Vorheriger Tag</button>
|
|
<span id="currentDay"></span>
|
|
<button onclick="nextDay()">Nächster Tag ></button>
|
|
</div>
|
|
|
|
<div class="template-container">
|
|
<div class="template-page">
|
|
<div class="form-overlay">
|
|
<form id="menuForm">
|
|
<div id="dayForm0" class="day-form active">
|
|
<input type="text" class="input-field-14" name="dateTitle0" style="bottom: 68%; left: 13.4%"
|
|
placeholder="Datum">
|
|
<input type="checkbox" class="input-field-13" name="halal0"
|
|
style="bottom: 62.2%; left: 22.1%">
|
|
<input type="text" class="input-field-12" name="meatMain0" style="bottom: 55%; left: 14%"
|
|
placeholder="Fleischgericht">
|
|
<input type="text" class="input-field-12" name="meatSide0" style="bottom: 50.2%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="meatPrice0" style="bottom: 40.4%; left: 14%"
|
|
placeholder="Preis">
|
|
<input type="text" class="input-field-12" name="veggiMain0" style="bottom: 25.6%; left: 14%"
|
|
placeholder="Veggie">
|
|
<input type="text" class="input-field-12" name="veggiSide0" style="bottom: 20.8%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="veggiPrice0"
|
|
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
|
</div>
|
|
<div id="dayForm1" class="day-form">
|
|
<input type="text" class="input-field-14" name="dateTitle1" style="bottom: 68%; left: 13.4%"
|
|
placeholder="Datum">
|
|
<input type="checkbox" class="input-field-13" name="halal1"
|
|
style="bottom: 62.2%; left: 22.1%">
|
|
<input type="text" class="input-field-12" name="meatMain1" style="bottom: 55%; left: 14%"
|
|
placeholder="Fleischgericht">
|
|
<input type="text" class="input-field-12" name="meatSide1" style="bottom: 50.2%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="meatPrice1" style="bottom: 40.4%; left: 14%"
|
|
placeholder="Preis">
|
|
<input type="text" class="input-field-12" name="veggiMain1" style="bottom: 25.6%; left: 14%"
|
|
placeholder="Veggie">
|
|
<input type="text" class="input-field-12" name="veggiSide1" style="bottom: 20.8%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="veggiPrice1"
|
|
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
|
</div>
|
|
<div id="dayForm2" class="day-form">
|
|
<input type="text" class="input-field-14" name="dateTitle2" style="bottom: 68%; left: 13.4%"
|
|
placeholder="Datum">
|
|
<input type="checkbox" class="input-field-13" name="halal2"
|
|
style="bottom: 62.2%; left: 22.1%">
|
|
<input type="text" class="input-field-12" name="meatMain2" style="bottom: 55%; left: 14%"
|
|
placeholder="Fleischgericht">
|
|
<input type="text" class="input-field-12" name="meatSide2" style="bottom: 50.2%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="meatPrice2" style="bottom: 40.4%; left: 14%"
|
|
placeholder="Preis">
|
|
<input type="text" class="input-field-12" name="veggiMain2" style="bottom: 25.6%; left: 14%"
|
|
placeholder="Veggie">
|
|
<input type="text" class="input-field-12" name="veggiSide2" style="bottom: 20.8%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="veggiPrice2"
|
|
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
|
</div>
|
|
<div id="dayForm3" class="day-form">
|
|
<input type="text" class="input-field-14" name="dateTitle3" style="bottom: 68%; left: 13.4%"
|
|
placeholder="Datum">
|
|
<input type="checkbox" class="input-field-13" name="halal3"
|
|
style="bottom: 62.2%; left: 22.1%">
|
|
<input type="text" class="input-field-12" name="meatMain3" style="bottom: 55%; left: 14%"
|
|
placeholder="Fleischgericht">
|
|
<input type="text" class="input-field-12" name="meatSide3" style="bottom: 50.2%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="meatPrice3" style="bottom: 40.4%; left: 14%"
|
|
placeholder="Preis">
|
|
<input type="text" class="input-field-12" name="veggiMain3" style="bottom: 25.6%; left: 14%"
|
|
placeholder="Veggie">
|
|
<input type="text" class="input-field-12" name="veggiSide3" style="bottom: 20.8%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="veggiPrice3"
|
|
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
|
</div>
|
|
<div id="dayForm4" class="day-form">
|
|
<input type="text" class="input-field-14" name="dateTitle4" style="bottom: 68%; left: 13.4%"
|
|
placeholder="Datum">
|
|
<input type="checkbox" class="input-field-13" name="halal4"
|
|
style="bottom: 62.2%; left: 22.1%">
|
|
<input type="text" class="input-field-12" name="meatMain4" style="bottom: 55%; left: 14%"
|
|
placeholder="Fleischgericht">
|
|
<input type="text" class="input-field-12" name="meatSide4" style="bottom: 50.2%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="meatPrice4" style="bottom: 40.4%; left: 14%"
|
|
placeholder="Preis">
|
|
<input type="text" class="input-field-12" name="veggiMain4" style="bottom: 25.6%; left: 14%"
|
|
placeholder="Veggie">
|
|
<input type="text" class="input-field-12" name="veggiSide4" style="bottom: 20.8%; left: 14%"
|
|
placeholder="Beilage">
|
|
<input type="text" class="input-field-10" name="veggiPrice4"
|
|
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bottom-controls">
|
|
<button onclick="saveWeek()">Woche speichern</button>
|
|
<button onclick="generatePDF()">PDF generieren</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentWeek = new Date();
|
|
currentWeek.setDate(currentWeek.getDate() - currentWeek.getDay() + 1); // Set to Monday
|
|
let currentDayIndex = 0; // 0 = Monday, 4 = Friday
|
|
|
|
function getWeekNumber(date) {
|
|
const target = new Date(date.valueOf());
|
|
const dayNumber = (date.getDay() + 6) % 7;
|
|
target.setDate(target.getDate() - dayNumber + 3);
|
|
const firstThursday = target.valueOf();
|
|
target.setMonth(0, 1);
|
|
if (target.getDay() !== 4) {
|
|
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
|
|
}
|
|
return 1 + Math.ceil((firstThursday - target) / 604800000);
|
|
}
|
|
|
|
function updateWeekDisplay() {
|
|
const startOfWeek = new Date(currentWeek);
|
|
const endOfWeek = new Date(currentWeek);
|
|
endOfWeek.setDate(startOfWeek.getDate() + 4); // Friday
|
|
|
|
const weekNumber = getWeekNumber(startOfWeek);
|
|
|
|
const startDate = startOfWeek.toLocaleDateString('de-DE', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: '2-digit'
|
|
});
|
|
const endDate = endOfWeek.toLocaleDateString('de-DE', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: '2-digit'
|
|
});
|
|
|
|
document.getElementById('currentWeek').textContent =
|
|
`KW${weekNumber} ${startDate} - ${endDate}`;
|
|
}
|
|
|
|
function updateDayDisplay() {
|
|
const currentDate = new Date(currentWeek);
|
|
currentDate.setDate(currentDate.getDate() + currentDayIndex);
|
|
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' });
|
|
const dateStr = currentDate.toLocaleDateString('de-DE', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: '2-digit'
|
|
});
|
|
document.getElementById('currentDay').textContent = `${dayName} ${dateStr}`;
|
|
|
|
// Show the correct form for the current day
|
|
document.querySelectorAll('.day-form').forEach((form, index) => {
|
|
form.classList.toggle('active', index === currentDayIndex);
|
|
});
|
|
}
|
|
|
|
function previousDay() {
|
|
if (currentDayIndex > 0) {
|
|
currentDayIndex--;
|
|
updateDayDisplay();
|
|
}
|
|
}
|
|
|
|
function nextDay() {
|
|
if (currentDayIndex < 4) {
|
|
currentDayIndex++;
|
|
updateDayDisplay();
|
|
}
|
|
}
|
|
|
|
function previousWeek() {
|
|
currentWeek.setDate(currentWeek.getDate() - 7);
|
|
currentDayIndex = 0; // Reset to Monday
|
|
updateWeekDisplay();
|
|
updateDayDisplay();
|
|
const weekNumber = getWeekNumber(currentWeek);
|
|
const year = currentWeek.getFullYear();
|
|
const week = `KW${weekNumber} ${year}`;
|
|
loadWeekData(week);
|
|
}
|
|
|
|
function nextWeek() {
|
|
currentWeek.setDate(currentWeek.getDate() + 7);
|
|
currentDayIndex = 0; // Reset to Monday
|
|
updateWeekDisplay();
|
|
updateDayDisplay();
|
|
const weekNumber = getWeekNumber(currentWeek);
|
|
const year = currentWeek.getFullYear();
|
|
const week = `KW${weekNumber} ${year}`;
|
|
loadWeekData(week);
|
|
}
|
|
|
|
function saveWeek() {
|
|
const weekNumber = getWeekNumber(currentWeek);
|
|
const year = currentWeek.getFullYear();
|
|
const week = `KW${weekNumber} ${year}`;
|
|
const entries = [];
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
const currentDate = new Date(currentWeek);
|
|
currentDate.setDate(currentDate.getDate() + i);
|
|
|
|
const entry = {
|
|
date: currentDate.toISOString().split('T')[0], // Reines Datum
|
|
dayIndex: i,
|
|
dateTitle: document.querySelector(`input[name="dateTitle${i}"]`).value,
|
|
meatMain: document.querySelector(`input[name="meatMain${i}"]`).value,
|
|
meatSide: document.querySelector(`input[name="meatSide${i}"]`).value,
|
|
halal: document.querySelector(`input[name="halal${i}"]`).checked,
|
|
meatPrice: document.querySelector(`input[name="meatPrice${i}"]`).value,
|
|
veggiMain: document.querySelector(`input[name="veggiMain${i}"]`).value,
|
|
veggiSide: document.querySelector(`input[name="veggiSide${i}"]`).value,
|
|
veggiPrice: document.querySelector(`input[name="veggiPrice${i}"]`).value
|
|
};
|
|
|
|
entries.push(entry);
|
|
}
|
|
|
|
fetch('/save-week', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ week, entries })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
alert(data.message);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error saving week:', error);
|
|
alert('Fehler beim Speichern der Woche');
|
|
});
|
|
}
|
|
|
|
function loadWeekData(week) {
|
|
fetch(`/load-week?week=${encodeURIComponent(week)}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
// Clear all input fields
|
|
for (let i = 0; i < 5; i++) {
|
|
document.querySelector(`input[name="dateTitle${i}"]`).value = '';
|
|
document.querySelector(`input[name="meatMain${i}"]`).value = '';
|
|
document.querySelector(`input[name="meatSide${i}"]`).value = '';
|
|
document.querySelector(`input[name="halal${i}"]`).checked = false;
|
|
document.querySelector(`input[name="meatPrice${i}"]`).value = '';
|
|
document.querySelector(`input[name="veggiMain${i}"]`).value = '';
|
|
document.querySelector(`input[name="veggiSide${i}"]`).value = '';
|
|
document.querySelector(`input[name="veggiPrice${i}"]`).value = '';
|
|
}
|
|
|
|
// Fill input fields with loaded data
|
|
const loadedDays = new Set(data.map(entry => entry.day_index));
|
|
data.forEach(entry => {
|
|
const dayIndex = entry.day_index;
|
|
const dateTitleInput = document.querySelector(`input[name="dateTitle${dayIndex}"]`);
|
|
dateTitleInput.value = entry.date_title;
|
|
|
|
document.querySelector(`input[name="meatMain${dayIndex}"]`).value = entry.meat_main;
|
|
document.querySelector(`input[name="meatSide${dayIndex}"]`).value = entry.meat_side;
|
|
document.querySelector(`input[name="halal${dayIndex}"]`).checked = entry.halal === 1;
|
|
document.querySelector(`input[name="meatPrice${dayIndex}"]`).value = entry.meat_price;
|
|
document.querySelector(`input[name="veggiMain${dayIndex}"]`).value = entry.veggi_main;
|
|
document.querySelector(`input[name="veggiSide${dayIndex}"]`).value = entry.veggi_side;
|
|
document.querySelector(`input[name="veggiPrice${dayIndex}"]`).value = entry.veggi_price;
|
|
});
|
|
|
|
// Automatically fill dateTitle if empty or not in DB
|
|
for (let i = 0; i < 5; i++) {
|
|
if (!loadedDays.has(i)) {
|
|
const dateTitleInput = document.querySelector(`input[name="dateTitle${i}"]`);
|
|
if (!dateTitleInput.value) {
|
|
const currentDate = new Date(currentWeek);
|
|
currentDate.setDate(currentDate.getDate() + i);
|
|
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' }).toUpperCase();
|
|
const dateStr = currentDate.toLocaleDateString('de-DE', {
|
|
day: '2-digit',
|
|
month: 'long',
|
|
year: 'numeric'
|
|
});
|
|
dateTitleInput.value = `${dayName}, ${dateStr}`;
|
|
}
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading week:', error);
|
|
alert('Fehler beim Laden der Woche');
|
|
});
|
|
}
|
|
|
|
// Initialize the display when page loads
|
|
updateWeekDisplay();
|
|
updateDayDisplay();
|
|
const weekNumber = getWeekNumber(currentWeek);
|
|
const year = currentWeek.getFullYear();
|
|
const week = `KW${weekNumber} ${year}`;
|
|
loadWeekData(week);
|
|
</script>
|
|
</body>
|
|
|
|
</html> |