Files
sls/admin/delete_bdd.php
Bruno21 b35196fdb8 Version 1.0
-déplacement des fichiers d’admin dans un dossier admin
-corrections dans la fonction data_for_lightbox($data). Celle-ci est maintenant toujours utilisé pour l’affichage des vignettes et des images dans la lightbox
-les chemins sont nettoyés avec 2 variables: $chemin pour les images, $base pour la base Sqlite
-corrections diverses
2025-02-13 10:07:21 +01:00

296 lines
13 KiB
PHP

<?php
require ("3-protect.php");
//session_start();
include '../i18n_setup.php';
/*include 'localize.php';
$domain = 'sentier';
localize($domain);
*/
include '../functions.php';
$chemin = '../photos/img/';
$base = "../db_photo.sqlite3";
$conn = new PDO("sqlite:$base");
$conn2 = new PDO("sqlite:$base");
$msg = "";
$req_suppress = "";
$req_delete = "";
$files_deleted = "";
$files = array();
//_pr($_POST);
/*
// view_bdd2.php:
supress ; coche => delete_bdd.php (delete ; coche)
edit; coche => edit_bdd.php => modify_bdd.php (modif sur la bdd)
*/
if (isset($_SESSION["user"])) {
if ((isset($_POST["suppress"])) && ($_POST["suppress"] == "suppress")) {
if (isset($_POST['coche']) && (! empty($_POST['coche']))) {
$rr = "";
foreach($_POST['coche'] as $key => $value) {
$r = "id = '" . $value . "' OR ";
$rr .= $r;
}
$req = substr($rr, 0, -4);
$req_suppress = "SELECT * FROM photos WHERE " . $req . " ORDER BY id";
}
else {
$url = "view_bdd.php?message=" . urlencode(gettext("No images select !"));
header("location: $url");
}
}
elseif ((isset($_POST["delete"])) && ($_POST["delete"] == "delete")) {
if (isset($_POST['id']) && (! empty($_POST['id']))) {
$rr = "";
foreach($_POST['id'] as $key => $value) {
$r = "id = '" . $value . "' OR ";
$rr .= $r;
}
$req = substr($rr, 0, -4);
/**/
$req_suppress = "SELECT id, filename FROM photos WHERE " . $req . " ORDER BY id"; // Pour supprimer les fichiers
$stmt = $conn->prepare($req_suppress);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$ids[] = $row['id'];
$file = $row['filename'];
if (file_exists($file)) {
$files[] = realpath('.') . "/" . $file;
}
else {
//$msg .= "File $file doesn't exist !";
$msg .= sprintf( gettext("File %s doesn't exist !"), $file);
}
}
//_pr($files);
$req_delete = "DELETE FROM photos WHERE id in (".str_repeat("?,", count($ids) - 1)."?)";
// DELETE FROM photos WHERE id in (?,?)
$stmt = $conn->prepare($req_delete);
$stmt->execute($ids);
$count = $stmt->rowCount();
if ($count = count($files)) {
foreach ($files as $file) {
if (unlink($file)) {
//echo "File: " . $file . " deleted!" . "<br />";
$files_deleted .= sprintf( gettext("File: %s deleted!"), $file ) . "\n";
//echo $a;
}
}
}
}
else {
$url = "view_bdd.php?message=" . urlencode(gettext("No images select !"));
header("location: $url");
}
}
else {
$url = "view_bdd.php?message=" . urlencode(gettext("No images select !"));
header("location: $url");
}
}
else {
$url = "admin.php?message=" . urlencode(gettext("Please log in !"));
header("location: $url");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="Sur le sentier: admin">
<title><?php echo gettext('View photos in Sqlite base'); ?></title>
<meta name="msapplication-TileColor" content="#2b5797">
<meta name="msapplication-config" content="/icons/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
<link rel="manifest" href="/icons/site.webmanifest">
<link rel="shortcut icon" href="/icons/favicon.ico">
<link rel="stylesheet" href="../css/sls.css">
<link rel='stylesheet' href='../lc-lightbox/css/lc_lightbox.min.css'>
<link rel='stylesheet' href='../lc-lightbox/css/open_close_fx.css'>
<link rel='stylesheet' href='../lc-lightbox/skins/minimal.css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
<?php
//debug_to_console($_GET);
//debug_to_console($req_edit);
echo '<h1>' . gettext('Suppress images ') . ': ' . $base . '</h1><br />';
if (($req_suppress != "") and ($req_delete == "")) {
echo '<h3>' . $msg . '</h3>';
try {
$conn3 = new PDO("sqlite:$base");
$stmt3 = $conn3->prepare($req_suppress);
$stmt3->execute();
echo '<form id="deleteImage" name="deleteImage" action="delete_bdd.php" method="post" class="myForm" >';
echo '<table class="styled-table">';
echo '<thead>';
echo '<th>' . gettext('Id') . '</th><th>' . gettext('Thumb') . '</th><th>' . gettext('Filename') . '</th><th>' . gettext('Date') . ' </th><th>' . gettext('Speed') . '</th><th>' . gettext('Iso') . '</th><th>' . gettext('Aperture') . '</th><th>' . gettext('Expo. correct') . '</th>';
echo '<th>' . gettext('Model') . '</th><th>' . gettext('Lens') . '</th><th>' . gettext('Focal') . '</th><th>' . gettext('Metering') . '</th><th>' . gettext('Program') . '</th><th>' . gettext('Wb') . '</th>';
echo '<th>' . gettext('Flash') . '</th><th>' . gettext('Software') . '</th><th>' . gettext('Keywords') . '</th><th>' . gettext('Title') . '</th><th>' . gettext('Creator') . '</th><th>' . gettext('City') . '</th><th>' . gettext('Department') . '</th><th>' . gettext('Code') . '</th><th>' . gettext('Country') . '</th><th>' . gettext('Copyright') . '</th><th>' . gettext('Legende') . '</th>';
echo '</thead>';
echo '<tbody>';
$nRows = 0;
while ($row = $stmt3->fetch(PDO::FETCH_ASSOC)) {
$lb = data_for_lightbox($row);
echo '<tr><td>' . $row['id'] . '</td><td>' . '<a href="' . $lb['big'] . '" title="' . htmlspecialchars($lb['title']) . '" data-lcl-txt="' . htmlspecialchars($lb['description']) . '" data-lcl-author="' . htmlspecialchars($lb['creator']) . '"><img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '"></a>' . '</td>';
echo '<td>' . $row['filename'] . '</td><td>' . $row['dateoriginal'] . '</td>';
echo '<td>' . $row['speed'] . '</td><td>' . $row['iso'] . '</td><td>' . $row['aperture'] . '</td><td>' . $row['correctexpo'] . '</td>';
echo '<td>' . $row['model'] . '</td>';
echo '<td><input type="text" id="lens" name="lens[]" value="' . $row['lens'] . '" size=""></td>';
echo '<td>' . $row['focal'] . '</td><td>' . $row['metering'] . '</td><td>' . $row['program'] . '</td><td>' . $row['wb'] . '</td>';
echo '<td>' . $row['flash'] . '</td><td>' . $row['software'] . '</td>';
echo "<td><input type='text' id='keywords' name='keywords[]' value='" . $row['keywords'] . "' size=''></td>";
echo '<td><input type="text" id="title" name="title[]" value="' . $row['title'] . '" size=""></td>';
echo '<td><input type="text" id="creator" name="creator[]" value="' . $row['creator'] . '" size=""></td>';
echo '<td><input type="text" id="city" name="city[]" value="' . $row['city'] . '" size=""></td>';
echo '<td><input type="text" id="department" name="department[]" value="' . $row['department'] . '" size=""></td>';
echo '<td><input type="text" id="code" name="code[]" value="' . $row['code'] . '" size=""></td>';
echo '<td><input type="text" id="country" name="country[]" value="' . $row['country'] . '" size=""></td>';
echo '<td><input type="text" id="copyright" name="copyright[]" value="' . $row['copyright'] . '" size=""></td>';
echo '<td><input type="text" id="legende" name="legende[]" value="' . $row['legende'] . '" size=""></td></tr>';
echo '<input type="hidden" id="id" name="id[]" value="' . $row['id'] . '">';
$nRows++;
}
echo '</tbody></table>';
echo '<p class="alert">' . ngettext("Clic on <b>Delete</b> button will delete the image in the database and the file on the server.", "Clic on <b>Delete</b> button will delete the images in the database and the files on the server.", $nRows) . '</p>';
echo '<button type="submit" name="delete" value="delete" class="myButton all">' . gettext('Delete') . '</button>';
echo '</form>';
//$conn = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
$req_suppress = "";
}
if ($req_delete != "") {
$msg = sprintf(ngettext("%d row deleted and the following file:","%d rows deleted and the following files:", $count), $count);
//$msg = $count . gettext(" rows deleted and the following files:");
echo '<h3 class="greenstyle">' . $msg . '</h3>';
echo '<h3>' . nl2br($files_deleted) . '</h3>';
//echo '<pre><code>' . $req_delete . '</code></pre>';
}
?>
<script>
$(document).ready(function() {
var $obj = lc_lightbox('td a', {
img_zoom : true, // whether to enable zooming system
author_by_txt : '<?php echo gettext("by"); ?>', // which text is used before the author name, by default is "by"
slideshow : true, // whether to enable slideshow
open_close_time : 200, // durée de l'animation pour l'ouverture et la fermeture de la lightbox
ol_time_diff : 100, // animation de superposition avance (à l'ouverture) et retard (à la fermeture) à la fenêtre
fading_time : 50, // durée de l'animation de fondu des éléments
animation_time : 100,
slideshow_time : 4000, // durée de l'intervalle du diaporama
autoplay : false, // autoplay slideshow - bool
counter : false, // s'il faut afficher le compteur d'éléments
progressbar : false, // s'il faut afficher une barre de progression lors de l'exécution du diaporama
max_width : '95%', // largeur maximale de la lightbox
max_height : '95%', // hauteur maximale de la lightbox
ol_opacity : 0.7, // overlay opacity / value between 0 and 1
ol_color : '#111', // background color of the overlay
ol_pattern : false, // overlay patterns - insert the pattern name or false
wrap_class : 'lcl_fade_oc', // Classes personnalisées ajoutées au wrapper: effet à l'ouverture de la lb (lcl_fade_oc | lcl_zoomin_oc | lcl_rtl_oc)
skin : 'minimal', // minimal | light | dark
data_position : 'over', // Spécifie où les données des éléments seront affichées. Les modes disponibles sont :over, under|rside|lside
cmd_position : 'inner', // Déclare où les commandes doivent être affichées : inner|outer
ins_close_pos : 'normal', // set closing button position for inner commands - normal/corner
nav_btn_pos : 'normal', // Régle les flèches et la position de lecture/pause. Options disponibles: normal|middle
txt_hidden : true, // whether to hide texts on lightbox opening - bool or int (related to browser's smaller side)
shox_title : true, // s'il faut afficher les titres
show_descr : true, // s'il faut afficher les descriptions
show_author : true, // s'il faut afficher les auteurs
thumbs_nav : false, // permet la navigation par vignettes (nécessite des éléments affiche ou images)
fullscreen : true, // Autoriser ou non le mode plein écran
fs_img_behavior : 'smart', //Comportement de l'image en plein écran : fit|fill|smart
fs_only : 500, // s'il faut utiliser uniquement l'ouverture de la lightbox en mode plein écran (utile pour les appareils mobiles) : false | (integer)
browser_fs_mode : true, // utiliser ou non le mode plein écran du navigateur
txt_toggle_cmd : true, // s'il faut afficher le bouton de basculement du texte de l'élément
download : true, // whether to show element's file download button
autoplay_videos : false, // bool / whether to autoplay videos (NB: modern browsers ignore this for deeplinked elements. Not applied if video has poster)
touchswipe : true, // permet les interactions tactiles (nécessite AlloyFinger)
rclick_prevent : true, // s'il faut éviter le clic droit sur les éléments de la lightbox
});
});
</script>
<?php $logout = (isset($_SESSION["user"])) ? '<a class="" href="4-logout.php" role="button">' . gettext("Log out") . '</a>' : ''; ?>
<p class="navPage"><a href="../index.php" title="<?php echo gettext("Home"); ?>"><?php echo gettext("Home"); ?></a> | <a href="../photo-du-mois.php" title="<?php echo gettext("Picture of the month"); ?>"><?php echo gettext("Picture of the month"); ?></a> | <a href="../maps.php" title="<?php echo gettext("Maps"); ?>"><?php echo gettext("Maps"); ?></a> | <a href="admin.php" title="<?php echo gettext("Admin page"); ?>"><?php echo gettext("Admin page"); ?></a> | <?php echo $logout; ?></p>
<p><em><small>&copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</small></em></p>
<script src='../lc-lightbox/js/lc_lightbox.min.js'></script>
<script src='../lc-lightbox/lib/AlloyFinger/alloy_finger.min.js'></script>
</body>
</html>