7 const TABLE_NAME =
"AdminAccount";
10 public $Username =
"";
11 public $Password =
"";
16 public function __construct($src = null, $stripSlashes =
false) {
22 $this->_loadByRow($src, $stripSlashes);
23 }
else if (is_numeric($src) && intval($src) > 0) {
25 $this->_loadFilter(self::GetTableName(__CLASS__),
"Id = " . intval($src));
28 $this->_loadFilter(self::GetTableName(__CLASS__),
"Username = '" . $Database->Escape($src) .
"'");
39 $sql =
"SELECT Id FROM " . self::GetTableName(__CLASS__) .
" WHERE Username = '" . $Database->Escape($this->Username) .
"'";
41 $sql .=
" AND Id <> " . $this->Id;
42 $res = $Database->Query($sql);
44 $row = $Database->FetchAssoc($res);
58 return ($this->Id > 0 && $this->Id == $AdminLogged->Id);
71 public static function Load($username =
"", $limit = null, $offset = null, &$count = null, $returnArray =
false) {
75 $where .= ($where ==
"" ?
"" :
" AND ") .
"Username LIKE '" . $Database->Escape($username) .
"%'";
76 return self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), $where,
"Username", $limit, $offset, $count);
87 public static function CheckLogin($username, $password, &$account = null) {
90 $query = sprintf(
"SELECT * FROM " . self::GetTableName(__CLASS__) .
" WHERE Username = '%s' AND Password = '%s'", $Database->Escape($username), $Database->Escape(md5($password)));
91 $res = $Database->Query($query);
93 $row = $Database->FetchAssoc($res);
95 $account =
new self($row);
108 $id = (!isset($_SESSION[
"AdminId"]) ? 0 : intval($_SESSION[
"AdminId"]));
109 $account =
new self($id);
119 global $AdminLogged, $Database;
120 if ($account && is_a($account, __CLASS__) && $account->Id > 0) {
121 $AdminLogged = $account;
122 $_SESSION[
"AdminId"] = $account->Id;
131 $AdminLogged =
new self();
132 $_SESSION[
"AdminId"] = 0;
139 self::UnsetSession();
150 $query = sprintf(
"INSERT INTO %s (Username, Password) VALUES ('%s', '%s')",
151 self::GetTableName(__CLASS__),
152 $Database->Escape($this->Username),
153 $Database->Escape($this->Password));
155 $query = sprintf(
"UPDATE %s SET Username = '%s', Password = '%s' WHERE Id = %d",
156 self::GetTableName(__CLASS__),
157 $Database->Escape($this->Username),
158 $Database->Escape($this->Password),
161 $saved = $Database->Query($query);
164 $this->Id = $Database->InsertedId();
178 return $this->_Delete(self::GetTableName(__CLASS__),
"Id = " . $this->Id);
183 return json_decode(array());
184 $array = Utils::ObjectToArray($this);
186 unset($array[
"Password"]);
187 return json_encode($array);
__construct($src=null, $stripSlashes=false)
static CheckLogin($username, $password, &$account=null)
static Load($username="", $limit=null, $offset=null, &$count=null, $returnArray=false)
static SetSession(&$account)