Added comments to javascript code #215

Merged
11319801 merged 65 commits from kevin-prototype into master 2017-02-03 21:19:51 +01:00
4 changed files with 113 additions and 6 deletions
Showing only changes of commit ab21226925 - Show all commits

View File

@@ -23,12 +23,27 @@ $alertClass;
$alertMessage; $alertMessage;
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
try { try {
if ($_POST["form"] == "group") { switch ($_POST["form"]) {
updateGroupSettings($_POST["groupID"]); case "group":
} else if ($_POST["form"] == "picture") { updateGroupSettings($_POST["groupID"]);
if (checkGroupAdmin($_POST["groupID"], $_SESSION["userID"])) { break;
updateAvatar($_POST["groupID"]); case "picture":
} if (checkGroupAdmin($_POST["groupID"], $_SESSION["userID"])) {
updateAvatar($_POST["groupID"]);
}
break;
case "mod":
if (!array_key_exists("userID", $_POST)) {
throw new AngryAlert("Geen gebruiker geselecteerd.");
}
upgradeUser($_POST["groupID"], $_POST["userID"], "mod");
break;
case "admin":
if (!array_key_exists("userID", $_POST)) {
throw new AngryAlert("Geen gebruiker geselecteerd.");
}
upgradeUser($_POST["groupID"], $_POST["userID"], "admin");
break;
} }
} catch (AlertMessage $w) { } catch (AlertMessage $w) {
$alertClass = $w->getClass(); $alertClass = $w->getClass();

View File

@@ -59,3 +59,51 @@ function checkGroupAdmin(int $groupID, int $userID) : bool {
$role = $stmt->fetch()["role"]; $role = $stmt->fetch()["role"];
return ($role == "admin"); return ($role == "admin");
} }
function getAllGroupMembers(int $groupID) {
$stmt = prepareQuery("
SELECT
`username`,
`user`.`userID`,
CONCAT(`fname`, ' ', `lname`) AS `fullname`,
`group_member`.`role`
FROM
`group_member`
LEFT JOIN
`user`
ON
`group_member`.`userID` = `user`.`userID`
WHERE
`groupID` = :groupID AND `group_member`.`role` = 'member'
");
$stmt->bindParam(':groupID', $groupID);
if (!$stmt->execute()) {
return False;
}
return $stmt->fetchAll();
}
function upgradeUser(int $groupID, int $userID, string $role) {
if (!checkGroupAdmin($groupID, $_SESSION["userID"])) {
throw new AngryAlert("Geen toestemming om te wijzigen");
}
$stmt = prepareQuery("
UPDATE
`group_member`
SET
`role` = :role
WHERE
`userID` = :userID AND `groupID` = :groupID
");
$stmt->bindValue(":groupID", $groupID);
$stmt->bindValue(":userID", $userID);
$stmt->bindValue(":role", $role);
$stmt->execute();
if ($stmt->rowCount()) {
throw new HappyAlert("Permissie aangepast!");
} else {
throw new AngryAlert("Er is iets mis gegaan");
}
}

View File

@@ -148,6 +148,10 @@ function doChangePassword() {
} }
} }
/**
* Changes the users email if it is valid.
* @throws AngryAlert
*/
function changeEmail() { function changeEmail() {
if (test_input($_POST["email"]) == test_input($_POST["email-confirm"])) { if (test_input($_POST["email"]) == test_input($_POST["email-confirm"])) {
@@ -164,6 +168,11 @@ function changeEmail() {
} }
} }
/**
* Checks if an emailadres is available in the database.
* @param $email
* @throws AngryAlert
*/
function emailIsAvailableInDatabase($email) { function emailIsAvailableInDatabase($email) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -181,6 +190,12 @@ function emailIsAvailableInDatabase($email) {
} }
} }
/**
* Does the actual changing of an email-adress.
* @param $email
* @throws AngryAlert
* @throws HappyAlert
*/
function doChangeEmail($email) { function doChangeEmail($email) {
$stmt = prepareQuery(" $stmt = prepareQuery("
UPDATE UPDATE

View File

@@ -85,6 +85,35 @@ $groupinfo = getGroupSettings($_GET["groupID"]);
</li> </li>
</ul> </ul>
</form> </form>
<form class="platform" method="post">
<h5>Voeg een admin/mod toe</h5>
<ul>
<il>
<input name="groupID" value="<?=$_GET["groupID"]?>" type="hidden">
<label>Selecteer gebruiker</label>
<select name="userID">
<option disabled selected>Geen gebruiker geselecteerd:</option>
<?php
$groupMembers = getAllGroupMembers($_GET["groupID"]);
foreach ($groupMembers as $groupMember) {?>
<option value="<?=$groupMember["userID"]?>">
<?=$groupMember["fullname"]?> (<?=$groupMember["username"]?>)
</option>
<?php } ?>
</select>
<button name="form"
value="admin"
>
Maak Admin
</button>
<button name="form"
value="mod"
>
Maak Moderator
</button>
</il>
</ul>
</form>
<div class="platform"> <div class="platform">
<ul> <ul>
<li> <li>