]> 91.132.146.200 Git - insipid.git/commitdiff
edit tags
authorBanana <banana@ironhide>
Sun, 29 Sep 2019 19:32:49 +0000 (21:32 +0200)
committerBanana <banana@ironhide>
Sun, 29 Sep 2019 19:32:49 +0000 (21:32 +0200)
webroot/lib/management.class.php
webroot/lib/tag.class.php
webroot/view/editlink.inc.php
webroot/view/editlink.php
webroot/view/edittags.inc.php [new file with mode: 0644]
webroot/view/edittags.php [new file with mode: 0644]

index 82cba80437e2f22368d294a14864b3514c552d26..cee705f1a1cea18b7598d7ebfdedf4199072bccc 100644 (file)
@@ -136,11 +136,11 @@ class Management {
                $query = $this->DB->query($queryStr);
                if(!empty($query)) {
                        while($result = $query->fetch_assoc()) {
-                               if($stats === true) {
+                               if($stats === true && isset($statsInfo[$result['id']])) {
                                        $ret[$result['id']] = array('name' => $result['name'], 'amount' => $statsInfo[$result['id']]);
                                }
                                else {
-                                       $ret[$result['id']] = array('name' => $result['name']);
+                                       $ret[$result['id']] = array('name' => $result['name'], 'amount' => 0);
                                }
                        }
                }
index b15f749a45368336e1d369483558c1ae8e1c0c18..45caae7303f30b668a38450a3228d714fb811d0c 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2017 Johannes Keßler
+ * Copyright 2016-2019 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -91,4 +91,39 @@ class Tag {
                        $this->DB->query($queryStr);
                }
        }
+
+       /**
+        * deletes the current loaded tag from db
+        * @return boolean
+        */
+       public function delete() {
+               $ret = false;
+
+               if(!empty($this->id)) {
+                       $this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
+                       try {
+                               $queryStr = "DELETE
+                                       FROM `".DB_PREFIX."_tagrelation`
+                                       WHERE `tagid` = '".$this->DB->real_escape_string($this->id)."'";
+                               $this->DB->query($queryStr);
+
+                               $queryStr = "DELETE
+                                       FROM `".DB_PREFIX."_tag`
+                                       WHERE `id` = '".$this->DB->real_escape_string($this->id)."'";
+                               $this->DB->query($queryStr);
+
+                               $this->DB->commit();
+                       } catch (Exception $e) {
+                               if(DEBUG) {
+                                       var_dump($e->getMessage());
+                               }
+                               error_log('Failed to remove tag: '.var_export($e->getMessage(),true));
+
+                               $this->DB->rollback();
+                       }
+               }
+
+               return $ret;
+       }
 }
