197 lines
7.2 KiB
PHP
197 lines
7.2 KiB
PHP
<?php require_once '../Connections/cmctrfdb.php'; ?>
|
|
<?php require_once '../webassist/mysqli/rsobj.php'; ?>
|
|
<?php
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', TRUE);
|
|
ini_set('display_startup_errors', TRUE);
|
|
include 'include/headscript.php';
|
|
include('languages/' . $_SESSION['langselect'] . '/tdgen.php');
|
|
?>
|
|
<?php
|
|
// Controlla se il form è stato inviato
|
|
if (isset($_POST['submit'])) {
|
|
$description = $_POST['descriptionlogo']; // Assumi che la validazione dell'input sia già stata fatta
|
|
$targetDir = "logos/"; // Assicurati che questa directory esista e sia scrivibile
|
|
|
|
$file = $_FILES['logofile'];
|
|
$fileName = $file['name'];
|
|
$fileTmpName = $file['tmp_name'];
|
|
$fileError = $file['error'];
|
|
|
|
// Estrai l'estensione del file
|
|
$exploded = explode('.', $fileName);
|
|
$fileExt = strtolower(end($exploded));
|
|
|
|
// Controlla se non ci sono errori e se il file è un PNG o JPG
|
|
if ($fileError === 0 && ($fileExt === 'png' || $fileExt === 'jpg' || $fileExt === 'jpeg')) {
|
|
$newFileName = $idcompany . "_" . time() . "." . $fileExt; // Rinomina il file
|
|
$fileDestination = $targetDir . $newFileName;
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
// Sposta il file nella directory definitiva
|
|
if (move_uploaded_file($fileTmpName, $fileDestination)) {
|
|
// Qui esegui l'inserimento nel database
|
|
$sql = "INSERT INTO logo_td (descriptionlogo, filenamelogo, idcompany) VALUES (?, ?, ?)";
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
if ($stmt) {
|
|
|
|
$stmt->bind_param("ssi", $description, $newFileName, $idcompany);
|
|
$stmt->execute();
|
|
} else {
|
|
echo "Errore durante l'inserimento nel database.";
|
|
}
|
|
} else {
|
|
echo "C'è stato un errore nel caricamento del file.";
|
|
}
|
|
} else {
|
|
echo "Sono ammessi solo file PNG e JPG.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Aggiungi Logo</title>
|
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
|
|
|
|
<style>
|
|
.drag-area {
|
|
border: 2px dashed #ccc;
|
|
border-radius: 20px;
|
|
width: auto;
|
|
margin: 10px 0;
|
|
padding: 20px;
|
|
text-align: center;
|
|
font-size: 20px;
|
|
color: #ccc;
|
|
}
|
|
|
|
.drag-area.highlight {
|
|
border-color: blue;
|
|
background-color: rgba(0, 0, 255, 0.1);
|
|
}
|
|
|
|
.custom-file-label::after {
|
|
content: "Sfoglia";
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container mt-5">
|
|
<button onclick="closeAndRefresh()">Chiudi e Aggiorna</button>
|
|
<h3 style="display: inline-block;">Aggiungi Logo</h3>
|
|
|
|
<form id="uploadLogoForm" action="logopopup.php" method="post" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="logoDescription">Descrizione Logo:</label>
|
|
<input type="text" class="form-control" id="logoDescription" name="descriptionlogo" required>
|
|
</div>
|
|
|
|
<div class="drag-area" id="drag-area">
|
|
<p>Trascina qui il file o clicca per selezionare</p>
|
|
</div>
|
|
|
|
<div class="custom-file mb-3">
|
|
<input type="file" class="custom-file-input" id="logoFile" name="logofile" accept=".png, .jpg, .jpeg" required hidden>
|
|
<label class="custom-file-label" for="logoFile">Scegli file</label>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary" name="submit">Carica Logo</button>
|
|
</form>
|
|
</div>
|
|
<div class="container mt-5">
|
|
<h3>Loghi Caricati</h3>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Descrizione</th>
|
|
<th>Logo</th>
|
|
<th>Azione</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
$query = "SELECT idlogo_td, descriptionlogo, filenamelogo FROM logo_td WHERE idcompany = ?";
|
|
$stmt = $conn->prepare($query);
|
|
$stmt->bind_param("i", $idcompany); // Assumi che $idcompany sia già definita e pulita
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
echo "<tr>";
|
|
echo "<td>" . htmlspecialchars($row['descriptionlogo']) . "</td>";
|
|
echo "<td><img src='logos/" . htmlspecialchars($row['filenamelogo']) . "' alt='Logo' style='width: 50px;'></td>";
|
|
echo "<td><a href='deleteLogo.php?id=" . $row['idlogo_td'] . "' onclick='return confirm(\"Sei sicuro di voler cancellare questo logo?\");'><i class='fas fa-trash-alt' style='color: red;'></i></a></td>";
|
|
echo "</tr>";
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
<script>
|
|
// Mostra il nome del file nel campo custom file di Bootstrap quando selezionato
|
|
$(".custom-file-input").on("change", function() {
|
|
var fileName = $(this).val().split("\\").pop();
|
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
|
});
|
|
|
|
var dragArea = document.getElementById('drag-area');
|
|
var input = document.getElementById('logoFile');
|
|
|
|
// Highlight drag area
|
|
['dragenter', 'dragover'].forEach(eventName => {
|
|
dragArea.addEventListener(eventName, (e) => {
|
|
preventDefaults(e);
|
|
dragArea.classList.add('highlight');
|
|
}, false);
|
|
});
|
|
|
|
// Unhighlight drag area
|
|
['dragleave', 'drop'].forEach(eventName => {
|
|
dragArea.addEventListener(eventName, (e) => {
|
|
preventDefaults(e);
|
|
dragArea.classList.remove('highlight');
|
|
}, false);
|
|
});
|
|
|
|
// Handle drop
|
|
dragArea.addEventListener('drop', (e) => {
|
|
preventDefaults(e);
|
|
let dt = e.dataTransfer;
|
|
let files = dt.files;
|
|
input.files = files;
|
|
$(".custom-file-label").addClass("selected").html(files[0].name);
|
|
}, false);
|
|
|
|
function preventDefaults(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
// Click on drag area to open file dialog
|
|
dragArea.addEventListener('click', () => input.click());
|
|
</script>
|
|
<script>
|
|
function closeAndRefresh() {
|
|
if (window.opener && !window.opener.closed) {
|
|
window.opener.updateSelectDropdown();
|
|
}
|
|
window.close();
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|