Merge branch 'kevin-prototype' into 'master'
GROUP BUTTONS AND GROUP STYLE See merge request !167
This commit was merged in pull request #171.
This commit is contained in:
40
website/public/API/editMembership.php
Normal file
40
website/public/API/editMembership.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if(empty($_POST["grp"]) or empty($_POST["role"])) {
|
||||||
|
header('HTTP/1.1 500 Non enough arguments');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(in_array($_POST["role"], array('request', 'member', 'banned', 'mod', 'admin'))) {
|
||||||
|
header('HTTP/1.1 500 Wrong argument given for role');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once ("../../queries/group_member.php");
|
||||||
|
require_once ("../../queries/group_page.php");
|
||||||
|
require_once ("../../queries/group_member.php");
|
||||||
|
|
||||||
|
$currentRole = selectGroupRole($_POST["grp"]);
|
||||||
|
$groupStatus = selectGroupStatus($_POST["grp"]);
|
||||||
|
echo "role: $currentRole status: $groupStatus ";
|
||||||
|
|
||||||
|
if($_POST["role"] == 'request' and $currentRole == 'none') {
|
||||||
|
if($groupStatus = 'public') {
|
||||||
|
// Add member to public group
|
||||||
|
addMember($_POST["grp"], $_SESSION["userID"], 'member');
|
||||||
|
echo "ADDED";
|
||||||
|
} else if($groupStatus = 'membersonly') {
|
||||||
|
// Send request to members only group
|
||||||
|
addMember($_POST["grp"], $_SESSION["userID"], 'request');
|
||||||
|
} else {
|
||||||
|
// Can't invite yourself to hidden groups
|
||||||
|
header('HTTP/1.1 500 This group is hidden');
|
||||||
|
}
|
||||||
|
header('HTTP/1.1 200');
|
||||||
|
} else if($_POST["role"] == 'none' and $currentRole != 'none') {
|
||||||
|
// Remove yourself from a group
|
||||||
|
deleteMember($_POST["grp"], $_SESSION["userID"]);
|
||||||
|
} else {
|
||||||
|
echo "failure";
|
||||||
|
header('HTTP/1.1 500 Wrong argument given for role');
|
||||||
|
}
|
||||||
12
website/public/API/getGrouprole.php
Normal file
12
website/public/API/getGrouprole.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if(empty($_POST["grp"])) {
|
||||||
|
header('HTTP/1.1 500 Non enough arguments');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once("../../queries/group_page.php");
|
||||||
|
|
||||||
|
echo selectGroupRole($_POST["grp"]);
|
||||||
|
|
||||||
@@ -40,12 +40,15 @@ if ($group["role"] == "mod" OR $group["role"] == "admin") {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<script src="js/masonry.js"></script>
|
<script src="js/masonry.js"></script>
|
||||||
|
<script src="js/groupButtons.js"></script>
|
||||||
<script src="js/post.js"></script>
|
<script src="js/post.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
userID = 0;
|
userID = 0;
|
||||||
groupID = <?= $group["groupID"] ?>;
|
groupID = <?= $group["groupID"] ?>;
|
||||||
|
|
||||||
|
placeGroupButtons();
|
||||||
|
|
||||||
masonry(<?= $masonry_mode ?>);
|
masonry(<?= $masonry_mode ?>);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
33
website/public/js/groupButtons.js
Normal file
33
website/public/js/groupButtons.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
function placeGroupButtons() {
|
||||||
|
$.post("API/getGrouprole.php", { grp: groupID })
|
||||||
|
.done(function(data) {
|
||||||
|
var $buttonContainer = $("div.group-button-container");
|
||||||
|
|
||||||
|
if(data == 'none') {
|
||||||
|
$buttonContainer.append(
|
||||||
|
"<button class='green group-button' value='request'>" +
|
||||||
|
"<i class='fa fa-plus'></i> Voeg toe" +
|
||||||
|
"</button>");
|
||||||
|
} else if(data == 'request') {
|
||||||
|
$buttonContainer.append(
|
||||||
|
"<button class='red group-button' value='none'>" +
|
||||||
|
"<i class='fa fa-times'></i> Trek verzoek in" +
|
||||||
|
"</button>");
|
||||||
|
} else {
|
||||||
|
$buttonContainer.append(
|
||||||
|
"<button class='red group-button' value='none'>" +
|
||||||
|
"<i class='fa fa-times'></i> Verlaat groep" +
|
||||||
|
"</button>");
|
||||||
|
}
|
||||||
|
|
||||||
|
$buttonContainer.children().click(function() {
|
||||||
|
$.post("API/editMembership.php", { grp: groupID, role: this.value })
|
||||||
|
.done(function() {
|
||||||
|
$buttonContainer.children().remove();
|
||||||
|
placeGroupButtons();
|
||||||
|
}).fail(function() {
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -102,6 +102,7 @@ p {
|
|||||||
|
|
||||||
.group-picture {
|
.group-picture {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-box, .item-box-full-width {
|
.item-box, .item-box-full-width {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.friend-button-container button, .status-buttons-container button {
|
.friend-button-container button, .status-buttons-container button, .group-button-container button {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
margin: 7px 0;
|
margin: 7px 0;
|
||||||
@@ -27,6 +27,10 @@
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.group-button-container button {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
.empty-button {
|
.empty-button {
|
||||||
background: none;
|
background: none;
|
||||||
cursor: auto;
|
cursor: auto;
|
||||||
@@ -51,8 +55,18 @@
|
|||||||
width: 150px;
|
width: 150px;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
margin-bottom: -45px;
|
margin-bottom: -45px;
|
||||||
|
|
||||||
|
object-fit: cover;
|
||||||
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.group-picture {
|
||||||
|
border: none;
|
||||||
|
margin-bottom: 0;
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Old */
|
/* Old */
|
||||||
|
|
||||||
.profile-box h1.profile-username {
|
.profile-box h1.profile-username {
|
||||||
|
|||||||
@@ -54,3 +54,48 @@ function searchSomeOwnGroups($n, $m, $search) {
|
|||||||
|
|
||||||
return json_encode($stmt->fetchAll());
|
return json_encode($stmt->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addMember($groupID, $userID, $role) {
|
||||||
|
$stmt = prepareQuery("
|
||||||
|
INSERT INTO
|
||||||
|
`group_member` (`userID`, `groupID`, `role`)
|
||||||
|
VALUES
|
||||||
|
(:userID, :groupID, :role)
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmt->bindParam(':userID', $userID);
|
||||||
|
$stmt->bindParam(':groupID', $groupID);
|
||||||
|
$stmt->bindParam(':role', $role);
|
||||||
|
return $stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeMember($groupID, $userID, $role) {
|
||||||
|
$stmt = prepareQuery("
|
||||||
|
UPDATE
|
||||||
|
`group_member`
|
||||||
|
SET
|
||||||
|
`role` = :role
|
||||||
|
WHERE
|
||||||
|
`userID` = :userID AND
|
||||||
|
`groupID` = :groupID
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmt->bindParam(':userID', $userID);
|
||||||
|
$stmt->bindParam(':groupID', $groupID);
|
||||||
|
$stmt->bindParam(':role', $role);
|
||||||
|
return $stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteMember($groupID, $userID) {
|
||||||
|
$stmt = prepareQuery("
|
||||||
|
DELETE FROM
|
||||||
|
`group_member`
|
||||||
|
WHERE
|
||||||
|
`userID` = :userID AND
|
||||||
|
`groupID` = :groupID
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmt->bindParam(':userID', $userID);
|
||||||
|
$stmt->bindParam(':groupID', $groupID);
|
||||||
|
return $stmt->execute();
|
||||||
|
}
|
||||||
@@ -58,6 +58,23 @@ function selectGroupRole(int $groupID) {
|
|||||||
return $stmt->fetch()["role"];
|
return $stmt->fetch()["role"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectGroupStatus(int $groupID) {
|
||||||
|
$stmt = prepareQuery("
|
||||||
|
SELECT
|
||||||
|
`status`
|
||||||
|
FROM
|
||||||
|
`group_page`
|
||||||
|
WHERE
|
||||||
|
`groupID` = :groupID
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmt->bindParam(':groupID', $groupID, PDO::PARAM_INT);
|
||||||
|
if(!$stmt->execute()) {
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
return $stmt->fetch()["status"];
|
||||||
|
}
|
||||||
|
|
||||||
function selectGroupMembers(int $groupID) {
|
function selectGroupMembers(int $groupID) {
|
||||||
$stmt = prepareQuery("
|
$stmt = prepareQuery("
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="profile-box platform">
|
<div class="profile-box platform">
|
||||||
<img class="left main-picture" src="<?= $group['picture'] ?>">
|
<img class="left main-picture group-picture" src="<?= $group['picture'] ?>">
|
||||||
<div class="profile-button">
|
<div class="group-button-container"></div>
|
||||||
<p><img src="img/leave-group.png"> Groep verlaten</p>
|
|
||||||
</div>
|
|
||||||
<h1 class="profile-username"><?= $group['name'] ?></h1>
|
<h1 class="profile-username"><?= $group['name'] ?></h1>
|
||||||
<p><?= $group['description'] ?></p>
|
<p><?= $group['description'] ?></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item-box-full-width platform">
|
<div class="item-box-full-width platform">
|
||||||
|
|||||||
Reference in New Issue
Block a user