Files
karczma-aplikacja-stoliki/public/staff/generator.php

100 lines
3.8 KiB
PHP

<?php
require_once __DIR__ . '/../../config/database.php';
$tsql = "SELECT ID, Nazwa FROM dbo.NGastroStolik ORDER BY Nazwa";
$stmt = sqlsrv_query($conn, $tsql);
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$baseUrl = "https://$host/app/public/app.html?h=";
echo "<!DOCTYPE html>
<html lang='pl'>
<head>
<meta charset='UTF-8'>
<title>Generator Linków QR - Stoliki</title>
<style>
body { font-family: sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; max-width: 800px; }
th, td { border: 1px solid #ccc; padding: 10px; text-align: left; }
th { background: #eee; }
a { color: #0066cc; text-decoration: none; }
a:hover { text-decoration: underline; }
.btn-qr { padding: 5px 10px; background: #3b82f6; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.btn-qr:hover { background: #2563eb; }
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); align-items: center; justify-content: center; }
.modal-content { background: #fff; padding: 20px; border-radius: 8px; text-align: center; max-width: 400px; width: 90%; }
.close { float: right; font-size: 24px; font-weight: bold; cursor: pointer; line-height: 20px; }
#qrcode { margin-top: 20px; display: flex; justify-content: center; }
</style>
<script src='https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js'></script>
</head>
<body>
<h1>Linki do aplikacji (Kody QR)</h1>
<p>Skopiuj poniższe linki lub wygeneruj z nich kody QR do umieszczenia na stolikach.</p>
<table>
<tr>
<th>Nazwa stolika</th>
<th>Hash (ID z bazy)</th>
<th>Bezpieczny Link (KOD QR)</th>
<th>Akcje</th>
</tr>";
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$id = strtoupper($row['ID']);
$nazwa = htmlspecialchars($row['Nazwa']);
$link = $baseUrl . $id;
echo "<tr>
<td><strong>$nazwa</strong></td>
<td style='font-size: 0.8em; color: #666;'>$id</td>
<td><a href='$link' target='_blank'>$link</a></td>
<td><button class='btn-qr' onclick='openQR(\"$link\", \"$nazwa\")'>Pokaż QR</button></td>
</tr>";
}
echo " </table>
<div id='qrModal' class='modal'>
<div class='modal-content'>
<span class='close' onclick='closeQR()'>&times;</span>
<h2 id='qrTitle'>Kod QR</h2>
<div id='qrcode'></div>
<p style='margin-top:20px;'><a id='qrLink' href='' target='_blank' style='color: #3b82f6;'>Otwórz link w nowym oknie</a></p>
</div>
</div>
<script>
function openQR(link, nazwa) {
document.getElementById('qrModal').style.display = 'flex';
document.getElementById('qrTitle').innerText = 'Stolik: ' + nazwa;
document.getElementById('qrLink').href = link;
var qrContainer = document.getElementById('qrcode');
qrContainer.innerHTML = ''; // Wyczyść poprzedni kod
new QRCode(qrContainer, {
text: link,
width: 250,
height: 250,
colorDark : '#000000',
colorLight : '#ffffff',
correctLevel : QRCode.CorrectLevel.H
});
}
function closeQR() {
document.getElementById('qrModal').style.display = 'none';
}
window.onclick = function(event) {
var modal = document.getElementById('qrModal');
if (event.target == modal) {
closeQR();
}
}
</script>
</body>
</html>";
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);