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

Last change on this file since 624 was 576, checked in by quyenla, 10 years ago
File size: 7.9 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    }
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'][]=array("content"=>"Tên cộng tác viên khÃŽng được để trống","field"=>"full_name");
78        }
79        if (strlen($input['login_name'])==0)
80        {
81            $result['errors'][]=array("content"=>"Tên đăng nhập khÃŽng được để trống","field"=>"login_name");
82        }
83        else
84        {
85            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'])))
86            {
87                $result['errors'][]=array("content"=>"Tên đăng nhập đã được sá»­ dụng","field"=>"login_name");
88            }
89        }
90        if (strlen($input['cellphone'])==0)
91        {
92            $result['errors'][]=array("content"=>"Số điện thoại khÃŽng được để trống","field"=>"cellphone");
93        }
94        else
95        {
96            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'])))
97            {
98                $result['errors'][]=array("content"=>"Số điện thoại đã được sá»­ dụng","field"=>"cellphone");
99            }
100        }
101        if (strlen($input['passwd'])==0)
102        {
103            $result['errors'][]=array("content"=>"Mật khẩu khÃŽng được để trống","field"=>"passwd");
104        }
105        else
106        {
107            if ($input['passwd'] != $input['passwd2'])
108            {
109                $result['errors'][]=array("content"=>"Mật khẩu phải trùng nhau","field"=>"passwd");
110            }
111        }
112        if (!isset($result['errors']))
113        {
114            unset($input['passwd2']);
115            $input['passwd']=md5($input['activated']);
116            $input['activated']=1;
117            $input['created_time']=date("Y-m-d H:i:s");
118            $input['updated_time']=date("Y-m-d H:i:s");
119            $this->load->model('collabolator_model');
120            $this->collabolator_model->insert($input);
121            $result['success'] = 1;
122        }
123
124       
125        echo json_encode($result);
126    }
127    public function viewUser()
128    {
129        $id=$this->uri->segment(4);
130        $this->load->model('collabolator_model');
131        $data=$this->collabolator_model->getCollaborator($id);
132        $this->load->view('collaborator/viewUser',$data);
133    }
134    public function editUser()
135    {
136        $id=$this->uri->segment(4);
137        $this->load->model('collabolator_model');
138        $data=$this->collabolator_model->getCollaborator($id);
139        $this->load->view('collaborator/editUser',$data);
140    }
141    public function dodeleteUser()
142    {
143        $input=$this->input->post();
144        $id=$input['id'];
145        $this->load->model('collabolator_model');
146        $data=$this->collabolator_model->delete($id);
147        $result['success']=1;
148        echo json_encode($result);
149    }
150    public function deleteUser()
151    {
152        $id=$this->uri->segment(4);
153        $this->load->model('collabolator_model');
154        $data=$this->collabolator_model->getCollaborator($id);
155        $this->load->view('collaborator/deleteUser',$data);
156    }
157    public function updateUser()
158    {
159        $input['activated']=0;
160        $input=  array_merge($input,$this->input->post());
161        $this->load->model('collabolator_model');
162        if (strlen($input['full_name'])==0)
163        {
164            $result['errors'][]="Tên cộng tác viên khÃŽng được để trống";
165        }
166        if (strlen($input['login_name'])==0)
167        {
168            $result['errors'][]="Tên đăng nhập khÃŽng được để trống";
169        }
170        else
171        {
172            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
173            {
174                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
175            }
176        }
177        if (strlen($input['cellphone'])==0)
178        {
179            $result['errors'][]="Số điện thoại khÃŽng được để trống";
180        }
181        else
182        {
183            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
184            {
185                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
186            }
187        }
188        if (strlen($input['passwd'])==0)
189        {
190            //$result['errors'][]="Mật khẩu khÃŽng được để trống";
191        }
192        if ($input['passwd'] != $input['passwd2'])
193        {
194            $result['errors'][]="Mật khẩu khÃŽng trùng nhau";
195        }
196        if (!isset($result['errors']))
197        {
198            unset($input['passwd2']);
199            $input['passwd']=md5($input['activated']);
200            $input['updated_time']=date("Y-m-d H:i:s");
201            $this->load->model('collabolator_model');
202            $this->collabolator_model->update($input['id'],$input);
203            $result['success'] = 1;
204        }
205        echo json_encode($result);
206    }
207    public function test() {
208       
209       
210        for ($i = 1; $i <= 500; $i++) {
211            $input['full_name']="Full Name ".$i;
212            $input['login_name']="loginname".$i;
213            $input['passwd']=md5("12345678");
214            $input['cellphone']="01234567".(100+$i);
215            $input['activated']=rand(0,1);
216            $input['created_time']=date("Y-m-d H:i:s");
217            $input['updated_time']=date("Y-m-d H:i:s");
218            $this->load->model('collabolator_model');
219            $this->collabolator_model->insert($input);
220        }
221       
222       
223    }
224
225}
Note: See TracBrowser for help on using the repository browser.