13 Commits

Author SHA1 Message Date
Lars van Hijfte
1ac6a7da87 Changed admin checkbox buttons 2017-02-03 12:40:33 +01:00
Lars van Hijfte
52ce787241 Merge remote-tracking branch 'origin/hendrik-testing' into lars 2017-02-03 12:34:19 +01:00
Lars van Hijfte
fb5f76c499 ? 2017-02-03 12:32:57 +01:00
Lars van Hijfte
3aae884bb5 Added comments 2017-02-03 12:12:16 +01:00
Lars van Hijfte
1fd984cc02 Merge branch 'marijn-groups' into lars 2017-02-03 11:31:58 +01:00
Lars van Hijfte
16f83d93ce Merge branch 'lars' into 'master'
Lars

See merge request !206
2017-02-03 11:21:12 +01:00
Lars van Hijfte
306fd3090f Merge branch 'hendrik-testing' into 'master'
removed session id lol

See merge request !205
2017-02-03 11:20:24 +01:00
Lars van Hijfte
4eae09dfc7 Merge branch 'master' into lars 2017-02-03 11:19:02 +01:00
Lars van Hijfte
53e1d7fef3 Fixed admin layout 2017-02-03 11:18:32 +01:00
Lars van Hijfte
c29be662bc Session logout now works 2017-02-03 11:18:17 +01:00
Lars van Hijfte
000d1f4072 Merge branch 'joey-testing' into 'master'
fixed login

See merge request !202
2017-02-03 11:16:48 +01:00
Lars van Hijfte
d260bf04bc Merge branch 'hendrik-testing' into 'master'
Hendrik testing

See merge request !204
2017-02-03 11:16:36 +01:00
Joey Lai
ba6f86e70e fixed login 2017-02-03 11:12:30 +01:00
13 changed files with 225 additions and 18 deletions

View File

@@ -13,7 +13,7 @@
include_once("../queries/group_page.php"); include_once("../queries/group_page.php");
if(!$group = selectGroupByName($_GET["groupname"])) { if(isset($_SESSION["userID"]) and !$group = selectGroupByName($_GET["groupname"])) {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
header("Location: error/404.php"); header("Location: error/404.php");
die(); die();

View File

@@ -51,6 +51,7 @@ function sendMessage() {
}); });
$("#newContent").val(""); $("#newContent").val("");
$("#newContent").focus();
} }
// Add messages to the chat. // Add messages to the chat.

View File

@@ -25,7 +25,8 @@ if(empty($_GET["username"])) {
$userID = getUserID($_GET["username"]); $userID = getUserID($_GET["username"]);
} }
if(!$user = selectUser($_SESSION["userID"], $userID)) {
if (isset($_SESSION["userID"]) and !$user = selectUser($_SESSION["userID"], $userID)) {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
header("Location: error/404.php"); header("Location: error/404.php");
die(); die();

View File

@@ -1,11 +1,13 @@
.admin-panel {
min-width: 800px;
}
.admin-panel input[type="radio"], input[type="checkbox"] { .admin-panel input[type="radio"], input[type="checkbox"] {
vertical-align: middle; vertical-align: middle;
height: 28px; height: 14px;
margin: 2px; width: 14px;
margin: 7px;
}
.table-checkbox {
width: 28px;
} }
.admin-searchform { .admin-searchform {
@@ -42,6 +44,7 @@
.usertable th, td { .usertable th, td {
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
padding: 3px; padding: 3px;
word-wrap: break-word;
} }
.usertable th, tr { .usertable th, tr {

View File

@@ -52,7 +52,7 @@ function updateGroupSettings(int $groupID)
} }
/** /**
* Checks if an user is an admin for a page. * Checks if a user is an admin for a page.
* @param int $groupID * @param int $groupID
* @param int $userID * @param int $userID
* @return bool * @return bool

View File

@@ -38,8 +38,7 @@ function getUserID() {
} }
function validateLogin($username, $password, $url){ function validateLogin($username, $password, $url){
echo $url; // Empty username or password field
// Empty username or password field
if (empty($username) || empty($password)) { if (empty($username) || empty($password)) {
throw new loginException("Inloggegevens zijn niet ingevuld"); throw new loginException("Inloggegevens zijn niet ingevuld");
} }

View File

@@ -1,9 +1,16 @@
<?php <?php
/**
* Return a relative dutch and readable text when given a datetime.
* @param $date
* @return string
*/
function nicetime($date) { function nicetime($date) {
if(empty($date)) { if(empty($date)) {
return "No date provided"; return "No date provided";
} }
// Create dutch arrays so it has dutch words.
$single_periods = array("seconde", "minuut", "uur", "dag", "week", "maand", "jaar", "decennium"); $single_periods = array("seconde", "minuut", "uur", "dag", "week", "maand", "jaar", "decennium");
$multiple_periods = array("seconden", "minuten", "uur", "dagen", "weken", "maanden", "jaar", "decennia"); $multiple_periods = array("seconden", "minuten", "uur", "dagen", "weken", "maanden", "jaar", "decennia");
$lengths = array("60", "60", "24", "7", "4.35", "12", "10", "0"); $lengths = array("60", "60", "24", "7", "4.35", "12", "10", "0");
@@ -15,7 +22,8 @@ function nicetime($date) {
return "Bad date"; return "Bad date";
} }
if($now > $unix_date) { // Check if it is in the future or not.
if($now >= $unix_date) {
$difference = $now - $unix_date; $difference = $now - $unix_date;
$tense = "geleden"; $tense = "geleden";
} else { } else {
@@ -23,6 +31,7 @@ function nicetime($date) {
$tense = "vanaf nu"; $tense = "vanaf nu";
} }
// Get the nice time.
for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) { for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) {
$difference /= $lengths[$i]; $difference /= $lengths[$i];
} }

View File

@@ -2,6 +2,12 @@
require_once("connect.php"); require_once("connect.php");
/**
* Select all posts on a user.
* @param $userID
* @param $groupID
* @return bool|PDOStatement
*/
function selectAllPosts($userID, $groupID) { function selectAllPosts($userID, $groupID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -46,6 +52,14 @@ function selectAllPosts($userID, $groupID) {
} }
/**
* Select $limit posts from $offset from a user or group.
* @param $userID
* @param $groupID
* @param $offset
* @param $limit
* @return bool|PDOStatement
*/
function selectSomePosts($userID, $groupID, $offset, $limit) { function selectSomePosts($userID, $groupID, $offset, $limit) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -94,9 +108,13 @@ function selectSomePosts($userID, $groupID, $offset, $limit) {
return False; return False;
} }
return $stmt; return $stmt;
} }
/**
* Select all the post information from an postID.
* @param $postID
* @return PDOStatement
*/
function selectPostById($postID) { function selectPostById($postID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -122,6 +140,11 @@ function selectPostById($postID) {
return $stmt; return $stmt;
} }
/**
* Get all the comments from a post.
* @param $postID
* @return PDOStatement
*/
function selectCommentsByPostId($postID) { function selectCommentsByPostId($postID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -148,6 +171,13 @@ function selectCommentsByPostId($postID) {
return $stmt; return $stmt;
} }
/**
* Insert a post to a group or user
* @param $userID
* @param $groupID
* @param $title
* @param $content
*/
function makePost($userID, $groupID, $title, $content) { function makePost($userID, $groupID, $title, $content) {
$stmt = prepareQuery(" $stmt = prepareQuery("
INSERT INTO INSERT INTO
@@ -172,6 +202,13 @@ function makePost($userID, $groupID, $title, $content) {
$stmt->execute(); $stmt->execute();
} }
/**
* Insert a comment by a post.
* @param $postID
* @param $userID
* @param $content
* @return int
*/
function makeComment($postID, $userID, $content) : int { function makeComment($postID, $userID, $content) : int {
$stmt = prepareQuery(" $stmt = prepareQuery("
INSERT INTO INSERT INTO
@@ -194,6 +231,12 @@ function makeComment($postID, $userID, $content) : int {
return $stmt->rowCount(); return $stmt->rowCount();
} }
/**
* If a post already is niet slechted.
* @param int $postID
* @param int $userID
* @return int
*/
function makeNietSlecht(int $postID, int $userID) : int { function makeNietSlecht(int $postID, int $userID) : int {
if (checkNietSlecht($postID, $userID)) { if (checkNietSlecht($postID, $userID)) {
return deleteNietSlecht($postID, $userID); return deleteNietSlecht($postID, $userID);
@@ -202,6 +245,12 @@ function makeNietSlecht(int $postID, int $userID) : int {
} }
} }
/**
* Toggle a niet slecht of a post.
* @param int $postID
* @param int $userID
* @return int
*/
function checkNietSlecht(int $postID, int $userID) { function checkNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -218,6 +267,12 @@ function checkNietSlecht(int $postID, int $userID) {
return $stmt->rowCount(); return $stmt->rowCount();
} }
/**
* Add a niet slecht to a post.
* @param int $postID
* @param int $userID
* @return int
*/
function addNietSlecht(int $postID, int $userID) { function addNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
INSERT INTO INSERT INTO
@@ -230,6 +285,12 @@ function addNietSlecht(int $postID, int $userID) {
return $stmt->rowCount(); return $stmt->rowCount();
} }
/**
* Delete a niet slecht.
* @param int $postID
* @param int $userID
* @return int
*/
function deleteNietSlecht(int $postID, int $userID) { function deleteNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
DELETE FROM DELETE FROM
@@ -244,6 +305,11 @@ function deleteNietSlecht(int $postID, int $userID) {
return $stmt->rowCount(); return $stmt->rowCount();
} }
/**
* Delete a post
* @param int $postID
* @param int $userID
*/
function deletePost(int $postID, int $userID) { function deletePost(int $postID, int $userID) {
if (checkPermissionOnPost($postID, $userID)) { if (checkPermissionOnPost($postID, $userID)) {
$stmt = prepareQuery(" $stmt = prepareQuery("
@@ -257,6 +323,12 @@ function deletePost(int $postID, int $userID) {
} }
} }
/**
* Check if a user has premissions to delete a post.
* @param int $postID
* @param int $userID
* @return bool
*/
function checkPermissionOnPost(int $postID, int $userID) : bool { function checkPermissionOnPost(int $postID, int $userID) : bool {
$getGroupID = prepareQuery(" $getGroupID = prepareQuery("
SELECT SELECT
@@ -282,10 +354,10 @@ function checkPermissionOnPost(int $postID, int $userID) : bool {
} }
/** /**
* Returns role of an user. * Returns role of a user.
* @param int $userID * @param int $userID
* @param int $groupID * @param int $groupID
* @return mixed role of an user. * @return mixed role of a user.
*/ */
function getRoleInGroup(int $userID, int $groupID) { function getRoleInGroup(int $userID, int $groupID) {
$stmt = prepareQuery(" $stmt = prepareQuery("

View File

@@ -1,5 +1,10 @@
<?php <?php
/**
* Get the the last 100 chat messages.
* @param $user2ID
* @return string
*/
function getOldChatMessages($user2ID) { function getOldChatMessages($user2ID) {
require_once ("friendship.php"); require_once ("friendship.php");
$user1ID = $_SESSION["userID"]; $user1ID = $_SESSION["userID"];
@@ -36,6 +41,12 @@ function getOldChatMessages($user2ID) {
} }
} }
/**
* Send a chat message.
* @param $destination
* @param $content
* @return bool
*/
function sendMessage($destination, $content) { function sendMessage($destination, $content) {
require_once("friendship.php"); require_once("friendship.php");
if (getFriendshipStatus($destination) == 1) { if (getFriendshipStatus($destination) == 1) {
@@ -65,6 +76,12 @@ function sendMessage($destination, $content) {
} }
} }
/**
* Get all the chat messages after an messageID ($lastID).
* @param $lastID
* @param $destination
* @return string
*/
function getNewChatMessages($lastID, $destination) { function getNewChatMessages($lastID, $destination) {
require_once("friendship.php"); require_once("friendship.php");
if (getFriendshipStatus($destination) == 1) { if (getFriendshipStatus($destination) == 1) {
@@ -96,7 +113,10 @@ function getNewChatMessages($lastID, $destination) {
} }
} }
/**
* Get of every friend the first unread chat message.
* @return string
*/
function selectAllUnreadChat() { function selectAllUnreadChat() {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT

View File

@@ -2,6 +2,10 @@
require_once ("connect.php"); require_once ("connect.php");
/**
* This sets the last activity of the session user to now.
* @return bool, true is it ran correctly
*/
function updateLastActivity() { function updateLastActivity() {
$stmt = prepareQuery(" $stmt = prepareQuery("
UPDATE UPDATE
@@ -15,6 +19,11 @@ function updateLastActivity() {
return $stmt->execute(); return $stmt->execute();
} }
/**
* This gets the userID from a username
* @param $username
* @return mixed
*/
function getUserID($username) { function getUserID($username) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -30,6 +39,11 @@ function getUserID($username) {
return $stmt->fetch()["userID"]; return $stmt->fetch()["userID"];
} }
/**
* This gets the username from a userID
* @param $userID
* @return mixed
*/
function getUsername($userID) { function getUsername($userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -45,6 +59,12 @@ function getUsername($userID) {
return $stmt->fetch()["username"]; return $stmt->fetch()["username"];
} }
/**
* This selects the information about the other user and the connection between the two.
* @param $me
* @param $other
* @return bool|mixed
*/
function selectUser($me, $other) { function selectUser($me, $other) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -107,6 +127,11 @@ function selectUser($me, $other) {
return $stmt->fetch(); return $stmt->fetch();
} }
/**
* Select all the users from a group.
* @param $userID
* @return PDOStatement
*/
function selectAllUserGroups($userID) { function selectAllUserGroups($userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -130,6 +155,11 @@ function selectAllUserGroups($userID) {
return $stmt; return $stmt;
} }
/**
* Selects 20 users from a given point in the table, ordered by role and name
* @param $n
* @return PDOStatement
*/
function select20UsersFromN($n) { function select20UsersFromN($n) {
$q = prepareQuery(" $q = prepareQuery("
SELECT SELECT
@@ -155,6 +185,12 @@ function select20UsersFromN($n) {
return $q; return $q;
} }
/**
* Search 20 users from a given point in the table, ordered by role and name
* @param $n
* @param $keyword
* @return PDOStatement
*/
function search20UsersFromN($n, $keyword) { function search20UsersFromN($n, $keyword) {
$q = prepareQuery(" $q = prepareQuery("
SELECT SELECT
@@ -183,6 +219,13 @@ function search20UsersFromN($n, $keyword) {
return $q; return $q;
} }
/**
* Search 20 users from a given point in the database where the status @param $status
* @param $n
* @param $keyword
* @param $status
* @return PDOStatement
*/
function search20UsersFromNByStatus($n, $keyword, $status) { function search20UsersFromNByStatus($n, $keyword, $status) {
$q = prepareQuery(" $q = prepareQuery("
SELECT SELECT
@@ -215,6 +258,14 @@ function search20UsersFromNByStatus($n, $keyword, $status) {
return $q; return $q;
} }
/**
* Search users from a given point in the database where the status @param $status
* @param $n
* @param $m
* @param $search
* @param $status
* @return PDOStatement
*/
function searchSomeUsersByStatus($n, $m, $search, $status) { function searchSomeUsersByStatus($n, $m, $search, $status) {
// parentheses not needed in where clause, for clarity as // parentheses not needed in where clause, for clarity as
// role search should override status filter. // role search should override status filter.
@@ -252,6 +303,12 @@ function searchSomeUsersByStatus($n, $m, $search, $status) {
return $q; return $q;
} }
/**
* Count the users with a name like $search and a $status
* @param $search
* @param $status
* @return PDOStatement
*/
function countSomeUsersByStatus($search, $status) { function countSomeUsersByStatus($search, $status) {
$q = prepareQuery(" $q = prepareQuery("
SELECT SELECT
@@ -276,7 +333,12 @@ function countSomeUsersByStatus($search, $status) {
return $q; return $q;
} }
/**
* Change the user status
* @param $id
* @param $status
* @return PDOStatement
*/
function changeUserStatusByID($id, $status) { function changeUserStatusByID($id, $status) {
$q = prepareQuery(" $q = prepareQuery("
UPDATE UPDATE
@@ -293,6 +355,12 @@ function changeUserStatusByID($id, $status) {
return $q; return $q;
} }
/**
* Change multiple user statuses by an id array.
* @param $ids
* @param $status
* @return PDOStatement
*/
function changeMultipleUserStatusByID($ids, $status) { function changeMultipleUserStatusByID($ids, $status) {
$q = prepareQuery(" $q = prepareQuery("
UPDATE UPDATE
@@ -310,6 +378,13 @@ function changeMultipleUserStatusByID($ids, $status) {
return $q; return $q;
} }
/**
* Change multiple user statuses by an id array.
* This excludes that admins and owners statuses can be changed.
* @param $ids
* @param $status
* @return PDOStatement
*/
function changeMultipleUserStatusByIDAdmin($ids, $status) { function changeMultipleUserStatusByIDAdmin($ids, $status) {
$q = prepareQuery(" $q = prepareQuery("
UPDATE UPDATE
@@ -329,6 +404,11 @@ function changeMultipleUserStatusByIDAdmin($ids, $status) {
return $q; return $q;
} }
/**
* Select a random user that is nog your friend.
* @param $userID
* @return mixed
*/
function selectRandomNotFriendUser($userID) { function selectRandomNotFriendUser($userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -357,6 +437,13 @@ function selectRandomNotFriendUser($userID) {
return $stmt->fetch(); return $stmt->fetch();
} }
/**
* Search users.
* @param $n
* @param $m
* @param $search
* @return string
*/
function searchSomeUsers($n, $m, $search) { function searchSomeUsers($n, $m, $search) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -397,6 +484,11 @@ function searchSomeUsers($n, $m, $search) {
return json_encode($stmt->fetchAll()); return json_encode($stmt->fetchAll());
} }
/**
* Count the users that you get searching for a user with a keyword.
* @param $search
* @return PDOStatement
*/
function countSomeUsers($search) { function countSomeUsers($search) {
$q = prepareQuery(" $q = prepareQuery("
SELECT SELECT
@@ -420,6 +512,11 @@ function countSomeUsers($search) {
return $q; return $q;
} }
/**
* Get the role of a user by userID.
* @param $userID
* @return mixed
*/
function getRoleByID($userID) { function getRoleByID($userID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
@@ -435,6 +532,11 @@ function getRoleByID($userID) {
return $stmt->fetch()["role"]; return $stmt->fetch()["role"];
} }
/**
* Edit the ban comment.
* @param $userID
* @param $comment
*/
function editBanCommentByID($userID, $comment) { function editBanCommentByID($userID, $comment) {
$stmt = prepareQuery(" $stmt = prepareQuery("
UPDATE UPDATE

View File

@@ -1,5 +1,5 @@
<tr> <tr>
<th><input class="table-checkbox" type="checkbox" id="checkall" name="checkall" onchange="checkAll()"></th> <th class="table-checkbox"><input class="table-checkbox" type="checkbox" id="checkall" name="checkall" onchange="checkAll()"></th>
<th class="table-username">Gebruikersnaam</th> <th class="table-username">Gebruikersnaam</th>
<th class="table-status">Status</th> <th class="table-status">Status</th>
<th class="table-comment">Aantekening</th> <th class="table-comment">Aantekening</th>

View File

@@ -1,7 +1,7 @@
<?php <?php
session_start(); session_start();
// Checks if there's an user already logged in // Checks if there's a user already logged in
if(isset($_SESSION["userID"])){ if(isset($_SESSION["userID"])){
echo "<script> echo "<script>
window.onload=checkLoggedIn(); window.onload=checkLoggedIn();