1 | <?php |
---|
2 | |
---|
3 | if (!defined('BASEPATH')) |
---|
4 | exit('No direct script access allowed'); |
---|
5 | |
---|
6 | class Collaborator extends MX_Controller { |
---|
7 | |
---|
8 | public function __construct() { |
---|
9 | parent::__construct(); |
---|
10 | $this->load->helper('cookie'); |
---|
11 | } |
---|
12 | |
---|
13 | public function index() { |
---|
14 | $data = array(); |
---|
15 | $admin_info = $this->session->userdata('adminInfo'); |
---|
16 | if ($admin_info) { |
---|
17 | $data['content'] = $this->getCollaborators(); |
---|
18 | $this->load->view('collaborator/index', $data); |
---|
19 | } else { |
---|
20 | $this->load->view('login'); |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | public function getCollaborators($filters = array()) { |
---|
25 | $this->load->helper('pagging'); |
---|
26 | $this->load->model('collabolator_model'); |
---|
27 | $data['current_page'] = $this->uri->segment(4, 1); |
---|
28 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
29 | $data['perpage'] = 10; |
---|
30 | $data['keyword'] = ""; |
---|
31 | $data['sorting_order']="sorting_desc"; |
---|
32 | $data['sorting_field']="created_time"; |
---|
33 | |
---|
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 | $data['perpage'] = $this->input->post('items'); |
---|
43 | } |
---|
44 | if ($this->input->post('keyword')) { |
---|
45 | $data['search_field']=""; |
---|
46 | $data['keyword'] = $this->input->post('keyword'); |
---|
47 | $data['search_field']="cellphone"; |
---|
48 | |
---|
49 | if (preg_match("/[0-9]/", $data['keyword'])) |
---|
50 | { |
---|
51 | $data['search_field']="cellphone"; |
---|
52 | } |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
57 | $data['total'] = $this->collabolator_model->countCollaborator($data); |
---|
58 | $data['collaborators'] = $this->collabolator_model->getCollaborators($data); |
---|
59 | |
---|
60 | $data['paging_url'] = base_url() . "/admin/cong_tac_vien/trang/"; |
---|
61 | $data['num_links'] = 2; |
---|
62 | $data['paging'] = pagging($data); |
---|
63 | |
---|
64 | if ($this->input->is_ajax_request()) { |
---|
65 | return $this->load->view('collaborator/listview', $data); |
---|
66 | } |
---|
67 | return $this->load->view('collaborator/listview', $data, true); |
---|
68 | } |
---|
69 | |
---|
70 | public function addCollaborator() { |
---|
71 | $result['success'] = 0; |
---|
72 | $result = array(); |
---|
73 | $input = $this->input->post(); |
---|
74 | $this->load->model('collabolator_model'); |
---|
75 | if (strlen($input['full_name'])==0) |
---|
76 | { |
---|
77 | $result['errors'][]="Tên cá»ng tác viên khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
78 | } |
---|
79 | if (strlen($input['login_name'])==0) |
---|
80 | { |
---|
81 | $result['errors'][]="Tên ÄÄng nháºp khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name']))) |
---|
86 | { |
---|
87 | $result['errors'][]="Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng"; |
---|
88 | } |
---|
89 | } |
---|
90 | if (strlen($input['cellphone'])==0) |
---|
91 | { |
---|
92 | $result['errors'][]="Sá» Äiá»n thoại khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone']))) |
---|
97 | { |
---|
98 | $result['errors'][]="Sá» Äiá»n thoại Äã ÄÆ°á»£c sá» dụng"; |
---|
99 | } |
---|
100 | } |
---|
101 | if (strlen($input['passwd'])==0) |
---|
102 | { |
---|
103 | $result['errors'][]="Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
104 | } |
---|
105 | if ($input['passwd'] != $input['passwd2']) |
---|
106 | { |
---|
107 | $result['errors'][]="Máºt khẩu khÃŽng trùng nhau"; |
---|
108 | } |
---|
109 | if (!isset($result['errors'])) |
---|
110 | { |
---|
111 | unset($input['passwd2']); |
---|
112 | $input['passwd']=md5($input['activated']); |
---|
113 | $input['activated']=1; |
---|
114 | $input['created_time']=date("Y-m-d H:i:s"); |
---|
115 | $input['updated_time']=date("Y-m-d H:i:s"); |
---|
116 | $this->load->model('collabolator_model'); |
---|
117 | $this->collabolator_model->insert($input); |
---|
118 | $result['success'] = 1; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | echo json_encode($result); |
---|
123 | } |
---|
124 | public function viewUser() |
---|
125 | { |
---|
126 | $id=$this->uri->segment(4); |
---|
127 | $this->load->model('collabolator_model'); |
---|
128 | $data=$this->collabolator_model->getCollaborator($id); |
---|
129 | $this->load->view('collaborator/viewUser',$data); |
---|
130 | } |
---|
131 | public function editUser() |
---|
132 | { |
---|
133 | $id=$this->uri->segment(4); |
---|
134 | $this->load->model('collabolator_model'); |
---|
135 | $data=$this->collabolator_model->getCollaborator($id); |
---|
136 | $this->load->view('collaborator/editUser',$data); |
---|
137 | } |
---|
138 | public function dodeleteUser() |
---|
139 | { |
---|
140 | $input=$this->input->post(); |
---|
141 | $id=$input['id']; |
---|
142 | $this->load->model('collabolator_model'); |
---|
143 | $data=$this->collabolator_model->delete($id); |
---|
144 | $result['success']=1; |
---|
145 | echo json_encode($result); |
---|
146 | } |
---|
147 | public function deleteUser() |
---|
148 | { |
---|
149 | $id=$this->uri->segment(4); |
---|
150 | $this->load->model('collabolator_model'); |
---|
151 | $data=$this->collabolator_model->getCollaborator($id); |
---|
152 | $this->load->view('collaborator/deleteUser',$data); |
---|
153 | } |
---|
154 | public function updateUser() |
---|
155 | { |
---|
156 | $input['activated']=0; |
---|
157 | $input= array_merge($input,$this->input->post()); |
---|
158 | $this->load->model('collabolator_model'); |
---|
159 | if (strlen($input['full_name'])==0) |
---|
160 | { |
---|
161 | $result['errors'][]="Tên cá»ng tác viên khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
162 | } |
---|
163 | if (strlen($input['login_name'])==0) |
---|
164 | { |
---|
165 | $result['errors'][]="Tên ÄÄng nháºp khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id']))) |
---|
170 | { |
---|
171 | $result['errors'][]="Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng"; |
---|
172 | } |
---|
173 | } |
---|
174 | if (strlen($input['cellphone'])==0) |
---|
175 | { |
---|
176 | $result['errors'][]="Sá» Äiá»n thoại khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id']))) |
---|
181 | { |
---|
182 | $result['errors'][]="Sá» Äiá»n thoại Äã ÄÆ°á»£c sá» dụng"; |
---|
183 | } |
---|
184 | } |
---|
185 | if (strlen($input['passwd'])==0) |
---|
186 | { |
---|
187 | //$result['errors'][]="Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
188 | } |
---|
189 | if ($input['passwd'] != $input['passwd2']) |
---|
190 | { |
---|
191 | $result['errors'][]="Máºt khẩu khÃŽng trùng nhau"; |
---|
192 | } |
---|
193 | if (!isset($result['errors'])) |
---|
194 | { |
---|
195 | unset($input['passwd2']); |
---|
196 | $input['passwd']=md5($input['activated']); |
---|
197 | $input['updated_time']=date("Y-m-d H:i:s"); |
---|
198 | $this->load->model('collabolator_model'); |
---|
199 | $this->collabolator_model->update($input['id'],$input); |
---|
200 | $result['success'] = 1; |
---|
201 | } |
---|
202 | echo json_encode($result); |
---|
203 | } |
---|
204 | public function test() { |
---|
205 | |
---|
206 | |
---|
207 | for ($i = 1; $i <= 500; $i++) { |
---|
208 | $input['full_name']="Full Name ".$i; |
---|
209 | $input['login_name']="loginname".$i; |
---|
210 | $input['passwd']=md5("12345678"); |
---|
211 | $input['cellphone']="01234567".(100+$i); |
---|
212 | $input['activated']=rand(0,1); |
---|
213 | $input['created_time']=date("Y-m-d H:i:s"); |
---|
214 | $input['updated_time']=date("Y-m-d H:i:s"); |
---|
215 | $this->load->model('collabolator_model'); |
---|
216 | $this->collabolator_model->insert($input); |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | } |
---|
221 | |
---|
222 | } |
---|