mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-03 20:12:59 +00:00
Add files via upload
This commit is contained in:
@@ -30,5 +30,7 @@ require (
|
|||||||
golang.org/x/sys v0.31.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
golang.org/x/text v0.23.0 // indirect
|
golang.org/x/text v0.23.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.6 // indirect
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -104,7 +104,11 @@ google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFW
|
|||||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
||||||
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
+402
@@ -0,0 +1,402 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="cs">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Poppe Potthoff - Záznam jízdy služebního vozu</title>
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<script>
|
||||||
|
tailwind.config = {
|
||||||
|
theme: {
|
||||||
|
extend: {
|
||||||
|
colors: {
|
||||||
|
'brand-blue': '#004990',
|
||||||
|
'brand-light-blue': '#0072b0',
|
||||||
|
'brand-gray': '#f0f2f5'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.suggest-container {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.suggest-list {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||||
|
margin-top: 4px;
|
||||||
|
z-index: 100;
|
||||||
|
background: white;
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.suggest-item {
|
||||||
|
padding: 8px 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-bottom: 1px solid #f3f4f6;
|
||||||
|
}
|
||||||
|
.suggest-item:hover, .suggest-item.highlighted {
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
}
|
||||||
|
.suggest-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="bg-brand-gray min-h-screen">
|
||||||
|
<!-- Navigation Bar -->
|
||||||
|
<nav class="bg-brand-blue text-white shadow-lg">
|
||||||
|
<div class="max-w-6xl mx-auto px-4 py-3 flex justify-between items-center">
|
||||||
|
<div class="flex items-center space-x-2">
|
||||||
|
<img src="http://pp-kunovice.cz/wp-content/uploads/2022/04/logo-retina-white.png" alt="Poppe Potthoff Logo" class="h-10">
|
||||||
|
<div class="hidden md:block text-xl font-semibold">Poppe + Potthoff</div>
|
||||||
|
</div>
|
||||||
|
<div class="md:hidden">
|
||||||
|
<button class="focus:outline-none">
|
||||||
|
<i class="fas fa-bars text-xl"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page Header -->
|
||||||
|
<div class="bg-gradient-to-r from-brand-blue to-brand-light-blue text-white py-6 mb-8">
|
||||||
|
<div class="max-w-6xl mx-auto px-4">
|
||||||
|
<h1 class="text-3xl font-bold">Záznam jízdy služebního vozu</h1>
|
||||||
|
<p class="text-gray-100 mt-2">Systém pro evidenci služebních jízd společnosti Poppe + Potthoff</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<div class="max-w-2xl mx-auto px-4 pb-16">
|
||||||
|
<div class="bg-white shadow-xl rounded-lg overflow-hidden">
|
||||||
|
<!-- Card Header -->
|
||||||
|
<div class="bg-brand-blue text-white py-4 px-6 flex items-center">
|
||||||
|
<i class="fas fa-car-side text-xl mr-3"></i>
|
||||||
|
<h2 class="text-xl font-semibold">Nový záznam jízdy</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Form -->
|
||||||
|
<div class="p-6">
|
||||||
|
<form id="tripForm" class="space-y-5">
|
||||||
|
<div class="grid md:grid-cols-2 gap-5">
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="name" class="block text-sm font-medium text-gray-700">Jméno řidiče</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-user text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="text" id="name" name="name" required title="Pouze písmena a mezery, bez čísel a speciálních znaků." pattern="^[A-Za-zÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž\s\-]+$"
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="date" class="block text-sm font-medium text-gray-700">Datum cesty</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-calendar text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="date" id="date" name="date" required
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="destination" class="block text-sm font-medium text-gray-700">Cíl cesty</label>
|
||||||
|
<div class="suggest-container">
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-map-marker-alt text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="text" id="destination" name="destination" required autocomplete="off"
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue"
|
||||||
|
placeholder="Začněte psát pro vyhledání místa...">
|
||||||
|
<div class="absolute inset-y-0 right-0 pr-3 flex items-center">
|
||||||
|
<i class="fas fa-search text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="suggest-list" class="suggest-list"></div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="destination-lat" name="destination-lat">
|
||||||
|
<input type="hidden" id="destination-lon" name="destination-lon">
|
||||||
|
<p class="text-xs text-gray-500">Powered by Mapy.cz</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="purpose" class="block text-sm font-medium text-gray-700">Účel cesty</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-briefcase text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="text" id="purpose" name="purpose" required
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid md:grid-cols-2 gap-5">
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="km_start" class="block text-sm font-medium text-gray-700">Stav tachometru na začátku</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-tachometer-alt text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="number" id="km_start" name="km_start" required min="0"
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue">
|
||||||
|
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
||||||
|
<span class="text-gray-500">km</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label for="km_end" class="block text-sm font-medium text-gray-700">Stav tachometru na konci</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<i class="fas fa-tachometer-alt text-gray-400"></i>
|
||||||
|
</div>
|
||||||
|
<input type="number" id="km_end" name="km_end" required min="0"
|
||||||
|
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-brand-light-blue focus:border-brand-light-blue">
|
||||||
|
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
||||||
|
<span class="text-gray-500">km</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-5 pt-3">
|
||||||
|
<div class="p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div class="flex justify-between items-center">
|
||||||
|
<span class="text-sm text-gray-700">Celkem ujetá vzdálenost:</span>
|
||||||
|
<span id="totalDistance" class="font-bold text-brand-blue">0 km</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pt-2">
|
||||||
|
<button type="submit" class="w-full flex justify-center items-center px-6 py-3 border border-transparent rounded-md shadow-sm text-base font-medium text-white bg-brand-blue hover:bg-brand-light-blue focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-light-blue transition-colors duration-200">
|
||||||
|
<i class="fas fa-save mr-2"></i>
|
||||||
|
Odeslat záznam
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Status Messages -->
|
||||||
|
<div id="message" class="mt-4 py-3 px-4 rounded-md hidden">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<i id="messageIcon" class="mr-2"></i>
|
||||||
|
<p id="messageText" class="text-sm"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="bg-gray-800 text-gray-300 py-8">
|
||||||
|
<div class="max-w-6xl mx-auto px-4">
|
||||||
|
<div class="flex flex-col md:flex-row justify-between">
|
||||||
|
<div class="mb-6 md:mb-0">
|
||||||
|
<img src="http://pp-kunovice.cz/wp-content/uploads/2022/04/logo-retina-white.png" alt="Poppe Potthoff Logo" class="h-8 mb-3">
|
||||||
|
<p class="text-sm">© 2025 Poppe Potthoff CZ. Všechna práva vyhrazena.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-8 text-xs text-gray-400 text-center">
|
||||||
|
<p>Created by: TDvorak 2025</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// API Key for Mapy.cz REST API
|
||||||
|
const API_KEY = "N-p8s7xa3-1ZdYGnvCcSo6RdEOLv1wMI2y74-I9EL98"; //Test API KEY
|
||||||
|
|
||||||
|
const form = document.getElementById('tripForm');
|
||||||
|
const message = document.getElementById('message');
|
||||||
|
const messageText = document.getElementById('messageText');
|
||||||
|
const messageIcon = document.getElementById('messageIcon');
|
||||||
|
const totalDistance = document.getElementById('totalDistance');
|
||||||
|
const kmStart = document.getElementById('km_start');
|
||||||
|
const kmEnd = document.getElementById('km_end');
|
||||||
|
const destinationInput = document.getElementById('destination');
|
||||||
|
const suggestionsList = document.getElementById('suggest-list');
|
||||||
|
const destinationLat = document.getElementById('destination-lat');
|
||||||
|
const destinationLon = document.getElementById('destination-lon');
|
||||||
|
|
||||||
|
let debounceTimer;
|
||||||
|
|
||||||
|
// Event handlers
|
||||||
|
destinationInput.addEventListener('input', function() {
|
||||||
|
clearTimeout(debounceTimer);
|
||||||
|
debounceTimer = setTimeout(() => {
|
||||||
|
const query = destinationInput.value.trim();
|
||||||
|
if (query.length >= 3) {
|
||||||
|
fetchSuggestions(query);
|
||||||
|
} else {
|
||||||
|
suggestionsList.style.display = 'none';
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
destinationInput.addEventListener('focus', function() {
|
||||||
|
if (destinationInput.value.trim().length >= 3) {
|
||||||
|
suggestionsList.style.display = 'block';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (!destinationInput.contains(e.target) && !suggestionsList.contains(e.target)) {
|
||||||
|
suggestionsList.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Suggestions API
|
||||||
|
async function fetchSuggestions(query) {
|
||||||
|
try {
|
||||||
|
const url = `https://api.mapy.cz/v1/suggest?query=${encodeURIComponent(query)}&limit=5&lang=cs&apikey=${API_KEY}`;
|
||||||
|
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
displaySuggestions(data.items);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching suggestions:', error);
|
||||||
|
showMessage('Chyba při načítání našeptávače.', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function displaySuggestions(items) {
|
||||||
|
suggestionsList.innerHTML = '';
|
||||||
|
|
||||||
|
if (items && items.length > 0) {
|
||||||
|
items.forEach(item => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.className = 'suggest-item';
|
||||||
|
div.textContent = item.name;
|
||||||
|
|
||||||
|
div.addEventListener('click', () => {
|
||||||
|
selectSuggestion(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
suggestionsList.appendChild(div);
|
||||||
|
});
|
||||||
|
|
||||||
|
suggestionsList.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
suggestionsList.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectSuggestion(item) {
|
||||||
|
destinationInput.value = item.name;
|
||||||
|
|
||||||
|
// Store coordinates
|
||||||
|
if (item.position && item.position.lat && item.position.lon) {
|
||||||
|
destinationLat.value = item.position.lat;
|
||||||
|
destinationLon.value = item.position.lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
suggestionsList.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate distance
|
||||||
|
function calculateDistance() {
|
||||||
|
const start = parseInt(kmStart.value) || 0;
|
||||||
|
const end = parseInt(kmEnd.value) || 0;
|
||||||
|
const distance = end - start;
|
||||||
|
|
||||||
|
totalDistance.textContent = distance > 0 ? `${distance} km` : '0 km';
|
||||||
|
|
||||||
|
if (distance < 0 && kmEnd.value !== '') {
|
||||||
|
totalDistance.classList.add('text-red-600');
|
||||||
|
totalDistance.classList.remove('text-brand-blue');
|
||||||
|
} else {
|
||||||
|
totalDistance.classList.add('text-brand-blue');
|
||||||
|
totalDistance.classList.remove('text-red-600');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kmStart.addEventListener('input', calculateDistance);
|
||||||
|
kmEnd.addEventListener('input', calculateDistance);
|
||||||
|
|
||||||
|
// Form submission
|
||||||
|
form.addEventListener('submit', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const start = parseInt(kmStart.value);
|
||||||
|
const end = parseInt(kmEnd.value);
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
showMessage('Stav tachometru na konci nemůže být menší než na začátku.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: document.getElementById('name').value,
|
||||||
|
destination: destinationInput.value,
|
||||||
|
date: document.getElementById('date').value,
|
||||||
|
purpose: document.getElementById('purpose').value,
|
||||||
|
km_start: start,
|
||||||
|
km_end: end,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add coordinates if available
|
||||||
|
if (destinationLat.value && destinationLon.value) {
|
||||||
|
data.coordinates = {
|
||||||
|
lat: destinationLat.value,
|
||||||
|
lng: destinationLon.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
showMessage('Odesílání záznamu...', 'info');
|
||||||
|
|
||||||
|
const res = await fetch('http://localhost:8080/submit', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await res.json();
|
||||||
|
showMessage(result.message, 'success');
|
||||||
|
form.reset();
|
||||||
|
totalDistance.textContent = '0 km';
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
showMessage('Nepodařilo se odeslat záznam. Zkontrolujte připojení k internetu.', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function showMessage(text, type) {
|
||||||
|
message.classList.remove('hidden', 'bg-green-50', 'bg-red-50', 'bg-blue-50', 'text-green-800', 'text-red-800', 'text-blue-800');
|
||||||
|
messageText.textContent = text;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case 'success':
|
||||||
|
message.classList.add('bg-green-50', 'text-green-800');
|
||||||
|
messageIcon.className = 'fas fa-check-circle text-green-600 mr-2';
|
||||||
|
break;
|
||||||
|
case 'error':
|
||||||
|
message.classList.add('bg-red-50', 'text-red-800');
|
||||||
|
messageIcon.className = 'fas fa-exclamation-circle text-red-600 mr-2';
|
||||||
|
break;
|
||||||
|
case 'info':
|
||||||
|
message.classList.add('bg-blue-50', 'text-blue-800');
|
||||||
|
messageIcon.className = 'fas fa-info-circle text-blue-600 mr-2';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,117 +1,223 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"crypto/tls"
|
||||||
"log"
|
"encoding/json"
|
||||||
"net/http"
|
"fmt"
|
||||||
"net/smtp"
|
"io"
|
||||||
|
"log"
|
||||||
"github.com/gin-contrib/cors"
|
"net/http"
|
||||||
"github.com/gin-gonic/gin"
|
"os"
|
||||||
)
|
"strings"
|
||||||
|
"time"
|
||||||
type TripEntry struct {
|
|
||||||
Name string `json:"name" binding:"required"`
|
"gopkg.in/gomail.v2"
|
||||||
Destination string `json:"destination" binding:"required"`
|
)
|
||||||
Date string `json:"date" binding:"required"`
|
|
||||||
Purpose string `json:"purpose" binding:"required"`
|
type TripEntry struct {
|
||||||
KmStart int `json:"km_start" binding:"required"`
|
Name string `json:"name"`
|
||||||
KmEnd int `json:"km_end" binding:"required"`
|
Destination string `json:"destination"`
|
||||||
}
|
Date string `json:"date"`
|
||||||
|
Purpose string `json:"purpose"`
|
||||||
func main() {
|
KmStart int `json:"km_start"`
|
||||||
r := gin.Default()
|
KmEnd int `json:"km_end"`
|
||||||
|
Coordinates *GeoCoords `json:"coordinates,omitempty"`
|
||||||
// Enable CORS for all origins
|
}
|
||||||
r.Use(cors.Default())
|
|
||||||
|
type GeoCoords struct {
|
||||||
r.POST("/submit", func(c *gin.Context) {
|
Lat string `json:"lat"`
|
||||||
var entry TripEntry
|
Lng string `json:"lng"`
|
||||||
if err := c.ShouldBindJSON(&entry); err != nil {
|
}
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
func main() {
|
||||||
}
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
// Send email with trip details
|
http.HandleFunc("/submit", enableCORS(handleSubmit))
|
||||||
err := sendEmail(entry)
|
http.HandleFunc("/health", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
w.Header().Set("Content-Type", "application/json")
|
||||||
log.Println("Failed to send email:", err)
|
w.Write([]byte(`{"status":"ok"}`))
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Failed to send email"})
|
}))
|
||||||
return
|
|
||||||
}
|
http.HandleFunc("/", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.ServeFile(w, r, "index.html")
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Entry submitted and email sent successfully"})
|
}))
|
||||||
})
|
|
||||||
|
port := os.Getenv("PORT")
|
||||||
r.Run(":8080")
|
if port == "" {
|
||||||
}
|
port = "8080"
|
||||||
|
}
|
||||||
func sendEmail(entry TripEntry) error {
|
|
||||||
smtpHost := "smtp.gmail.com"
|
log.Printf("Server běží na portu %s", port)
|
||||||
smtpPort := "465"
|
err := http.ListenAndServe(":"+port, nil)
|
||||||
sender := "contact.dvorak@gmail.com"
|
if err != nil {
|
||||||
password := "pnhkcsahbwsbpyqj"
|
log.Fatalf("Chyba při spuštění serveru: %v", err)
|
||||||
recipient := "contact.dvorak@gmail.com"
|
}
|
||||||
|
}
|
||||||
auth := smtp.PlainAuth("", sender, password, smtpHost)
|
|
||||||
|
func enableCORS(next http.HandlerFunc) http.HandlerFunc {
|
||||||
subject := "Nový záznam o jízdě služebním autem"
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
body := fmt.Sprintf(`
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||||
<html>
|
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
|
||||||
<head>
|
|
||||||
<style>
|
if r.Method == "OPTIONS" {
|
||||||
body {
|
w.WriteHeader(http.StatusOK)
|
||||||
font-family: Arial, sans-serif;
|
return
|
||||||
background-color: #f9f9f9;
|
}
|
||||||
padding: 20px;
|
|
||||||
}
|
if next != nil {
|
||||||
.container {
|
next(w, r)
|
||||||
background-color: #ffffff;
|
}
|
||||||
border: 1px solid #ddd;
|
}
|
||||||
border-radius: 8px;
|
}
|
||||||
padding: 20px;
|
|
||||||
max-width: 600px;
|
func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
||||||
margin: auto;
|
w.Header().Set("Content-Type", "application/json")
|
||||||
}
|
|
||||||
h2 {
|
if r.Method != http.MethodPost {
|
||||||
color: #2c3e50;
|
if r.Method == http.MethodOptions {
|
||||||
border-bottom: 2px solid #3498db;
|
w.WriteHeader(http.StatusOK)
|
||||||
padding-bottom: 10px;
|
return
|
||||||
}
|
}
|
||||||
p {
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
font-size: 16px;
|
w.Write([]byte(`{"error":"Only POST method is allowed"}`))
|
||||||
color: #34495e;
|
return
|
||||||
line-height: 1.5;
|
}
|
||||||
}
|
|
||||||
.label {
|
body, err := io.ReadAll(r.Body)
|
||||||
font-weight: bold;
|
if err != nil {
|
||||||
color: #2980b9;
|
log.Printf("Chyba při čtení těla požadavku: %v", err)
|
||||||
}
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
</style>
|
w.Write([]byte(`{"error":"Failed to read request body"}`))
|
||||||
</head>
|
return
|
||||||
<body>
|
}
|
||||||
<div class="container">
|
defer r.Body.Close()
|
||||||
<h2>Záznam o jízdě služebním autem</h2>
|
|
||||||
<p><span class="label">Řidič:</span> %s</p>
|
log.Printf("Přijatá data: %s", string(body))
|
||||||
<p><span class="label">Kam:</span> %s</p>
|
|
||||||
<p><span class="label">Datum:</span> %s</p>
|
var entry TripEntry
|
||||||
<p><span class="label">Účel jízdy:</span> %s</p>
|
err = json.Unmarshal(body, &entry)
|
||||||
<p><span class="label">Kilometry na začátku:</span> %d km</p>
|
if err != nil {
|
||||||
<p><span class="label">Kilometry na konci:</span> %d km</p>
|
log.Printf("Chyba při parsování JSON: %v", err)
|
||||||
<p><span class="label">Ujeté kilometry:</span> %d km</p>
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
</div>
|
w.Write([]byte(fmt.Sprintf(`{"error":"Failed to parse JSON: %v"}`, err)))
|
||||||
</body>
|
return
|
||||||
</html>
|
}
|
||||||
`, entry.Name, entry.Destination, entry.Date, entry.Purpose, entry.KmStart, entry.KmEnd, entry.KmEnd-entry.KmStart)
|
|
||||||
|
if entry.Name == "" || entry.Destination == "" || entry.Date == "" || entry.Purpose == "" {
|
||||||
msg := []byte(
|
log.Printf("Chybějící povinná pole: %+v", entry)
|
||||||
"MIME-Version: 1.0\r\n" +
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
"Content-Type: text/html; charset=\"UTF-8\"\r\n" +
|
w.Write([]byte(`{"error":"Missing required fields"}`))
|
||||||
"To: " + recipient + "\r\n" +
|
return
|
||||||
"Subject: " + subject + "\r\n" +
|
}
|
||||||
"\r\n" + body + "\r\n",
|
|
||||||
)
|
if entry.KmEnd < entry.KmStart {
|
||||||
|
log.Printf("Neplatný stav tachometru: %d -> %d", entry.KmStart, entry.KmEnd)
|
||||||
return smtp.SendMail(smtpHost+":"+smtpPort, auth, sender, []string{recipient}, msg)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
}
|
w.Write([]byte(`{"error":"End kilometers must be greater than or equal to start kilometers"}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Formátování data do českého formátu
|
||||||
|
parsedDate, err := time.Parse("2006-01-02", entry.Date)
|
||||||
|
if err == nil {
|
||||||
|
czechMonths := []string{
|
||||||
|
"ledna", "února", "března", "dubna", "května", "června",
|
||||||
|
"července", "srpna", "září", "října", "listopadu", "prosince",
|
||||||
|
}
|
||||||
|
monthName := czechMonths[parsedDate.Month()-1]
|
||||||
|
entry.Date = fmt.Sprintf("%d. %s %d", parsedDate.Day(), monthName, parsedDate.Year())
|
||||||
|
} else {
|
||||||
|
log.Printf("Chyba při parsování data: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sendEmail(entry)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Chyba při odesílání emailu: %v", err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte(fmt.Sprintf(`{"error":"Failed to send email: %v"}`, err)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte(`{"message":"Záznam byl úspěšně uložen a email odeslán"}`))
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendEmail(entry TripEntry) error {
|
||||||
|
smtpHost := "mail.pp-kunovice.cz"
|
||||||
|
smtpPort := 465
|
||||||
|
sender := "sluzebnicek@pp-kunovice.cz"
|
||||||
|
password := "7g}qznB5bj"
|
||||||
|
recipient := "sluzebnicek@pp-kunovice.cz"
|
||||||
|
|
||||||
|
m := gomail.NewMessage()
|
||||||
|
m.SetHeader("From", sender)
|
||||||
|
m.SetHeader("To", recipient)
|
||||||
|
m.SetHeader("Subject", "Nový záznam o jízdě služebním autem")
|
||||||
|
|
||||||
|
var htmlContent strings.Builder
|
||||||
|
|
||||||
|
htmlContent.WriteString(`
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
color: #2c3e50;
|
||||||
|
border-bottom: 2px solid #3498db;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #34495e;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.label {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #2980b9;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Záznam o jízdě služebním autem</h2>
|
||||||
|
`)
|
||||||
|
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Řidič:</span> %s</p>`, entry.Name)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Kam:</span> %s</p>`, entry.Destination)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Datum:</span> %s</p>`, entry.Date)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Účel jízdy:</span> %s</p>`, entry.Purpose)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Kilometry na začátku:</span> %d km</p>`, entry.KmStart)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Kilometry na konci:</span> %d km</p>`, entry.KmEnd)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">Ujeté kilometry:</span> %d km</p>`, entry.KmEnd-entry.KmStart)
|
||||||
|
|
||||||
|
if entry.Coordinates != nil {
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><span class="label">GPS souřadnice:</span> %s, %s</p>`, entry.Coordinates.Lat, entry.Coordinates.Lng)
|
||||||
|
fmt.Fprintf(&htmlContent, `<p><a href="https://mapy.cz/zakladni?x=%s&y=%s&z=15" target="_blank">Zobrazit na mapě</a></p>`, entry.Coordinates.Lng, entry.Coordinates.Lat)
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlContent.WriteString(`
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`)
|
||||||
|
|
||||||
|
m.SetBody("text/html", htmlContent.String())
|
||||||
|
|
||||||
|
d := gomail.NewDialer(smtpHost, smtpPort, sender, password)
|
||||||
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
|
|
||||||
|
return d.DialAndSend(m)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user