Guest User

Untitled

a guest
Jan 20th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. <?php
  2. require_once(LIBRARY . '/DBWrapper.lib.php');
  3.  
  4. class User extends DBWrapper {
  5.  
  6. public function __construct($db = GDBNAME, $host = GDBHOST) {
  7. parent::__construct($db, $host);
  8. }
  9.  
  10. public function isValidPass($pass) { return preg_match('/^[a-z0-9]+$/i', $pass); }
  11. public function isValidUser($user) {
  12. if (!preg_match('/^[a-z0-9_]+$/i', $user)) return false; // a-z9-0 case insensitive
  13. else if (strlen($user) > 15) return false;
  14. else return true;
  15. }
  16. public function userExists($user) {
  17. if (!$this->isValidUser($user)) return false;
  18. $result = parent::query("SELECT COUNT(*) FROM TB_USER WHERE strAccountID=?", array(&$user));
  19. return (count($result) > 0 && $result[0][""] > 0 ? true : false);
  20. }
  21.  
  22.  
  23. public function updateWidgets($user, $widgets) {
  24. $w = serialize($widgets);
  25. parent::query("UPDATE TB_USER set Widgets=? where strAccountID=?", array(&$w, &$user));
  26.  
  27. }
  28. public function getWidgets($user) {
  29. $w = parent::query("SELECT Widgets from TB_USER where strAccountID=?", array(&$user));
  30.  
  31. return (count($w) > 0 ? unserialize($w[0]["Widgets"]) : array());
  32.  
  33. }
  34. public function getAllWidgets() {
  35. $w = parent::query("SELECT * FROM PANEL_HOME");
  36. if (count($w) == 0) return false;
  37. $output = array();
  38. foreach ($w as $widget) {
  39. if (isset($_SESSION['authority']) && $_SESSION['authority'] >= $widget['accessLevel']) {
  40. $output[$widget["templateID"]] = $widget;
  41.  
  42. }
  43.  
  44. }
  45.  
  46. return $output;
  47. }
  48. public function changePassword($oldPassword, $newPassword, $confirmNewPassword, $user) {
  49. if (!$this->isValidPass($oldPassword)) return false;
  50. if (!$this->isValidPass($newPassword)) return false;
  51. if (!$this->isValidUser($user)) return false;
  52. if ($newPassword !== $confirmNewPassword) return false;
  53.  
  54. $oldPassword = md5($oldPassword);
  55. $oldPass = parent::query("SELECT COUNT(*) FROM TB_USER where strAccountID=? AND strPasswd=?", array(&$user, &$oldPassword));
  56.  
  57. if (count($oldPass) > 0 && $oldPass[0][""] > 0 ) {
  58. $newPassword = md5($newPassword);
  59. parent::query("UPDATE TB_USER set strPasswd=? where strAccountID=?", array(&$newPassword, &$user));
  60. return true;
  61. }
  62. return false;
  63. }
  64. public function checkFriend($user, $strFriend) {
  65. $query = "SELECT COUNT(*) FROM panelFriends WHERE userid=(SELECT customerID from TB_USER where strAccountID=?) and friendid=(SELECT customerID from TB_USER where strAccountID=?)";
  66. $result = parent::query($query, array(&$user, &$strFriend));
  67. return (count($result) > 0 && $result[0][""] > 0 ? true : false);
  68. }
  69. public function addFriend($user, $strFriend) {
  70. if ($this->checkFriend($user, $strFriend) == true) return false;
  71. $query = "INSERT INTO panelFriends(userid, friendid, date) VALUES ((SELECT customerID from TB_USER where strAccountID=?), (SELECT customerID from TB_USER where strAccountID=?), ?)";
  72. parent::query($query, array(&$user, &$strFriend, time()));
  73. return true;
  74. }
  75. public function delFriend($user, $strFriend) {
  76. parent::query("DELETE FROM panelFriends WHERE userid=(SELECT customerID from TB_USER where strAccountID=?) and friendid=(SELECT customerID from TB_USER where strAccountID=?)", array(&$user, &$strFriend));
  77. }
  78. public function getFriends($user, $n = 8) {
  79. $query = sprintf("SELECT TOP %d t.strAccountID, p.date, a.bNation FROM panelFriends p left join TB_USER t on t.customerID=p.friendid left join ACCOUNT_CHAR a on a.strAccountID=t.strAccountID where userid=(SELECT customerID from TB_USER where strAccountID=?)", $n);
  80. return parent::query($query, array(&$user));
  81. }
  82.  
  83. public function lastSeen($user) {
  84. $r = parent::query("SELECT TOP 1 date from site_statistics where username=? order by date desc", array(&$user));
  85.  
  86. return (isset($r[0]["date"]) ? date("D jS H:i", $r[0]["date"]) : 'never');
  87. }
  88. public function latestTopics($user, $n = 5) {
  89. $result = parent::query(sprintf("SELECT TOP %d * from forumTopics
  90. WHERE posterid=(SELECT CustomerID from TB_USER where strAccountID=?) ORDER BY created DESC", $n), array(&$user));
  91. return $result;
  92. }
  93. public function getNPRank($char) {
  94. $query = "SELECT u1.strUserID, u1.Loyalty, u1.Level,
  95. (SELECT COUNT(*) FROM USERDATA u2 where u2.Loyalty>=u1.Loyalty) as rank
  96. FROM USERDATA u1 WHERE strUserID=?";
  97. $result = parent::query($query, array(&$char));
  98. return $result;
  99. }
  100. public function latestPosts($user, $n = 5) {
  101. $query = sprintf("SELECT TOP %d posted, topicid, t.title, postid, forumPosts.posterid, forumPosts.viewable
  102. FROM forumPosts INNER JOIN forumTopics AS t ON t.id = forumPosts.topicid
  103. WHERE (forumPosts.viewable = 1) and
  104. (forumPosts.posterid=(select customerid from tb_user where strAccountID=?))
  105. ORDER BY forumPosts.posted DESC", $n);
  106.  
  107. $result = parent::query($query, array(&$user));
  108. return $result;
  109. }
  110. public function postCount($user) {
  111.  
  112. }
  113. public function topicCount($user) {
  114.  
  115. }
  116. public function getRank($user) {
  117. $query = "SELECT strTitle from forumGroups where groupID=(SELECT forumGroup from TB_USER where strAccountID=?)";
  118. $result = parent::query($query, array(&$user));
  119. return $result[0]["strTitle"];
  120. }
  121. public function getCharacters($user) {
  122. $cols = array('strCharID1', 'strCharID2', 'strCharID3', 'strCharID4', 'strCharID5');
  123. $query = sprintf("SELECT %s FROM ACCOUNT_CHAR WHERE strAccountID=?", implode(",", $cols));
  124. $chars = parent::query($query, array(&$user));
  125. if (count($chars) == 0) return false;
  126. $count = count($chars[0]);
  127. $output = array();
  128. for ($i = 0; $i<$count; ++$i)
  129. if ($chars[0][$cols[$i]] != NULL) $output[] = $chars[0][$cols[$i]];
  130.  
  131. return $output;
  132. }
  133.  
  134. /**
  135. * edit
  136. * @author DeathsEffigy <Fabi.Schn@googlemail.com>
  137. */
  138. public function can_transfer ()
  139. {
  140. $interval = 7 * 24 * 60 * 60; // days * hours * minutes * seconds
  141. $user = $_SESSION['username'];
  142. $query = "SELECT * FROM PANEL_NT WHERE strAccountID = ?";
  143. $result = parent::query ($query, array (&$user));
  144. if (count ($result) == 0) return true;
  145. $last = $result[0]['nTime'];
  146. return (($last + $interval) < time ()) ? true : false;
  147. }
  148.  
  149. public function nation_transfer ()
  150. {
  151. $user = $_SESSION['username'];
  152. $query = "SELECT * FROM KNIGHTS_USER k LEFT OUTER JOIN ACCOUNT_CHAR a ON ((a.strCharID1 = k.strUserID) OR (a.strCharID2 = k.strUserID) OR (a.strCharID3 = k.strUserID)) WHERE a.strAccountID = ?";
  153. $result = parent::query ($query, array (&$user));
  154. if (count ($result) > 0) return false;
  155. $query = "EXEC ACCOUNT_NATION_CHANGE ?";
  156. parent::query ($query, array (&$user));
  157. $query = "DELETE FROM PANEL_NT WHERE strAccountID = ?";
  158. parent::query ($query, array (&$user));
  159. $query = "INSERT INTO PANEL_NT VALUES (?, ?)";
  160. parent::query ($query, array (&$user, time ()));
  161. return true;
  162. }
  163.  
  164. public function can_delete_char ()
  165. {
  166. $user = $_SESSION['username'];
  167. $query = "SELECT * FROM ACCOUNT_CHAR WHERE strAccountID = ?";
  168. $result = parent::query ($query, array (&$user));
  169. if (count ($result) == 0) return false;
  170. $row = $result[0];
  171. if (empty ($row['strCharID1']) && empty ($row['strCharID2']) && empty ($row['strCharID3'])) return false;
  172. return array ('char1' => $result[0]['strCharID1'], 'char2' => $result[0]['strCharID2'], 'char3' => $result[0]['strCharID3']);
  173. }
  174.  
  175. public function get_delete_char_nec ()
  176. {
  177. $user = $_SESSION['username'];
  178. $query = "SELECT * FROM TB_USER WHERE strAccountID = ?";
  179. $result = parent::query ($query, array (&$user));
  180. return $result[0];
  181. }
  182.  
  183. public function delete_char ($char, $answer)
  184. {
  185. $user = $_SESSION['username'];
  186. $acc = $this->get_delete_char_nec ();
  187. if ($answer != $acc['sAnswer']) return false;
  188. $query = "SELECT * FROM ACCOUNT_CHAR WHERE strAccountID = ?";
  189. $result = parent::query ($query, array (&$user));
  190. $chara = $result[0]['strCharID' . intval ($char)];
  191. $query = "SELECT * FROM CURRENTUSER WHERE strCharID = ?";
  192. $result = parent::query ($query, array (&$chara));
  193. if (count ($result) > 0) return false;
  194. $query = "UPDATE ACCOUNT_CHAR SET strCharID$char = NULL WHERE strAccountID = ?";
  195. parent::query ($query, array (&$user));
  196. $query = "DELETE FROM USERDATA WHERE strUserId = ?";
  197. parent::query ($query, array (&$chara));
  198. $query = "DELETE FROM KNIGHTS_USER WHERE strUserID = ?";
  199. parent::query ($query, array (&$chara));
  200. $query = "DELETE FROM FRIEND_LIST WHERE strUserID = ?";
  201. parent::query ($query, array (&$chara));
  202. $query = "DELETE FROM USER_RENTAL_ITEM WHERE strUserID = ?";
  203. parent::query ($query, array (&$chara));
  204. $query = "DELETE FROM USERDATA_SKILLSHORTCUT WHERE strCharID = ?";
  205. parent::query ($query, array (&$chara));
  206. return true;
  207. }
  208.  
  209. public function secret_password_correct ($password)
  210. {
  211. $user = $_SESSION['username'];
  212. $query = "SELECT * FROM TB_USER WHERE strAccountID = ? AND strPasswd = ?";
  213. $result = parent::query ($query, array (&$user, &$password));
  214. return $result == 0 ? false : true;
  215. }
  216.  
  217. public function secret_update ($question, $answer)
  218. {
  219. $user = $_SESSION['username'];
  220. $query = "UPDATE TB_USER SET sQuestion = ?, sAnswer = ? WHERE strAccountID = ?";
  221. $result = parent::query ($query, array (&$question, &$answer, &$user));
  222. return true;
  223. }
  224. /**
  225. * edit end
  226. */
  227. }
Add Comment
Please, Sign In to add comment