added photo functionality
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
// photos_popup.php
|
||||
include('include/headscript.php');
|
||||
// Includi l'autoloader di Composer
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\Encoding\Encoding;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\RoundBlockSizeMode;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Verifica che l'iddatadb sia stato passato
|
||||
if (!isset($_GET['iddatadb']) || empty($_GET['iddatadb'])) {
|
||||
echo json_encode(['error' => 'ID riga non fornito']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$iddatadb = intval($_GET['iddatadb']);
|
||||
|
||||
// Recupera i dettagli della riga (idriga e sample_code)
|
||||
$stmt = $pdo->prepare("SELECT iddatadb, sample_code FROM datadb WHERE iddatadb = ?");
|
||||
$stmt->execute([$iddatadb]);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'Riga non trovata']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$idriga = $row['iddatadb'];
|
||||
$sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||
|
||||
// Recupera le foto associate alla riga
|
||||
$stmt = $pdo->prepare("SELECT id, file_path, file_name, description, uploaded_at FROM datadb_photos WHERE iddatadb = ? ORDER BY uploaded_at DESC");
|
||||
$stmt->execute([$iddatadb]);
|
||||
$photos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Definisci il percorso base per le foto
|
||||
$photoBasePath = '../photostrf/';
|
||||
|
||||
// Genera l'URL per il QR code
|
||||
$baseUrl = "http://localhost/trf_certest/public/userarea/"; // Sostituisci con il tuo dominio
|
||||
$uploadUrl = $baseUrl . "upload_photos_mobile.php?iddatadb=" . $iddatadb;
|
||||
|
||||
// Genera il QR code con endroid/qr-code 6.0.6
|
||||
$qrCodeDir = '../photostrf/qrcodes/';
|
||||
if (!is_dir($qrCodeDir)) {
|
||||
mkdir($qrCodeDir, 0755, true);
|
||||
}
|
||||
$qrCodeFile = $qrCodeDir . "qrcode_{$iddatadb}.png";
|
||||
|
||||
$writer = new PngWriter();
|
||||
|
||||
// Crea il QR code usando il costruttore
|
||||
$qrCode = new QrCode(
|
||||
data: $uploadUrl,
|
||||
encoding: new Encoding('UTF-8'),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::Low,
|
||||
size: 150,
|
||||
margin: 10,
|
||||
roundBlockSizeMode: RoundBlockSizeMode::Margin,
|
||||
foregroundColor: new Color(0, 0, 0),
|
||||
backgroundColor: new Color(255, 255, 255)
|
||||
);
|
||||
|
||||
$result = $writer->write($qrCode);
|
||||
$result->saveToFile($qrCodeFile);
|
||||
?>
|
||||
|
||||
<div class="popup-content">
|
||||
<h3>Gestione Foto</h3>
|
||||
<p><strong>ID Riga:</strong> <?= htmlspecialchars($idriga) ?></p>
|
||||
<p><strong>Sample Code:</strong> <?= htmlspecialchars($sampleCode) ?></p>
|
||||
|
||||
<!-- QR Code per il caricamento da mobile -->
|
||||
<div style="text-align: center; margin-bottom: 20px;">
|
||||
<p>Scansiona il QR code per caricare foto dal tuo telefono:</p>
|
||||
<img src="../photostrf/qrcodes/qrcode_<?= $iddatadb ?>.png" alt="QR Code" style="max-width: 150px;">
|
||||
<p style="margin-top: 10px;">
|
||||
<a href="<?= htmlspecialchars($uploadUrl) ?>" target="_blank"><?= htmlspecialchars($uploadUrl) ?></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Area drag-and-drop per il caricamento delle foto -->
|
||||
<div id="dropArea" style="border: 2px dashed #ccc; padding: 20px; text-align: center; margin-bottom: 20px;">
|
||||
<p>Trascina qui le foto o clicca per selezionarle</p>
|
||||
<input type="file" id="photoInput" multiple accept="image/*" style="display: none;">
|
||||
</div>
|
||||
|
||||
<!-- Elenco delle foto -->
|
||||
<div id="photosList">
|
||||
<?php if (empty($photos)): ?>
|
||||
<p>Nessuna foto presente.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($photos as $photo): ?>
|
||||
<?php
|
||||
$filePath = $photoBasePath . $photo['file_path'];
|
||||
$fileExists = file_exists($filePath);
|
||||
?>
|
||||
<div class="photo-item" data-photo-id="<?= $photo['id'] ?>" style="display: flex; align-items: center; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 10px;">
|
||||
<div style="flex: 1;">
|
||||
<?php if ($fileExists): ?>
|
||||
<img src="../photostrf/<?= htmlspecialchars($photo['file_path']) ?>" alt="<?= htmlspecialchars($photo['file_name']) ?>" style="max-width: 100px; max-height: 100px; margin-right: 10px;">
|
||||
<?php else: ?>
|
||||
<p style="color: red;">[File non trovato]</p>
|
||||
<?php endif; ?>
|
||||
<p style="margin: 0;">
|
||||
<strong>Nome:</strong> <?= htmlspecialchars($photo['file_name']) ?><br>
|
||||
<strong>Caricata il:</strong> <?= htmlspecialchars($photo['uploaded_at']) ?><br>
|
||||
<strong>Descrizione:</strong> <?= htmlspecialchars($photo['description'] ?? 'Nessuna descrizione') ?>
|
||||
</p>
|
||||
</div>
|
||||
<button class="delete-photo-btn" data-photo-id="<?= $photo['id'] ?>" style="background: none; border: none; color: #dc3545; cursor: pointer;">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.photo-item {
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.photo-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
#dropArea.highlight {
|
||||
border-color: #28a745;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user