193 lines
8.4 KiB
PHP
193 lines
8.4 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
|
|
// Check if the form has been submitted
|
|
if (isset($_POST['submit'])) {
|
|
$description = $_POST['descriptionlogo']; // Assume input validation is already done
|
|
$targetDir = "logos/"; // Ensure this directory exists and is writable
|
|
|
|
$loadedFile = $_FILES['logofile'];
|
|
$fileName = $loadedFile['name'];
|
|
$fileTmpName = $loadedFile['tmp_name'];
|
|
$fileError = $loadedFile['error'];
|
|
|
|
// Extract file extension
|
|
$exploded = explode('.', $fileName);
|
|
$fileExt = strtolower(end($exploded));
|
|
|
|
// Check for errors and if file is PNG or JPG
|
|
if ($fileError === 0 && ($fileExt === 'png' || $fileExt === 'jpg' || $fileExt === 'jpeg')) {
|
|
$newFileName = $idcompany . "_" . time() . "." . $fileExt; // Rename file
|
|
$fileDestination = $targetDir . $newFileName;
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
// Move file to destination directory
|
|
if (move_uploaded_file($fileTmpName, $fileDestination)) {
|
|
// Perform database insertion
|
|
$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 ($_SESSION['langselect'] == 'en') ? "Error during database insertion." : "Errore durante l'inserimento nel database.";
|
|
}
|
|
} else {
|
|
echo ($_SESSION['langselect'] == 'en') ? "There was an error uploading the file." : "C'è stato un errore nel caricamento del file.";
|
|
}
|
|
} else {
|
|
echo ($_SESSION['langselect'] == 'en') ? "Only PNG and JPG files are allowed." : "Sono ammessi solo file PNG e JPG.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="<?php echo ($_SESSION['langselect'] == 'en') ? 'en' : 'it'; ?>">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo ($_SESSION['langselect'] == 'en') ? 'Add Logo' : '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: "<?php echo ($_SESSION['langselect'] == 'en') ? 'Browse' : 'Sfoglia'; ?>";
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container mt-5">
|
|
<?php echo $_SESSION['langselect'];
|
|
<button onclick="closeAndRefresh()"><?php echo ($_SESSION['langselect'] == 'en') ? 'Close and Refresh' : 'Chiudi e Aggiorna'; ?></button>
|
|
<h3 style="display: inline-block;"><?php echo ($_SESSION['langselect'] == 'en') ? 'Add Logo' : 'Aggiungi Logo'; ?></h3>
|
|
|
|
<form id="uploadLogoForm" action="logopopup.php" method="post" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="logoDescription"><?php echo ($_SESSION['langselect'] == 'en') ? 'Logo Description:' : 'Descrizione Logo:'; ?></label>
|
|
<input type="text" class="form-control" id="logoDescription" name="descriptionlogo" required>
|
|
</div>
|
|
<div class="drag-area" id="drag-area">
|
|
<p><?php echo ($_SESSION['langselect'] == 'en') ? 'Drag file here or click to select' : '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"><?php echo ($_SESSION['langselect'] == 'en') ? 'Choose file' : 'Scegli file'; ?></label>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary" name="submit"><?php echo ($_SESSION['langselect'] == 'en') ? 'Upload Logo' : 'Carica Logo'; ?></button>
|
|
</form>
|
|
</div>
|
|
<div class="container mt-5">
|
|
<h3><?php echo ($_SESSION['langselect'] == 'en') ? 'Uploaded Logos' : 'Loghi Caricati'; ?></h3>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th><?php echo ($_SESSION['langselect'] == 'en') ? 'Description' : 'Descrizione'; ?></th>
|
|
<th><?php echo ($_SESSION['langselect'] == 'en') ? 'Logo' : 'Logo'; ?></th>
|
|
<th><?php echo ($_SESSION['langselect'] == 'en') ? 'Action' : '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); // Assume $idcompany is already defined and sanitized
|
|
$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(\"" . ($_SESSION['langselect'] == 'en' ? 'Are you sure you want to delete this logo?' : '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>
|
|
// Show file name in Bootstrap custom file input when selected
|
|
$(".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>
|