From 97a73cc2d18c099876eff2ae1716fc7d30ef2f8d Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Wed, 20 Apr 2022 06:59:20 +0200 Subject: [PATCH] Add clean_bpp.php page --- admin/index.php | 4 +- clean_bdd.php | 174 ++++++++++++++++++++++++++++++++++++++++++++++ css/sls.css | 5 ++ insert_bdd.php | 4 +- maps.php | 2 +- photo-du-mois.php | 2 +- view_bdd.php | 174 ++++++++++++++++++++++++++++++++++++++++++++++ view_bdd_get.php | 174 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 533 insertions(+), 6 deletions(-) create mode 100644 clean_bdd.php create mode 100644 view_bdd.php create mode 100644 view_bdd_get.php diff --git a/admin/index.php b/admin/index.php index 0713598..fcbcf89 100644 --- a/admin/index.php +++ b/admin/index.php @@ -47,13 +47,13 @@

Insert_bdd

Viewing

-

View_bdd

+

View_bdd

Cleaning

-

Clean_bdd

+

Clean_bdd

diff --git a/clean_bdd.php b/clean_bdd.php new file mode 100644 index 0000000..1b5b029 --- /dev/null +++ b/clean_bdd.php @@ -0,0 +1,174 @@ + + + + + + + <?php gettext('Clean photos in Sqlite base'); ?> + + + + + + + + + + + + + + +match('/heic|HEIC|jpg|jpeg|JPG|JPEG|webp|WEBP$/'); + +//echo '

' . count($dir) . gettext(' images found in folder') . ' photos/img/ ...

