Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once(LIBRARY . '/DBWrapper.lib.php');
- class User extends DBWrapper {
- public function __construct($db = GDBNAME, $host = GDBHOST) {
- parent::__construct($db, $host);
- }
- public function isValidPass($pass) { return preg_match('/^[a-z0-9]+$/i', $pass); }
- public function isValidUser($user) {
- if (!preg_match('/^[a-z0-9_]+$/i', $user)) return false; // a-z9-0 case insensitive
- else if (strlen($user) > 15) return false;
- else return true;
- }
- public function userExists($user) {
- if (!$this->isValidUser($user)) return false;
- $result = parent::query("SELECT COUNT(*) FROM TB_USER WHERE strAccountID=?", array(&$user));
- return (count($result) > 0 && $result[0][""] > 0 ? true : false);
- }
- public function updateWidgets($user, $widgets) {
- $w = serialize($widgets);
- parent::query("UPDATE TB_USER set Widgets=? where strAccountID=?", array(&$w, &$user));
- }
- public function getWidgets($user) {
- $w = parent::query("SELECT Widgets from TB_USER where strAccountID=?", array(&$user));
- return (count($w) > 0 ? unserialize($w[0]["Widgets"]) : array());
- }
- public function getAllWidgets() {
- $w = parent::query("SELECT * FROM PANEL_HOME");
- if (count($w) == 0) return false;
- $output = array();
- foreach ($w as $widget) {
- if (isset($_SESSION['authority']) && $_SESSION['authority'] >= $widget['accessLevel']) {
- $output[$widget["templateID"]] = $widget;
- }
- }
- return $output;
- }
- public function changePassword($oldPassword, $newPassword, $confirmNewPassword, $user) {
- if (!$this->isValidPass($oldPassword)) return false;
- if (!$this->isValidPass($newPassword)) return false;
- if (!$this->isValidUser($user)) return false;
- if ($newPassword !== $confirmNewPassword) return false;
- $oldPassword = md5($oldPassword);
- $oldPass = parent::query("SELECT COUNT(*) FROM TB_USER where strAccountID=? AND strPasswd=?", array(&$user, &$oldPassword));
- if (count($oldPass) > 0 && $oldPass[0][""] > 0 ) {
- $newPassword = md5($newPassword);
- parent::query("UPDATE TB_USER set strPasswd=? where strAccountID=?", array(&$newPassword, &$user));
- return true;
- }
- return false;
- }
- public function checkFriend($user, $strFriend) {
- $query = "SELECT COUNT(*) FROM panelFriends WHERE userid=(SELECT customerID from TB_USER where strAccountID=?) and friendid=(SELECT customerID from TB_USER where strAccountID=?)";
- $result = parent::query($query, array(&$user, &$strFriend));
- return (count($result) > 0 && $result[0][""] > 0 ? true : false);
- }
- public function addFriend($user, $strFriend) {
- if ($this->checkFriend($user, $strFriend) == true) return false;
- $query = "INSERT INTO panelFriends(userid, friendid, date) VALUES ((SELECT customerID from TB_USER where strAccountID=?), (SELECT customerID from TB_USER where strAccountID=?), ?)";
- parent::query($query, array(&$user, &$strFriend, time()));
- return true;
- }
- public function delFriend($user, $strFriend) {
- 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));
- }
- public function getFriends($user, $n = 8) {
- $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);
- return parent::query($query, array(&$user));
- }
- public function lastSeen($user) {
- $r = parent::query("SELECT TOP 1 date from site_statistics where username=? order by date desc", array(&$user));
- return (isset($r[0]["date"]) ? date("D jS H:i", $r[0]["date"]) : 'never');
- }
- public function latestTopics($user, $n = 5) {
- $result = parent::query(sprintf("SELECT TOP %d * from forumTopics
- WHERE posterid=(SELECT CustomerID from TB_USER where strAccountID=?) ORDER BY created DESC", $n), array(&$user));
- return $result;
- }
- public function getNPRank($char) {
- $query = "SELECT u1.strUserID, u1.Loyalty, u1.Level,
- (SELECT COUNT(*) FROM USERDATA u2 where u2.Loyalty>=u1.Loyalty) as rank
- FROM USERDATA u1 WHERE strUserID=?";
- $result = parent::query($query, array(&$char));
- return $result;
- }
- public function latestPosts($user, $n = 5) {
- $query = sprintf("SELECT TOP %d posted, topicid, t.title, postid, forumPosts.posterid, forumPosts.viewable
- FROM forumPosts INNER JOIN forumTopics AS t ON t.id = forumPosts.topicid
- WHERE (forumPosts.viewable = 1) and
- (forumPosts.posterid=(select customerid from tb_user where strAccountID=?))
- ORDER BY forumPosts.posted DESC", $n);
- $result = parent::query($query, array(&$user));
- return $result;
- }
- public function postCount($user) {
- }
- public function topicCount($user) {
- }
- public function getRank($user) {
- $query = "SELECT strTitle from forumGroups where groupID=(SELECT forumGroup from TB_USER where strAccountID=?)";
- $result = parent::query($query, array(&$user));
- return $result[0]["strTitle"];
- }
- public function getCharacters($user) {
- $cols = array('strCharID1', 'strCharID2', 'strCharID3', 'strCharID4', 'strCharID5');
- $query = sprintf("SELECT %s FROM ACCOUNT_CHAR WHERE strAccountID=?", implode(",", $cols));
- $chars = parent::query($query, array(&$user));
- if (count($chars) == 0) return false;
- $count = count($chars[0]);
- $output = array();
- for ($i = 0; $i<$count; ++$i)
- if ($chars[0][$cols[$i]] != NULL) $output[] = $chars[0][$cols[$i]];
- return $output;
- }
- /**
- * edit
- * @author DeathsEffigy <Fabi.Schn@googlemail.com>
- */
- public function can_transfer ()
- {
- $interval = 7 * 24 * 60 * 60; // days * hours * minutes * seconds
- $user = $_SESSION['username'];
- $query = "SELECT * FROM PANEL_NT WHERE strAccountID = ?";
- $result = parent::query ($query, array (&$user));
- if (count ($result) == 0) return true;
- $last = $result[0]['nTime'];
- return (($last + $interval) < time ()) ? true : false;
- }
- public function nation_transfer ()
- {
- $user = $_SESSION['username'];
- $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 = ?";
- $result = parent::query ($query, array (&$user));
- if (count ($result) > 0) return false;
- $query = "EXEC ACCOUNT_NATION_CHANGE ?";
- parent::query ($query, array (&$user));
- $query = "DELETE FROM PANEL_NT WHERE strAccountID = ?";
- parent::query ($query, array (&$user));
- $query = "INSERT INTO PANEL_NT VALUES (?, ?)";
- parent::query ($query, array (&$user, time ()));
- return true;
- }
- public function can_delete_char ()
- {
- $user = $_SESSION['username'];
- $query = "SELECT * FROM ACCOUNT_CHAR WHERE strAccountID = ?";
- $result = parent::query ($query, array (&$user));
- if (count ($result) == 0) return false;
- $row = $result[0];
- if (empty ($row['strCharID1']) && empty ($row['strCharID2']) && empty ($row['strCharID3'])) return false;
- return array ('char1' => $result[0]['strCharID1'], 'char2' => $result[0]['strCharID2'], 'char3' => $result[0]['strCharID3']);
- }
- public function get_delete_char_nec ()
- {
- $user = $_SESSION['username'];
- $query = "SELECT * FROM TB_USER WHERE strAccountID = ?";
- $result = parent::query ($query, array (&$user));
- return $result[0];
- }
- public function delete_char ($char, $answer)
- {
- $user = $_SESSION['username'];
- $acc = $this->get_delete_char_nec ();
- if ($answer != $acc['sAnswer']) return false;
- $query = "SELECT * FROM ACCOUNT_CHAR WHERE strAccountID = ?";
- $result = parent::query ($query, array (&$user));
- $chara = $result[0]['strCharID' . intval ($char)];
- $query = "SELECT * FROM CURRENTUSER WHERE strCharID = ?";
- $result = parent::query ($query, array (&$chara));
- if (count ($result) > 0) return false;
- $query = "UPDATE ACCOUNT_CHAR SET strCharID$char = NULL WHERE strAccountID = ?";
- parent::query ($query, array (&$user));
- $query = "DELETE FROM USERDATA WHERE strUserId = ?";
- parent::query ($query, array (&$chara));
- $query = "DELETE FROM KNIGHTS_USER WHERE strUserID = ?";
- parent::query ($query, array (&$chara));
- $query = "DELETE FROM FRIEND_LIST WHERE strUserID = ?";
- parent::query ($query, array (&$chara));
- $query = "DELETE FROM USER_RENTAL_ITEM WHERE strUserID = ?";
- parent::query ($query, array (&$chara));
- $query = "DELETE FROM USERDATA_SKILLSHORTCUT WHERE strCharID = ?";
- parent::query ($query, array (&$chara));
- return true;
- }
- public function secret_password_correct ($password)
- {
- $user = $_SESSION['username'];
- $query = "SELECT * FROM TB_USER WHERE strAccountID = ? AND strPasswd = ?";
- $result = parent::query ($query, array (&$user, &$password));
- return $result == 0 ? false : true;
- }
- public function secret_update ($question, $answer)
- {
- $user = $_SESSION['username'];
- $query = "UPDATE TB_USER SET sQuestion = ?, sAnswer = ? WHERE strAccountID = ?";
- $result = parent::query ($query, array (&$question, &$answer, &$user));
- return true;
- }
- /**
- * edit end
- */
- }
Add Comment
Please, Sign In to add comment