source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/admin_acc.php @ 590

Last change on this file since 590 was 590, checked in by namnd, 10 years ago
File size: 8.5 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class Admin_Acc 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                        $role_id = $admin_info['role_id'];
17                        if($role_id == 1){
18                                $data['content'] = $this->get_admins();
19                                $this->load->model('admin_model');
20                                $data['roles'] = $this->admin_model->get_roles();
21                                $this->load->view('admin_acc/index', $data);
22                        }else
23                        {
24                                show_404();
25                        }
26                }else
27                {
28                        $this->load->view('login');
29                }
30        }
31       
32        public function get_admins()
33        {
34                $this->load->helper('pagging');
35                $this->load->model('admin_model');
36                $data['current_page'] = $this->uri->segment(4, 1);
37                $data['itemsoptions'] = array(10, 25, 50, 100);
38                $data['perpage'] = 10;
39                $data['keyword'] = "";
40                $data['sorting_order']="sorting_desc";
41        $data['sorting_field']="created_time";
42                if ($this->input->post('sorting_order')) {
43                        if ($this->input->post('sorting_order') != "sorting")
44                        {
45                                $data['sorting_order'] = $this->input->post('sorting_order');
46                                $data['sorting_field'] = $this->input->post('sorting_field');
47                        }
48                }
49                if ($this->input->post('items'))
50                {
51                        $data['perpage'] = $this->input->post('items');
52                }
53                if ($this->input->post('keyword')) {
54            $data['keyword'] = $this->input->post('keyword');
55        }
56                $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
57                $data['total'] = $this->admin_model->get_total_admins($data);
58                $data['admins'] = $this->admin_model->get_list_admins($data);
59                $data['paging_url'] = base_url() . "admin/quan_tri_vien/trang/";
60                $data['num_links'] = 2;
61                $data['paging'] = pagging($data);
62                if ($this->input->is_ajax_request())
63                {
64                        return $this->load->view('admin_acc/listview', $data);
65                }
66                return $this->load->view('admin_acc/listview', $data, true);
67        }
68       
69        public function add_admin()
70        {
71                $admin_info = $this->session->userdata('adminInfo');
72                if ($admin_info)
73                {
74                        $this->load->helper('email');
75                        $result = array();
76                        $result['success'] = 0;
77                        $input = $this->input->post();
78                        $this->load->model('admin_model');
79                        if (strlen($input['full_name'])==0)
80                        {
81                                $result['errors']['full_name_err']="Tên Admin khÃŽng được để trống";
82                        }
83                        if (strlen($input['login_name'])==0)
84                        {
85                                $result['errors']['login_name_err']="Tên đăng nhập khÃŽng được để trống";
86                        }
87                        else
88                        {
89                                if ($this->admin_model->check_exist(array('field'=>'login_name','value'=>$input['login_name'])))
90                                {
91                                        $result['errors']['login_name_err']="Tên đăng nhập đã được sá»­ dụng";
92                                }
93                        }
94                        if (strlen($input['phone'])==0)
95                        {
96                                $result['errors']['phone_err']="Số điện thoại khÃŽng được để trống";
97                        }
98                        else
99                        {
100                                if(!preg_match('/[0-9]/', $input['phone'])){
101                                        $result['errors']['phone_err']="Phone khÃŽng đúng định dạng";
102                                }else if ($this->admin_model->check_exist(array('field'=>'phone','value'=>$input['phone'])))
103                                {
104                                        $result['errors']['phone_err']="Số điện thoại đã được sá»­ dụng";
105                                }
106                               
107                        }
108                        if (strlen($input['passwd'])==0)
109                        {
110                                $result['errors']['pwd1_err']="Mật khẩu khÃŽng được để trống";
111                        }
112                        if ($input['passwd'] != $input['pwd2'])
113                        {
114                                $result['errors']['pwd2_err']="Mật khẩu khÃŽng trùng nhau";
115                        }
116                        if(strlen($input['email'])==0)
117                        {
118                                $result['errors']['email_err']="Email khÃŽng được để trống";
119                        }else{
120                                if(!valid_email($input['email']))
121                                {
122                                        $result['errors']['email_err']="Email khÃŽng đúng định dạng";
123                                }
124                        }
125                        if (!isset($result['errors']))
126                        {
127                                unset($input['pwd2']);
128                                $input['passwd'] = md5($input['passwd']);
129                                $input['created_time']=date("Y-m-d H:i:s");
130                                $input['updated_time']=date("Y-m-d H:i:s");
131                                $this->admin_model->insert($input);
132                                $result['success'] = 1;
133                        }
134                        echo json_encode($result);
135                }else{
136                        $this->load->view('login');
137                }
138        }
139       
140        public function edit_admin()
141        {
142                $admin_info = $this->session->userdata('adminInfo');
143                if ($admin_info)
144                {
145                        $admin_id = $this->uri->segment(4);
146                        $this->load->model('admin_model');
147                        $data = $this->admin_model->search_by_id($admin_id);
148                        $this->load->view('admin_acc/edit_admin', $data);
149                }else
150                {
151                        $this->load->view('login');
152                }
153        }
154       
155        public function update_admin()
156        {
157                $admin_info = $this->session->userdata('adminInfo');
158                if ($admin_info)
159                {
160                        $input = $this->input->post();
161                        $result = array();
162                        $result['success'] = 0;
163                        $this->load->model('admin_model');
164                        $input['updated_time']=date("Y-m-d H:i:s");
165                        $this->admin_model->update($input['admin_id'], $input);
166                        $result['success'] = 1;
167                        echo json_encode($result);
168                }else
169                {
170                        $this->load->view('login');
171                }
172        }
173       
174        public function delete_admin()
175        {
176                $admin_info = $this->session->userdata('adminInfo');
177                if ($admin_info)
178                {
179                        $result = array();
180                        $result['success'] = 0;
181                        $admin_id = (int)$this->uri->segment(4, 0);
182                        if ($admin_id == 0){
183                                $result['success'] = 0;
184                        }else
185                        {
186                                $this->load->model('admin_model');
187                                $this->admin_model->delete($admin_id);
188                                $result['success'] = 1;
189                        }
190                        echo json_encode($result);
191                }else
192                {
193                        $this->load->view('login');
194                }
195        }
196       
197        public function get_admin_by_id()
198        {
199                $admin_info = $this->session->userdata('adminInfo');
200                if ($admin_info)
201                {
202                        $admin_id = (int)$this->uri->segment(4);
203                        $this->load->model('admin_model');
204                        $data = $this->admin_model->search_by_id($admin_id);
205                        $this->load->view('admin_acc/view_admin', $data);
206                }else
207                {
208                        $this->load->view('login');
209                }
210        }
211       
212        public function admin_profile()
213        {
214                $admin_info = $this->session->userdata('adminInfo');
215                if($admin_info)
216                {
217                        $admin_id = $admin_info['admin_id'];
218                        $this->load->model(array('admin_model'));
219                        $data = $this->admin_model->search_by_id($admin_id);
220                        $this->load->view('admin_acc/admin_profile', $data);
221                }else
222                {
223                        $this->load->view('login');
224                }
225        }
226       
227        public function update_info()
228        {
229                $admin_info = $this->session->userdata('adminInfo');
230                if ($admin_info)
231                {
232                        $this->load->helper('email');
233                        $input = $this->input->post();
234                        $result = array();
235                        $result['success'] = 0;
236                        if(strlen($input['email'])>0){
237                                if(!valid_email($input['email']))
238                                {
239                                        $result['errors']['email_err']="Email khÃŽng đúng định dạng";
240                                }
241                        }
242                        if(strlen($input['phone'])>0){
243                                if (!preg_match('/[0-9]/', $input['phone']))
244                                {
245                                        $result['errors']['phone_err']="Phone khÃŽng đúng định dạng";
246                                }
247                        }
248                        if (!isset($result['errors']))
249                        {
250                                $input['admin_id'] = $admin_info['admin_id'];
251                                $input['updated_time']=date("Y-m-d H:i:s");
252                                $this->load->model('admin_model');
253                                $this->admin_model->update($input['admin_id'], $input);
254                                $result['success'] = 1;
255                        }
256                        echo json_encode($result);
257                }else
258                {
259                        $this->load->view('login');
260                }
261        }
262       
263        public function change_password()
264        {
265                $admin_info = $this->session->userdata('adminInfo');
266                if ($admin_info){
267                        $result = array();
268                        $result['success'] = 0;
269                        $this->load->model('admin_model');
270                        $input = $this->input->post();
271                        $input['admin_id'] = $admin_info['admin_id'];
272                        if (strlen($input['passwd']) == 0)
273                        {
274                                $result['errors']['passwd_old_err'] = "Mật khẩu khÃŽng được để trống !";
275                        }else
276                        {
277                                $check_pass = $this->admin_model->check_password($input['admin_id'], $input['passwd']);
278                                if (!$check_pass)
279                                {
280                                        $result['errors']['passwd_old_err'] = "Mật khẩu cung cấp khÃŽng đúng !";
281                                }
282                        }
283                        if (strlen($input['passwd_new']) == 0)
284                        {
285                                $result['errors']['passwd_new_err'] = "Mật khẩu khÃŽng được để trống !";
286                        }else if($input['passwd'] == $input['passwd_new'])
287                        {
288                                $result['errors']['passwd_new_err'] = "Mật khẩu trùng với mật khẩu hiện tại !";
289                        }
290                        if ($input['passwd_new'] != $input['confirm_passwd_new'])
291                        {
292                                $result['errors']['confirm_passwd_new_err'] = "Mật khẩu khÃŽng trùng nhau !";
293                        }
294                        if (!isset($result['errors']))
295                        {
296                                $updated_time=date("Y-m-d H:i:s");
297                                $data = array('passwd'=>md5($input['passwd_new']), 'updated_time'=>$updated_time);
298                                $this->admin_model->update($input['admin_id'], $data);
299                                $result['success'] = 1;
300                        }
301                       
302                        echo json_encode($result);
303                }else
304                {
305                        $this->load->view('login');
306                }
307               
308        }
309       
310}
Note: See TracBrowser for help on using the repository browser.