/
Category.php
88 lines (77 loc) · 2.87 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
* @author : Imran Shah
* @support: shahmian@gmail.com
* date : 18 April, 2018
* website: phptiger.com
* Kandi Inventory Management System
* version: 1.0
*/
class Category extends MY_Controller
{
public function __construct()
{
parent::__construct();
//Check if user is logged in or id exists in session
if ($this->session->userdata('user_id')) {
} else {
redirect(base_url() . 'index.php/Users/login');
}
}
// List Categories
public function list_category()
{
$group_id = $this->session->userdata("group_id");
if ($group_id != 1) {
$Page = $this->General->check_url_permission_single();
}
$data['category'] = $this->General->fetch_records("category");
$this->header($title = 'Category List');
$this->load->view('category/list_category', $data);
$this->footer();
}
// Add new category to Databse
public function insert_category()
{
$this->load->library('form_validation');
extract($_POST);
$this->form_validation->set_rules('category_name', 'Category Name', 'trim|required|min_length[5]|max_length[12]');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('error', 'Invalid Input');
redirect(base_url() . 'index.php/category/list_category');
} else {
$data = array(
'category_name' => $this->security->xss_clean($category_name)
);
$response = $this->Main_model->add_record('category', $data);
if ($response) {
$this->session->set_flashdata('success', 'Record added Successfully..!');
redirect(base_url() . 'index.php/category/list_category');
}
}
}
// Update category Details
public function update_category()
{
$cat_id = $this->input->post('cid');
$this->load->library('form_validation');
extract($_POST);
$this->form_validation->set_rules('category_name', 'Category Name', 'trim|required|min_length[5]|max_length[12]');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('error', 'Invalid Input');
redirect(base_url() . 'index.php/category/list_category');
} else {
$data = array(
'category_name' => $this->security->xss_clean($category_name)
);
$where = array('category_id' => $cat_id);
$this->load->model('Main_model');
$response = $this->Main_model->update_record('category', $category, $where);
if ($response) {
$this->session->set_flashdata('info', 'Record Updated Successfully..!');
redirect(base_url() . 'index.php/category/list_category');
}
}
}