From e0d8d235c42b7a7a696e579e60c645741b097117 Mon Sep 17 00:00:00 2001 From: Banana Date: Sun, 4 Aug 2019 00:14:20 +0200 Subject: [PATCH] new and delete category. modular display of form action --- webroot/lib/category.class.php | 8 +++---- webroot/lib/management.class.php | 2 +- webroot/view/_displaySubmitStatus.inc.php | 19 +++++++++++++++ webroot/view/editcategories.inc.php | 29 ++++++++++++++++++----- webroot/view/editcategories.php | 3 +++ webroot/view/editlink.php | 19 ++------------- webroot/view/home.php | 18 +------------- 7 files changed, 53 insertions(+), 45 deletions(-) create mode 100644 webroot/view/_displaySubmitStatus.inc.php diff --git a/webroot/lib/category.class.php b/webroot/lib/category.class.php index 4c48913..b901f40 100644 --- a/webroot/lib/category.class.php +++ b/webroot/lib/category.class.php @@ -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; } /** diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index f66f8da..1de7a3a 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -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 index 0000000..3e3b6db --- /dev/null +++ b/webroot/view/_displaySubmitStatus.inc.php @@ -0,0 +1,19 @@ +", $message); + } +?> +
+
+
+

+
+
+
+ diff --git a/webroot/view/editcategories.inc.php b/webroot/view/editcategories.inc.php index d739a37..ffacd24 100644 --- a/webroot/view/editcategories.inc.php +++ b/webroot/view/editcategories.inc.php @@ -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 diff --git a/webroot/view/editcategories.php b/webroot/view/editcategories.php index 0fd5615..d8dbca5 100644 --- a/webroot/view/editcategories.php +++ b/webroot/view/editcategories.php @@ -50,6 +50,9 @@ + + +
diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index 84bf049..a1d1da1 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -37,23 +37,8 @@ - -
-
- -
-
Error
-

-
- -
-
Success
-

-
- -
-
- + +
diff --git a/webroot/view/home.php b/webroot/view/home.php index 4b44530..dbe2b16 100644 --- a/webroot/view/home.php +++ b/webroot/view/home.php @@ -62,26 +62,10 @@

-
-
+ - -
-
-
- -
- -
- -
-

-
-
-
-
-- 2.39.5