Combu Server  3.1.1
PHP API Documentation
IpBan.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class IpBan extends DataClass {
11 
12  const TABLE_NAME = "IpBan";
13 
14  public $Id = 0;
15  public $DateCreated = NULL;
16  public $DateUpdated = NULL;
17  public $IdApp = 0;
18  public $IdAdminAccount = 0;
19  public $FromIp = "";
20  public $ToIp = "";
21  public $FromIpInt = 0;
22  public $ToIpInt = 0;
23  public $Reason = "";
24 
28  public function __construct($src = null, $stripSlashes = false) {
29  if (!empty($src)) {
30  if (is_array($src)) {
31  // Load by array
32  $this->_loadByRow($src, $stripSlashes);
33  } else if (is_numeric($src)) {
34  // Load by Id
35  $this->_loadFilter(self::GetTableName(__CLASS__), sprintf("Id = %d", $src));
36  }
37  }
38  }
39 
51  public static function Load ($idApp = 0, $idAdminAccount = 0, $ip = NULL, $limit = null, $offset = null, &$count = null) {
52  global $Database;
53  $where = "";
54  if ($idApp > 0) {
55  $where .= ($where ? " AND " : "") . sprintf("(IdApp = 0 OR IdApp = %d)", $idApp);
56  }
57  if ($idAdminAccount > 0) {
58  $where .= ($where ? " AND " : "") . sprintf("(IdAdminAccount = %d)", $idAdminAccount);
59  }
60  if (!empty($ip)) {
61  $where .= ($where ? " AND " : "") . sprintf("(INET6_ATON('%s') BETWEEN FromIpInt AND ToIpInt)", $Database->Escape($ip));
62  }
63  return self::_load(self::GetTableName(__CLASS__), __CLASS__, $where, NULL, $limit, $offset, $count);
64  }
65 
71  public function Save() {
72  global $Database;
73  $this->DateUpdated = Utils::GetCurrentDateTimeFormat();
74  if ($this->Id > 0) {
75  $query = sprintf("UPDATE %s SET IdApp = %d, FromIp = '%s', ToIp = '%s', FromIpInt = INET6_ATON('%s'), ToIpInt = INET6_ATON('%s'), Reason = '%s', DateUpdated = %s, IdAdminAccount = %d WHERE Id = %d",
76  self::GetTableName(__CLASS__),
77  $this->IdApp,
78  $Database->Escape($this->FromIp),
79  $Database->Escape($this->ToIp),
80  $Database->Escape($this->FromIp),
81  $Database->Escape($this->ToIp),
82  $Database->Escape($this->Reason),
83  $Database->EscapeDate($this->DateUpdated),
84  $this->IdAdminAccount,
85  $this->Id);
86  } else {
87  $this->DateCreated = $this->DateUpdated;
88  $query = sprintf("INSERT INTO %s (IdApp, IdAdminAccount, DateCreated, DateUpdated, FromIp, ToIp, FromIpInt, ToIpInt, Reason) VALUES (%d, %d, %s, %s, '%s', '%s', INET6_ATON('%s'), INET6_ATON('%s'), '%s')",
89  self::GetTableName(__CLASS__),
90  $this->IdApp,
91  $this->IdAdminAccount,
92  $Database->EscapeDate($this->DateCreated),
93  $Database->EscapeDate($this->DateUpdated),
94  $Database->Escape($this->FromIp),
95  $Database->Escape($this->ToIp),
96  $Database->Escape($this->FromIp),
97  $Database->Escape($this->ToIp),
98  $Database->Escape($this->Reason));
99  }
100  if ($Database->Query($query)) {
101  if ($this->Id < 1) {
102  $this->Id = $Database->InsertedId();
103  }
104  return TRUE;
105  }
106  return FALSE;
107  }
108 
114  public function Delete() {
115  if ($this->Id > 0) {
116  return $this->_Delete(self::GetTableName(__CLASS__), sprintf("Id = %d", $this->Id));
117  }
118  return FALSE;
119  }
120 }
static Load($idApp=0, $idAdminAccount=0, $ip=NULL, $limit=null, $offset=null, &$count=null)
Definition: IpBan.php:51
Definition: Account.php:3
__construct($src=null, $stripSlashes=false)
Definition: IpBan.php:28