]> 91.132.146.200 Git - insipid.git/commitdiff
new and delete category. modular display of form action
authorBanana <banana@ironhide>
Sat, 3 Aug 2019 22:14:20 +0000 (00:14 +0200)
committerBanana <banana@ironhide>
Sat, 3 Aug 2019 22:14:20 +0000 (00:14 +0200)
webroot/lib/category.class.php
webroot/lib/management.class.php
webroot/view/_displaySubmitStatus.inc.php [new file with mode: 0644]
webroot/view/editcategories.inc.php
webroot/view/editcategories.php
webroot/view/editlink.php
webroot/view/home.php

index 4c4891370ba2c4a1b41c5e7a8f4aecfbdacc339b..b901f404a2fe5be99f88eb749c3b84b994f39d76 100644 (file)
@@ -66,15 +66,16 @@ class Category {
                                }
                        }
                }
+               return $this->id;
        }
 
        /**
         * by given DB table id load all the info we need
         * @param int $id
-        * @return boolean
+        * @return mixed
         */
        public function initbyid($id) {
-               $ret = false;
+               $this->id = false;
 
                if(!empty($id)) {
                        $queryStr = "SELECT id,name
@@ -84,11 +85,10 @@ class Category {
                        if(!empty($query) && $query->num_rows > 0) {
                                $result = $query->fetch_assoc();
                                $this->id = $id;
-                               $ret = true;
                        }
                }
 
-               return $ret;
+               return $this->id;
        }
 
        /**
index f66f8da1e2e158b4bb8b21f5fdb911edf6ee1fb9..1de7a3a703f5cc6ce2486ab4159dc476aa76cfc9 100644 (file)
@@ -87,7 +87,7 @@ 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 {
diff --git a/webroot/view/_displaySubmitStatus.inc.php b/webroot/view/_displaySubmitStatus.inc.php
new file mode 100644 (file)
index 0000000..3e3b6db
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+if(!empty($submitFeedback)) {
+       $cssClass="is-success";
+       if($submitFeedback['status'] == "error") {
+               $cssClass="is-danger";
+       }
+       $message = $submitFeedback['message'];
+       if(is_array($message)) {
+               $message = implode("<br />", $message);
+       }
+?>
+       <div class="columns">
+               <div class="column">
+                       <div class="notification <?php echo $cssClass; ?>">
+                               <p><?php echo $message; ?></p>
+                       </div>
+               </div>
+       </div>
+<?php } ?>
index d739a372d56db75f3db0beeb26417bf3f01ab099..ffacd240d1a4b8b6a12d742ca6b66b7abb871154 100644 (file)
@@ -46,23 +46,40 @@ if(isset($_POST['category']) && !empty($_POST['category']) && isset($_POST['upda
        # 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($deleteCategoryData)) {
+               $submitFeedback['message'][] = 'Categories deleted successfully.';
+
                foreach($deleteCategoryData as $k=>$v) {
                        if($v == "delete") {
                                $catObj = new Category($DB);
                                $load = $catObj->initbyid($k);
-                               if($load === true) {
+                               if($load !== false) {
                                        $catObj->delete();
                                }
+                               else {
+                                       $submitFeedback['message'][] = 'Categories could not be deleted.';
+                                       $submitFeedback['status'] = 'error';
+                               }
                        }
                }
-
-               $submitFeedback['message'] = 'Link updated successfully.';
-               $submitFeedback['status'] = 'success';
        }
 
-       $submitFeedback['message'] = 'Something went wrong...';
-                       $submitFeedback['status'] = 'error';
+       if(!empty($newCategory)) {
+               $submitFeedback['message'][] = 'Categories added successfully.';
+               $catArr = Summoner::prepareTagOrCategoryStr($newCategory);
+
+               foreach($catArr as $c) {
+                       $catObj = new Category($DB);
+                       $do = $catObj->initbystring($c);
+                       if($do === false) {
+                               $submitFeedback['message'][] = 'Category could not be added.';
+                               $submitFeedback['status'] = 'error';
+                       }
+               }
+       }
 }
 
 # show all the categories we have
index 0fd56151e4e538d8f58547701c49cdc83adcd877..d8dbca59065bf113b4be3198d4380dceabd2e92b 100644 (file)
@@ -50,6 +50,9 @@
                        <?php } ?>
                </div>
        </div>
+
+<?php require('_displaySubmitStatus.inc.php'); ?>
+
 </section>
 
 <section>
index 84bf049f07124abae0988e05878c114900fcb628..a1d1da1be7eb1d7acd96bf40c538e26b2c682093 100644 (file)
                </div>
        </div>
 <?php } ?>
-<?php if(!empty($submitFeedback)) { ?>
-       <div class="columns">
-               <div class="column">
-<?php if($submitFeedback['status'] == "error") { ?>
-                       <div class="notification is-danger">
-                               <h5>Error</h5>
-                               <p><?php echo $submitFeedback['message']; ?></p>
-                       </div>
-<?php } else { ?>
-                       <div class="notification is-success">
-                               <h5>Success</h5>
-                               <p><?php echo $submitFeedback['message']; ?></p>
-                       </div>
-<?php } ?>
-               </div>
-       </div>
-<?php } ?>
+
+<?php require('_displaySubmitStatus.inc.php'); ?>
 
        <div class="columns">
                <div class="column">
index 4b44530f347e9c85e7b270aded7f3d4fea14408b..dbe2b16f02548cdcb548022d907f630cd400906e 100644 (file)
                        </p>
                </div>
 
-       </div>
-</section>
+<?php require('_displaySubmitStatus.inc.php'); ?>
 
-<?php if(!empty($submitFeedback)) { ?>
-<section class="section">
-<div class="columns">
-       <div class="column">
-<?php if($submitFeedback['status'] == "error") { ?>
-               <div class="notification is-danger">
-                       <?php echo $submitFeedback['message']; ?>
-               </div>
-<?php } else { ?>
-               <div class="notification is-success">
-                       <p><?php echo $submitFeedback['message']; ?></p>
-               </div>
-<?php } ?>
        </div>
-</div>
 </section>
-<?php } ?>
 
 <?php if(!empty($searchResult)) { ?>
 <section class="section">