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

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

collaborator order sourcecode

File size: 4.8 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['keyword'] = $this->input->post('keyword');
46        }
47       
48        $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
49        $data['total'] = $this->collabolator_model->countCollaborator($data); 
50        $data['collaborators'] = $this->collabolator_model->getCollaborator($data);
51
52        $data['paging_url'] = base_url() . "/admin/cong_tac_vien/trang/";
53        $data['num_links'] = 2;
54        $data['paging'] = pagging($data);
55
56        if ($this->input->is_ajax_request()) {
57            return $this->load->view('collaborator/listview', $data);
58        }
59        return $this->load->view('collaborator/listview', $data, true);
60    }
61
62    public function addCollaborator() {
63        $result['success'] = 0;
64        $result = array();
65        $input = $this->input->post();
66        $this->load->model('collabolator_model');
67        if (strlen($input['full_name'])==0)
68        {
69            $result['errors'][]="Tên cộng tác viên khÃŽng được để trống";
70        }
71        if (strlen($input['login_name'])==0)
72        {
73            $result['errors'][]="Tên đăng nhập khÃŽng được để trống";
74        }
75        else
76        {
77            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'])))
78            {
79                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
80            }
81        }
82        if (strlen($input['cellphone'])==0)
83        {
84            $result['errors'][]="Số điện thoại khÃŽng được để trống";
85        }
86        else
87        {
88            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'])))
89            {
90                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
91            }
92        }
93        if (strlen($input['passwd'])==0)
94        {
95            $result['errors'][]="Mật khẩu khÃŽng được để trống";
96        }
97        if ($input['passwd'] != $input['passwd2'])
98        {
99            $result['errors'][]="Mật khẩu khÃŽng trùng nhau";
100        }
101        if (!isset($result['errors']))
102        {
103            unset($input['passwd2']);
104            $input['activated']=1;
105            $input['created_time']=date("Y-m-d H:i:s");
106            $input['updated_time']=date("Y-m-d H:i:s");
107            $this->load->model('collabolator_model');
108            $this->collabolator_model->insert($input);
109            $result['success'] = 1;
110        }
111
112       
113        echo json_encode($result);
114    }
115
116    public function test() {
117       
118        $this->load->library('doctrine');
119        for ($i = 1; $i <= 500; $i++) {
120            $collaborator = new Entities\Tblcollaborator();
121            $collaborator->setActivated(rand(0, 1));
122            $collaborator->setAuthor(1);
123            $collaborator->setCellphone('0' . (1695061706 + $i));
124            $collaborator->setCreatedTime(date("Y-m-d H:i:s"));
125            $collaborator->setFullName("Full Name " . $i);
126            $collaborator->setLoginName("loginname" . $i);
127            $collaborator->setPasswd(md5("12345678"));
128            $collaborator->setUpdatedTime(date("Y-m-d H:i:s"));
129            try {
130                $this->doctrine->em->persist($collaborator);
131                $this->doctrine->em->flush();
132                $result['success'] = 1;
133            } catch (Exception $e) {
134
135                echo $e;
136            }
137        }
138    }
139
140}
Note: See TracBrowser for help on using the repository browser.