Guest User

Untitled

a guest
May 30th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. <?php
  2. class admin
  3. {
  4. private $table;
  5. private $id;
  6.  
  7. private $data;
  8.  
  9. public $username;
  10. public $real_name;
  11. public $password;
  12. public $last_login;
  13.  
  14. public $error;
  15.  
  16. public function __construct($table)
  17. {
  18. $this->table = $table;
  19.  
  20. $sQuery = @mysql_query("CHECK TABLE ".$this->table."");
  21.  
  22. if ($sQuery == false)
  23. {
  24. die("Error while checking table: ".$this->table."");
  25. }
  26.  
  27. else
  28. {
  29. $aData = mysql_fetch_array($sQuery);
  30.  
  31. $t_message = strtolower($aData['Msg_text']);
  32.  
  33. if ($t_message != "ok")
  34. {
  35. die("Table \"".$this->table."\" doesn't exists or is corrupt");
  36. }
  37. }
  38. }
  39.  
  40. public function getData($ad_id)
  41. {
  42. $this->id = $ad_id;
  43.  
  44. if (is_numeric($ad_id))
  45. {
  46.  
  47. $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = ".$this->id."");
  48.  
  49. if ($sQuery == false)
  50. {
  51. die("Error while executing the Query, error of MySQL: ".mysql_error()."");
  52. }
  53.  
  54. else
  55. {
  56. $aData = @mysql_fetch_array($sQuery);
  57.  
  58. if ($aData == false)
  59. {
  60. return "user_not_found";
  61. }
  62.  
  63. else
  64. {
  65. $this->username = $aData['username'];
  66. $this->real_name = $aData['real_name'];
  67. $this->password = $aData['password'];
  68. $this->last_login = $aData['last_login'];
  69. }
  70. }
  71. }
  72.  
  73. else
  74. {
  75. return "not_numeric";
  76. }
  77. }
  78.  
  79. public function addAdmin($data_ar)
  80. {
  81. $this->data = $data_ar;
  82.  
  83. if(isset($this->data))
  84. {
  85. if (is_array($this->data))
  86. {
  87. $this->username = $this->data['username'];
  88. $this->real_name = $this->data['real_name'];
  89. $this->password = $this->data['password'];
  90.  
  91. if (empty($this->username))
  92. {
  93. $this->username = "Default";
  94. }
  95.  
  96. if (empty($this->real_name))
  97. {
  98. $this->real_name = "Default";
  99. }
  100.  
  101. if (empty($this->password))
  102. {
  103. $this->password = "Default";
  104. }
  105.  
  106. $this->password = md5($this->password);
  107.  
  108. $rResult = @mysql_query("INSERT INTO ".$this->table." (username, real_name, password, last_login) VALUES ('".$this->username."', '".$this->real_name."', '".$this->password."', NOW())");
  109.  
  110. if ($rResult == false)
  111. {
  112. return "useradd_error";
  113. $this->error = "A error occured while adding the user to the Database, MySQL error: ".mysql_error()."";
  114. }
  115.  
  116. else
  117. {
  118. $sQuery = @mysql_query("SELECT admin_id FROM ".$this->table." ORDER BY admin_id DESC");
  119.  
  120. if ($sQuery == false)
  121. {
  122. die("A error occured while selecting the added user");
  123. }
  124.  
  125. else
  126. {
  127. $rResult = @mysql_fetch_array($sQuery);
  128.  
  129. if ($rResult == false)
  130. {
  131. die("A error occured while fetching the data from the user");
  132. }
  133.  
  134. else
  135. {
  136. return $rResult['admin_id'];
  137. }
  138. }
  139.  
  140. }
  141. }
  142.  
  143. else
  144. {
  145. die("Data is not a array !");
  146. }
  147. }
  148.  
  149. else
  150. {
  151. die("No data found");
  152. }
  153.  
  154. }
  155.  
  156. public function editAdmin($id, $data_ar)
  157. {
  158. $this->id = $id;
  159. $this->data = $data_ar;
  160.  
  161. if (is_numeric($id))
  162. {
  163. if (!empty($this->data))
  164. {
  165. $this->username = $this->data['username'];
  166. $this->real_name = $this->data['real_name'];
  167. $this->password = $this->data['password'];
  168.  
  169.  
  170. $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = ".$this->id."");
  171.  
  172. if ($sQuery == false)
  173. {
  174. die("Error while executing the Query, error of mysql: ".mysql_error()."");
  175. }
  176.  
  177. else
  178. {
  179. $cCount = @mysql_num_rows($sQuery);
  180.  
  181. if ($cCount == 0)
  182. {
  183. return "user_not_found";
  184. $this->error = "An error occured while searching the user, error of MySQL: ".mysql_error()."";
  185. }
  186.  
  187. else
  188. {
  189. if (empty($this->password))
  190. {
  191. $sQuery = @mysql_query("SELECT password FROM ".$this->table." WHERE admin_id = '".$this->id."'");
  192.  
  193. if ($sQuery == false)
  194. {
  195. die("Problem while executing the Query, error of mysql: ".mysql_error()."");
  196. }
  197.  
  198. else
  199. {
  200. $aData = @mysql_fetch_array($sQuery);
  201.  
  202. if ($aData == false)
  203. {
  204. die("User not found !");
  205. }
  206.  
  207. else
  208. {
  209. $this->password = $aData['password'];
  210. }
  211. }
  212. }
  213.  
  214. else
  215. {
  216. $this->password = md5($this->password);
  217. }
  218.  
  219. $uQuery = mysql_query("UPDATE ".$this->table." SET username = '".$this->username."', real_name = '".$this->real_name."', password = '".$this->password."' WHERE admin_id = '".$this->id."'");
  220.  
  221. if ($uQuery == false)
  222. {
  223. die("Critical error while updating the Admin, error of MySQL: ".mysql_error()."");
  224. }
  225.  
  226. else
  227. {
  228. return "user_updated";
  229. }
  230.  
  231. }
  232. }
  233. }
  234.  
  235. else
  236. {
  237. return "data_empty";
  238. }
  239. }
  240.  
  241. else
  242. {
  243. return "not_numeric";
  244. }
  245. }
  246.  
  247. public function deleteAdmin($id)
  248. {
  249. $this->id = $id;
  250.  
  251. if (!empty($this->id))
  252. {
  253. if (is_numeric($this->id))
  254. {
  255. $sQuery = @mysql_query("SELECT * FROM ".$this->table." WHERE admin_id = '".$this->id."'");
  256.  
  257. if ($sQuery == false)
  258. {
  259. die("An error occured while executing the Query, error of MySQL: ".mysql_error()."");
  260. }
  261.  
  262. else
  263. {
  264. $cCount = @mysql_num_rows($sQuery);
  265.  
  266. if ($cCount == false)
  267. {
  268. return "user_not_found";
  269. $this->error = "No admin was found on id#".$this->id."";
  270. }
  271.  
  272. else
  273. {
  274. $dQuery = @mysql_query("DELETE FROM ".$this->table." WHERE admin_id = '".$this->id."'");
  275.  
  276. if ($dQuery == false)
  277. {
  278. die("An error occured while executing the Query, error of MySQL: ".mysql_error()."");
  279. }
  280.  
  281. else
  282. {
  283. return "user_deleted";
  284. }
  285. }
  286. }
  287. }
  288.  
  289. else
  290. {
  291. return "not_numeric";
  292. }
  293. }
  294.  
  295. else
  296. {
  297. return "no_id";
  298. }
  299. }
  300. }
  301.  
  302.  
  303. ?>
Add Comment
Please, Sign In to add comment