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

Last change on this file since 423 was 423, checked in by namnd, 11 years ago
File size: 5.8 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['success'] = 0;
68                        $result = array();
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['created_time']=date("Y-m-d H:i:s");
118                                $input['updated_time']=date("Y-m-d H:i:s");
119                                $this->admin_model->insert($input);
120                                $result['success'] = 1;
121                        }
122                        echo json_encode($result);
123                }else{
124                        $this->load->view('login');
125                }
126        }
127       
128        public function edit_admin()
129        {
130                $admin_info = $this->session->userdata('adminInfo');
131                if ($admin_info)
132                {
133                        /*
134                        $input = $this->input->post();
135                        $result = array();
136                        $result['success'] = 0;
137                        $admin_id = (int)$this->uri->segment(4, 0);
138                        if ($admin_id==0){
139                                $result['success'] = 0;
140                        }else
141                        {
142                                $this->load->model('admin_model');
143                                $input['updated_time']=date("Y-m-d H:i:s");
144                                $this->admin_model->update($admin_id, $input);
145                                $result['success'] = 1;
146                        }
147                        echo json_encode($result);*
148                        */
149                        $admin_id = $this->uri->segment(4);
150                        $this->load->model('admin_model');
151                        $data = $this->admin_model->search_by_id($admin_id);
152                        $this->load->view('admin_acc/edit_admin', $data);
153                }else
154                {
155                        $this->load->view('login');
156                }
157        }
158       
159        public function update_admin()
160        {
161                $admin_info = $this->session->userdata('adminInfo');
162                if ($admin_info)
163                {
164                        $input = $this->input->post();
165                        $result = array();
166                        $result['success'] = 0;
167                        //$admin_id = $this->uri->segment(4);
168                        $this->load->model('admin_model');
169                        $input['updated_time']=date("Y-m-d H:i:s");
170                        $this->admin_model->update($input['admin_id'], $input);
171                        $result['success'] = 1;
172                        echo json_encode($result);
173                }else
174                {
175                        $this->load->view('login');
176                }
177        }
178       
179        public function delete_admin()
180        {
181                $admin_info = $this->session->userdata('adminInfo');
182                if ($admin_info)
183                {
184                        $result = array();
185                        $result['success'] = 0;
186                        $admin_id = (int)$this->uri->segment(4, 0);
187                        if ($admin_id == 0){
188                                $result['success'] = 0;
189                        }else
190                        {
191                                $this->load->model('admin_model');
192                                $this->admin_model->delete($admin_id);
193                                $result['success'] = 1;
194                        }
195                        echo json_encode($result);
196                }else
197                {
198                        $this->load->view('login');
199                }
200        }
201       
202        public function get_admin_by_id()
203        {
204                $admin_info = $this->session->userdata('adminInfo');
205                if ($admin_info)
206                {
207                        $admin_id = (int)$this->uri->segment(4);
208                        $this->load->model('admin_model');
209                        $data = $this->admin_model->search_by_id($admin_id);
210                        $this->load->view('admin_acc/view_admin', $data);
211                }else
212                {
213                        $this->load->view('login');
214                }
215        }
216}
Note: See TracBrowser for help on using the repository browser.