index 522106b9ebc4155c895d6492f0fece42fac977c2..b819360c35756861b5f2ca33267c71e06e091c15 100644 (file)
@@ -122,4 +122,3 @@ if(!empty($linkData['categories'])) {
 
 $existingCategories = $Management->categories();
 $existingTags = $Management->tags();
-
index a1d1da1be7eb1d7acd96bf40c538e26b2c682093..d7c03ac1e21904b4a35c35ff0d492e237c2702e6 100644 (file)
@@ -53,6 +53,8 @@
        <div class="columns">
                <div class="column">
                        <h1 class="is-size-2"><?php echo $linkData['title']; ?></h1>
+                       <h3><a href="index.php?p=linkinfo&id=<?php echo Summoner::ifset($formData, 'hash'); ?>">
+                               <i class="icon ion-md-return-left"></i></a></h3>
                </div>
        </div>
 </section>
diff --git a/webroot/view/edittags.inc.php b/webroot/view/edittags.inc.php
new file mode 100644 (file)
index 0000000..45da0e6
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2019 Johannes Keßler
+ *
+ * Development starting from 2011: Johannes Keßler
+ * https://www.bananas-playground.net/projekt/insipid/
+ *
+ * creator:
+ * Luke Reeves <luke@neuro-tech.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
+ *
+ */
+$submitFeedback = false;
+$formData = false;
+
+# very simple security check.
+# can/should be extended in the future.
+Summoner::simpleAuth();
+
+
+if(isset($_POST['tag']) && !empty($_POST['tag']) && isset($_POST['updateTags'])) {
+       $tagData = $_POST['tag'];
+
+       $deleteTagData = array();
+       if(isset($_POST['deleteTag'])) {
+               $deleteTagData = $_POST['deleteTag'];
+       }
+
+       $newTag = $_POST['newTag'];
+
+       # first deletion, then update and then add
+       # adding a new one which matches an existing one will update it.
+
+       $submitFeedback['message'] = array();
+       $submitFeedback['status'] = 'success';
+
+       if(!empty($deleteTagData)) {
+               $submitFeedback['message'][] = 'Tags deleted successfully.';
+
+               foreach($deleteTagData as $k=>$v) {
+                       if($v == "delete") {
+                               $tagObj = new Tag($DB);
+                               $load = $tagObj->initbyid($k);
+                               if($load !== false) {
+                                       $tagObj->delete();
+                               }
+                               else {
+                                       $submitFeedback['message'][] = 'Tags could not be deleted.';
+                                       $submitFeedback['status'] = 'error';
+                               }
+                       }
+               }
+       }
+
+       if(!empty($newTag)) {
+               $submitFeedback['message'][] = 'Tags added successfully.';
+               $tagArr = Summoner::prepareTagOrCategoryStr($newTag);
+
+               foreach($tagArr as $c) {
+                       $tagObj = new Tag($DB);
+                       $do = $tagObj->initbystring($c);
+                       if($do === false) {
+                               $submitFeedback['message'][] = 'Tag could not be added.';
+                               $submitFeedback['status'] = 'error';
+                       }
+               }
+       }
+}
+
+# show all the tags we have
+$tagCollection = $Management->tags(false, true);
+$subHeadline = 'All the tags <i class="ion-md-filing"></i>';
diff --git a/webroot/view/edittags.php b/webroot/view/edittags.php
new file mode 100644 (file)
index 0000000..5c31193
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Insipid
+ * Personal web-bookmark-system
+ *
+ * Copyright 2016-2019 Johannes Keßler
+ *
+ * Development starting from 2011: Johannes Keßler
+ * https://www.bananas-playground.net/projekt/insipid/
+ *
+ * creator:
+ * Luke Reeves <luke@neuro-tech.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
+ *
+ */
+ ?>
+<section class="section">
+       <div class="columns">
+               <div class="column">
+                       <p class="has-text-right">
+                               <a href="index.php?p=overview&m=tag" title="all tags" class="button">
+                                       <span class="icon"><i class="ion-md-pricetags"></i></span>
+                               </a>
+                               <a href="index.php?p=overview&m=category" title="all categories" class="button">
+                                       <span class="icon"><i class="ion-md-filing"></i></span>
+                               </a>
+                               <a href="index.php" title="... back to home" class="button">
+                                       <span class="icon"><i class="ion-md-home"></i></span>
+                               </a>
+                       </p>
+               </div>
+       </div>
+
+       <div class="columns">
+               <div class="column">
+                       <?php if(!empty($subHeadline)) { ?>
+                       <h2 class="is-size-2"><?php echo $subHeadline; ?></h2>
+                       <?php } ?>
+               </div>
+       </div>
+
+<?php require('_displaySubmitStatus.inc.php'); ?>
+
+</section>
+
+<section>
+<?php if(!empty($tagCollection)) { ?>
+<div class="columns">
+       <div class="column">
+               <form method="post">
+                       <table class="table">
+                               <tr>
+                                       <th>Name</th>
+                                       <th>New name</th>
+                                       <th>Deletion</th>
+                               </tr>
+                       <?php foreach ($tagCollection as $k=>$v) { ?>
+                               <tr>
+                                       <td>
+                                               <a href="index.php?p=overview&m=tag&id=<?php echo urlencode($k); ?>"
+                                               target="_blank"><?php echo $v['name']; ?></a></td>
+                                       <td>
+                                               <input class="input" type="text" name="tag[<?php echo urlencode($k); ?>]">
+                                       </td>
+                                       <td>
+                                               <input type="checkbox" value="delete" name="deleteTag[<?php echo urlencode($k); ?>]">
+                                       </td>
+                               </tr>
+                       <?php } ?>
+                               <tr>
+                                       <td>New tag</td>
+                                       <td>
+                                               <input class="input" type="text" name="newTag">
+                                       </td>
+                                       <td>
+                                               &nbsp;
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td colspan="3">
+                                               <input type="submit" class="button is-primary" name="updateTags" value="Update tags">
+                                       </td>
+                               </tr>
+                       </table>
+               </form>
+       </div>
+</div>
+<?php } ?>
+</section>