From c7bd30da52fa90c3576fcf675c416cd23e550afd Mon Sep 17 00:00:00 2001
From: Joshua Perry <45966243+jpez-development@users.noreply.github.com>
Date: Sun, 5 Feb 2023 12:30:28 +0000
Subject: [PATCH] can now add categories
---
jobs/controllers/Portal.php | 40 ++++++++++++++++++++++++-------
templates/category_add.html.php | 7 ++++++
templates/category_table.html.php | 2 +-
templates/login.html.php | 2 +-
4 files changed, 41 insertions(+), 10 deletions(-)
create mode 100644 templates/category_add.html.php
diff --git a/jobs/controllers/Portal.php b/jobs/controllers/Portal.php
index 2a112d3..3af29ba 100644
--- a/jobs/controllers/Portal.php
+++ b/jobs/controllers/Portal.php
@@ -56,12 +56,6 @@ class Portal {
'title' => 'Jo\'s Jobs- Categories',
'vars' => $this->vars];
}
- else {
- $this->vars['response'] = 'You do not have access to this page';
- return ['template' => 'response.html.php',
- 'title' => 'Jo\'s Jobs- Access Denied',
- 'vars' => $this->vars];
- }
}
public function applicants() {
@@ -86,8 +80,38 @@ class Portal {
//TODO: add functions for adding jobs and categories
public function addJob() {
return ['template' => 'add.html.php',
- 'title' => 'Add Job',
- 'vars' => $this->vars];
+ 'title' => 'Jo\'s Jobs- Add Job',
+ 'vars' => $this->vars
+ ];
+ }
+
+ public function addCategory() {
+ if ($_SESSION['userType'] == 'admin') {
+ return ['template' => 'category_add.html.php',
+ 'title' => 'Jo\'s Jobs- Add Category',
+ 'vars' => $this->vars
+ ];
+ }
+ }
+
+ public function addCategorySubmit() {
+ if ($_SESSION['userType'] == 'admin') {
+
+ 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';
+ }
+ return ['template' => 'response.html.php',
+ 'title' => 'Jo\'s Jobs- Add Category',
+ 'vars' => $this->vars
+ ];
+ }
}
}
?>
\ No newline at end of file
diff --git a/templates/category_add.html.php b/templates/category_add.html.php
new file mode 100644
index 0000000..e7e3abd
--- /dev/null
+++ b/templates/category_add.html.php
@@ -0,0 +1,7 @@
+