146 lines
4.3 KiB
PHP
146 lines
4.3 KiB
PHP
<?php
|
|
// upload_photos_mobile.php
|
|
include('include/headscript.php');
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
// Verifica che l'iddatadb sia stato passato
|
|
if (!isset($_GET['iddatadb']) || empty($_GET['iddatadb'])) {
|
|
die('ID riga non fornito');
|
|
}
|
|
|
|
$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) {
|
|
die('Riga non trovata');
|
|
}
|
|
|
|
$idriga = $row['iddatadb'];
|
|
$sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Carica Foto da Mobile</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.upload-area {
|
|
border: 2px dashed #ccc;
|
|
padding: 20px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.upload-area.highlight {
|
|
border-color: #28a745;
|
|
background-color: #e9ecef;
|
|
}
|
|
|
|
.photo-item {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 10px;
|
|
border-bottom: 1px solid #eee;
|
|
padding-bottom: 10px;
|
|
}
|
|
|
|
.photo-item img {
|
|
max-width: 100px;
|
|
max-height: 100px;
|
|
margin-right: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h2>Carica Foto per ID Riga: <?= htmlspecialchars($idriga) ?></h2>
|
|
<p><strong>Sample Code:</strong> <?= htmlspecialchars($sampleCode) ?></p>
|
|
|
|
<div class="upload-area" id="uploadArea">
|
|
<p>Scatta una foto o seleziona un'immagine</p>
|
|
<input type="file" id="photoInput" accept="image/*" capture="camera">
|
|
</div>
|
|
|
|
<div id="photosList">
|
|
<!-- Le foto verranno caricate dinamicamente -->
|
|
</div>
|
|
|
|
<script>
|
|
const uploadArea = document.getElementById('uploadArea');
|
|
const photoInput = document.getElementById('photoInput');
|
|
const photosList = document.getElementById('photosList');
|
|
|
|
// Carica le foto esistenti all'avvio
|
|
loadPhotos();
|
|
|
|
// Gestione del click sull'area di upload
|
|
uploadArea.addEventListener('click', () => {
|
|
photoInput.click();
|
|
});
|
|
|
|
// Gestione del caricamento delle foto
|
|
photoInput.addEventListener('change', () => {
|
|
handleFiles(photoInput.files);
|
|
});
|
|
|
|
async function handleFiles(files) {
|
|
for (const file of files) {
|
|
if (!file.type.startsWith('image/')) {
|
|
alert('Per favore, carica solo immagini!');
|
|
continue;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('photo', file);
|
|
formData.append('iddatadb', '<?= $iddatadb ?>');
|
|
|
|
try {
|
|
const response = await fetch('upload_photo.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
loadPhotos(); // Ricarica le foto
|
|
} else {
|
|
alert('Errore durante il caricamento: ' + result.message);
|
|
}
|
|
} catch (error) {
|
|
alert('Errore durante il caricamento: ' + error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Funzione per caricare le foto esistenti
|
|
async function loadPhotos() {
|
|
try {
|
|
const response = await fetch(`photos_popup.php?iddatadb=<?= $iddatadb ?>`);
|
|
const html = await response.text();
|
|
const parser = new DOMParser();
|
|
const doc = parser.parseFromString(html, 'text/html');
|
|
const photosListContent = doc.querySelector('#photosList').innerHTML;
|
|
photosList.innerHTML = photosListContent;
|
|
} catch (error) {
|
|
photosList.innerHTML = `<p>Errore durante il caricamento delle foto: ${error.message}</p>`;
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|