shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ip.php (1480B)


      1 <?php
      2 class ModelExtensionFraudIp extends Model {
      3 	public function install() {
      4 		$this->db->query("
      5 		CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "fraud_ip` (
      6 		  `ip` varchar(40) NOT NULL,
      7 		  `date_added` datetime NOT NULL,
      8 		  PRIMARY KEY (`ip`)
      9 		) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
     10 		");
     11 	}
     12 
     13 	public function uninstall() {
     14 		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ip`");
     15 	}
     16 
     17     public function addIp($ip) {
     18         $this->db->query("INSERT INTO `" . DB_PREFIX . "fraud_ip` SET `ip` = '" . $this->db->escape($ip) . "', date_added = NOW()");
     19     }
     20 
     21     public function removeIp($ip) {
     22         $this->db->query("DELETE FROM `" . DB_PREFIX . "fraud_ip` WHERE `ip` = '" . $this->db->escape($ip) . "'");
     23     }
     24 
     25 	public function getIps($start = 0, $limit = 10) {
     26         if ($start < 0) {
     27 			$start = 0;
     28 		}
     29 
     30 		if ($limit < 1) {
     31 			$limit = 10;
     32 		}
     33 
     34         $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "fraud_ip` ORDER BY `ip` ASC LIMIT " . (int)$start . "," . (int)$limit);
     35 
     36 		return $query->rows;
     37 	}
     38 
     39 	public function getTotalIps() {
     40 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "fraud_ip`");
     41 
     42 		return $query->row['total'];
     43 	}
     44 
     45 	public function getTotalIpsByIp($ip) {
     46 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "fraud_ip` WHERE ip = '" . $this->db->escape($ip) . "'");
     47 
     48 		return $query->row['total'];
     49 	}
     50 }