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