]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
manage tags. move, rename and delete working now. needs some sanding.
authorBanana <mail@bananas-playground.net>
Mon, 4 Jan 2021 12:20:58 +0000 (13:20 +0100)
committerBanana <mail@bananas-playground.net>
Mon, 4 Jan 2021 12:20:58 +0000 (13:20 +0100)
webclient/lib/managetags.class.php [new file with mode: 0644]
webclient/lib/mancubus.class.php
webclient/view/default/managetags/managetags.html
webclient/view/default/managetags/managetags.php

diff --git a/webclient/lib/managetags.class.php b/webclient/lib/managetags.class.php
new file mode 100644 (file)
index 0000000..7e85bd6
--- /dev/null
@@ -0,0 +1,152 @@
+<?php
+/**
+ * Bibliotheca webclient
+ *
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Class ManageTags to manage the tags of a collection
+ */
+class ManageTags {
+       /**
+        * The database object
+        *
+        * @var mysqli
+        */
+       private $_DB;
+
+       /**
+        * The user object to query with
+        *
+        * @var Doomguy
+        */
+       private $_User;
+
+       /**
+        * Currently loaded collection to work with
+        *
+        * @var string Number
+        */
+       private $_collectionId;
+
+       /**
+        * ManageTags constructor.
+        *
+        * @param mysqli $databaseConnectionObject
+        * @param Doomguy $userObj
+        */
+       public function __construct($databaseConnectionObject, $userObj) {
+               $this->_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;
+       }
+}
index 67eac8b80a312438c79cf13dc114d20606be0f02..e8d276636ca8e2bf98ffa95036ec5e5b4c06608b 100644 (file)
@@ -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.
index a97a96199850cfdcdb4e7c4bec18d9ef74c199ea..db64dda6ea5b95ff5d904935fc5ad25f95d3ad76 100644 (file)
@@ -1,4 +1,75 @@
 <?php if(!empty($TemplateData['loadedCollection'])) { ?>
+<div class="uk-grid-small uk-grid-row-small" uk-grid>
+       <div class="uk-width-1-2">
+               <p>
+                       The actions are top down. If you choose to move and rename, only move will be executed.<br />
+                       Deletion will remove without recover!<br />
+                       If you rename and input an existing one a move will be done instead.<br />
+                       Tag values are stored how they come. But treated case insensitive in search.
+               </p>
+               <?php if(!empty($TemplateData['tags'])) { ?>
+
+               <form class="uk-form-horizontal uk-margin-small" method="post">
+
+               <?php foreach($TemplateData['tags'] as $k=>$v) { ?>
+                       <h4 class="uk-heading-line"><?php echo $v['displayname']; ?></h4>
+
+                       <div class="uk-margin">
+                               <label class="uk-form-label">Use</label>
+                               <div class="uk-form-controls">
+                                       <select class="uk-select" name="fdata[<?php echo $v['id']; ?>][use]">
+                                               <option value="">Please select</option>
+                                               <?php foreach($v['entries'] as $ek=>$ev) { ?>
+                                               <option value="<?php echo $ev; ?>"><?php echo $ev; ?></option>
+                                               <?php } ?>
+                                       </select>
+                               </div>
+                       </div>
+
+                       <div class="uk-margin">
+                               <label class="uk-form-label">Move to (rename to existing)</label>
+                               <div class="uk-form-controls">
+                                       <select class="uk-select" name="fdata[<?php echo $v['id']; ?>][move]">
+                                               <option value="">Please select</option>
+                                               <?php foreach($v['entries'] as $ek=>$ev) { ?>
+                                               <option value="<?php echo $ev; ?>"><?php echo $ev; ?></option>
+                                               <?php } ?>
+                                       </select>
+                               </div>
+                       </div>
+
+                       <div class="uk-margin">
+                               <label class="uk-form-label" >Rename</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" type="text" autocomplete="off"
+                                              name="fdata[<?php echo $v['id']; ?>][rename]"
+                                       >
+                               </div>
+                       </div>
+
+
+                       <div class="uk-margin">
+                               <div class="uk-form-label">Delete <span uk-icon="warning"></span></div>
+                               <div class="uk-form-controls uk-form-controls-text">
+                                       <label>
+                                               <input class="uk-checkbox" type="checkbox" name="fdata[<?php echo $v['id']; ?>][doDelete]" value="1">
+                                       </label>
+                               </div>
+                       </div>
+
+
+               <?php } ?>
+
+                       <div class="uk-margin">
+                               <button class="uk-button uk-button-primary" type="submit" name="submitForm">
+                                       Save
+                               </button>
+                       </div>
+               </form>
+
+               <?php } ?>
+       </div>
+</div>
 
 <?php } else { ?>
 <h3 class="uk-h3">Collection overview</h3>
index 246bc6b61f95c9cf44450b51d8d3904d9fd4df44..5167fd7e316817dffadd320a6c12e09eb03a33b6 100644 (file)
@@ -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('<br / >',$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.";