From: Banana Date: Mon, 4 Jan 2021 12:20:58 +0000 (+0100) Subject: manage tags. move, rename and delete working now. needs some sanding. X-Git-Tag: 1.0~7 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=ea4999da160e2efcae8d5e29fcf481c3081da884;p=bibliotheca-php.git manage tags. move, rename and delete working now. needs some sanding. --- diff --git a/webclient/lib/managetags.class.php b/webclient/lib/managetags.class.php new file mode 100644 index 0000000..7e85bd6 --- /dev/null +++ b/webclient/lib/managetags.class.php @@ -0,0 +1,152 @@ +_DB = $databaseConnectionObject; + $this->_User = $userObj; + } + + /** + * Set the to work with collection id + * + * @param string $collectionId Number + */ + public function setCollection($collectionId) { + if(!empty($collectionId)) { + $this->_collectionId = $collectionId; + } + } + + /** + * Either move, rename or delete (only one of those) with the given field + * and its value + * + * Return strategy here: empty string if everything works or nothing is to do. String error msg for error + * + * @param string $ident ID to use in lookup table + * @param array $data Needs use=fromString, move=toString, doDelete=true + * @return string + */ + public function doWithTag($ident, $data) { + $ret = ''; + + if(!empty($this->_collectionId) && !empty($ident) && !empty($data) && isset($data['use']) && !empty($data['use'])) { + if(isset($data['move']) && !empty($data['move'])) { + $ret = $this->_move($ident, $data['use'], $data['move']); + } + elseif (isset($data['rename']) && !empty($data['rename'])) { + $ret = $this->_move($ident, $data['use'], $data['rename']); + } + elseif (isset($data['doDelete']) && !empty($data['doDelete'])) { + $ret = $this->_delete($ident, $data['use']); + } + } + + return $ret; + } + + /** + * Move in field from to given new string + * + * @param string $field Field ID to use in lookup table + * @param string $from Value string to search for in lookup table + * @param string $to Value string to set to in lookup table + * @return string + */ + private function _move($field, $from, $to) { + $ret = ''; + + if(!Summoner::validate($field,'digit')) return 'Invalid field id for move/rename'; + if(!Summoner::validate($from)) return 'Invalid use data for move/rename'; + if(!Summoner::validate($to)) return 'Invalid to data for move/rename'; + + $queryStr = "UPDATE `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."` + SET `value` = '".$this->_DB->real_escape_string($to)."' + WHERE `fk_field` = '".$this->_DB->real_escape_string($field)."' + AND `value` = '".$this->_DB->real_escape_string($from)."'"; + if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true)); + try { + $this->_DB->query($queryStr); + } + catch (Exception $e) { + error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); + $ret = 'Error in move/rename query. See logs.'; + } + + return $ret; + } + + /** + * Delete the given $what for field $field in entry lookup table + * + * @param string $field Field ID to use in lookup table + * @param string $what Value to search for and delete from lookup table + * @return string + */ + private function _delete($field, $what) { + $ret = ''; + + if(!Summoner::validate($field,'digit')) return 'Invalid field id for delete'; + if(!Summoner::validate($what)) return 'Invalid use data for delete'; + + $queryStr = "DELETE FROM `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."` + WHERE `fk_field` = '".$this->_DB->real_escape_string($field)."' + AND `value` = '".$this->_DB->real_escape_string($what)."'"; + if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true)); + try { + $this->_DB->query($queryStr); + } + catch (Exception $e) { + error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); + $ret = 'Error in delete query. See logs.'; + } + + return $ret; + } +} diff --git a/webclient/lib/mancubus.class.php b/webclient/lib/mancubus.class.php index 67eac8b..e8d2766 100644 --- a/webclient/lib/mancubus.class.php +++ b/webclient/lib/mancubus.class.php @@ -2,7 +2,7 @@ /** * Bibliotheca webclient * - * Copyright 2018-2020 Johannes Keßler + * Copyright 2018-2021 Johannes Keßler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/webclient/view/default/managetags/managetags.html b/webclient/view/default/managetags/managetags.html index a97a961..db64dda 100644 --- a/webclient/view/default/managetags/managetags.html +++ b/webclient/view/default/managetags/managetags.html @@ -1,4 +1,75 @@ +
+
+

+ The actions are top down. If you choose to move and rename, only move will be executed.
+ Deletion will remove without recover!
+ If you rename and input an existing one a move will be done instead.
+ Tag values are stored how they come. But treated case insensitive in search. +

+ + +
+ + $v) { ?> +

+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+
Delete
+
+ +
+
+ + + + +
+ +
+
+ + +
+

Collection overview

diff --git a/webclient/view/default/managetags/managetags.php b/webclient/view/default/managetags/managetags.php index 246bc6b..5167fd7 100644 --- a/webclient/view/default/managetags/managetags.php +++ b/webclient/view/default/managetags/managetags.php @@ -18,6 +18,8 @@ require_once 'lib/trite.class.php'; $Trite = new Trite($DB,$Doomguy); +require_once 'lib/managetags.class.php'; +$ManageTags = new ManageTags($DB,$Doomguy); $_collection = false; if(isset($_GET['collection']) && !empty($_GET['collection'])) { @@ -37,6 +39,34 @@ $TemplateData['collections'] = array(); if(!empty($_collection)) { $TemplateData['loadedCollection'] = $Trite->load($_collection); if(!empty($TemplateData['loadedCollection'])) { + $ManageTags->setCollection($_collection); + + + if(isset($_POST['submitForm'])) { + $fdata = $_POST['fdata']; + $do = array(); + if(!empty($fdata)) { + foreach ($fdata as $ident=>$data) { + $do[] = $ManageTags->doWithTag($ident, $data); + } + } + if(!empty($do)) { + if(empty(implode($do))) { + $TemplateData['refresh'] = 'index.php?p=managetags&collection='.$_collection; + } + else { + $TemplateData['message']['content'] = implode('
',$do); + $TemplateData['message']['status'] = "error"; + } + } + else { + $TemplateData['message']['content'] = "Can not execute given options. See logs for more."; + $TemplateData['message']['status'] = "error"; + } + } + else { + $TemplateData['tags'] = $Trite->getTags(); + } } else { $TemplateData['message']['content'] = "Can not load given collection.";