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

Last change on this file since 424 was 424, checked in by namnd, 11 years ago
File size: 8.2 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 ($this->admin_model->check_exist(array('field'=>'phone','value'=>$input['phone'])))
93                                {
94                                        $result['errors']['phone_err']="Số điện thoại đã được sá»­ dụng";
95                                }
96                        }
97                        if (strlen($input['passwd'])==0)
98                        {
99                                $result['errors']['pwd1_err']="Mật khẩu khÃŽng được để trống";
100                        }
101                        if ($input['passwd'] != $input['pwd2'])
102                        {
103                                $result['errors']['pwd2_err']="Mật khẩu khÃŽng trùng nhau";
104                        }
105                        if(strlen($input['email'])==0)
106                        {
107                                $result['errors']['email_err']="Email khÃŽng được để trống";
108                        }else{
109                                if(!valid_email($input['email']))
110                                {
111                                        $result['errors']['email_err']="Email khÃŽng đúng định dạng";
112                                }
113                        }
114                        if (!isset($result['errors']))
115                        {
116                                unset($input['pwd2']);
117                                $input['passwd'] = md5($input['passwd']);
118                                $input['created_time']=date("Y-m-d H:i:s");
119                                $input['updated_time']=date("Y-m-d H:i:s");
120                                $this->admin_model->insert($input);
121                                $result['success'] = 1;
122                        }
123                        echo json_encode($result);
124                }else{
125                        $this->load->view('login');
126                }
127        }
128       
129        public function edit_admin()
130        {
131                $admin_info = $this->session->userdata('adminInfo');
132                if ($admin_info)
133                {
134                        $admin_id = $this->uri->segment(4);
135                        $this->load->model('admin_model');
136                        $data = $this->admin_model->search_by_id($admin_id);
137                        $this->load->view('admin_acc/edit_admin', $data);
138                }else
139                {
140                        $this->load->view('login');
141                }
142        }
143       
144        public function update_admin()
145        {
146                $admin_info = $this->session->userdata('adminInfo');
147                if ($admin_info)
148                {
149                        $input = $this->input->post();
150                        $result = array();
151                        $result['success'] = 0;
152                        $this->load->model('admin_model');
153                        $input['updated_time']=date("Y-m-d H:i:s");
154                        $this->admin_model->update($input['admin_id'], $input);
155                        $result['success'] = 1;
156                        echo json_encode($result);
157                }else
158                {
159                        $this->load->view('login');
160                }
161        }
162       
163        public function delete_admin()
164        {
165                $admin_info = $this->session->userdata('adminInfo');
166                if ($admin_info)
167                {
168                        $result = array();
169                        $result['success'] = 0;
170                        $admin_id = (int)$this->uri->segment(4, 0);
171                        if ($admin_id == 0){
172                                $result['success'] = 0;
173                        }else
174                        {
175                                $this->load->model('admin_model');
176                                $this->admin_model->delete($admin_id);
177                                $result['success'] = 1;
178                        }
179                        echo json_encode($result);
180                }else
181                {
182                        $this->load->view('login');
183                }
184        }
185       
186        public function get_admin_by_id()
187        {
188                $admin_info = $this->session->userdata('adminInfo');
189                if ($admin_info)
190                {
191                        $admin_id = (int)$this->uri->segment(4);
192                        $this->load->model('admin_model');
193                        $data = $this->admin_model->search_by_id($admin_id);
194                        $this->load->view('admin_acc/view_admin', $data);
195                }else
196                {
197                        $this->load->view('login');
198                }
199        }
200       
201        public function admin_profile()
202        {
203                $admin_info = $this->session->userdata('adminInfo');
204                if($admin_info)
205                {
206                        $admin_id = $admin_info['admin_id'];
207                        $this->load->model(array('admin_model'));
208                        $data = $this->admin_model->search_by_id($admin_id);
209                        $this->load->view('admin_acc/admin_profile', $data);
210                }else
211                {
212                        $this->load->view('login');
213                }
214        }
215       
216        public function update_info()
217        {
218                $admin_info = $this->session->userdata('adminInfo');
219                if ($admin_info)
220                {
221                        $this->load->helper('email');
222                        $input = $this->input->post();
223                        $result = array();
224                        $result['success'] = 0;
225                        if(strlen($input['email'])>0){
226                                if(!valid_email($input['email']))
227                                {
228                                        $result['errors']['email_err']="Email khÃŽng đúng định dạng";
229                                }
230                        }
231                        if(strlen($input['phone'])>0){
232                                if (!preg_match('/[0-9]/', $input['phone']))
233                                {
234                                        $result['errors']['phone_err']="Phone khÃŽng đúng định dạng";
235                                }
236                        }
237                        if (!isset($result['errors']))
238                        {
239                                $input['admin_id'] = $admin_info['admin_id'];
240                                $input['updated_time']=date("Y-m-d H:i:s");
241                                $this->load->model('admin_model');
242                                $this->admin_model->update($input['admin_id'], $input);
243                                $result['success'] = 1;
244                        }
245                        echo json_encode($result);
246                }else
247                {
248                        $this->load->view('login');
249                }
250        }
251       
252        public function change_password()
253        {
254                $admin_info = $this->session->userdata('adminInfo');
255                if ($admin_info){
256                        $result = array();
257                        $result['success'] = 0;
258                        $this->load->model('admin_model');
259                        $input = $this->input->post();
260                        $input['admin_id'] = $admin_info['admin_id'];
261                        if (strlen($input['passwd']) == 0)
262                        {
263                                $result['errors']['passwd_old_err'] = "Mật khẩu khÃŽng được để trống !";
264                        }else
265                        {
266                                $check_pass = $this->admin_model->check_password($input['admin_id'], $input['passwd']);
267                                if (!$check_pass)
268                                {
269                                        $result['errors']['passwd_old_err'] = "Mật khẩu cung cấp khÃŽng đúng !";
270                                }
271                        }
272                        if (strlen($input['passwd_new']) == 0)
273                        {
274                                $result['errors']['passwd_new_err'] = "Mật khẩu khÃŽng được để trống !";
275                        }else if($input['passwd'] == $input['passwd_new'])
276                        {
277                                $result['errors']['passwd_new_err'] = "Mật khẩu trùng với mật khẩu hiện tại !";
278                        }
279                        if ($input['passwd_new'] != $input['confirm_passwd_new'])
280                        {
281                                $result['errors']['confirm_passwd_new_err'] = "Mật khẩu khÃŽng trùng nhau !";
282                        }
283                        if (!isset($result['errors']))
284                        {
285                                $updated_time=date("Y-m-d H:i:s");
286                                $data = array('passwd'=>md5($input['passwd_new']), 'updated_time'=>$updated_time);
287                                $this->admin_model->update($input['admin_id'], $data);
288                                $result['success'] = 1;
289                        }
290                       
291                        echo json_encode($result);
292                }else
293                {
294                        $this->load->view('login');
295                }
296               
297        }
298       
299}
Note: See TracBrowser for help on using the repository browser.