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 @@
- - + + + + + + + + +
\ No newline at end of file diff --git a/templates/category_table.html.php b/templates/category_table.html.php index 0d68d56..af23fcc 100644 --- a/templates/category_table.html.php +++ b/templates/category_table.html.php @@ -10,7 +10,7 @@ name?> - Edit + Edit