Add mods/admin to a group.
This commit is contained in:
@@ -58,4 +58,52 @@ function checkGroupAdmin(int $groupID, int $userID) : bool {
|
||||
}
|
||||
$role = $stmt->fetch()["role"];
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -148,6 +148,10 @@ function doChangePassword() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the users email if it is valid.
|
||||
* @throws AngryAlert
|
||||
*/
|
||||
function changeEmail() {
|
||||
|
||||
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) {
|
||||
$stmt = prepareQuery("
|
||||
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) {
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
|
||||
Reference in New Issue
Block a user