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

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