=$user["username"]?>
-= $user["fname"]?> =$user["lname"]?>
+ + += $user["fname"]?> =$user["lname"]?>
+=$user["username"]?>
=$user["bio"]?>
diff --git a/website/public/edit_friendship.php b/website/public/edit_friendship.php new file mode 100644 index 0000000..d88e264 --- /dev/null +++ b/website/public/edit_friendship.php @@ -0,0 +1,30 @@ +prepare(" SELECT @@ -21,8 +23,8 @@ function selectAllFriends($userID) { `friendship`.`user2ID` = `user`.`userID` OR `friendship`.`user2ID` = :userID AND `friendship`.`user1ID` = `user`.`userID`) AND - `role` != 5 AND - `status` = 1 + `role` != 'banned' AND + `status` = 'confirmed' "); $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); @@ -60,4 +62,76 @@ function selectAllFriendRequests() { $stmt->execute(); return json_encode($stmt->fetchAll()); +} + +function getFriendshipStatus($userID) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + CASE `status` IS NULL + WHEN TRUE THEN 0 + WHEN FALSE THEN + CASE `status` = 'confirmed' + WHEN TRUE THEN + 1 + WHEN FALSE THEN + CASE `user1ID` = :me AND `user2ID` = :other + WHEN TRUE THEN + 2 + WHEN FALSE THEN + 3 + END + END + END AS `friend_state` + FROM + `friendship` + WHERE + `user1ID` = :other AND `user2ID` = :me OR + `user1ID` = :me AND `user2ID` = :other + "); + + $stmt->bindParam(':me', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->bindParam(':other', $userID, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetch()["friend_state"]; +} + +function requestFriendship($userID) { + $stmt = $GLOBALS["db"]->prepare(" + INSERT INTO `friendship` (user1ID, user2ID) + VALUES (:user1, :user2) + "); + + $stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->bindParam(':user2', $userID, PDO::PARAM_INT); + $stmt->execute(); +} + +function removeFriendship($userID) { + $stmt = $GLOBALS["db"]->prepare(" + DELETE FROM `friendship` + WHERE + `user1ID` = :user1 AND + `user2ID` = :user2 OR + `user1ID` = :user2 AND + `user2ID` = :user1 + "); + + $stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->bindParam(':user2', $userID, PDO::PARAM_INT); + $stmt->execute(); +} + +function acceptFriendship($userID) { + $stmt = $GLOBALS["db"]->prepare(" + UPDATE `friendship` + SET `status`='confirmed' + WHERE + `user1ID` = :user1 AND + `user2ID` = :user2 + LIMIT 1 + "); + + $stmt->bindParam(':user1', $userID, PDO::PARAM_INT); + $stmt->bindParam(':user2', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->execute(); } \ No newline at end of file diff --git a/website/queries/user.php b/website/queries/user.php index 114d673..04f379e 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -17,27 +17,53 @@ function getUserID($username) { return $stmt->fetch()["userID"]; } -function selectUser($userID) { +function getUsername($userID) { $stmt = $GLOBALS["db"]->prepare(" SELECT - `username`, - IFNULL( - `profilepicture`, - '../img/notbad.jpg' - ) AS profilepicture, - `bio`, - `role`, - `onlinestatus`, - `loggedin`, - `fname`, - `lname` + `username` FROM `user` WHERE `userID` = :userID "); - $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); + $stmt->bindParam(':userID', $userID, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetch()["username"]; +} + +function selectUser($me, $other) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + `username`, `birthdate`, `location`, `profilepicture`, `bio`, `user`.`creationdate`, `onlinestatus`, `fname`, `lname`, + CASE `status` IS NULL + WHEN TRUE THEN 0 + WHEN FALSE THEN + CASE `status` = 'confirmed' + WHEN TRUE THEN + 1 + WHEN FALSE THEN + CASE `user1ID` = `userID` AND `user2ID` = :me + WHEN TRUE THEN + 2 + WHEN FALSE THEN + 3 + END + END + END AS `friend_status` + FROM + `user` + LEFT JOIN + `friendship` + ON + `user1ID` = `userID` AND `user2ID` = :me OR + `user1ID` = :me AND `user2ID` = `userID` + WHERE + `user`.`userID` = :other + "); + + $stmt->bindParam(':me', $me, PDO::PARAM_INT); + $stmt->bindParam(':other', $other, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetch(); } diff --git a/website/views/profile.php b/website/views/profile.php index 19bd908..83dbca7 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -1,11 +1,24 @@