From d68119f130c9337c9482f6a17f7367790f1d4db8 Mon Sep 17 00:00:00 2001 From: Banana Date: Tue, 28 Nov 2023 15:45:48 +0100 Subject: [PATCH] adding a very simply duplicate search --- CHANGELOG | 4 ++- TODO | 2 ++ webclient/lib/manageentry.class.php | 36 +++++++++++++++++++ .../view/98/manageentry/manageentry.html | 10 ++++++ .../view/default/manageentry/manageentry.html | 10 ++++++ .../view/default/manageentry/manageentry.php | 2 ++ 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a72a05c..8f40272 100644 --- 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 2dd355a..65590e5 100644 --- 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. diff --git a/webclient/lib/manageentry.class.php b/webclient/lib/manageentry.class.php index a09542b..377e8a3 100644 --- a/webclient/lib/manageentry.class.php +++ b/webclient/lib/manageentry.class.php @@ -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); diff --git a/webclient/view/98/manageentry/manageentry.html b/webclient/view/98/manageentry/manageentry.html index 442071c..b849aa6 100644 --- a/webclient/view/98/manageentry/manageentry.html +++ b/webclient/view/98/manageentry/manageentry.html @@ -8,6 +8,16 @@ if(!empty($TemplateData['editFields'])) {

View entry

+ +Possible duplicate + +

Add an entry to:

diff --git a/webclient/view/default/manageentry/manageentry.html b/webclient/view/default/manageentry/manageentry.html index 2a72f81..99c8f68 100644 --- a/webclient/view/default/manageentry/manageentry.html +++ b/webclient/view/default/manageentry/manageentry.html @@ -9,6 +9,16 @@ if(!empty($TemplateData['editFields'])) { View entry

+ +Possible duplicate + +

Add an entry to:

diff --git a/webclient/view/default/manageentry/manageentry.php b/webclient/view/default/manageentry/manageentry.php index 1b6ccb8..498aacd 100644 --- a/webclient/view/default/manageentry/manageentry.php +++ b/webclient/view/default/manageentry/manageentry.php @@ -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']); } } -- 2.39.5