Added comments to javascript code #215
36
website/public/createGroup.php
Normal file
36
website/public/createGroup.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once "../queries/createGroup.php";
|
||||
require_once "../queries/connect.php";
|
||||
require_once "../queries/alerts.php"?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<?php include("../views/head.php"); ?>
|
||||
<style>
|
||||
@import url("styles/settings.css");
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
* This view adds the main layout over the screen.
|
||||
* Header and menu.
|
||||
*/
|
||||
include("../views/main.php");
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
try {
|
||||
createGroup();
|
||||
} catch (AlertMessage $e) {
|
||||
|
||||
}
|
||||
$groupname = $_POST["groupName"];
|
||||
header("location: group.php?groupname=$groupname");
|
||||
}
|
||||
/* Add your view files here. */
|
||||
include("../views/createGroup.php");
|
||||
|
||||
/* This adds the footer. */
|
||||
include("../views/footer.php");
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -13,9 +13,16 @@
|
||||
|
||||
include_once("../queries/group_page.php");
|
||||
|
||||
$group = selectGroupByName($_GET["groupname"]);
|
||||
if(!$group = selectGroupByName($_GET["groupname"])) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
header("Location: error/404.php");
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
$members = selectGroupMembers($group["groupID"]);
|
||||
|
||||
|
||||
/*
|
||||
* This view adds the main layout over the screen.
|
||||
* Header, menu, footer.
|
||||
|
||||
46
website/public/groupAdmin.php
Normal file
46
website/public/groupAdmin.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once "../queries/picture.php";
|
||||
require_once "../queries/groupAdmin.php";
|
||||
require_once "../queries/alerts.php";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<?php include("../views/head.php"); ?>
|
||||
<style>
|
||||
/*Insert own stylesheet here ;)*/
|
||||
@import url("styles/settings.css");
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
* This view adds the main layout over the screen.
|
||||
* Header and menu.
|
||||
*/
|
||||
include("../views/main.php");
|
||||
$alertClass;
|
||||
$alertMessage;
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
try {
|
||||
if ($_POST["form"] == "group") {
|
||||
updateGroupSettings($_POST["groupID"]);
|
||||
} else if ($_POST["form"] == "picture") {
|
||||
if (checkGroupAdmin($_POST["groupID"], $_SESSION["userID"])) {
|
||||
updateAvatar($_POST["groupID"]);
|
||||
}
|
||||
}
|
||||
} catch (AlertMessage $w) {
|
||||
$alertClass = $w->getClass();
|
||||
$alertMessage = $w->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/* Add your view files here. */
|
||||
include("../views/groupAdmin.php");
|
||||
|
||||
/* This adds the footer. */
|
||||
include("../views/footer.php");
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -21,19 +21,19 @@ include_once("../queries/calcAge.php");
|
||||
|
||||
if(empty($_GET["username"])) {
|
||||
$userID = $_SESSION["userID"];
|
||||
$showProfile = True;
|
||||
} else {
|
||||
$userID = getUserID($_GET["username"]);
|
||||
$showProfile = False;
|
||||
}
|
||||
|
||||
$user = selectUser($_SESSION["userID"], $userID);
|
||||
if(!$user = selectUser($_SESSION["userID"], $userID)) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
header("Location: error/404.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$profile_friends = selectAllFriends($userID);
|
||||
$profile_groups = selectAllUserGroups($userID);
|
||||
$showProfile = $showProfile || $user["showProfile"] || ($user["status"] == 'confirmed');
|
||||
echo " friendship status: " . $user["status"];
|
||||
echo " showprofile: $showProfile";
|
||||
echo " userID: " . $user["userID"];
|
||||
$showProfile = $user["showProfile"] || ($user["status"] == 'confirmed') || $_SESSION["userID"] == $userID;
|
||||
|
||||
|
||||
if ($userID == $_SESSION["userID"]) {
|
||||
|
||||
37
website/queries/createGroup.php
Normal file
37
website/queries/createGroup.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once "../queries/checkInput.php";
|
||||
require_once "../queries/picture.php";
|
||||
require_once "../queries/alerts.php";
|
||||
function createGroup()
|
||||
{
|
||||
$createGroup = prepareQuery("
|
||||
INSERT INTO
|
||||
`group_page` (`name`, `description`)
|
||||
VALUES (:name, :description);
|
||||
");
|
||||
$createGroup->bindValue(':name', test_input($_POST["groupName"]), PDO::PARAM_STR);
|
||||
$createGroup->bindValue(':description', test_input($_POST["bio"]));
|
||||
$createGroup->execute();
|
||||
|
||||
$getGroupID = prepareQuery("
|
||||
SELECT
|
||||
`groupID`
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`name` LIKE :name");
|
||||
$getGroupID->bindValue(':name', test_input($_POST["groupName"]), PDO::PARAM_STR);
|
||||
$getGroupID->execute();
|
||||
$groupID = $getGroupID->fetch()["groupID"];
|
||||
|
||||
$makeUserAdmin = prepareQuery("
|
||||
INSERT INTO
|
||||
`group_member` (userID, groupID, role)
|
||||
VALUES (:userID, :groupID, 'admin')
|
||||
");
|
||||
$makeUserAdmin->bindValue(":userID", $_SESSION["userID"]);
|
||||
$makeUserAdmin->bindValue("groupID", $groupID);
|
||||
$makeUserAdmin->execute();
|
||||
|
||||
updateAvatar($groupID);
|
||||
}
|
||||
61
website/queries/groupAdmin.php
Normal file
61
website/queries/groupAdmin.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
function getGroupSettings(int $groupID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`name`,
|
||||
`picture`,
|
||||
`description`
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`groupID` = :groupID
|
||||
");
|
||||
$stmt->bindParam(":groupID", $groupID);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
function updateGroupSettings(int $groupID)
|
||||
{
|
||||
if (!checkGroupAdmin($groupID, $_SESSION["userID"])) {
|
||||
throw new AngryAlert("Je hebt geen rechten in deze groep");
|
||||
}
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
`group_page`
|
||||
SET
|
||||
`name` = :name,
|
||||
`description` = :bio
|
||||
WHERE
|
||||
`groupID` = :groupID
|
||||
");
|
||||
$stmt->bindValue(":bio", test_input($_POST["bio"]));
|
||||
$stmt->bindValue(":name", test_input($_POST["name"]));
|
||||
$stmt->bindValue(":groupID", test_input($_POST["groupID"]));
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount()) {
|
||||
throw new HappyAlert("Groep aangepast!");
|
||||
} else {
|
||||
throw new AngryAlert("Er is iets mis gegaan");
|
||||
}
|
||||
}
|
||||
|
||||
function checkGroupAdmin(int $groupID, int $userID) : bool {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`role`
|
||||
FROM
|
||||
`group_member`
|
||||
WHERE
|
||||
`groupID` = :groupID AND
|
||||
`userID` = :userID
|
||||
");
|
||||
$stmt->bindValue(":userID", $userID);
|
||||
$stmt->bindValue(":groupID", $groupID);
|
||||
$stmt->execute();
|
||||
if (!$stmt->rowCount()) {
|
||||
return false;
|
||||
}
|
||||
$role = $stmt->fetch()["role"];
|
||||
return ($role == "admin");
|
||||
}
|
||||
@@ -33,7 +33,12 @@ function selectGroupByName($name) {
|
||||
if (!$stmt->execute()) {
|
||||
return False;
|
||||
}
|
||||
return $stmt->fetch();
|
||||
$row = $stmt->fetch();
|
||||
if($row["groupID"] == null) {
|
||||
return False;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
function selectGroupRole(int $groupID) {
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
* @throws AngryAlert
|
||||
* @throws HappyAlert
|
||||
*/
|
||||
function updateAvatar(bool $group = false) {
|
||||
function updateAvatar(int $group = 0) {
|
||||
if (!array_key_exists("pp", $_FILES)) {
|
||||
throw new AngryAlert("Geen afbeelding meegegeven!");
|
||||
}
|
||||
$publicDir = "/var/www/html/public/";
|
||||
$tmpImg = $_FILES["pp"]["tmp_name"];
|
||||
$avatarDir = $group ? "uploads/groupavatar/" : "uploads/profilepictures/";
|
||||
@@ -16,17 +19,17 @@ function updateAvatar(bool $group = false) {
|
||||
if ($_FILES["pp"]["size"] > 4000000) {
|
||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||
}
|
||||
$relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.gif";
|
||||
$group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar();
|
||||
$relativePath = $group ? $avatarDir . $group . "_avatar.gif" : $avatarDir . $_SESSION["userID"] . "_avatar.gif";
|
||||
$group ? removeOldGroupAvatar($group) : removeOldUserAvatar();
|
||||
move_uploaded_file($tmpImg, $publicDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.png";
|
||||
$relativePath = $group ? $avatarDir . $group . "_avatar.png": $avatarDir . $_SESSION["userID"] . "_avatar.png";
|
||||
$scaledImg = scaleAvatar($tmpImg);
|
||||
$group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar();
|
||||
$group ? removeOldGroupAvatar($group) : removeOldUserAvatar();
|
||||
imagepng($scaledImg, $publicDir . $relativePath);
|
||||
}
|
||||
|
||||
$group ? setGroupAvatarToDatabase("../" . $relativePath, $_POST["groupID"]) : setUserAvatarToDatabase("../" . $relativePath);
|
||||
$group ? setGroupAvatarToDatabase("../" . $relativePath, $group) : setUserAvatarToDatabase("../" . $relativePath);
|
||||
throw new HappyAlert("Profielfoto veranderd.");
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,9 @@ function selectUser($me, $other) {
|
||||
|
||||
$stmt->bindParam(':me', $me, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':other', $other, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
if(!$stmt->execute() || $stmt->rowCount() == 0) {
|
||||
return False;
|
||||
}
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ function selectAllUserGroups($userID) {
|
||||
`group_page`.`groupID` = `group_member`.`groupID`
|
||||
WHERE
|
||||
`userID` = :userID AND
|
||||
`role` = 'member'
|
||||
`role` IN ('member', 'mod', 'admin')
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
|
||||
|
||||
42
website/views/createGroup.php
Normal file
42
website/views/createGroup.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
?>
|
||||
|
||||
<div class="content">
|
||||
<div class="createGroup">
|
||||
<form class="platform settings" method="post" action="createGroup.php" enctype="multipart/form-data">
|
||||
<h5>Maak een groep!</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<label for="groupName">Groepsnaam</label>
|
||||
<input type="text"
|
||||
name="groupName"
|
||||
id="groupName"
|
||||
maxlength="63"
|
||||
placeholder="Groepsnaam"
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label for="bio">Bio</label>
|
||||
<textarea name="bio"
|
||||
rows="5"
|
||||
title="bio"
|
||||
id="bio"
|
||||
maxlength="1000"
|
||||
></textarea>
|
||||
</li>
|
||||
<li>
|
||||
<label>Selecteer foto</label>
|
||||
<input type="file"
|
||||
name="pp"
|
||||
accept="image/*"
|
||||
size="4000000"
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label></label>
|
||||
<button type="submit">Maak Groep</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
78
website/views/groupAdmin.php
Normal file
78
website/views/groupAdmin.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
require_once "../queries/connect.php";
|
||||
require_once "../queries/groupAdmin.php";
|
||||
require_once "../queries/checkInput.php";
|
||||
$groupinfo = getGroupSettings($_GET["groupID"]);
|
||||
?>
|
||||
<div class="content">
|
||||
<div class="settings">
|
||||
<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
|
||||
<div class='platform settings-message <?=$alertClass?>'>
|
||||
<?=$alertMessage?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form class="platform" method="post">
|
||||
<h5>Groep Instellingen</h5>
|
||||
<input type="hidden" name="groupID" value="<?=$_GET["groupID"]?>">
|
||||
<ul>
|
||||
<li>
|
||||
<label for="name">Groepsnaam</label>
|
||||
<input type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
maxlength="63"
|
||||
placeholder="Groepsnaam"
|
||||
title="Groepsnaam"
|
||||
value="<?=$groupinfo["name"]?>"
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label for="bio">Bio</label>
|
||||
<textarea name="bio"
|
||||
rows="5"
|
||||
title="bio"
|
||||
id="bio"
|
||||
maxlength="1000"
|
||||
><?=$groupinfo["description"]?></textarea>
|
||||
<label></label>
|
||||
</li>
|
||||
<li>
|
||||
<label></label>
|
||||
<button type="submit"
|
||||
name="form"
|
||||
value="group"
|
||||
class="fa fa-save"
|
||||
> Opslaan</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
<form class="platform" method="post" enctype="multipart/form-data">
|
||||
<h5>Verander groepsafbeelding.</h5>
|
||||
<input type="hidden" name="groupID" value="<?=$_GET["groupID"]?>">
|
||||
<ul>
|
||||
<li>
|
||||
<label>Huidige profielfoto</label>
|
||||
<img src="<?=$groupinfo["picture"]?>"
|
||||
class="group-picture"
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label>Selecteer foto</label>
|
||||
<input type="file"
|
||||
name="pp"
|
||||
accept="image/*"
|
||||
size="4000000"
|
||||
required
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label></label>
|
||||
<button type="submit"
|
||||
name="form"
|
||||
value="picture"
|
||||
>Verander profielfoto</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,7 +16,7 @@
|
||||
<section>
|
||||
<ul class="nav-list">
|
||||
<li>
|
||||
<a href="#">
|
||||
<a href="createGroup.php">
|
||||
Maak een groep aan
|
||||
</a>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user