edit category fixed
This commit is contained in:
parent
27d8600ea8
commit
2e21773018
|
|
@ -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,7 +166,7 @@ class Portal {
|
|||
|
||||
public function addCategorySubmit() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
|
||||
if ($_POST['submit'] == 'Create') {
|
||||
if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
|
||||
$this->vars['response'] = 'This category already exists';
|
||||
}
|
||||
|
|
@ -172,8 +177,17 @@ class Portal {
|
|||
$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 Updated';
|
||||
}
|
||||
return ['template' => 'response.html.php',
|
||||
'title' => 'Jo\'s Jobs- Add Category',
|
||||
'title' => 'Jo\'s Jobs- Edit Category',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
<main class="home">
|
||||
<form method="post" action="/portal/addCategory">
|
||||
<label>Enter Category Name</label>
|
||||
<?php if($update) { ?>
|
||||
<input type="text" name="name" value="<?=$cat->name?>"/>
|
||||
<input type="hidden" name="id" value="<?=$cat->id?>"/>
|
||||
<input type="submit" name="submit" value="Update"/>
|
||||
<?php }
|
||||
else { ?>
|
||||
<input type="text" name="name"/>
|
||||
<input type="submit" name="submit" value="Create"/>
|
||||
<?php } ?>
|
||||
|
||||
</form>
|
||||
</main>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<?php foreach ($cats as $cat) { ?>
|
||||
<tr>
|
||||
<td><?=$cat->name?></td>
|
||||
<td><a style="float: right" href="/portal/edit?cat_id=<?=$cat->id?>">Edit</a></td>
|
||||
<td><a style="float: right" href="/portal/addCategory?cat_id=<?=$cat->id?>">Edit</a></td>
|
||||
<td><form method="post" action="/portal/">
|
||||
<input type="hidden" name="cat_id" value="<?=$cat->id?>" />
|
||||
<input type="submit" name="submit" value="Delete" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue