5 Commits

Author SHA1 Message Date
Hendrik
f566c6eec4 comments 2017-02-03 12:43:24 +01:00
Hendrik
f3aebddfea commentses 2017-02-03 12:21:37 +01:00
Hendrik
b07d0712aa Merge branch 'marijn-groups' into hendrik-testing 2017-02-03 12:08:42 +01:00
Marijn Jansen
6d5de98c1d comments 2017-02-03 11:31:18 +01:00
Marijn Jansen
ac2ce3d07b Merge branch 'master' into marijn-groups 2017-02-03 11:13:20 +01:00
12 changed files with 267 additions and 8 deletions

View File

@@ -1,4 +1,9 @@
/**
* Posts a comment or "Niet slecht." on a post.
* Button specifies between comment and "Niet slecht.".
* Alerts or redirects if frozen or not logged in.
*/
function postComment(buttonValue) {
formData = $("#newcommentform").serializeArray();
formData.push({name: "button", value: buttonValue});
@@ -24,6 +29,10 @@ function postComment(buttonValue) {
});
}
/**
* Deletes a post given by postID, closes modal and reloads posts.
* @param postID
*/
function deletePost(postID) {
var formData = [{name: "postID", value: postID}];
$.post(

View File

@@ -1,3 +1,4 @@
// Checks if user is logged in and offers to logout.
function checkLoggedIn() {
if (confirm("U bent al ingelogd!\nWilt u uitloggen?\nKlik ok om uit te loggen.") == true) {
window.location.href = "logout.php";
@@ -6,18 +7,22 @@ function checkLoggedIn() {
}
}
// Alert for validation mail.
function emailAlert(){
alert("Bevestigingsemail is gestuurd!\n");
}
// Alert for banned account.
function bannedAlert(){
alert("Uw account is geband!");
}
// Alert for frozen account.
function frozenAlert(){
alert("Uw account is bevroren!\n");
}
// Alert for unconfirmed email.
function emailNotConfirmed(){
alert("Uw account is nog niet bevestigd!\nEr is een nieuwe email gestuurd om uw account te bevestigen");
}

View File

@@ -41,7 +41,11 @@ function checkInputChoice($variable, $option){
}
}
/* Checks for only letters and spaces. */
/**
* Checks for only letters and spaces.
* @param $variable
* @throws lettersAndSpacesException
*/
function checkName($variable){
if (empty($variable)) {
throw new lettersAndSpacesException("Verplicht!");
@@ -52,7 +56,11 @@ function checkName($variable){
}
}
/* Checks for bday */
/**
* Checks for bday
* @param $variable
* @throws bdayException
*/
function validateBday($variable){
if (empty($variable)) {
throw new bdayException("Verplicht!");
@@ -220,6 +228,9 @@ function test_input($data) {
return $data;
}
/**
* Class lettersAndSpacesException
*/
class lettersAndSpacesException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -228,7 +239,9 @@ class lettersAndSpacesException extends Exception
}
}
/**
* Class bdayException
*/
class bdayException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -237,6 +250,9 @@ class bdayException extends Exception
}
}
/**
* Class usernameException
*/
class usernameException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -245,6 +261,9 @@ class usernameException extends Exception
}
}
/**
* Class passwordException
*/
class passwordException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -253,6 +272,9 @@ class passwordException extends Exception
}
}
/**
* Class confirmPasswordException
*/
class confirmPasswordException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -261,6 +283,9 @@ class confirmPasswordException extends Exception
}
}
/**
* Class fbConfirmPasswordException
*/
class fbConfirmPasswordException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -269,6 +294,9 @@ class fbConfirmPasswordException extends Exception
}
}
/**
* Class emailException
*/
class emailException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -277,6 +305,9 @@ class emailException extends Exception
}
}
/**
* Class confirmEmailException
*/
class confirmEmailException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -285,6 +316,9 @@ class confirmEmailException extends Exception
}
}
/**
* Class captchaException
*/
class captchaException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)
@@ -293,6 +327,9 @@ class captchaException extends Exception
}
}
/**
* Class registerException
*/
class registerException extends Exception
{
public function __construct($message = "", $code = 0, Exception $previous = null)

View File

@@ -8,6 +8,7 @@ require_once "../queries/alerts.php";
*/
function createGroup()
{
// Creates the group.
$createGroup = prepareQuery("
INSERT INTO
`group_page` (`name`, `description`)
@@ -17,6 +18,7 @@ function createGroup()
$createGroup->bindValue(':description', test_input($_POST["bio"]));
$createGroup->execute();
// Gets the groupID just created.
$getGroupID = prepareQuery("
SELECT
`groupID`
@@ -28,6 +30,7 @@ function createGroup()
$getGroupID->execute();
$groupID = $getGroupID->fetch()["groupID"];
// Adds the user as an admin.
$makeUserAdmin = prepareQuery("
INSERT INTO
`group_member` (userID, groupID, role)

View File

@@ -1,5 +1,8 @@
<?php
/**
* Sends a confirm email if you know the username.
* @param string $username
*/
function sendConfirmEmailUsername(string $username) {
$stmt = prepareQuery("
SELECT
@@ -15,6 +18,10 @@ function sendConfirmEmailUsername(string $username) {
sendConfirmEmail($userID);
}
/**
* Sends a confirm email if you know the userID.
* @param int $userID
*/
function sendConfirmEmail(int $userID) {
$stmt = prepareQuery("
SELECT

View File

@@ -2,10 +2,21 @@
require_once ("connect.php");
/**
* Selects all friends of a user.
* @param $userID
* @return string
*/
function selectFriends($userID) {
return selectLimitedFriends($userID, 9999);
}
/**
* Returns a limited amount of friends of a user.
* @param $userID
* @param $limit
* @return string
*/
function selectLimitedFriends($userID, $limit) {
$stmt = prepareQuery("
SELECT
@@ -46,7 +57,11 @@ function selectLimitedFriends($userID, $limit) {
return json_encode($stmt->fetchAll());
}
/**
* Selects all friends of a user.
* @param $userID
* @return PDOStatement
*/
function selectAllFriends($userID) {
$stmt = prepareQuery("
SELECT
@@ -83,6 +98,10 @@ function selectAllFriends($userID) {
return $stmt;
}
/**
* Returns all friend requests of the current user.
* @return string
*/
function selectAllFriendRequests() {
$stmt = prepareQuery("
SELECT
@@ -119,6 +138,11 @@ function selectAllFriendRequests() {
return json_encode($stmt->fetchAll());
}
/**
* Gets the friendship status from current user and userID.
* @param $userID
* @return int
*/
function getFriendshipStatus($userID) {
# -2: Query failed.
# -1: user1 and 2 are the same user
@@ -162,6 +186,11 @@ function getFriendshipStatus($userID) {
return intval($stmt->fetch()["friend_state"]);
}
/**
* Request friendship from current user to target user.
* @param $userID
* @return bool
*/
function requestFriendship($userID) {
$stmt = prepareQuery("
INSERT INTO `friendship` (user1ID, user2ID)
@@ -173,6 +202,11 @@ function requestFriendship($userID) {
return $stmt->execute();
}
/**
* Removes friendship between current and target user.
* @param $userID
* @return bool
*/
function removeFriendship($userID) {
$stmt = prepareQuery("
DELETE FROM `friendship`
@@ -189,6 +223,11 @@ function removeFriendship($userID) {
return $stmt->execute();
}
/**
* Sets the friendship between current and target user to accepted.
* @param $userID
* @return bool
*/
function acceptFriendship($userID) {
$stmt = prepareQuery("
UPDATE `friendship`
@@ -204,6 +243,11 @@ function acceptFriendship($userID) {
return $stmt->execute();
}
/**
* Sets the last time the user visited the chat with specified friend.
* @param $friend
* @return PDOStatement
*/
function setLastVisited($friend) {
$stmt = prepareQuery("
UPDATE
@@ -234,6 +278,13 @@ function setLastVisited($friend) {
return $stmt;
}
/**
* Searches m friends from n filtered by search.
* @param $n
* @param $m
* @param $search
* @return string
*/
function searchSomeFriends($n, $m, $search) {
$stmt = prepareQuery("
SELECT
@@ -281,6 +332,11 @@ function searchSomeFriends($n, $m, $search) {
return json_encode($stmt->fetchAll());
}
/**
* Counts all friends of current user filtered by search.
* @param $search
* @return string
*/
function countSomeFriends($search) {
$stmt = prepareQuery("
SELECT

View File

@@ -1,9 +1,20 @@
<?php
/**
* Returns all groups a user is member of.
* @param $userID
* @return string
*/
function selectAllGroupsFromUser($userID) {
return selectLimitedGroupsFromUser($userID, 9999);
}
/**
* Selects number of groups that a user is member of.
* @param $userID
* @param $limit
* @return string
*/
function selectLimitedGroupsFromUser($userID, $limit) {
$stmt = prepareQuery("
SELECT
@@ -27,6 +38,13 @@ function selectLimitedGroupsFromUser($userID, $limit) {
return json_encode($stmt->fetchAll());
}
/**
* Returns m groups offset by n filtered by search that the current user is part of.
* @param $n
* @param $m
* @param $search
* @return string
*/
function searchSomeOwnGroups($n, $m, $search) {
$stmt = prepareQuery("
SELECT
@@ -55,6 +73,11 @@ function searchSomeOwnGroups($n, $m, $search) {
return json_encode($stmt->fetchAll());
}
/**
* Counts all groups filtered by search that the current user is member of.
* @param $search
* @return string
*/
function countSomeOwnGroups($search) {
$stmt = prepareQuery("
SELECT
@@ -78,6 +101,13 @@ function countSomeOwnGroups($search) {
return $stmt->fetchColumn();
}
/**
* Adds a user by userID to a group by groupID with a specified role.
* @param $groupID
* @param $userID
* @param $role
* @return bool
*/
function addMember($groupID, $userID, $role) {
$stmt = prepareQuery("
INSERT INTO
@@ -92,6 +122,13 @@ function addMember($groupID, $userID, $role) {
return $stmt->execute();
}
/**
* Changes te role of a user within a group to the specified one.
* @param $groupID
* @param $userID
* @param $role
* @return bool
*/
function changeMember($groupID, $userID, $role) {
$stmt = prepareQuery("
UPDATE
@@ -109,6 +146,12 @@ function changeMember($groupID, $userID, $role) {
return $stmt->execute();
}
/**
* Removes a user from a group.
* @param $groupID
* @param $userID
* @return bool
*/
function deleteMember($groupID, $userID) {
$stmt = prepareQuery("
DELETE FROM

View File

@@ -2,6 +2,10 @@
require_once("connect.php");
/**
* Selects some info from a group by name.
* @return bool|mixed
*/
function selectGroupByName($name) {
$stmt = prepareQuery("
SELECT
@@ -41,6 +45,11 @@ function selectGroupByName($name) {
return $row;
}
/**
* Selects the current user's role within a group by the group's ID.
* @param int $groupID
* @return bool|string
*/
function selectGroupRole(int $groupID) {
$stmt = prepareQuery("
SELECT
@@ -63,6 +72,11 @@ function selectGroupRole(int $groupID) {
return $stmt->fetch()["role"];
}
/**
* Returns the status of a group by it's ID.
* @param int $groupID
* @return bool
*/
function selectGroupStatus(int $groupID) {
$stmt = prepareQuery("
SELECT
@@ -80,6 +94,11 @@ function selectGroupStatus(int $groupID) {
return $stmt->fetch()["status"];
}
/**
* Returns some info of all group members.
* @param int $groupID
* @return bool|PDOStatement
*/
function selectGroupMembers(int $groupID) {
$stmt = prepareQuery("
SELECT
@@ -105,9 +124,14 @@ function selectGroupMembers(int $groupID) {
if (!$stmt->execute()) {
return False;
}
return $stmt->fetchAll();
return $stmt;
}
/**
* Returns group info by it's ID.
* @param $groupID
* @return PDOStatement
*/
function selectGroupById($groupID) {
$q = prepareQuery("
SELECT
@@ -127,6 +151,11 @@ function selectGroupById($groupID) {
return $q;
}
/**
* Returns some info of 20 groups offset by n.
* @param $n
* @return PDOStatement
*/
function select20GroupsFromN($n) {
$q = prepareQuery("
SELECT
@@ -149,6 +178,12 @@ function select20GroupsFromN($n) {
return $q;
}
/**
* Returns info of 20 groups offset by n, filtered by status.
* @param $n
* @param $status
* @return PDOStatement
*/
function select20GroupsByStatusFromN($n, $status) {
$q = prepareQuery("
SELECT
@@ -174,6 +209,13 @@ function select20GroupsByStatusFromN($n, $status) {
return $q;
}
/**
* Returns info of 20 groups offset by n, filtered by status, filtered by search.
* @param $n
* @param $keyword
* @param $status
* @return PDOStatement
*/
function search20GroupsFromNByStatus($n, $keyword, $status) {
$q = prepareQuery("
SELECT
@@ -201,6 +243,14 @@ function search20GroupsFromNByStatus($n, $keyword, $status) {
return $q;
}
/**
* Returns info of n groups offset by m, filtered by status and search.
* @param $n
* @param $m
* @param $search
* @param $status
* @return PDOStatement
*/
function searchSomeGroupsByStatus($n, $m, $search, $status) {
// parentheses not needed in where clause, for clarity as
// role search should override status filter.
@@ -233,6 +283,12 @@ function searchSomeGroupsByStatus($n, $m, $search, $status) {
return $q;
}
/**
* Count all groups filtered by status and search.
* @param $search
* @param $status
* @return PDOStatement
*/
function countSomeGroupsByStatus($search, $status) {
$q = prepareQuery("
SELECT
@@ -256,6 +312,12 @@ function countSomeGroupsByStatus($search, $status) {
return $q;
}
/**
* Changes the status of a group with the given ID.
* @param $id
* @param $status
* @return PDOStatement
*/
function changeGroupStatusByID($id, $status) {
$q = prepareQuery("
UPDATE
@@ -272,6 +334,12 @@ function changeGroupStatusByID($id, $status) {
return $q;
}
/**
* Changes the status of multiple groups to 1 status by an array of IDs.
* @param $ids
* @param $status
* @return PDOStatement
*/
function changeMultipleGroupStatusByID($ids, $status) {
$q = prepareQuery("
UPDATE
@@ -289,6 +357,13 @@ function changeMultipleGroupStatusByID($ids, $status) {
return $q;
}
/**
* Returns m groups offset by n, filtered by search.
* @param $n
* @param $m
* @param $search
* @return string
*/
function searchSomeGroups($n, $m, $search) {
$stmt = prepareQuery("
SELECT
@@ -312,6 +387,11 @@ function searchSomeGroups($n, $m, $search) {
return json_encode($stmt->fetchAll());
}
/**
* Counts all group filtered by search.
* @param $search
* @return PDOStatement
*/
function countSomeGroups($search) {
$stmt = prepareQuery("
SELECT

View File

@@ -1,6 +1,9 @@
<?php
//Find matching password with the inputted username/emailadress.
/**
* Find matching password with the inputted username/emailadress.
* @return mixed
*/
function getUser() {
$stmt = prepareQuery("
SELECT

View File

@@ -281,6 +281,12 @@ function checkPermissionOnPost(int $postID, int $userID) : bool {
}
}
/**
* Returns role of an user.
* @param int $userID
* @param int $groupID
* @return mixed role of an user.
*/
function getRoleInGroup(int $userID, int $groupID) {
$stmt = prepareQuery("
SELECT

View File

@@ -13,6 +13,7 @@ Pagina:
id="currentpage"
form="admin-searchform"
onchange="adminSearch();">
<!-- Construct the options. -->
<?php
for ($i=1; $i <= ceil($countresults / $entries); $i++) {
if ($currentpage == $i) {

View File

@@ -16,9 +16,18 @@
<h2>Leden (<?= $group['members'] ?>)</h2>
<p>
<?php
foreach($members as $member) {
$membercount = $members->rowCount();
$memberdif = $membercount - 7;
for ($i = 0; $i < min($membercount, 7); $i += 1) {
$member = $members->fetch();
echo "<a href=\"profile.php?username=" . $member["username"] . "\" data-title=\"" . $member["username"] . "\"><img class=\"profile-picture\" src=\"" . $member["profilepicture"] . "\" alt=\"" . $member["username"] . "'s profielfoto\"></a>";
}
if ($memberdif > 0) {
echo $memberdif === 1 ? "en nog 1 andere." : "...en nog $memberdif anderen.";
}
?>
</p>
</div>