online.php (1782B)
1 <?php 2 class ModelReportOnline extends Model { 3 public function getOnline($data = array()) { 4 $sql = "SELECT co.ip, co.customer_id, co.url, co.referer, co.date_added FROM " . DB_PREFIX . "customer_online co LEFT JOIN " . DB_PREFIX . "customer c ON (co.customer_id = c.customer_id)"; 5 6 $implode = array(); 7 8 if (!empty($data['filter_ip'])) { 9 $implode[] = "co.ip LIKE '" . $this->db->escape($data['filter_ip']) . "'"; 10 } 11 12 if (!empty($data['filter_customer'])) { 13 $implode[] = "co.customer_id > 0 AND CONCAT(c.firstname, ' ', c.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "'"; 14 } 15 16 if ($implode) { 17 $sql .= " WHERE " . implode(" AND ", $implode); 18 } 19 20 $sql .= " ORDER BY co.date_added DESC"; 21 22 if (isset($data['start']) || isset($data['limit'])) { 23 if ($data['start'] < 0) { 24 $data['start'] = 0; 25 } 26 27 if ($data['limit'] < 1) { 28 $data['limit'] = 20; 29 } 30 31 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; 32 } 33 34 $query = $this->db->query($sql); 35 36 return $query->rows; 37 } 38 39 public function getTotalOnline($data = array()) { 40 $sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer_online` co LEFT JOIN " . DB_PREFIX . "customer c ON (co.customer_id = c.customer_id)"; 41 42 $implode = array(); 43 44 if (!empty($data['filter_ip'])) { 45 $implode[] = "co.ip LIKE '" . $this->db->escape($data['filter_ip']) . "'"; 46 } 47 48 if (!empty($data['filter_customer'])) { 49 $implode[] = "co.customer_id > 0 AND CONCAT(c.firstname, ' ', c.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "'"; 50 } 51 52 if ($implode) { 53 $sql .= " WHERE " . implode(" AND ", $implode); 54 } 55 56 $query = $this->db->query($sql); 57 58 return $query->row['total']; 59 } 60 }