1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Category Controller |
5
|
|
|
*/ |
6
|
|
|
class Category extends MY_Controller { |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Constructor |
10
|
|
|
*/ |
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
parent::__construct(); |
14
|
|
|
$this->page->set_foot_js_group('js'); |
15
|
|
|
$this->page->set_title('Categories'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Redirect to list |
20
|
|
|
*/ |
21
|
|
|
public function index() |
22
|
|
|
{ |
23
|
|
|
$this->todo->redirect_303(site_url('category/list')); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* List of categories |
28
|
|
|
*/ |
29
|
|
|
public function category_list() |
30
|
|
|
{ |
31
|
|
|
$data = [ |
32
|
|
|
'category' => $this->todo->get_category_list() |
33
|
|
|
]; |
34
|
|
|
$this->page->set_title("Category List"); |
35
|
|
|
$this->page->build('task/cat_list', $data); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add a category |
40
|
|
|
*/ |
41
|
|
|
public function add_sub() |
42
|
|
|
{ |
43
|
|
|
if($this->input->post('add_sub') != FALSE) |
44
|
|
|
{ |
45
|
|
|
$this->todo->add_category(); |
46
|
|
|
$this->todo->redirect_303(site_url('category/list')); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Category edit form |
52
|
|
|
*/ |
53
|
|
|
public function edit($cat_id) |
54
|
|
|
{ |
55
|
|
|
$data = [ |
56
|
|
|
'cat' => $this->todo->get_category((int) $cat_id) |
57
|
|
|
]; |
58
|
|
|
$this->page->set_title("Edit Category"); |
59
|
|
|
$this->page->build('task/cat_add', $data); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Update the category |
64
|
|
|
*/ |
65
|
|
|
public function edit_sub() |
66
|
|
|
{ |
67
|
|
|
$title = $this->input->post('title', TRUE); |
68
|
|
|
$desc = $this->input->post('desc', TRUE); |
69
|
|
|
$cat_id = (int) $this->input->post('id'); |
70
|
|
|
$group_id = $this->todo->get_user_group(); |
71
|
|
|
|
72
|
|
|
$this->db->set('title', $title) |
73
|
|
|
->set('description', $desc) |
74
|
|
|
->where('group_id', $group_id) |
75
|
|
|
->where('id', $cat_id) |
76
|
|
|
->update('category'); |
77
|
|
|
|
78
|
|
|
$this->todo->redirect_303('category/list'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Delete a category |
83
|
|
|
*/ |
84
|
|
|
public function del_sub($cat_id) |
85
|
|
|
{ |
86
|
|
|
$this->output->set_output($this->todo->del_cat((int) $cat_id)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
// End of controllers/category.php |