Files
pdf-writer/public/index.html
T

464 lines
18 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Speiseplan Generator</title>
<style>
body {
margin: 0;
padding: 20px;
background: #a81411;
background-image: url("/assets/background.png");
color: white;
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;
border-radius: 20px;
overflow: hidden;
background: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
}
.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.07);
padding: 2px 4px;
font-size: 24px;
color: rgb(159, 28, 12);
font-weight: bold;
width: 333px;
font-family: 'Fira Sans', sans-serif
}
.input-field-13 {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 23px;
color: #00B050;
font-weight: 500;
font-family: 'Fira Sans', sans-serif
}
.input-field-12 {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 20px;
width: 500px;
font-family: 'Fira Sans', sans-serif
}
.input-field-12-b {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 20px;
font-weight: bold;
width: 500px;
font-family: 'Fira Sans', sans-serif
}
.input-field-10 {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 16px;
font-style: italic;
width: 333px;
font-family: 'Fira Sans', sans-serif
}
.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()">&lt; Vorherige Woche</button>
<span id="currentWeek"></span>
<button onclick="nextWeek()">Nächste Woche &gt;</button>
</div>
<div class="day-controls">
<button onclick="previousDay()">&lt; Vorheriger Tag</button>
<span id="currentDay"></span>
<button onclick="nextDay()">Nächster Tag &gt;</button>
</div>
<div class="template-container">
<div class="template-page">
<div class="form-overlay">
<form id="menuForm">
<script>
for (let i = 0; i < 5; i++) {
document.write(`
<div id="dayForm${i}" class="day-form ${i === 0 ? 'active' : ''}">
<input type="text" class="input-field-14" name="dateTitle${i}" style="bottom: 67%; left: 13.4%" placeholder="Datum">
<select class="input-field-13" name="halal${i}" style="bottom: 61%; left: 30%">
<option value="" style="color:red;">----</option>
<option value="halal" style="color:#00B050;">„HALAL“</option>
</select>
<input type="text" class="input-field-12-b" name="meatMain${i}" style="bottom: 55%; left: 13.4%" placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide${i}" style="bottom: 50.2%; left: 13.4%" placeholder="Beilage">
<input type="text" class="input-field-10" name="meatPrice${i}" style="bottom: 43.3%; left: 13.4%" placeholder="Preis">
<input type="text" class="input-field-12-b" name="veggiMain${i}" style="bottom: 29.1%; left: 13.4%" placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide${i}" style="bottom: 24.3%; left: 13.4%" placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice${i}" style="bottom: 17.6%; left: 13.4%" placeholder="Preis">
</div>
`);
}
</script>
</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(`select[name="halal${i}"]`).value === 'halal',
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(`select[name="halal${i}"]`).value = '';
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}"]`);
const meatPriceInput = document.querySelector(`input[name="meatPrice${dayIndex}"]`);
const veggiPriceInput = document.querySelector(`input[name="veggiPrice${dayIndex}"]`);
const halalSelect = document.querySelector(`select[name="halal${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;
halalSelect.value = entry.halal ? 'halal' : '';
meatPriceInput.value = entry.meat_price;
document.querySelector(`input[name="veggiMain${dayIndex}"]`).value = entry.veggi_main;
document.querySelector(`input[name="veggiSide${dayIndex}"]`).value = entry.veggi_side;
veggiPriceInput.value = entry.veggi_price;
// Automatically fill dateTitle if empty
if (!dateTitleInput.value) {
const currentDate = new Date(currentWeek);
currentDate.setDate(currentDate.getDate() + dayIndex);
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' }).toUpperCase();
const dateStr = currentDate.toLocaleDateString('de-DE', {
day: '2-digit',
month: 'long'
}).toUpperCase();
dateTitleInput.value = `${dayName}, ${dateStr}`;
}
// Automatically fill meatPrice if empty
if (!meatPriceInput.value) {
meatPriceInput.value = (dayIndex === 4) ? "9,50 € / 6,80 € - Business Lunch 7,50 € / 5,10 €" : "9,00 € / 6,30 € - Business Lunch 7,00 € / 4,90 €";
}
// Automatically fill veggiPrice if empty
if (!veggiPriceInput.value) {
veggiPriceInput.value = "8,50 € / 5,95 € - Business Lunch 6,50 € / 4,55 €";
}
});
// Automatically fill dateTitle, meatPrice, and veggiPrice if not in DB
for (let i = 0; i < 5; i++) {
if (!loadedDays.has(i)) {
const dateTitleInput = document.querySelector(`input[name="dateTitle${i}"]`);
const meatPriceInput = document.querySelector(`input[name="meatPrice${i}"]`);
const veggiPriceInput = document.querySelector(`input[name="veggiPrice${i}"]`);
const halalSelect = document.querySelector(`select[name="halal${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'
}).toUpperCase();
dateTitleInput.value = `${dayName}, ${dateStr}`;
}
if (!meatPriceInput.value) {
meatPriceInput.value = (i === 4) ? "9,50 € / 6,80 € - Business Lunch 7,50 € / 5,10 €" : "9,00 € / 6,30 € - Business Lunch 7,00 € / 4,90 €";
}
if (!veggiPriceInput.value) {
veggiPriceInput.value = "8,50 € / 5,95 € - Business Lunch 6,50 € / 4,55 €";
}
}
}
})
.catch(error => {
console.error('Error loading week:', error);
alert('Fehler beim Laden der Woche');
});
}
function generatePDF() {
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber}-${year}`;
fetch('/generate-pdf', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ week })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('PDF erfolgreich generiert');
} else {
alert('Fehler beim Generieren der PDF');
}
})
.catch(error => {
console.error('Error generating PDF:', error);
alert('Fehler beim Generieren der PDF');
});
}
// 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>