Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class admin
- {
- private $table;
- private $id;
- private $data;
- public $username;
- public $real_name;
- public $password;
- public $last_login;
- public $error;
- public function __construct($table)
- {
- $this->table = $table;
- $sQuery = @mysql_query("CHECK TABLE ".$this->table."");
- if ($sQuery == false)
- {
- die("Error while checking table: ".$this->table."");
- }
- else
- {
- $aData = mysql_fetch_array($sQuery);
- $t_message = strtolower($aData['Msg_text']);
- if ($t_message != "ok")
- {
- die("Table \"".$this->table."\" doesn't exists or is corrupt");
- }
- }
- }
- public function getData($ad_id)
- {
- $this->id = $ad_id;
- if (is_numeric($ad_id))
- {
- $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = ".$this->id."");
- if ($sQuery == false)
- {
- die("Error while executing the Query, error of MySQL: ".mysql_error()."");
- }
- else
- {
- $aData = @mysql_fetch_array($sQuery);
- if ($aData == false)
- {
- return "user_not_found";
- }
- else
- {
- $this->username = $aData['username'];
- $this->real_name = $aData['real_name'];
- $this->password = $aData['password'];
- $this->last_login = $aData['last_login'];
- }
- }
- }
- else
- {
- return "not_numeric";
- }
- }
- public function addAdmin($data_ar)
- {
- $this->data = $data_ar;
- if(isset($this->data))
- {
- if (is_array($this->data))
- {
- $this->username = $this->data['username'];
- $this->real_name = $this->data['real_name'];
- $this->password = $this->data['password'];
- if (empty($this->username))
- {
- $this->username = "Default";
- }
- if (empty($this->real_name))
- {
- $this->real_name = "Default";
- }
- if (empty($this->password))
- {
- $this->password = "Default";
- }
- $this->password = md5($this->password);
- $rResult = @mysql_query("INSERT INTO ".$this->table." (username, real_name, password, last_login) VALUES ('".$this->username."', '".$this->real_name."', '".$this->password."', NOW())");
- if ($rResult == false)
- {
- return "useradd_error";
- $this->error = "A error occured while adding the user to the Database, MySQL error: ".mysql_error()."";
- }
- else
- {
- $sQuery = @mysql_query("SELECT admin_id FROM ".$this->table." ORDER BY admin_id DESC");
- if ($sQuery == false)
- {
- die("A error occured while selecting the added user");
- }
- else
- {
- $rResult = @mysql_fetch_array($sQuery);
- if ($rResult == false)
- {
- die("A error occured while fetching the data from the user");
- }
- else
- {
- return $rResult['admin_id'];
- }
- }
- }
- }
- else
- {
- die("Data is not a array !");
- }
- }
- else
- {
- die("No data found");
- }
- }
- public function editAdmin($id, $data_ar)
- {
- $this->id = $id;
- $this->data = $data_ar;
- if (is_numeric($id))
- {
- if (!empty($this->data))
- {
- $this->username = $this->data['username'];
- $this->real_name = $this->data['real_name'];
- $this->password = $this->data['password'];
- $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = ".$this->id."");
- if ($sQuery == false)
- {
- die("Error while executing the Query, error of mysql: ".mysql_error()."");
- }
- else
- {
- $cCount = @mysql_num_rows($sQuery);
- if ($cCount == 0)
- {
- return "user_not_found";
- $this->error = "An error occured while searching the user, error of MySQL: ".mysql_error()."";
- }
- else
- {
- if (empty($this->password))
- {
- $sQuery = @mysql_query("SELECT password FROM ".$this->table." WHERE admin_id = '".$this->id."'");
- if ($sQuery == false)
- {
- die("Problem while executing the Query, error of mysql: ".mysql_error()."");
- }
- else
- {
- $aData = @mysql_fetch_array($sQuery);
- if ($aData == false)
- {
- die("User not found !");
- }
- else
- {
- $this->password = $aData['password'];
- }
- }
- }
- else
- {
- $this->password = md5($this->password);
- }
- $uQuery = mysql_query("UPDATE ".$this->table." SET username = '".$this->username."', real_name = '".$this->real_name."', password = '".$this->password."' WHERE admin_id = '".$this->id."'");
- if ($uQuery == false)
- {
- die("Critical error while updating the Admin, error of MySQL: ".mysql_error()."");
- }
- else
- {
- return "user_updated";
- }
- }
- }
- }
- else
- {
- return "data_empty";
- }
- }
- else
- {
- return "not_numeric";
- }
- }
- public function deleteAdmin($id)
- {
- $this->id = $id;
- if (!empty($this->id))
- {
- if (is_numeric($this->id))
- {
- $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = '".$this->id."'");
- if ($sQuery == false)
- {
- die("An error occured while executing the Query, error of MySQL: ".mysql_error()."");
- }
- else
- {
- $cCount = @mysql_num_rows($sQuery);
- if ($cCount == false)
- {
- return "user_not_found";
- $this->error = "No admin was found on id#".$this->id."";
- }
- else
- {
- $dQuery = @mysql_query("DELETE FROM ".$this->table." WHERE admin_id = '".$this->id."'");
- if ($dQuery == false)
- {
- die("An error occured while executing the Query, error of MySQL: ".mysql_error()."");
- }
- else
- {
- return "user_deleted";
- }
- }
- }
- }
- else
- {
- return "not_numeric";
- }
- }
- else
- {
- return "no_id";
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment