fixed quotations
This commit is contained in:
@@ -5,24 +5,41 @@ 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');
|
||||
// Verifica che almeno uno degli ID sia passato
|
||||
$iddatadb = isset($_GET['iddatadb']) && !empty($_GET['iddatadb']) ? intval($_GET['iddatadb']) : null;
|
||||
$idquotations = isset($_GET['idquotations']) && !empty($_GET['idquotations']) ? intval($_GET['idquotations']) : null;
|
||||
|
||||
if (!$iddatadb && !$idquotations) {
|
||||
die('ID riga o ID quotations non fornito');
|
||||
}
|
||||
|
||||
$iddatadb = intval($_GET['iddatadb']);
|
||||
if ($iddatadb && $idquotations) {
|
||||
die('Non è possibile specificare sia iddatadb che idquotations');
|
||||
}
|
||||
|
||||
// Recupera i dettagli della riga (idriga e sample_code)
|
||||
$stmt = $pdo->prepare("SELECT iddatadb, sample_code FROM datadb WHERE iddatadb = ?");
|
||||
$stmt->execute([$iddatadb]);
|
||||
// Verifica che l'utente loggato esista
|
||||
$stmt = $pdo->prepare("SELECT id FROM auth_users WHERE id = ?");
|
||||
$stmt->execute([$iduserlogin]);
|
||||
if (!$stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
die('Utente non valido');
|
||||
}
|
||||
|
||||
// Determina quale ID usare e verifica l'esistenza
|
||||
$paramName = $iddatadb ? 'iddatadb' : 'idquotations';
|
||||
$paramValue = $iddatadb ?: $idquotations;
|
||||
$table = $iddatadb ? 'datadb' : 'quotations';
|
||||
$field = $iddatadb ? 'sample_code' : 'quotation_code';
|
||||
|
||||
$stmt = $pdo->prepare("SELECT {$paramName}, {$field} FROM {$table} WHERE {$paramName} = ?");
|
||||
$stmt->execute([$paramValue]);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
die('Riga non trovata');
|
||||
}
|
||||
|
||||
$idriga = $row['iddatadb'];
|
||||
$sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||
$id = $row[$paramName];
|
||||
$code = $row[$field] ?? 'Non disponibile';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -32,17 +49,23 @@ $sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Carica Foto da Mobile</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
background: #f4f4f4;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
border: 2px dashed #ccc;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
margin: 20px auto;
|
||||
max-width: 500px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.upload-area.highlight {
|
||||
@@ -56,57 +79,121 @@ $sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
max-width: 500px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.photo-item img {
|
||||
max-width: 100px;
|
||||
max-height: 100px;
|
||||
margin-right: 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.loader {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.loader i {
|
||||
font-size: 40px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: red;
|
||||
margin: 10px 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
button.delete-photo-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #dc3545;
|
||||
cursor: pointer;
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Carica Foto per ID Riga: <?= htmlspecialchars($idriga) ?></h2>
|
||||
<p><strong>Sample Code:</strong> <?= htmlspecialchars($sampleCode) ?></p>
|
||||
|
||||
<h2>Carica Foto per ID: <?= htmlspecialchars($id) ?></h2>
|
||||
<p><strong>Codice:</strong> <?= htmlspecialchars($code) ?></p>
|
||||
<div class="loader" id="loader">
|
||||
<div>
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
<p>Caricamento in corso...</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="error-message" id="errorMessage"></div>
|
||||
<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 -->
|
||||
<p>Scatta una foto o seleziona immagini</p>
|
||||
<input type="file" id="photoInput" accept="image/*" capture="camera" multiple style="display: none;">
|
||||
</div>
|
||||
<div id="photosList"></div>
|
||||
|
||||
<script>
|
||||
const uploadArea = document.getElementById('uploadArea');
|
||||
const photoInput = document.getElementById('photoInput');
|
||||
const photosList = document.getElementById('photosList');
|
||||
const loader = document.getElementById('loader');
|
||||
const errorMessage = document.getElementById('errorMessage');
|
||||
const iddatadb = '<?= $iddatadb ?>';
|
||||
const idquotations = '<?= $idquotations ?>';
|
||||
const endpoint = idquotations ? 'load_photo_quotation.php' : 'load_photo.php';
|
||||
const dataParam = idquotations ? {
|
||||
idquotations: idquotations
|
||||
} : {
|
||||
iddatadb: iddatadb
|
||||
};
|
||||
|
||||
// Carica le foto esistenti all'avvio
|
||||
loadPhotos();
|
||||
|
||||
// Gestione del click sull'area di upload
|
||||
uploadArea.addEventListener('click', () => {
|
||||
photoInput.click();
|
||||
// Gestione drag-and-drop
|
||||
uploadArea.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
uploadArea.classList.add('highlight');
|
||||
});
|
||||
uploadArea.addEventListener('dragleave', () => {
|
||||
uploadArea.classList.remove('highlight');
|
||||
});
|
||||
uploadArea.addEventListener('drop', (e) => {
|
||||
e.preventDefault();
|
||||
uploadArea.classList.remove('highlight');
|
||||
handleFiles(e.dataTransfer.files);
|
||||
});
|
||||
|
||||
// Gestione del caricamento delle foto
|
||||
photoInput.addEventListener('change', () => {
|
||||
handleFiles(photoInput.files);
|
||||
});
|
||||
// Gestione click sull'area di upload
|
||||
uploadArea.addEventListener('click', () => photoInput.click());
|
||||
|
||||
// Gestione caricamento foto
|
||||
photoInput.addEventListener('change', () => handleFiles(photoInput.files));
|
||||
|
||||
async function handleFiles(files) {
|
||||
loader.style.display = 'flex';
|
||||
errorMessage.style.display = 'none';
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
alert('Per favore, carica solo immagini!');
|
||||
showError('Per favore, carica solo immagini!');
|
||||
continue;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('photo', file);
|
||||
formData.append('iddatadb', '<?= $iddatadb ?>');
|
||||
if (iddatadb) formData.append('iddatadb', iddatadb);
|
||||
if (idquotations) formData.append('idquotations', idquotations);
|
||||
|
||||
try {
|
||||
const response = await fetch('upload_photo.php', {
|
||||
@@ -114,32 +201,86 @@ $sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
loadPhotos(); // Ricarica le foto
|
||||
} else {
|
||||
alert('Errore durante il caricamento: ' + result.message);
|
||||
if (!result.success) {
|
||||
showError('Errore durante il caricamento: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Errore durante il caricamento: ' + error.message);
|
||||
showError('Errore di rete: ' + error.message);
|
||||
}
|
||||
}
|
||||
loadPhotos();
|
||||
loader.style.display = 'none';
|
||||
}
|
||||
|
||||
// Funzione per caricare le foto esistenti
|
||||
async function loadPhotos() {
|
||||
loader.style.display = 'flex';
|
||||
errorMessage.style.display = 'none';
|
||||
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;
|
||||
const response = await fetch(`${endpoint}?${new URLSearchParams(dataParam)}`);
|
||||
const result = await response.json();
|
||||
photosList.innerHTML = '';
|
||||
if (result.success && result.photos && result.photos.length > 0) {
|
||||
for (const photo of result.photos) {
|
||||
const photoName = photo.split('/').pop();
|
||||
const photoItem = document.createElement('div');
|
||||
photoItem.className = 'photo-item';
|
||||
photoItem.innerHTML = `
|
||||
<img src="${photo}" alt="${photoName}">
|
||||
<div style="flex: 1; text-align: left;">
|
||||
<strong>Nome:</strong> ${photoName}<br>
|
||||
<strong>Caricata il:</strong> Non disponibile
|
||||
</div>
|
||||
<button class="delete-photo-btn" data-photo-path="${photo}">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>`;
|
||||
photosList.appendChild(photoItem);
|
||||
}
|
||||
} else {
|
||||
photosList.innerHTML = '<p>Nessuna foto presente.</p>';
|
||||
}
|
||||
} catch (error) {
|
||||
photosList.innerHTML = `<p>Errore durante il caricamento delle foto: ${error.message}</p>`;
|
||||
showError('Errore durante il caricamento delle foto: ' + error.message);
|
||||
}
|
||||
loader.style.display = 'none';
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
errorMessage.textContent = message;
|
||||
errorMessage.style.display = 'block';
|
||||
setTimeout(() => errorMessage.style.display = 'none', 5000);
|
||||
}
|
||||
|
||||
// Gestione eliminazione foto
|
||||
photosList.addEventListener('click', async (e) => {
|
||||
if (e.target.closest('.delete-photo-btn')) {
|
||||
const button = e.target.closest('.delete-photo-btn');
|
||||
const photoPath = button.dataset.photoPath;
|
||||
if (confirm('Sei sicuro di voler eliminare questa foto?')) {
|
||||
loader.style.display = 'flex';
|
||||
try {
|
||||
const response = await fetch('delete_photo.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
file_path: photoPath
|
||||
})
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
loadPhotos();
|
||||
} else {
|
||||
showError('Errore durante l\'eliminazione: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError('Errore durante l\'eliminazione: ' + error.message);
|
||||
}
|
||||
loader.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
Reference in New Issue
Block a user