1 | <?php |
---|
2 | |
---|
3 | if (!defined('BASEPATH')) |
---|
4 | exit('No direct script access allowed'); |
---|
5 | |
---|
6 | class Home extends MX_Controller { |
---|
7 | |
---|
8 | const TOKENPW = 'violet'; |
---|
9 | |
---|
10 | public function __construct() { |
---|
11 | parent::__construct(); |
---|
12 | $this->load->helper('cookie'); |
---|
13 | $this->load->helper('language'); |
---|
14 | $this->lang->load('messages', 'message'); |
---|
15 | } |
---|
16 | |
---|
17 | public function index() { |
---|
18 | |
---|
19 | $collaborator_info = $this->session->userdata('collaboratorInfo'); |
---|
20 | if ($collaborator_info) { |
---|
21 | $id = $collaborator_info['id']; |
---|
22 | $data['id'] = $id; |
---|
23 | $data['statistics'] = $this->getStatistics($id); |
---|
24 | $data['content'] = $this->getCollaboratorsUsers(array(), $id); |
---|
25 | $this->load->view('collaborator/reportAsistant/indexCollaborator', $data); |
---|
26 | } else { |
---|
27 | $this->load->view('login'); |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | public function login() { |
---|
32 | |
---|
33 | $login_name = $this->input->post('login_name'); |
---|
34 | $passwd = $this->input->post('passwd'); |
---|
35 | |
---|
36 | $this->load->model('admin/Collabolator_model'); |
---|
37 | $data = $this->Collabolator_model->check_login($login_name, $passwd); |
---|
38 | if ($data == null) { |
---|
39 | $this->session->set_flashdata('login_error', TRUE); |
---|
40 | redirect("/cong_tac_vien"); |
---|
41 | } else { |
---|
42 | $collaboratorData = array('login_name' => $login_name, 'id' => $data->id, 'fullname' => $data->full_name, 'logined_in' => TRUE); |
---|
43 | $this->session->set_userdata('collaboratorInfo', $collaboratorData); |
---|
44 | redirect("/cong_tac_vien"); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | public function logout() { |
---|
49 | $this->session->unset_userdata('collaboratorInfo'); |
---|
50 | redirect("/collaborator"); |
---|
51 | } |
---|
52 | |
---|
53 | public function is_timeout() |
---|
54 | { |
---|
55 | $result['login']=1; |
---|
56 | $collaborator_infor = $this->session->userdata('collaboratorInfo'); |
---|
57 | if (!$collaborator_infor) { |
---|
58 | $result['login']=0; |
---|
59 | } |
---|
60 | echo json_encode($result); |
---|
61 | } |
---|
62 | |
---|
63 | public function getStatistics($id = false) { |
---|
64 | $data = array(); |
---|
65 | |
---|
66 | $this_year['start'] = strtotime(date("Y") . "-01-01 00:00:00"); |
---|
67 | |
---|
68 | $this->load->model('admin/collabolator_model'); |
---|
69 | $collaborators = $this->collabolator_model->getAllCollaboratorUser($this_year['start'], $id); |
---|
70 | for ($i = 1; $i <= 12; $i++) { |
---|
71 | $statistics[$i] = 0; |
---|
72 | } |
---|
73 | $y = date("Y"); |
---|
74 | foreach ($collaborators as $collaborator) { |
---|
75 | for ($i = 1; $i <= 12; $i++) { |
---|
76 | if ($i < 12) { |
---|
77 | if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime($y . "-" . ($i + 1) . "-1 00:00:00")))) { |
---|
78 | $statistics[$i] ++; |
---|
79 | } |
---|
80 | } else { |
---|
81 | if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime(($y + 1) . "-1-1 00:00:00")))) { |
---|
82 | $statistics[$i] ++; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | $max = 0; |
---|
89 | foreach ($statistics as $index => $total) { |
---|
90 | if ($total > $max) { |
---|
91 | $max = $total; |
---|
92 | } |
---|
93 | $chart[] = array($index, $total); |
---|
94 | } |
---|
95 | |
---|
96 | $data['max'] = $max; |
---|
97 | $chard[] = array("color" => "#e67e22", "label" => "Lượng ngưá»i dùng giá»i thiá»u bá»i cá»ng tác viên theo từng tháng", "data" => $chart); |
---|
98 | $data['chard'] = $chard; |
---|
99 | |
---|
100 | return $this->load->view('collaborator/reportAsistant/statistics', $data, true); |
---|
101 | } |
---|
102 | |
---|
103 | public function getLastquarter() { |
---|
104 | $current_month = date('m'); |
---|
105 | $current_year = date('Y'); |
---|
106 | |
---|
107 | if ($current_month >= 1 && $current_month <= 3) { |
---|
108 | $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM |
---|
109 | $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year |
---|
110 | } else if ($current_month >= 4 && $current_month <= 6) { |
---|
111 | $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM |
---|
112 | $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March |
---|
113 | } else if ($current_month >= 7 && $current_month <= 9) { |
---|
114 | $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM |
---|
115 | $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June |
---|
116 | } else if ($current_month >= 10 && $current_month <= 12) { |
---|
117 | $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM |
---|
118 | $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September |
---|
119 | } |
---|
120 | return array("start" => $start_date, "end" => $end_date); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | public function getCollaboratorsUsers($filters = array(), $id = false) { |
---|
125 | |
---|
126 | $this->load->helper('pagging'); |
---|
127 | $this->load->model('admin/collabolator_model'); |
---|
128 | $data['current_page'] = $this->uri->segment(5, 1); |
---|
129 | |
---|
130 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
131 | $data['perpage'] = 10; |
---|
132 | if (!$id) { |
---|
133 | $data['id'] = $this->uri->segment(4, 1); |
---|
134 | } else { |
---|
135 | $data['id'] = $id; |
---|
136 | } |
---|
137 | |
---|
138 | $data['keyword'] = ""; |
---|
139 | $data['sorting_order'] = "sorting_desc"; |
---|
140 | $data['sorting_field'] = "id"; |
---|
141 | |
---|
142 | if ($this->input->post('sorting_order')) { |
---|
143 | if ($this->input->post('sorting_order') != "sorting") { |
---|
144 | $data['sorting_order'] = $this->input->post('sorting_order'); |
---|
145 | $data['sorting_field'] = $this->input->post('sorting_field'); |
---|
146 | } |
---|
147 | } |
---|
148 | if ($this->input->post('items')) { |
---|
149 | $data['perpage'] = $this->input->post('items'); |
---|
150 | } |
---|
151 | if ($this->input->post('keyword')) { |
---|
152 | $data['search_field'] = ""; |
---|
153 | $data['keyword'] = $this->input->post('keyword'); |
---|
154 | |
---|
155 | if (preg_match("/[0-9]/", $data['keyword'])) { |
---|
156 | $data['search_field'] = "cellphone"; |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | $data['daterange_start'] = ""; |
---|
161 | $data['daterange_end'] = ""; |
---|
162 | if ($this->input->post('daterange')){ |
---|
163 | $daterange = explode(" - ", $this->input->post('daterange')); |
---|
164 | $daterange[0] = str_replace('/', '-', $daterange[0]); |
---|
165 | $daterange[1] = str_replace('/', '-', $daterange[1]); |
---|
166 | $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0])); |
---|
167 | $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day')); |
---|
168 | } |
---|
169 | |
---|
170 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
171 | $data['total'] = $this->collabolator_model->countCountCollaboratorUsers($data); |
---|
172 | $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data); |
---|
173 | |
---|
174 | foreach ($data['paidlogs'] as $index => $paidlog) |
---|
175 | { |
---|
176 | |
---|
177 | $data['paidlogs'][$index]['username'] = $this->get_fullname($paidlog['us_id']); |
---|
178 | } |
---|
179 | |
---|
180 | $data['paging_url'] = base_url() . "cong_tac_vien/thong_ke_nguoi_dung/trang/" ; |
---|
181 | $data['num_links'] = 2; |
---|
182 | $data['paging'] = pagging($data); |
---|
183 | |
---|
184 | if ($this->input->is_ajax_request()) { |
---|
185 | return $this->load->view('collaborator/reportAsistant/listview_user', $data); |
---|
186 | } |
---|
187 | return $this->load->view('collaborator/reportAsistant/listview_user', $data, true); |
---|
188 | } |
---|
189 | |
---|
190 | private function get_fullname($us_id) { |
---|
191 | $fullname=""; |
---|
192 | $src = 'SBG'; |
---|
193 | $token = md5($us_id . self::TOKENPW); |
---|
194 | $this->load->model('admin/user_model'); |
---|
195 | $data = $this->user_model->get_user_info($src, $us_id, $token); |
---|
196 | parse_str($data,$data); |
---|
197 | if (isset($data['fullname'])) |
---|
198 | { |
---|
199 | $fullname=$data['fullname']; |
---|
200 | } |
---|
201 | return $fullname; |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|