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

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

collaborator

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