1 | <?php |
---|
2 | |
---|
3 | if (!defined('BASEPATH')) |
---|
4 | exit('No direct script access allowed'); |
---|
5 | |
---|
6 | class 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 | $this->load->driver("pp"); |
---|
16 | $admin_info = $this->session->userdata('adminInfo'); |
---|
17 | if ($admin_info) { |
---|
18 | $data['content'] = $this->getCollaborators(); |
---|
19 | $this->load->view('collaborator/index',$data); |
---|
20 | } else { |
---|
21 | $this->load->view('login'); |
---|
22 | } |
---|
23 | } |
---|
24 | public function getCollaborators($filters=array()) |
---|
25 | { |
---|
26 | |
---|
27 | $data['current_page'] = $this->uri->segment(4,1); |
---|
28 | $data['itemsoptions']=array(10,25,50,100); |
---|
29 | $data['perpage'] = 10; |
---|
30 | |
---|
31 | if ($this->input->post('items')) |
---|
32 | { |
---|
33 | $data['perpage'] = $this->input->post('items'); |
---|
34 | } |
---|
35 | $sql="SELECT * FROM tblcollaborator"; |
---|
36 | $data['keyword']=''; |
---|
37 | |
---|
38 | if ($this->input->post('keyword')) |
---|
39 | { |
---|
40 | $data['keyword']=$this->input->post('keyword'); |
---|
41 | $sql.=" WHERE (full_name LIKE '%".$data['keyword']."%' OR login_name LIKE '%".$data['keyword']."%')"; |
---|
42 | } |
---|
43 | |
---|
44 | $data['total']=$this->db->query($sql)->num_rows(); |
---|
45 | $data['start']=($data['current_page']-1)*$data['perpage']; |
---|
46 | $query = $this->db->query($sql." LIMIT ".$data['start'].", ".$data['perpage'].""); |
---|
47 | $data['collaborators']=$query->result_array(); |
---|
48 | $this->load->library('pagination'); |
---|
49 | $url = "http://$_SERVER[HTTP_HOST]/admin/cong_tac_vien/trang/"; |
---|
50 | $config['base_url'] = $url; |
---|
51 | $config['total_rows'] = $data['total']; |
---|
52 | $config['use_page_numbers'] = TRUE; |
---|
53 | $config['per_page'] = $data['perpage']; |
---|
54 | $config['num_tag_open'] = "<li>"; |
---|
55 | $config['num_tag_close'] = "</li>"; |
---|
56 | $config['cur_tag_open'] = "<li class='active'><a>"; |
---|
57 | $config['cur_tag_close'] = '</a></li>'; |
---|
58 | $config['last_link'] = '»'; |
---|
59 | $config['first_link'] = '«'; |
---|
60 | $config['first_tag_open'] = "<li title='Trang Äầu tiên'>"; |
---|
61 | $config['first_tag_close'] = '</li>'; |
---|
62 | $config['last_tag_open'] = "<li title='Trang cuá»i cùng'>"; |
---|
63 | $config['last_tag_close'] = '</li>'; |
---|
64 | $config['next_link'] = '>'; |
---|
65 | $config['next_tag_open'] = "<li title='Trang kế tiếp'>"; |
---|
66 | $config['next_tag_close'] = '</li>'; |
---|
67 | $config['prev_link'] = '<'; |
---|
68 | $config['prev_tag_open'] = "<li title='Trang trưá»c'>"; |
---|
69 | $config['prev_tag_close'] = '</li>'; |
---|
70 | $config['num_links'] = 2; |
---|
71 | $config['current_page'] = $data['current_page']; |
---|
72 | $config['ajax_class'] = 'ajax_paging'; |
---|
73 | $this->pagination->initialize($config); |
---|
74 | $data['paging'] = $this->pagination->create_links(); |
---|
75 | |
---|
76 | if ($this->input->is_ajax_request()) { |
---|
77 | return $this->load->view('collaborator/listview', $data); |
---|
78 | } |
---|
79 | return $this->load->view('collaborator/listview', $data,true); |
---|
80 | } |
---|
81 | public function addCollaborator() |
---|
82 | { |
---|
83 | $result=array(); |
---|
84 | $input=$this->input->post(); |
---|
85 | $this->db->insert('tblcollaborator', $input); |
---|
86 | $result['success']=1; |
---|
87 | echo json_encode($result); |
---|
88 | } |
---|
89 | public function test() { |
---|
90 | |
---|
91 | for ($i = 1; $i <= 500; $i++) { |
---|
92 | $collaborator = new Entities\Tblcollaborator(); |
---|
93 | $collaborator->setActivated(rand(0, 1)); |
---|
94 | $collaborator->setAuthor(1); |
---|
95 | $collaborator->setCellphone('0' . (1695061706+$i)); |
---|
96 | $collaborator->setCreatedTime(date("Y-m-d H:i:s")); |
---|
97 | $collaborator->setFullName("Full Name ".$i); |
---|
98 | $collaborator->setLoginName("loginname".$i); |
---|
99 | $collaborator->setPasswd(md5("12345678")); |
---|
100 | $collaborator->setUpdatedTime(date("Y-m-d H:i:s")); |
---|
101 | try { |
---|
102 | $this->doctrine->em->persist($collaborator); |
---|
103 | $this->doctrine->em->flush(); |
---|
104 | $result['success'] = 1; |
---|
105 | } catch (Exception $e) { |
---|
106 | |
---|
107 | echo $e; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | } |
---|