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

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

collaborator order sourcecode

File size: 5.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->getCollaborator($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
124    public function test() {
125       
126        $this->load->library('doctrine');
127        for ($i = 1; $i <= 500; $i++) {
128            $collaborator = new Entities\Tblcollaborator();
129            $collaborator->setActivated(rand(0, 1));
130            $collaborator->setAuthor(1);
131            $collaborator->setCellphone('0' . (1695061706 + $i));
132            $collaborator->setCreatedTime(date("Y-m-d H:i:s"));
133            $collaborator->setFullName("Full Name " . $i);
134            $collaborator->setLoginName("loginname" . $i);
135            $collaborator->setPasswd(md5("12345678"));
136            $collaborator->setUpdatedTime(date("Y-m-d H:i:s"));
137            try {
138                $this->doctrine->em->persist($collaborator);
139                $this->doctrine->em->flush();
140                $result['success'] = 1;
141            } catch (Exception $e) {
142
143                echo $e;
144            }
145        }
146    }
147
148}
Note: See TracBrowser for help on using the repository browser.