From 2e2177301819fd196c265bef9f986e7b7a307508 Mon Sep 17 00:00:00 2001
From: Joshua Perry <45966243+jpez-development@users.noreply.github.com>
Date: Sun, 5 Feb 2023 15:05:54 +0000
Subject: [PATCH] edit category fixed
---
jobs/controllers/Portal.php | 30 ++++++++++++++++++++++--------
templates/category_add.html.php | 12 ++++++++++--
templates/category_table.html.php | 2 +-
3 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/jobs/controllers/Portal.php b/jobs/controllers/Portal.php
index 0f6dfdc..c092234 100644
--- a/jobs/controllers/Portal.php
+++ b/jobs/controllers/Portal.php
@@ -96,9 +96,7 @@ class Portal {
}
public function edit() { //TODO: finish this function
- if (isset($_GET['cat_id'])) {
- $this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']]);
- }
+
}
public function addJob() {
@@ -152,6 +150,13 @@ class Portal {
public function addCategory() {
if ($_SESSION['userType'] == 'admin') {
+ if (isset($_GET['cat_id'])) {
+ $this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']])[0];
+ $this->vars['update'] = true;
+ }
+ else {
+ $this->vars['update'] = false;
+ }
return ['template' => 'category_add.html.php',
'title' => 'Jo\'s Jobs- Add Category',
'vars' => $this->vars
@@ -161,19 +166,28 @@ class Portal {
public function addCategorySubmit() {
if ($_SESSION['userType'] == 'admin') {
-
- if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
- $this->vars['response'] = 'This category already exists';
+ if ($_POST['submit'] == 'Create') {
+ if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
+ $this->vars['response'] = 'This category already exists';
+ }
+ else {
+ $record = [
+ 'name' => $_POST['name']
+ ];
+ $this->catsTable->save($record);
+ $this->vars['response'] = 'Category Created';
+ }
}
else {
$record = [
+ 'id' => $_POST['id'],
'name' => $_POST['name']
];
$this->catsTable->save($record);
- $this->vars['response'] = 'Category Created';
+ $this->vars['response'] = 'Category Updated';
}
return ['template' => 'response.html.php',
- 'title' => 'Jo\'s Jobs- Add Category',
+ 'title' => 'Jo\'s Jobs- Edit Category',
'vars' => $this->vars
];
}
diff --git a/templates/category_add.html.php b/templates/category_add.html.php
index e7e3abd..52323a8 100644
--- a/templates/category_add.html.php
+++ b/templates/category_add.html.php
@@ -1,7 +1,15 @@