From 9ff256429df3ac9f79840ad1dbaa65729256390a Mon Sep 17 00:00:00 2001 From: "K. Nobel" Date: Wed, 25 Jan 2017 15:06:37 +0100 Subject: [PATCH] Changed friendship buttons. We now use AJAX, changed button style and added FA icons. --- website/public/API/editFriendship.php | 28 ++++++++++++++ website/public/API/getFriendshipStatus.php | 18 +++++++++ website/public/profile.php | 45 ++++++++++++++++++++++ website/public/styles/main.css | 9 +++++ website/public/styles/profile.css | 7 ++-- website/queries/friendship.php | 23 ++++++++--- website/views/profile.php | 18 ++------- 7 files changed, 124 insertions(+), 24 deletions(-) create mode 100644 website/public/API/editFriendship.php create mode 100644 website/public/API/getFriendshipStatus.php diff --git a/website/public/API/editFriendship.php b/website/public/API/editFriendship.php new file mode 100644 index 0000000..721bf90 --- /dev/null +++ b/website/public/API/editFriendship.php @@ -0,0 +1,28 @@ + + + + diff --git a/website/public/styles/main.css b/website/public/styles/main.css index 8c50b19..b8f39ee 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -175,6 +175,15 @@ textarea:focus, input:focus, select:focus { } /* All buttons */ +button.red { + background-color: firebrick; +} + +button.green { + background-color: forestgreen; +} + + button, input[type="submit"], input[type="reset"] { diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css index fbd8775..85b2db5 100644 --- a/website/public/styles/profile.css +++ b/website/public/styles/profile.css @@ -78,17 +78,16 @@ div.posts .post form textarea.newpost { font-size: 0.8em; } -input.profile-button { +button.friend-button { float: right; height: auto; padding: 10px; + margin-left: 10px; border-radius: 5px; - background-color: #4CAF50; - color: #FFFFFF; transition-duration: 250ms; cursor: pointer; } -.profile-button:hover { +button.friend-button:hover { box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } \ No newline at end of file diff --git a/website/queries/friendship.php b/website/queries/friendship.php index d0279c9..f69522e 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -67,6 +67,16 @@ function selectAllFriendRequests() { } function getFriendshipStatus($userID) { + # -2: Query failed. + # -1: user1 and 2 are the same user + # 0 : no record found + # 1 : confirmed + # 2 : user1 sent request (you) + # 3 : user2 sent request (other) + if($_SESSION["userID"] == $userID) { + return -1; + } + $stmt = $GLOBALS["db"]->prepare(" SELECT CASE `status` IS NULL @@ -93,8 +103,10 @@ function getFriendshipStatus($userID) { $stmt->bindParam(':me', $_SESSION["userID"], PDO::PARAM_INT); $stmt->bindParam(':other', $userID, PDO::PARAM_INT); - $stmt->execute(); - return $stmt->fetch()["friend_state"]; + if(!$stmt->execute()) { + return -2; + } + return intval($stmt->fetch()["friend_state"]); } function requestFriendship($userID) { @@ -105,7 +117,7 @@ function requestFriendship($userID) { $stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT); $stmt->bindParam(':user2', $userID, PDO::PARAM_INT); - $stmt->execute(); + return $stmt->execute(); } function removeFriendship($userID) { @@ -116,11 +128,12 @@ function removeFriendship($userID) { `user2ID` = :user2 OR `user1ID` = :user2 AND `user2ID` = :user1 + LIMIT 1 "); $stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT); $stmt->bindParam(':user2', $userID, PDO::PARAM_INT); - $stmt->execute(); + return $stmt->execute(); } function acceptFriendship($userID) { @@ -135,7 +148,7 @@ function acceptFriendship($userID) { $stmt->bindParam(':user1', $userID, PDO::PARAM_INT); $stmt->bindParam(':user2', $_SESSION["userID"], PDO::PARAM_INT); - $stmt->execute(); + return $stmt->execute(); } function setLastVisited($friend) { diff --git a/website/views/profile.php b/website/views/profile.php index 0b2f4f2..d74f999 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -2,21 +2,9 @@
"> -
- - "; - } else if($user["friend_status"] == 1) { - echo ""; - } else if($user["friend_status"] == 2) { - echo ""; - echo ""; - } else if($user["friend_status"] == 3) { - echo ""; - } - ?> -
+
+ +