]> 91.132.146.200 Git - insipid.git/commitdiff
editing categories
authorBanana <banana@ironhide>
Tue, 23 Jul 2019 21:17:30 +0000 (23:17 +0200)
committerBanana <banana@ironhide>
Tue, 23 Jul 2019 21:17:30 +0000 (23:17 +0200)
webroot/lib/category.class.php
webroot/view/editcategories.inc.php [new file with mode: 0644]
webroot/view/editcategories.php [new file with mode: 0644]
webroot/view/overview.inc.php
webroot/view/overview.php

index db216f892af79af36f184595ae92f99f388be49e..4c4891370ba2c4a1b41c5e7a8f4aecfbdacc339b 100644 (file)
@@ -71,11 +71,24 @@ class Category {
        /**
         * by given DB table id load all the info we need
         * @param int $id
+        * @return boolean
         */
        public function initbyid($id) {
+               $ret = false;
+
                if(!empty($id)) {
-                       $this->id = $id;
+                       $queryStr = "SELECT id,name
+                               FROM `".DB_PREFIX."_category`
+                               WHERE `id` = '".$this->DB->real_escape_string($id)."'";
+                       $query = $this->DB->query($queryStr);
+                       if(!empty($query) && $query->num_rows > 0) {
+                               $result = $query->fetch_assoc();
+                               $this->id = $id;
+                               $ret = true;
+                       }
                }
+
+               return $ret;
        }
 
        /**
@@ -91,4 +104,39 @@ class Category {
                        $this->DB->query($queryStr);
                }
        }
+
+       /**
+        * deletes the current loaded category 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."_categoryrelation`
+                                       WHERE `categoryid` = '".$this->DB->real_escape_string($this->id)."'";
+                               $this->DB->query($queryStr);
+
+                               $queryStr = "DELETE
+                                       FROM `".DB_PREFIX."_category`
+                                       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 category: '.var_export($e->getMessage(),true));
+
+                               $this->DB->rollback();
+                       }
+               }
+
+               return $ret;
+       }
 }
diff --git a/webroot/view/editcategories.inc.php b/webroot/view/editcategories.inc.php
new file mode 100644 (file)
index 0000000..d739a37
--- /dev/null
@@ -0,0 +1,70 @@
+<?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['category']) && !empty($_POST['category']) && isset($_POST['updateCategories'])) {
+       $categoryData = $_POST['category'];
+
+       $deleteCategoryData = array();
+       if(isset($_POST['deleteCategory'])) {
+               $deleteCategoryData = $_POST['deleteCategory'];
+       }
+
+       $newCategory = $_POST['newCategory'];
+
+       # first deletion, then update and then add
+       # adding a new one which matches an existing one will update it.
+
+       if(!empty($deleteCategoryData)) {
+               foreach($deleteCategoryData as $k=>$v) {
+                       if($v == "delete") {
+                               $catObj = new Category($DB);
+                               $load = $catObj->initbyid($k);
+                               if($load === true) {
+                                       $catObj->delete();
+                               }
+                       }
+               }
+
+               $submitFeedback['message'] = 'Link updated successfully.';
+               $submitFeedback['status'] = 'success';
+       }
+
+       $submitFeedback['message'] = 'Something went wrong...';
+                       $submitFeedback['status'] = 'error';
+}
+
+# show all the categories we have
+$categoryCollection = $Management->categories(false, true);
+$subHeadline = 'All the categories <i class="ion-md-filing"></i>';
diff --git a/webroot/view/editcategories.php b/webroot/view/editcategories.php
new file mode 100644 (file)
index 0000000..0fd5615
--- /dev/null
@@ -0,0 +1,96 @@
+<?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>
+</section>
+
+<section>
+<?php if(!empty($categoryCollection)) { ?>
+<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 ($categoryCollection as $k=>$v) { ?>
+                               <tr>
+                                       <td><a href="index.php?p=overview&m=category&id=<?php echo urlencode($k); ?>" target="_blank"><?php echo $v['name']; ?></a></td>
+                                       <td>
+                                               <input class="input" type="text" name="category[<?php echo urlencode($k); ?>]">
+                                       </td>
+                                       <td>
+                                               <input type="checkbox" value="delete" name="deleteCategory[<?php echo urlencode($k); ?>]">
+                                       </td>
+                               </tr>
+                       <?php } ?>
+                               <tr>
+                                       <td>New category</td>
+                                       <td>
+                                               <input class="input" type="text" name="newCategory">
+                                       </td>
+                                       <td>
+                                               &nbsp;
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td colspan="3">
+                                               <input type="submit" class="button is-primary" name="updateCategories" value="Update categories">
+                                       </td>
+                               </tr>
+                       </table>
+               </form>
+       </div>
+</div>
+<?php } ?>
+</section>
index 0137dd0e12b3ad9193f65dddb8cf290bd8837385..05581ec96e465e9393abafec1d665fffe390b07c 100644 (file)
  */
 $_requestMode = false;
 if(isset($_GET['m']) && !empty($_GET['m'])) {
-    $_requestMode = trim($_GET['m']);
-    $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : "all";
+       $_requestMode = trim($_GET['m']);
+       $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : "all";
 }
 
 $_id = false;
 if(isset($_GET['id']) && !empty($_GET['id'])) {
-    $_id = trim($_GET['id']);
-    $_id = Summoner::validate($_id,'digit') ? $_id : false;
+       $_id = trim($_GET['id']);
+       $_id = Summoner::validate($_id,'digit') ? $_id : false;
 }
 
 $linkCollection = array();
@@ -43,34 +43,34 @@ $tagCollection = array();
 $categoryCollection = array();
 
 switch($_requestMode) {
-    case 'tag':
-        if(!empty($_id)) {
-            $linkCollection = $Management->linksByTag($_id,false,false);
-            if(!empty($linkCollection)) {
-                $subHeadline = $linkCollection[0]['tag'].' <i class="ion-md-pricetag"></i>';
-            }
-        }
-        else {
-            # show all the tags we have
-            $tagCollection = $Management->tags(false, true);
-            $subHeadline = 'All the tags <i class="ion-md-pricetags"></i>';
-        }
-    break;
-    case 'category':
-        if(!empty($_id)) {
-            $linkCollection = $Management->linksByCategory($_id,false,false);
-            if(!empty($linkCollection)) {
-                $subHeadline = $linkCollection[0]['category'].' <i class="ion-md-filing"></i>';
-            }
-        }
-        else {
-            # show all the categories we have
-            $categoryCollection = $Management->categories(false, true);
-            $subHeadline = 'All the categories <i class="ion-md-filing"></i>';
-        }
-    break;
-    case 'all':
-    default:
-        # show all
-        $linkCollection = $Management->links();
+       case 'tag':
+               if(!empty($_id)) {
+                       $linkCollection = $Management->linksByTag($_id,false,false);
+                       if(!empty($linkCollection)) {
+                               $subHeadline = $linkCollection[0]['tag'].' <i class="ion-md-pricetag"></i>';
+                       }
+               }
+               else {
+                       # show all the tags we have
+                       $tagCollection = $Management->tags(false, true);
+                       $subHeadline = 'All the tags <i class="ion-md-pricetags"></i>';
+               }
+       break;
+       case 'category':
+               if(!empty($_id)) {
+                       $linkCollection = $Management->linksByCategory($_id,false,false);
+                       if(!empty($linkCollection)) {
+                               $subHeadline = $linkCollection[0]['category'].' <i class="ion-md-filing"></i>';
+                       }
+               }
+               else {
+                       # show all the categories we have
+                       $categoryCollection = $Management->categories(false, true);
+                       $subHeadline = 'All the categories <i class="ion-md-filing"></i>';
+               }
+       break;
+       case 'all':
+       default:
+               # show all
+               $linkCollection = $Management->links();
 }
index 65cfdb3744f80402c8443087dd719db995752221..79e6536b6e28f03d7652d8936d0e77997d599cb4 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2018 Johannes Keßler
+ * Copyright 2016-2019 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -25,8 +25,7 @@
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
  */
- ?>
-
+?>
 <section class="section">
        <div class="columns">
                <div class="column">
                <?php } ?>
                </table>
        </div>
+       <div class="column">
+               <div class="content">
+                       <a href="index.php?p=edittags" class="button is-small is-danger">
+                               <span class="icon"><i class="ion-md-create"></i></span>
+                               <span>Edit tags</span>
+                       </a>
+               </div>
+       </div>
 </div>
 <?php } if(!empty($categoryCollection)) { ?>
 <div class="columns">
                <?php } ?>
                </table>
        </div>
+       <div class="column">
+               <div class="content">
+                       <a href="index.php?p=editcategories" class="button is-small is-danger">
+                               <span class="icon"><i class="ion-md-create"></i></span>
+                               <span>Edit categories</span>
+                       </a>
+               </div>
+       </div>
 </div>
 <?php } ?>
 </section>