1: | <?php
|
2: | namespace Opencart\Admin\Controller\Report;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Online extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('report/online');
|
16: |
|
17: | $this->document->setTitle($this->language->get('heading_title'));
|
18: |
|
19: | $url = '';
|
20: |
|
21: | if (isset($this->request->get['filter_customer'])) {
|
22: | $url .= '&filter_customer=' . urlencode(html_entity_decode((string)$this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
23: | }
|
24: |
|
25: | if (isset($this->request->get['filter_ip'])) {
|
26: | $url .= '&filter_ip=' . $this->request->get['filter_ip'];
|
27: | }
|
28: |
|
29: | if (isset($this->request->get['page'])) {
|
30: | $url .= '&page=' . $this->request->get['page'];
|
31: | }
|
32: |
|
33: | $data['breadcrumbs'] = [];
|
34: |
|
35: | $data['breadcrumbs'][] = [
|
36: | 'text' => $this->language->get('text_home'),
|
37: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
38: | ];
|
39: |
|
40: | $data['breadcrumbs'][] = [
|
41: | 'text' => $this->language->get('heading_title'),
|
42: | 'href' => $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'])
|
43: | ];
|
44: |
|
45: | $data['list'] = $this->getList();
|
46: |
|
47: | $data['user_token'] = $this->session->data['user_token'];
|
48: |
|
49: | $data['header'] = $this->load->controller('common/header');
|
50: | $data['column_left'] = $this->load->controller('common/column_left');
|
51: | $data['footer'] = $this->load->controller('common/footer');
|
52: |
|
53: | $this->response->setOutput($this->load->view('report/online', $data));
|
54: | }
|
55: |
|
56: | |
57: | |
58: | |
59: | |
60: |
|
61: | public function list(): void {
|
62: | $this->load->language('report/online');
|
63: |
|
64: | $this->response->setOutput($this->getList());
|
65: | }
|
66: |
|
67: | |
68: | |
69: | |
70: | |
71: |
|
72: | protected function getList(): string {
|
73: | if (isset($this->request->get['filter_customer'])) {
|
74: | $filter_customer = $this->request->get['filter_customer'];
|
75: | } else {
|
76: | $filter_customer = '';
|
77: | }
|
78: |
|
79: | if (isset($this->request->get['filter_ip'])) {
|
80: | $filter_ip = $this->request->get['filter_ip'];
|
81: | } else {
|
82: | $filter_ip = '';
|
83: | }
|
84: |
|
85: | if (isset($this->request->get['page'])) {
|
86: | $page = (int)$this->request->get['page'];
|
87: | } else {
|
88: | $page = 1;
|
89: | }
|
90: |
|
91: | $data['customers'] = [];
|
92: |
|
93: | $filter_data = [
|
94: | 'filter_customer' => $filter_customer,
|
95: | 'filter_ip' => $filter_ip,
|
96: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
97: | 'limit' => $this->config->get('config_pagination_admin')
|
98: | ];
|
99: |
|
100: | $this->load->model('report/online');
|
101: | $this->load->model('customer/customer');
|
102: |
|
103: | $results = $this->model_report_online->getOnline($filter_data);
|
104: |
|
105: | foreach ($results as $result) {
|
106: | $customer_info = $this->model_customer_customer->getCustomer($result['customer_id']);
|
107: |
|
108: | if ($customer_info) {
|
109: | $customer = $customer_info['firstname'] . ' ' . $customer_info['lastname'];
|
110: | } else {
|
111: | $customer = $this->language->get('text_guest');
|
112: | }
|
113: |
|
114: | $data['customers'][] = [
|
115: | 'customer_id' => $result['customer_id'],
|
116: | 'ip' => $result['ip'],
|
117: | 'customer' => $customer,
|
118: | 'url' => $result['url'],
|
119: | 'referer' => $result['referer'],
|
120: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
|
121: | 'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'])
|
122: | ];
|
123: | }
|
124: |
|
125: | $url = '';
|
126: |
|
127: | if (isset($this->request->get['filter_customer'])) {
|
128: | $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']);
|
129: | }
|
130: |
|
131: | if (isset($this->request->get['filter_ip'])) {
|
132: | $url .= '&filter_ip=' . $this->request->get['filter_ip'];
|
133: | }
|
134: |
|
135: | $customer_total = $this->model_report_online->getTotalOnline($filter_data);
|
136: |
|
137: | $data['pagination'] = $this->load->controller('common/pagination', [
|
138: | 'total' => $customer_total,
|
139: | 'page' => $page,
|
140: | 'limit' => $this->config->get('config_pagination_admin'),
|
141: | 'url' => $this->url->link('report/online.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
142: | ]);
|
143: |
|
144: | $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($customer_total - $this->config->get('config_pagination_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $customer_total, ceil($customer_total / $this->config->get('config_pagination_admin')));
|
145: |
|
146: | return $this->load->view('report/online_list', $data);
|
147: | }
|
148: | }
|
149: | |