Merge branch 'kevin-prototype' into 'master'

Kevin prototype

See merge request !120
This commit was merged in pull request #124.
This commit is contained in:
Lars van Hijfte
2017-01-25 16:20:30 +01:00
9 changed files with 128 additions and 25 deletions

View File

@@ -0,0 +1,27 @@
<?php
session_start();
require_once ("../../queries/friendship.php");
if(empty($_POST["usr"]) OR empty($_POST["action"]) OR !in_array($_POST["action"], array("request", "accept", "delete"))) {
header('HTTP/1.1 500 Non enough arguments');
}
$friendship_status = getFriendshipStatus($_POST["usr"]);
if($_POST["action"] == "request" AND $friendship_status == 0) {
if (!requestFriendship($_POST["usr"])) {
header('HTTP/1.1 500 Query (request) failed');
}
} else if($_POST["action"] == "delete" AND in_array($friendship_status, array(1, 2, 3))) {
if (!removeFriendship($_POST["usr"])) {
header('HTTP/1.1 500 Query (delete) failed');
}
} else if ($_POST["action"] == "accept" AND $friendship_status == 3) {
if (!acceptFriendship($_POST["usr"])) {
header('HTTP/1.1 500 Query (accept) failed');
}
} else {
header('HTTP/1.1 500 Not the right friendship status');
}

View File

@@ -0,0 +1,24 @@
<?php
# -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)
session_start();
require_once ("../../queries/friendship.php");
if(empty($_POST["usr"])) {
header('HTTP/1.1 500 Non enough arguments');
}
$friendship_status = getFriendshipStatus($_POST["usr"]);
if($friendship_status == -2) {
header('HTTP/1.1 500 Query failed');
}
echo $friendship_status;

View File

@@ -0,0 +1,27 @@
function placeFriendButtons() {
$.post("API/getFriendshipStatus.php", { usr: userID })
.done(function(data) {
friendshipStatus = data;
$buttonContainer = $("div.friend-button-container");
$buttonContainer.children().remove();
if (friendshipStatus == -1) {
return;
} else if(friendshipStatus == 0) {
$buttonContainer.append($("<button class=\"green friend-button\" value=\"request\"><i class=\"fa fa-handshake-o\"></i> Bevriend</button>"));
} else if(friendshipStatus == 1) {
$buttonContainer.append($("<button class=\"red friend-button\" value=\"delete\"><i class=\"fa fa-times\"></i> Verwijder</button>"));
} else if(friendshipStatus == 2) {
$buttonContainer.append($("<button class=\"red friend-button\" value=\"delete\"><i class=\"fa fa-times\"></i> Trek verzoek in</button>"));
} else if(friendshipStatus == 3) {
$buttonContainer.append($("<button class=\"red friend-button\" value=\"delete\"><i class=\"fa fa-times\"></i> Weiger</button>"));
$buttonContainer.append($("<button class=\"green friend-button\" value=\"accept\"><i class=\"fa fa-check\"></i> Accepteer</button>"));
}
$buttonContainer.children().click(function() {
$.post("API/editFriendship.php", { usr: userID, action: this.value })
.done(function() {
placeFriendButtons();
});
});
});
}

View File

@@ -24,6 +24,13 @@ $profile_friends = selectAllFriends($userID);
$profile_groups = selectAllUserGroups($userID);
$posts = selectAllUserPosts($userID);
if ($userID == $_SESSION["userID"]) {
$friendship_status = -1;
} else {
$friendship_status = $user["friend_status"];
}
/*
* This view adds the main layout over the screen.
* Header, menu, footer.
@@ -36,5 +43,13 @@ include("../views/profile.php");
/* This adds the footer. */
include("../views/footer.php");
?>
<script src="js/friendButtons.js"></script>
<script>
$(document).ready(function() {
userID = <?= $userID ?>;
placeFriendButtons();
});
</script>
</body>
</html>

View File

@@ -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"] {

View File

@@ -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);
}

View File

@@ -82,6 +82,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
@@ -108,8 +118,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) {
@@ -120,7 +132,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) {
@@ -131,11 +143,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) {
@@ -150,7 +163,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) {

View File

@@ -108,7 +108,7 @@ function selectAllUserPosts($userID) {
`postID`,
`author`,
`title`,
CASE LENGTH(`content`) >= 150
CASE LENGTH(`content`) >= 150 AND `content` NOT LIKE '<img%'
WHEN TRUE THEN
CONCAT(LEFT(`content`, 150), '...')
WHEN FALSE THEN

View File

@@ -2,21 +2,10 @@
<div class="profile-box platform">
<img class="left profile-picture" src="<?php echo $user["profilepicture"] ?>">
<form action="API/edit_friendship.php" method="post">
<input type="hidden" name="userID" value="<?= $userID ?>">
<?php
if($userID != $_SESSION["userID"] AND $user["friend_status"] == 0) {
echo "<input class='profile-button' type='submit' name='request' value='Stuur vriendschapsverzoek!'>";
} else if($user["friend_status"] == 1) {
echo "<input class='profile-button' type='submit' name='delete' value='Verwijder vriend!'>";
} else if($user["friend_status"] == 2) {
echo "<input class='profile-button' type='submit' name='accept' value='Accepteer vriendschapsverzoek!'>";
echo "<input class='profile-button' type='submit' name='delete' value='Weiger vriendschapsverzoek!'>";
} else if($user["friend_status"] == 3) {
echo "<input class='profile-button' type='submit' name='delete' value='Trek vriendschapsverzoek in!'>";
}
?>
</form>
<div class="friend-button-container">
</div>
<h1 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?></h1>
<h5 class="profile-username"><?=$user["username"]?></h5>
<p><?=$user["bio"]?></p>