-
Notifications
You must be signed in to change notification settings - Fork 96
/
manage_category.php
40 lines (34 loc) · 1.04 KB
/
manage_category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include('config.php');
logincheck();
$message = [];
$title = "Create category";
$category = new Category;
if(isset($_GET['id'])) {
$title = "Edit category";
$category = Category::where('id', '=', $_GET['id'])->first();
}
if (isset($_POST['submit'])) {
$category->name = $_POST['name'];
if(isset($_GET['id'])) {
$message['type'] = "success";
$message['message'] = "Category saved";
$category->save();
} else {
$exists = Category::where('name', '=', $_POST['name'])->get();
if(count($exists) > 0) {
$message['type'] = "error";
$message['message'] = "Categoryname already exists";
} else {
$message['type'] = "success";
$message['message'] = "Category created";
$category->save();
redirect("manage_category.php?id=" . $category->id, 2000);
}
}
}
echo $template->view()->make('manage_category')
->with('category', $category)
->with('message', $message)
->with('title', $title)
->render();