'; + +//_pr($dir); + + +/* +foreach($dir as $file){ + + //$file->getFilename() + //$file->getpathName() + + $file = $file->getpathName(); + + $x = in_bdd($file); + + if ($x == false) { //false + + } + } +*/ + +$originals = array_map('basename', glob('photos/img/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE)); +$thumbs = array_map('basename', glob('photos/thumb/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE)); + +$missing_thumbs = array_diff($originals, $thumbs); +$a = count($missing_thumbs); +echo '

' . gettext('Missing thumbs: ') . $a . '

'; +if ($a > 0) { + echo '

' . gettext('Create missing thumbs...') . '

'; + + foreach($missing_thumbs as $img){ + $file = $img_path . $img; + create_thumb($th_w, $th_h, $file); + echo gettext('Thumb for ') . $img . gettext(' was successfully created!') . '
'; + } + +} + +$missing_originals = array_diff($thumbs, $originals); +$b = count($missing_originals); +echo '

' . gettext('Extra thumbs: ') . $b . '

'; +if ($b > 0) { + echo '

' . gettext('Delete extra thumbs...') . '

'; + + foreach($missing_originals as $thumb){ + $file = $thumb_path . $thumb; + if (unlink($file)) { + echo $thumb . gettext(' was deleted successfully!') . '
'; + } else { + echo gettext('There was a error deleting the file ') . $thumb; + } + } +} + +_pr($missing_thumbs); +_pr($missing_originals); + +echo '

' . gettext('Compare folder img and daatabase...') . '

'; + +try { + $conn = new PDO("sqlite:db_photo.sqlite3"); + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $query = "SELECT filename FROM photos"; + + $stmt = $conn->prepare($query); + $stmt->execute();// (1,3...) 1=1ere valeur 3=valeur + + $result = $stmt->fetchAll(PDO::FETCH_CLASS); + $rowcount = count($result); + + //$conn = null; + } + catch(PDOException $e) { + echo $e->getMessage(); + } + +//_pr($result); +$bdd = array(); + +foreach($result as $file) { + //$img = $file->filename; + $bdd[] = $file->filename; + } + +$base = array_map('basename', $bdd); +$missing_originals = array_diff($base, $originals); +$c = count($missing_originals); +echo '

' . gettext('Extra images in database: ') . $c . '

'; +if ($c > 0) { + echo '

' . gettext('Delete extra images in database...') . '

'; + + //foreach($missing_originals as $img){ + foreach($missing_originals as $key => $img){ + echo $key; + $query2 = "DELETE FROM photos WHERE id=:id"; + + $stmt=$conn->prepare($query2); + $stmt->bindParam(':id',$key,PDO::PARAM_INT, 5); + + if($stmt->execute()){ + echo "Successfully deleted record "; + } else { + print_r($sql->errorInfo()); + } + } +} + +//_pr($bdd); + +//_pr($base); + +_pr($missing_originals); + +/* +foreach($fileList as $filename){ + echo $filename; + } +*/ +//_pr($fileList); +?> + + +

© 2013- sur-le-sentier.fr

+ + + + + + + diff --git a/css/sls.css b/css/sls.css index 353c842..cb92ed4 100644 --- a/css/sls.css +++ b/css/sls.css @@ -186,6 +186,11 @@ body { color: #ffffff; text-align: left; } + +.sort a:link, .sort a:visited, .sort a:hover { + color: #ffffff !important; + text-decoration: none; +} .styled-table th, .styled-table td { padding: 12px 15px; diff --git a/insert_bdd.php b/insert_bdd.php index ac8c224..b0c42e6 100644 --- a/insert_bdd.php +++ b/insert_bdd.php @@ -495,9 +495,9 @@ try { }); - + -

sur-le-sentier.fr@ 2022

+

© 2013- sur-le-sentier.fr

diff --git a/maps.php b/maps.php index bd8ed51..6c2bc83 100644 --- a/maps.php +++ b/maps.php @@ -182,7 +182,7 @@ -

@sur-le-sentier.fr 2022

+

© 2013- sur-le-sentier.fr

diff --git a/photo-du-mois.php b/photo-du-mois.php index 0bf4457..33239fc 100644 --- a/photo-du-mois.php +++ b/photo-du-mois.php @@ -271,7 +271,7 @@ echo ''; -

sur-le-sentier.fr@ 2022

+

© 2013- sur-le-sentier.fr

diff --git a/view_bdd.php b/view_bdd.php new file mode 100644 index 0000000..30338b2 --- /dev/null +++ b/view_bdd.php @@ -0,0 +1,174 @@ + + + + + + + <?php gettext('View photos in Sqlite base'); ?> + + + + + + + + + + + + + + + +match('/heic|HEIC|jpg|jpeg|JPG|JPEG|webp|WEBP$/'); + +echo '

' . count($dir) . gettext(' images found in folder') . ' photos/img/ ...

'; + +$conn = new PDO("sqlite:db_photo.sqlite3"); +$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +try { + $columns = array('date','lens','model','iso','lat'); + $column = isset($_GET['column']) && in_array($_GET['column'], $columns) ? $_GET['column'] : $columns[0]; + //$_SESSION['column'] = $column; + $sort_order = isset($_GET['order']) && strtolower($_GET['order']) == 'desc' ? 'DESC' : 'ASC'; + //$_SESSION['sort_order'] = $sort_order; + + $query4 = "SELECT id,filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos ORDER BY " . $column . " " . $sort_order . " LIMIT ? OFFSET ?"; + + //$query4 = "SELECT id,filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos ORDER BY date DESC LIMIT ? OFFSET ?"; + $perpage = 50; + $offset = $perpage * ($page -1); + + echo $query4 . "
"; + echo $perpage . " - " . $offset . "
"; + + $stmt = $conn->prepare($query4); + $stmt->execute(array($perpage, $offset));// (1,3...) 1=1ere valeur 3=valeur + # id 1 -> 3 + //$stmt->execute(array(1, 3)); // WHERE id >= ? AND id <= ? ORDER BY date DESC"; + $stmt->execute(); + + //$row = $stmt->fetchAll(PDO::FETCH_ASSOC); + //_pr($result); + //echo '

' . gettext('Reading added photos') . ':

'; + $up_or_down = str_replace(array('ASC','DESC'), array('up','down'), $sort_order); + $asc_or_desc = $sort_order == 'ASC' ? 'desc' : 'asc'; + $add_class = ' class="highlight"'; + + /* + ' . gettext('Date') . ' + ' . gettext('Lens') . ' + ' . gettext('Iso') . ' + ' . gettext('Model') . ' + ' . gettext('Latitude') . ' + */ + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $thumbnail = host() . str_replace("photos/img", "photos/thumb", $row['filename']); + $full = host() . $row['filename']; + + echo ''; + } + echo '
' . gettext('Id') . '' . gettext('Thumb') . '' . gettext('Filename') . '' . gettext('Date') . ' ' . gettext('Lens') . ' ' . gettext('Speed') . '' . gettext('Iso') . ' ' . gettext('Width') . '' . gettext('Height') . '' . gettext('Html') . '' . gettext('Aperture') . '' . gettext('Model') . ' ' . gettext('Latitude') . ' ' . gettext('Longitude') . '' . gettext('Alttitude') . '' . gettext('Legende') . '' . gettext('Copyright') . '' . gettext('Title') . '' . gettext('Creator') . '' . gettext('Keywords') . '' . gettext('Metering') . '' . gettext('Flash') . '' . gettext('Focal') . '' . gettext('Wb') . '' . gettext('Program') . '
' . $row['id'] . '' . '' . '' . $row['filename'] . '' . $row['date'] . '' . $row['lens'] . '' . $row['speed'] . '' . $row['iso'] . '' . $row['width'] . '' . $row['height'] . '' . $row['html'] . '' . $row['aperture'] . '' . $row['model'] . '' . $row['lat'] . '' . $row['long'] . '' . $row['alt'] . '' . $row['legende'] . '' . $row['copyright'] . '' . $row['title'] . '' . $row['creator'] . '' . $row['keywords'] . '' . $row['metering'] . '' . $row['flash'] . '' . $row['focal'] . '' . $row['wb'] . '' . $row['program'] . '
'; + echo '
'; + + $conn = null; + } + catch(PDOException $e) { + echo $e->getMessage(); + } +?> + + + +prepare($query4); + $stmt->execute(); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + $numRows = $result['count']; + + $conn4 = null; + } + catch(PDOException $e) { + echo $e->getMessage(); + } + + // calcul du nombre de pages (arrondi a l'entier supérieur) + $nbpages = ceil($numRows / $perpage); + $prec = $page - 1; + $suiv = $page + 1; + + echo ''; + ?> + + + +

© 2013- sur-le-sentier.fr

+ + + + + + + diff --git a/view_bdd_get.php b/view_bdd_get.php new file mode 100644 index 0000000..30338b2 --- /dev/null +++ b/view_bdd_get.php @@ -0,0 +1,174 @@ + + + + + + + <?php gettext('View photos in Sqlite base'); ?> + + + + + + + + + + + + + + + +match('/heic|HEIC|jpg|jpeg|JPG|JPEG|webp|WEBP$/'); + +echo '

' . count($dir) . gettext(' images found in folder') . ' photos/img/ ...

'; + +$conn = new PDO("sqlite:db_photo.sqlite3"); +$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +try { + $columns = array('date','lens','model','iso','lat'); + $column = isset($_GET['column']) && in_array($_GET['column'], $columns) ? $_GET['column'] : $columns[0]; + //$_SESSION['column'] = $column; + $sort_order = isset($_GET['order']) && strtolower($_GET['order']) == 'desc' ? 'DESC' : 'ASC'; + //$_SESSION['sort_order'] = $sort_order; + + $query4 = "SELECT id,filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos ORDER BY " . $column . " " . $sort_order . " LIMIT ? OFFSET ?"; + + //$query4 = "SELECT id,filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos ORDER BY date DESC LIMIT ? OFFSET ?"; + $perpage = 50; + $offset = $perpage * ($page -1); + + echo $query4 . "
"; + echo $perpage . " - " . $offset . "
"; + + $stmt = $conn->prepare($query4); + $stmt->execute(array($perpage, $offset));// (1,3...) 1=1ere valeur 3=valeur + # id 1 -> 3 + //$stmt->execute(array(1, 3)); // WHERE id >= ? AND id <= ? ORDER BY date DESC"; + $stmt->execute(); + + //$row = $stmt->fetchAll(PDO::FETCH_ASSOC); + //_pr($result); + //echo '

' . gettext('Reading added photos') . ':

'; + $up_or_down = str_replace(array('ASC','DESC'), array('up','down'), $sort_order); + $asc_or_desc = $sort_order == 'ASC' ? 'desc' : 'asc'; + $add_class = ' class="highlight"'; + + /* + ' . gettext('Date') . ' + ' . gettext('Lens') . ' + ' . gettext('Iso') . ' + ' . gettext('Model') . ' + ' . gettext('Latitude') . ' + */ + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $thumbnail = host() . str_replace("photos/img", "photos/thumb", $row['filename']); + $full = host() . $row['filename']; + + echo ''; + } + echo '
' . gettext('Id') . '' . gettext('Thumb') . '' . gettext('Filename') . '' . gettext('Date') . ' ' . gettext('Lens') . ' ' . gettext('Speed') . '' . gettext('Iso') . ' ' . gettext('Width') . '' . gettext('Height') . '' . gettext('Html') . '' . gettext('Aperture') . '' . gettext('Model') . ' ' . gettext('Latitude') . ' ' . gettext('Longitude') . '' . gettext('Alttitude') . '' . gettext('Legende') . '' . gettext('Copyright') . '' . gettext('Title') . '' . gettext('Creator') . '' . gettext('Keywords') . '' . gettext('Metering') . '' . gettext('Flash') . '' . gettext('Focal') . '' . gettext('Wb') . '' . gettext('Program') . '
' . $row['id'] . '' . '' . '' . $row['filename'] . '' . $row['date'] . '' . $row['lens'] . '' . $row['speed'] . '' . $row['iso'] . '' . $row['width'] . '' . $row['height'] . '' . $row['html'] . '' . $row['aperture'] . '' . $row['model'] . '' . $row['lat'] . '' . $row['long'] . '' . $row['alt'] . '' . $row['legende'] . '' . $row['copyright'] . '' . $row['title'] . '' . $row['creator'] . '' . $row['keywords'] . '' . $row['metering'] . '' . $row['flash'] . '' . $row['focal'] . '' . $row['wb'] . '' . $row['program'] . '
'; + echo '
'; + + $conn = null; + } + catch(PDOException $e) { + echo $e->getMessage(); + } +?> + + + +prepare($query4); + $stmt->execute(); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + $numRows = $result['count']; + + $conn4 = null; + } + catch(PDOException $e) { + echo $e->getMessage(); + } + + // calcul du nombre de pages (arrondi a l'entier supérieur) + $nbpages = ceil($numRows / $perpage); + $prec = $page - 1; + $suiv = $page + 1; + + echo ''; + ?> + + + +

© 2013- sur-le-sentier.fr

+ + + + + + +