Merge branch 'kevin-prototype' into 'master'
Kevin prototype See merge request !106
This commit was merged in pull request #110.
This commit is contained in:
30
website/public/edit_friendship.php
Normal file
30
website/public/edit_friendship.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
session_start();
|
||||
require("../queries/friendship.php");
|
||||
require("../queries/user.php");
|
||||
|
||||
if(empty($_POST["userID"]) OR empty($_POST["delete"]) AND empty($_POST["accept"]) AND empty($_POST["request"])) {
|
||||
echo "Not enough arguments.";
|
||||
return;
|
||||
}
|
||||
|
||||
$friendship_status = getFriendshipStatus($_POST["userID"]);
|
||||
echo "\nfriendshipstatus: $friendship_status";
|
||||
echo "You: " . $_SESSION["userID"];
|
||||
echo "other user: " . $_POST["userID"];
|
||||
|
||||
|
||||
if(!empty($_POST["request"]) AND $friendship_status == 0) {
|
||||
echo "request";
|
||||
requestFriendship($_POST["userID"]);
|
||||
} else if(!empty($_POST["delete"]) AND in_array($friendship_status, array(1, 2, 3))) {
|
||||
echo "delete";
|
||||
removeFriendship($_POST["userID"]);
|
||||
} else if (!empty($_POST["accept"]) AND $friendship_status == 3) {
|
||||
echo "accept";
|
||||
acceptFriendship($_POST["userID"]);
|
||||
}
|
||||
|
||||
$username = getUsername($_POST["userID"]);
|
||||
|
||||
header("Location: profile.php?username=$username");
|
||||
@@ -15,11 +15,14 @@ include("../queries/nicetime.php");
|
||||
|
||||
if(empty($_GET["username"])) {
|
||||
$userID = $_SESSION["userID"];
|
||||
echo "USERNAME NOT GIVEN";
|
||||
} else {
|
||||
$userID = getUserID($_GET["username"]);
|
||||
}
|
||||
|
||||
$user = selectUser($userID);
|
||||
echo "User ID: $userID";
|
||||
|
||||
$user = selectUser($_SESSION["userID"], $userID);
|
||||
$profile_friends = selectAllFriends($userID);
|
||||
$profile_groups = selectAllUserGroups($userID);
|
||||
$posts = selectAllUserPosts($userID);
|
||||
|
||||
@@ -78,8 +78,9 @@ div.posts .post form textarea.newpost {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.profile-button {
|
||||
input.profile-button {
|
||||
float: right;
|
||||
height: auto;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #4CAF50;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require("connect.php");
|
||||
|
||||
function selectAllFriends($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
@@ -64,6 +66,77 @@ function selectAllFriendRequests() {
|
||||
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();
|
||||
}
|
||||
|
||||
function setLastVisited($friend) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
|
||||
@@ -17,27 +17,64 @@ function getUserID($username) {
|
||||
return $stmt->fetch()["userID"];
|
||||
}
|
||||
|
||||
function selectUser($userID) {
|
||||
function getUsername($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`username`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/avatar-standard.png'
|
||||
) 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`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/avatar-standard.png'
|
||||
) AS 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();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
<div class="content">
|
||||
<div class="profile-box platform">
|
||||
<img class="left profile-picture" src="<?php echo $user["profilepicture"] ?>">
|
||||
<div class="profile-button">
|
||||
<p><img src="/img/add-friend.png"> Als vriend toevoegen</p>
|
||||
</div>
|
||||
<h1 class="profile-username"><?=$user["username"]?></h1>
|
||||
<h5 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?></h5>
|
||||
|
||||
<form action="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>
|
||||
<h1 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?></h1>
|
||||
<h5 class="profile-username"><?=$user["username"]?></h5>
|
||||
<p><?=$user["bio"]?></p>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +27,7 @@
|
||||
<p>
|
||||
<?php
|
||||
while($friend = $profile_friends->fetch()) {
|
||||
echo "<a href='/profile/${friend["username"]}/' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
|
||||
echo "<a href='profile.php?username=${friend["username"]}' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user