source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/collaborator.php @ 838

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