1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | class Home extends MX_Controller
|
---|
4 | {
|
---|
5 | public function __construct()
|
---|
6 | {
|
---|
7 | parent::__construct();
|
---|
8 | $this->load->helper('cookie');
|
---|
9 | }
|
---|
10 |
|
---|
11 | public function index ()
|
---|
12 | {
|
---|
13 | $admin_info = $this->session->userdata('adminInfo');
|
---|
14 | if ($admin_info)
|
---|
15 | {
|
---|
16 | $this->load->view('index');
|
---|
17 | }else
|
---|
18 | {
|
---|
19 | $this->load->view ( 'login');
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public function login()
|
---|
24 | {
|
---|
25 | $username = $this->input->post('user_admin');
|
---|
26 | $password = $this->input->post('password');
|
---|
27 |
|
---|
28 | $this->load->model(array('admin_model'));
|
---|
29 | $data = $this->admin_model->check_login($username, $password);
|
---|
30 | if ($data == null)
|
---|
31 | {
|
---|
32 | $this->session->set_flashdata('login_error', TRUE);
|
---|
33 | redirect("/admin/home");
|
---|
34 | }
|
---|
35 | else
|
---|
36 | {
|
---|
37 | $admindata = array('user_admin' => $username, "logined_in" => TRUE);
|
---|
38 | $this->session->set_userdata('adminInfo', $admindata);
|
---|
39 | redirect("/admin/home");
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public function logout()
|
---|
44 | {
|
---|
45 | $this->session->sess_destroy();
|
---|
46 | redirect("/admin/home");
|
---|
47 | }
|
---|
48 |
|
---|
49 | public function admin_acc()
|
---|
50 | {
|
---|
51 | $admin_info = $this->session->userdata('adminInfo');
|
---|
52 | if($admin_info){
|
---|
53 | $this->load->model('admin_model');
|
---|
54 | $data = $this->admin_model->get_list();
|
---|
55 | $this->load->view('admin_acc', array('data'=>$data));
|
---|
56 | }else
|
---|
57 | {
|
---|
58 | redirect("/admin/home");
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public function insert()
|
---|
63 | {
|
---|
64 | $admin_info = $this->session->userdata('adminInfo');
|
---|
65 | if($admin_info)
|
---|
66 | {
|
---|
67 | $login_name = $this->input->post('username');
|
---|
68 | $password = $this->input->post('password');
|
---|
69 | $full_name = $this->input->post('fullname');
|
---|
70 | $email = $this->input->post('email');
|
---|
71 | $phone = $this->input->post('phone');
|
---|
72 | $created_time = date('Y-m-d H:i:s', time());
|
---|
73 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
74 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'created_time'=>$created_time, 'updated_time'=>$updated_time);
|
---|
75 | $this->load->model('admin_model');
|
---|
76 | $this->admin_model->insert($data);
|
---|
77 | redirect("/admin/home/admin_acc");
|
---|
78 |
|
---|
79 | }else
|
---|
80 | {
|
---|
81 | redirect("/admin/home");
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | public function update()
|
---|
86 | {
|
---|
87 | $admin_info = $this->session->userdata('adminInfo');
|
---|
88 | if($admin_info)
|
---|
89 | {
|
---|
90 | $admin_id = (int)$this->input->post('id');
|
---|
91 | $login_name = $this->input->post('username');
|
---|
92 | //$password = $this->input->post('password');
|
---|
93 | $full_name = $this->input->post('fullname');
|
---|
94 | $email = $this->input->post('email');
|
---|
95 | $phone = $this->input->post('phone');
|
---|
96 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
97 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'updated_time'=>$updated_time);
|
---|
98 | $this->load->model('admin_model');
|
---|
99 | $this->admin_model->update($admin_id, $data);
|
---|
100 | redirect("/admin/home/admin_acc");
|
---|
101 | }else
|
---|
102 | {
|
---|
103 | redirect("/admin/home");
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | public function delete()
|
---|
108 | {
|
---|
109 | $admin_info = $this->session->userdata('adminInfo');
|
---|
110 | if($admin_info)
|
---|
111 | {
|
---|
112 | $admin_id = (int)$this->input->post('id');
|
---|
113 | //echo $admin_id;
|
---|
114 | $this->load->model('admin_model');
|
---|
115 | $this->admin_model->delete($admin_id);
|
---|
116 | redirect("/admin/home/admin_acc");
|
---|
117 | }else
|
---|
118 | {
|
---|
119 | redirect("/admin/home");
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | public function user_profile()
|
---|
124 | {
|
---|
125 | $admin_info = $this->session->userdata('adminInfo');
|
---|
126 | if($admin_info)
|
---|
127 | {
|
---|
128 | $this->load->view('user_profile');
|
---|
129 | }else
|
---|
130 | {
|
---|
131 | redirect("/admin/home");
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | } |
---|