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

Last change on this file since 757 was 690, checked in by namnd, 10 years ago
File size: 8.2 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                $data['daterange_start'] = "";
56                $data['daterange_end'] = "";
57        if ($this->input->post('daterange')){
58                        $daterange = explode(" - ", $this->input->post('daterange'));
59                        $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
60                        $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day'));
61                }
62        $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
63        $data['total'] = $this->collabolator_model->countCollaborator($data); 
64        $data['collaborators'] = $this->collabolator_model->getCollaborators($data);
65
66        $data['paging_url'] = base_url() . "/admin/cong_tac_vien/trang/";
67        $data['num_links'] = 2;
68        $data['paging'] = pagging($data);
69
70        if ($this->input->is_ajax_request()) {
71            return $this->load->view('collaborator/listview', $data);
72        }
73        return $this->load->view('collaborator/listview', $data, true);
74    }
75
76    public function addCollaborator() {
77        $result['success'] = 0;
78        $result = array();
79        $input = $this->input->post();
80        $this->load->model('collabolator_model');
81        if (strlen($input['full_name'])==0)
82        {
83            $result['errors'][]=array("content"=>"Tên cộng tác viên khÃŽng được để trống","field"=>"full_name");
84        }
85        if (strlen($input['login_name'])==0)
86        {
87            $result['errors'][]=array("content"=>"Tên đăng nhập khÃŽng được để trống","field"=>"login_name");
88        }
89        else
90        {
91            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'])))
92            {
93                $result['errors'][]=array("content"=>"Tên đăng nhập đã được sá»­ dụng","field"=>"login_name");
94            }
95        }
96        if (strlen($input['cellphone'])==0)
97        {
98            $result['errors'][]=array("content"=>"Số điện thoại khÃŽng được để trống","field"=>"cellphone");
99        }
100        else
101        {
102            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'])))
103            {
104                $result['errors'][]=array("content"=>"Số điện thoại đã được sá»­ dụng","field"=>"cellphone");
105            }
106        }
107        if (strlen($input['passwd'])==0)
108        {
109            $result['errors'][]=array("content"=>"Mật khẩu khÃŽng được để trống","field"=>"passwd");
110        }
111        else
112        {
113            if ($input['passwd'] != $input['passwd2'])
114            {
115                $result['errors'][]=array("content"=>"Mật khẩu phải trùng nhau","field"=>"passwd");
116            }
117        }
118        if (!isset($result['errors']))
119        {
120            unset($input['passwd2']);
121            $input['passwd']=md5($input['activated']);
122            $input['activated']=1;
123            $input['created_time']=date("Y-m-d H:i:s");
124            $input['updated_time']=date("Y-m-d H:i:s");
125            $this->load->model('collabolator_model');
126            $this->collabolator_model->insert($input);
127            $result['success'] = 1;
128        }
129
130       
131        echo json_encode($result);
132    }
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    }
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    }
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']);
205            $input['passwd']=md5($input['activated']);
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    }
213    public function test() {
214       
215       
216        for ($i = 1; $i <= 500; $i++) {
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);
226        }
227       
228       
229    }
230
231}
Note: See TracBrowser for help on using the repository browser.