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

Last change on this file since 401 was 401, checked in by quyenla, 11 years ago

collaborator

File size: 7.0 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'][]="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['activated']=1;
113            $input['created_time']=date("Y-m-d H:i:s");
114            $input['updated_time']=date("Y-m-d H:i:s");
115            $this->load->model('collabolator_model');
116            $this->collabolator_model->insert($input);
117            $result['success'] = 1;
118        }
119
120       
121        echo json_encode($result);
122    }
123    public function viewUser()
124    {
125        $id=$this->uri->segment(4);
126        $this->load->model('collabolator_model');
127        $data=$this->collabolator_model->getCollaborator($id);
128        $this->load->view('collaborator/viewUser',$data);
129    }
130    public function editUser()
131    {
132        $id=$this->uri->segment(4);
133        $this->load->model('collabolator_model');
134        $data=$this->collabolator_model->getCollaborator($id);
135        $this->load->view('collaborator/editUser',$data);
136    }
137    public function updateUser()
138    {
139        $input['activated']=0;
140        $input=  array_merge($input,$this->input->post());
141        $this->load->model('collabolator_model');
142        if (strlen($input['full_name'])==0)
143        {
144            $result['errors'][]="Tên cộng tác viên khÃŽng được để trống";
145        }
146        if (strlen($input['login_name'])==0)
147        {
148            $result['errors'][]="Tên đăng nhập khÃŽng được để trống";
149        }
150        else
151        {
152            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
153            {
154                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
155            }
156        }
157        if (strlen($input['cellphone'])==0)
158        {
159            $result['errors'][]="Số điện thoại khÃŽng được để trống";
160        }
161        else
162        {
163            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
164            {
165                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
166            }
167        }
168        if (strlen($input['passwd'])==0)
169        {
170            //$result['errors'][]="Mật khẩu khÃŽng được để trống";
171        }
172        if ($input['passwd'] != $input['passwd2'])
173        {
174            $result['errors'][]="Mật khẩu khÃŽng trùng nhau";
175        }
176        if (!isset($result['errors']))
177        {
178            unset($input['passwd2']);
179            $input['activated']=1;
180            $input['updated_time']=date("Y-m-d H:i:s");
181            $this->load->model('collabolator_model');
182            $this->collabolator_model->update($input['id'],$input);
183            $result['success'] = 1;
184        }
185        echo json_encode($result);
186    }
187    public function test() {
188       
189       
190        for ($i = 1; $i <= 500; $i++) {
191            $input['full_name']="Full Name ".$i;
192            $input['login_name']="loginname".$i;
193            $input['passwd']=md5("12345678");
194            $input['cellphone']="01234567".(100+$i);
195            $input['activated']=rand(0,1);
196            $input['created_time']=date("Y-m-d H:i:s");
197            $input['updated_time']=date("Y-m-d H:i:s");
198            $this->load->model('collabolator_model');
199            $this->collabolator_model->insert($input);
200        }
201    }
202
203}
Note: See TracBrowser for help on using the repository browser.