]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
adding a very simply duplicate search
authorBanana <mail@bananas-playground.net>
Tue, 28 Nov 2023 14:45:48 +0000 (15:45 +0100)
committerBanana <mail@bananas-playground.net>
Tue, 28 Nov 2023 14:45:48 +0000 (15:45 +0100)
CHANGELOG
TODO
webclient/lib/manageentry.class.php
webclient/view/98/manageentry/manageentry.html
webclient/view/default/manageentry/manageentry.html
webclient/view/default/manageentry/manageentry.php

index a72a05c4fa67be2fb7493f94d84b51df963d0dce..8f402721d64c7a4bdeefb256fd40055a7465016a 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,8 +1,9 @@
 1.x - Chizra
     * Config change: Added new entry. See upgrade/from-version-1.5.txt. It won't work if it is missing.
     * Config change: Added new theme config. See upgrade/from-version-1.5.txt. It won't work if it is missing.
+    * Added: #6 Feature: Duplicate search
+      This is a very limited like search based on the title field. Needs improvement and better search data.
     * Licence change to GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
-    * Cleanups
     * Fixed: #21 Debug? string in error log
     * Fixed: #22 98 theme. Attachment selection checkbox are not all selectable
     * Fixed: #26 98 theme. max column with
@@ -10,6 +11,7 @@
     * Fixed: #23 basic search result order
     * Fixed: Bulkedit in 98 theme and default
     * Fixed: #24 Image upload. Automatic resize?
+    * Cleanups
 
 1.5 - Sacred Passage 2023-05-01
     * Added google books parser. See upgrade file for more infos.
diff --git a/TODO b/TODO
index 2dd355a6acfed4dad60e50f4b9f23bc514b6fa91..65590e51e76bd2f25692b0663b80343c23887014 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+* change the search data. Maybe an extra search field in which all the searchable information of an entry will be
+  saved.
 * change multiple-attachment to a field which tells it is used for a image gallery
 * update JS and remove deprecations
 * complete profile view. Groups still missing.
index a09542b85c638c4e51532a365d8f3b9708854fbf..377e8a399cac00d5ac5c3086126d5a685e571fe1 100644 (file)
@@ -348,6 +348,38 @@ class Manageentry {
                return $ret;
        }
 
+    /**
+     * Check for duplicates based on the given entryData.
+     * Could be extended to use more attributes from the entry
+     * Currently uses the title field, which is a hard dependency
+     *
+     * @param array $entryData
+     * @return array
+     */
+    public function checkForDuplicates(array $entryData): array {
+        $ret = array();
+
+        $queryStr = "SELECT `id`, `title`
+                                               FROM `".DB_PREFIX."_collection_entry_".$this->_collectionId."`
+                                               WHERE `title` LIKE '".$this->_DB->real_escape_string($entryData['title'])."%'
+                                                   AND `id` != '".$this->_DB->real_escape_string($entryData['id'])."'
+                                                       AND ".$this->_User->getSQLRightsString()."";
+        if(QUERY_DEBUG) Summoner::sysLog("[QUERY] ".__METHOD__." query: ".Summoner::cleanForLog($queryStr));
+        try {
+            $query = $this->_DB->query($queryStr);
+            if ($query !== false && $query->num_rows > 0) {
+                if (($row = $query->fetch_assoc()) != false) {
+                    $ret[] = $row;
+                }
+            }
+        }
+        catch (Exception $e) {
+            Summoner::sysLog("[ERROR] ".__METHOD__."  mysql catch: ".$e->getMessage());
+        }
+
+        return $ret;
+    }
+
        /**
         * Check if given entryid can be deleted from current collection
         * and user
@@ -729,6 +761,10 @@ class Manageentry {
     private function _saveField_upload__coverimage(array $data, array $queryData): array {
         $queryData = $this->_saveField_upload($data, $queryData);
 
+        if(!isset($queryData['after']['upload'])) {
+            return $queryData;
+        }
+
         $workWith = $queryData['after']['upload'][0]['tmp_name'];
         if(file_exists($workWith)) {
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
index 442071c9d59d5667856c6ae13b60fd21269678e9..b849aa681cdafc832c2ffe3ee8e8d7dfae6b28d1 100644 (file)
@@ -8,6 +8,16 @@ if(!empty($TemplateData['editFields'])) {
                <p>
                        <a href="index.php?p=entry&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&id=<?php echo $TemplateData['editData']['id']; ?>">View entry</a>
                </p>
+<?php if(!empty($TemplateData['possibleDuplicates'])) { ?>
+Possible duplicate
+<ul>
+       <?php
+       foreach($TemplateData['possibleDuplicates'] as $key=>$entry) {
+               echo '<li><a href="index.php?p=entry&collection='.$TemplateData['loadedCollection']['id'].'&id='.$entry['id'].'" target="_blank">'.$entry['title'].'</a></li>';
+       }
+       ?>
+</ul>
+<?php } ?>
 <?php } else { ?>
                <h3>Add an entry to: <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>"><?php echo $TemplateData['loadedCollection']['name']; ?></a></h3>
 <?php } ?>
index 2a72f818fd704ec79df26cbdbfe6a2cf1b75b781..99c8f6812e72c02d02443fd711632bf303ddfb41 100644 (file)
@@ -9,6 +9,16 @@ if(!empty($TemplateData['editFields'])) {
                        <span uk-icon="arrow-left"></span>
                        <a href="index.php?p=entry&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&id=<?php echo $TemplateData['editData']['id']; ?>">View entry</a>
                </p>
+<?php if(!empty($TemplateData['possibleDuplicates'])) { ?>
+Possible duplicate
+<ul>
+       <?php
+       foreach($TemplateData['possibleDuplicates'] as $key=>$entry) {
+               echo '<li><a href="index.php?p=entry&collection='.$TemplateData['loadedCollection']['id'].'&id='.$entry['id'].'" target="_blank">'.$entry['title'].'</a></li>';
+       }
+       ?>
+</ul>
+<?php } ?>
 <?php } else { ?>
                <h3 class="uk-h3">Add an entry to: <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>"><?php echo $TemplateData['loadedCollection']['name']; ?></a></h3>
 <?php } ?>
index 1b6ccb81e431aee590ad52af6788ae38491b54e1..498aacdbac7fd40c5a2eca5c16e3f704aca8f891 100644 (file)
@@ -29,6 +29,7 @@ $TemplateData['editData'] = array();
 $TemplateData['loadedCollection'] = '';
 $TemplateData['storagePath'] = '';
 $TemplateData['existingCollections'] = array();
+$TemplateData['possibleDuplicates'] = array();
 
 $TemplateData['_editFieldViewDefault'] = Summoner::themefile('manageentry/field-unknown.html', UI_THEME);
 
@@ -67,6 +68,7 @@ if(!empty($_collection)) {
                        }
                        else {
                                $TemplateData['pageTitle'] = 'Edit - '.$TemplateData['editData']['title'].' - '.$Trite->param('name');
+                $TemplateData['possibleDuplicates'] = $ManageEntry->checkForDuplicates($TemplateData['editData']);
                        }
                }