can now add categories

This commit is contained in:
Joshua Perry 2023-02-05 12:30:28 +00:00
parent c4ca3de4e1
commit c7bd30da52
4 changed files with 41 additions and 10 deletions

View File

@ -56,12 +56,6 @@ class Portal {
'title' => 'Jo\'s Jobs- Categories', 'title' => 'Jo\'s Jobs- Categories',
'vars' => $this->vars]; '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() { public function applicants() {
@ -86,8 +80,38 @@ class Portal {
//TODO: add functions for adding jobs and categories //TODO: add functions for adding jobs and categories
public function addJob() { public function addJob() {
return ['template' => 'add.html.php', return ['template' => 'add.html.php',
'title' => 'Add Job', 'title' => 'Jo\'s Jobs- Add Job',
'vars' => $this->vars]; '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
];
}
} }
} }
?> ?>

View File

@ -0,0 +1,7 @@
<main class="home">
<form method="post" action="/portal/addCategory">
<label>Enter Category Name</label>
<input type="text" name="name"/>
<input type="submit" name="submit" value="Create"/>
</form>
</main>

View File

@ -1,5 +1,5 @@
<h2>Categories</h2> <h2>Categories</h2>
<a class="new" href="addcategory.php">Add new category</a> <a class="new" href="/portal/addCategory">Add new category</a>
<table> <table>
<thead> <thead>
<tr> <tr>

View File

@ -8,7 +8,7 @@
<label>Enter Password</label> <label>Enter Password</label>
<input type="password" name="password" /> <input type="password" name="password" />
<input type="submit" name="submit" value="Log In" /> <input type="submit" name="submit"/>
</form> </form>
</main> </main>
<p><?=nl2br($response)?></p> <p><?=nl2br($response)?></p>