18 Commits

Author SHA1 Message Date
Lars van Hijfte
dc11830c80 Fixed name length 2017-01-24 14:32:43 +01:00
Lars van Hijfte
dbb23922d8 Merge branch 'master' into lars-chat 2017-01-24 14:26:48 +01:00
Lars van Hijfte
a88483ae47 FINALLY FIXED THE UNREAD CHAT MESSAGES! 2017-01-24 14:26:15 +01:00
Marijn Jansen
ee6b55bd91 Merge branch 'marijn-settings' into 'master'
Marijn settings

See merge request !102
2017-01-24 14:02:34 +01:00
Marijn Jansen
08c3d73377 Merge branch 'master' into 'marijn-settings'
# Conflicts:
#   website/views/menu.php
2017-01-24 14:02:19 +01:00
Marijn Jansen
c1359920e0 New Standard avatar 2017-01-24 14:00:55 +01:00
Marijn Jansen
4579b98eb8 Checks and resize on profile pictures :) 2017-01-24 13:54:08 +01:00
Marijn Jansen
62a2b32c95 Changed Alerts to Exceptions. 2017-01-24 12:12:48 +01:00
Lars van Hijfte
96003b1bdc Merge branch 'hendrik-search' into 'master'
Hendrik search

See merge request !100
2017-01-24 10:21:17 +01:00
Lars van Hijfte
c4a0367fef Merge branch 'lars-chat' into 'master'
Lars chat

See merge request !101
2017-01-24 10:19:52 +01:00
Lars van Hijfte
c4e4508b53 Changed admin layout and fixed for enums 2017-01-24 10:19:13 +01:00
Lars van Hijfte
d7e84ee138 Merge branch 'lars-algemeen' into lars-chat 2017-01-23 17:22:38 +01:00
Lars van Hijfte
7eec0cfa2a Begin chat change 2017-01-23 17:22:22 +01:00
Lars van Hijfte
348b66c08c Merge branch 'master' into lars-chat 2017-01-23 17:08:43 +01:00
Lars van Hijfte
37aa073fc1 End of day commit 2017-01-23 16:45:16 +01:00
Lars van Hijfte
b6d166bdea Merge branch 'lars-algemeen' into 'master'
Lars algemeen

See merge request !98
2017-01-23 16:27:45 +01:00
Hendrik
2ff23ae668 Merge branch 'master' into hendrik-search 2017-01-23 16:06:03 +01:00
Hendrik
e6f5044a9a add page functionality 2017-01-23 16:04:59 +01:00
28 changed files with 508 additions and 309 deletions

View File

@@ -3,6 +3,6 @@
session_start(); session_start();
require_once ("../../queries/connect.php"); require_once ("../../queries/connect.php");
require_once ("../../queries/friendship.php"); require_once ("../../queries/private_message.php");
echo selectAllUnreadChat(); echo selectAllUnreadChat();

View File

@@ -5,9 +5,11 @@ session_start();
require_once("../../queries/connect.php"); require_once("../../queries/connect.php");
require_once("../../queries/private_message.php"); require_once("../../queries/private_message.php");
require_once("../../queries/checkInput.php"); require_once("../../queries/checkInput.php");
require_once("../../queries/friendship.php");
if (isset($_POST["lastID"]) && $_POST["lastID"] != "") { if (isset($_POST["lastID"]) && $_POST["lastID"] != "") {
echo getNewChatMessages(test_input($_POST["lastID"]), test_input($_POST["destination"])); echo getNewChatMessages(test_input($_POST["lastID"]), test_input($_POST["destination"]));
} else { } else {
echo getOldChatMessages(test_input($_POST["destination"])); echo getOldChatMessages(test_input($_POST["destination"]));
setLastVisited(test_input($_POST["destination"]));
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -28,7 +28,7 @@ function checkCheckAll(allbox) {
} }
function changeFilter() { function changeFilter() {
if (document.getElementById('group').checked) { if ($('#pagetype').find(":selected").val() == "group") {
document.getElementById('admin-filter').style.display = 'none'; document.getElementById('admin-filter').style.display = 'none';
document.getElementById('admin-groupfilter').style.display = 'inline-block'; document.getElementById('admin-groupfilter').style.display = 'inline-block';

View File

@@ -53,8 +53,8 @@ function switchUser(userID) {
$(".destinationID").val(userID); $(".destinationID").val(userID);
$("#chat-history").html(""); $("#chat-history").html("");
$("#lastID").val(""); $("#lastID").val("");
$(".chat-left .friend-item").removeClass("active-friend-chat"); $("#chat-recent-panel .friend-item").removeClass("active-friend-chat");
$(".chat-left #friend-item-" + userID).addClass("active-friend-chat"); $("#chat-left #friend-item-" + userID).addClass("active-friend-chat");
} }
function sayEmpty() { function sayEmpty() {

View File

@@ -1,26 +1,18 @@
$(document).ready(function() { $(document).ready(function() {
// Hide notification center.
$("#profile-menu-popup").hide();
// $("#own-profile-picture").click(function() {
// $("#profile-menu-popup").toggle();
// $("#profile-hello-popup").toggle();
// });
$("#own-profile-picture").click(function() { $("#own-profile-picture").click(function() {
if($("#notification-center").css('right') == "-256px") { if($("#notification-center").css('right') == "-256px") {
$(".content").animate({ $(".content").animate({
marginRight: "256px" marginRight: "256px"
}, 500); }, 500);
$(".chat-right").animate({ $(".chat-right").animate({
width: "calc(100% - 512px - 40px)" width: $(".chat-right").width() - 266
}, 500); }, 500);
$("#notification-center").animate({ $("#notification-center").animate({
right: "0px" right: "0px"
}, 500); }, 500);
} else { } else {
$(".chat-right").animate({ $(".chat-right").animate({
width: "calc(100% - 256px - 40px)" width: $(".chat-right").width() + 266
}, 500); }, 500);
$(".content").animate({ $(".content").animate({
marginRight: "0px" marginRight: "0px"
@@ -30,6 +22,4 @@ $(document).ready(function() {
}, 500); }, 500);
} }
}); });
$("#own-profile-picture").click();
}); });

View File

@@ -1,7 +1,7 @@
function showNotifications(notifications, id) { function showFriendNotifications(notifications) {
$("#" + id).html(""); $("#friendrequestslist").html("");
for (i in notifications) { for (i in notifications) {
$("#" + id).append(" \ $("#friendrequestslist").append(" \
<li class='friend-item $extraItem'> \ <li class='friend-item $extraItem'> \
<form action='profile.php' method='get'> \ <form action='profile.php' method='get'> \
<button type='submit' \ <button type='submit' \
@@ -18,19 +18,42 @@ function showNotifications(notifications, id) {
} }
} }
function showChatNotifications(notifications) {
$("#unreadChatlist").html("");
for (i in notifications) {
$("#unreadChatlist").append(" \
<li class='friend-item $extraItem'> \
<form action='chat.php' method='get'> \
<button type='submit' \
name='username' \
value='"+ notifications[i].userID +"'> \
<div class='friend'> \
<img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \
<div class='friend-name'> \
"+ notifications[i].name +"<br/> \
<span style='color: #666'>"+ notifications[i].content +"</span> \
</div> \
</div> \
</button> \
</form> \
</li> \
");
}
}
function loadNotifications() { function loadNotifications() {
$.post( $.post(
"API/loadFriendRequestNotifications.php" "API/loadFriendRequestNotifications.php"
).done(function(data) { ).done(function(data) {
if (data && data != "[]") { if (data && data != "[]") {
showNotifications(JSON.parse(data), "friendrequestslist"); showFriendNotifications(JSON.parse(data));
} }
}); });
$.post( $.post(
"API/loadChatNotifications.php" "API/loadChatNotifications.php"
).done(function(data) { ).done(function(data) {
if (data && data != "[]") { if (data && data != "[]") {
showNotifications(JSON.parse(data), "unreadChatlist"); showChatNotifications(JSON.parse(data));
} }
}); });

View File

@@ -12,23 +12,28 @@
</head> </head>
<body> <body>
<?php <?php
$notImplemented = new settingsMessage("angry", "Deze functie werkt nog niet :("); $alertClass;
$alertMessage;
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
switch ($_POST["form"]) { switch ($_POST["form"]) {
case "profile": case "profile":
$result = updateSettings(); updateSettings();
break; break;
case "password": case "password":
$result = changePassword(); changePassword();
break; break;
case "email": case "email":
$result = changeEmail(); changeEmail();
break; break;
case "picture": case "picture":
updateProfilePicture(); updateAvatar();
$result = new settingsMessage("happy", "Deze melding doet nog niks nuttigs.");
break; break;
}
} catch (AlertMessage $w) {
$alertClass = $w->getClass();
$alertMessage = $w->getMessage();
} }
} }
include("../views/main.php"); include("../views/main.php");

View File

@@ -1,71 +1,33 @@
.admin-panel { .admin-panel {
margin: auto;
min-width: 800px; min-width: 800px;
} }
.admin-title {
margin: 10px;
padding-bottom: 5px;
border-bottom: 4px solid #FBC02D;
}
.admin-panel input[type="radio"], input[type="checkbox"] { .admin-panel input[type="radio"], input[type="checkbox"] {
vertical-align: middle;
height: auto; height: auto;
} margin: 2px;
.admin-batchactions, .admin-groupbatchactions {
display: inline-block;
padding: 8px;
vertical-align: top;
border-radius: 10px;
border: 4px solid #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
} }
.admin-searchform { .admin-searchform {
display: inline-block; display: inline-block;
width: 100%;
} }
.admin-searchbar { .admin-searchbar {
display: inline-block;
margin: 10px;
vertical-align: top;
}
.admin-searchinput {
margin-bottom: 10px;
}
.admin-filter, .admin-filtertype, .admin-groupfilter {
display: inline-block;
margin: 10px;
vertical-align: top;
margin-right: 50px;
margin-left: 50px;
}
.admin-filter, .admin-groupfilter {
width: 120px;
}
.admin-users {
margin: 10px;
}
.admin-userheading {
width: auto;
float: left;
}
.admin-pageui {
text-align: right;
float: right;
width: auto;
margin-bottom: 20px; margin-bottom: 20px;
} }
.usertitle { .admin-pageui {
width: 150px; display: inline-block;
width: 100%;
}
.admin-pageselector {
display: inline-block;
}
.admin-users {
margin-top: 50px;
} }
.usertable { .usertable {

View File

@@ -1,39 +1,52 @@
/* Overall chat-screen */ /* Overall chat-screen */
.chat { .chat {
position: fixed; position: fixed;
top: 80px; top: 80px;
left: 256px; left: 256px;
padding: 15px 0;
width: calc(100% - 256px); width: calc(100% - 256px);
height: calc(100% - 120px); height: calc(100% - 120px);
display: inline-flex;
padding: 20px 0;
display: inline-block;
} }
.chat-left { #chat-recent-panel {
width: 256px; width: 256px;
height: calc(100% - 100px); height: calc(100% - 100px);
margin: 0 10px;
overflow-y: auto;
}
.chat-right { display: inline-block;
width: calc(100% - 256px - 40px);
height: calc(100% - 80px); overflow-y: auto;
margin-right: 10px;
} }
/* Chat history. */ /* Chat history. */
.chat-history { #chat-history {
overflow-y: auto; overflow-y: auto;
height: 100%; overflow-x: hidden;
width: calc(100% - 256px - 75px);
height: calc(100% - 80px);
padding: 10px; padding: 10px;
display: inline-block;
word-wrap: break-word;
} }
/* Chat-message takes the whole width of the chat area */ /* Chat-message takes the whole width of the chat area */
.chat-message { .chat-message {
width: 100%; width: 100%;
min-height: 40px; min-height: 40px;
padding-top: 10px; padding: 10px 0;
clear: both;
}
.chat-message::after {
content: '';
display: table;
clear: both; clear: both;
} }
@@ -46,20 +59,21 @@
.chat-message-self { .chat-message-self {
float: right; float: right;
margin-right: 10px; margin-right: 10px;
background-color: darkgreen; background-color: #FBC02D;
color: white; color: #333;
} }
.chat-message-other { .chat-message-other {
float: left; float: left;
margin-left: 10px; margin-left: 10px;
background-color: aquamarine; background-color: #4CAF50;
color: white;
} }
/* Chat reply field */ /* Chat reply field */
.chat-field { .chat-field {
width: 100%; width: calc(100% - 10px);
display: table; display: table;
} }
@@ -77,7 +91,6 @@
width: 100%; width: 100%;
border: none; border: none;
border-radius: 10px 0 0 10px; border-radius: 10px 0 0 10px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
} }
.chat-field input[type="submit"] { .chat-field input[type="submit"] {
@@ -87,10 +100,9 @@
color: white; color: white;
padding: 5px 10px; padding: 5px 10px;
border-radius: 0 10px 10px 0; border-radius: 0 10px 10px 0;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
} }
.active-friend-chat { .active-friend-chat {
background: aquamarine; background: #4CAF50;
color: #333; color: white;
} }

View File

@@ -7,7 +7,9 @@ header {
height: 80px; height: 80px;
width: 100%; width: 100%;
color: white; color: #FFF;
font-weight: bold;
letter-spacing: 1px;
background-color: #FBC02D; background-color: #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
} }

View File

@@ -242,3 +242,23 @@ div[data-title]:hover:after {
line-height: normal; line-height: normal;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
} }
.friend {
}
.friend-item, .group-item {
cursor: pointer;
transition-duration: 250ms;
}
.friend-item:hover, .group-item:hover {
background: #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.friend-name {
display: inline-block;
vertical-align: middle;
}

View File

@@ -34,16 +34,6 @@
cursor: pointer; cursor: pointer;
} }
.friend-item, .group-item {
cursor: pointer;
transition-duration: 250ms;
}
.friend-item:hover, .group-item:hover {
background: #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.menu button { .menu button {
background: none; background: none;
color: inherit; color: inherit;

View File

@@ -15,3 +15,15 @@
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;
} }
.user-pageselect, .searchleft h4, .group-pageselect, .searchright h4 {
display: inline-block;
}
.user-pageselect, .group-pageselect {
float: right;
}
li.search-item:hover{
background-color: #EEE;
}

View File

@@ -5,9 +5,10 @@ function selectAllFriends($userID) {
SELECT SELECT
`userID`, `userID`,
`username`, `username`,
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/avatar-standard.png'
) AS profilepicture, ) AS profilepicture,
`onlinestatus`, `onlinestatus`,
`role` `role`
@@ -36,9 +37,10 @@ function selectAllFriendRequests() {
SELECT SELECT
`userID`, `userID`,
`username`, `username`,
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/avatar-standard.png'
) AS profilepicture, ) AS profilepicture,
`onlinestatus`, `onlinestatus`,
`role` `role`
@@ -61,3 +63,34 @@ function selectAllFriendRequests() {
return json_encode($stmt->fetchAll()); return json_encode($stmt->fetchAll());
} }
function setLastVisited($friend) {
$stmt = $GLOBALS["db"]->prepare("
UPDATE
`friendship`
SET `friendship`.chatLastVisted1=(
CASE `user1ID` = :sessionUser
WHEN TRUE THEN NOW()
WHEN FALSE THEN `chatLastVisted1`
END
),
`friendship`.`chatLastVisted2`=(
CASE `user2ID` = :sessionUser
WHEN TRUE THEN NOW()
WHEN FALSE THEN `chatLastVisted2`
END
)
WHERE
`user1ID` = :sessionUser AND
`user2ID` = :friend OR
`user2ID` = :sessionUser AND
`user1ID` = :friend;
");
$stmt->bindParam(':sessionUser', $_SESSION["userID"], PDO::PARAM_INT);
$stmt->bindParam(':friend', $friend, PDO::PARAM_INT);
$stmt->execute();
return $stmt;
}

View File

@@ -194,4 +194,22 @@ function searchSomeGroups($n, $m, $search) {
$stmt->execute(); $stmt->execute();
return $stmt; return $stmt;
} }
function countSomeGroups($search) {
$stmt = $GLOBALS["db"]->prepare("
SELECT
COUNT(*)
FROM
`group_page`
WHERE
`name` LIKE :keyword
ORDER BY
`name`
");
$search = "%$search%";
$stmt->bindParam(':keyword', $search);
$stmt->execute();
return $stmt;
}
?> ?>

View File

@@ -6,7 +6,7 @@ function getHeaderInfo() {
`lname`, `lname`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'img/notbad.jpg' 'img/avatar-standard.png'
) AS profilepicture ) AS profilepicture
FROM FROM
`user` `user`

View File

@@ -74,3 +74,38 @@ function getNewChatMessages($lastID, $destination) {
return json_encode($stmt->fetchAll()); return json_encode($stmt->fetchAll());
} }
function selectAllUnreadChat() {
$stmt = $GLOBALS["db"]->prepare("
SELECT
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
IFNULL(
`profilepicture`,
'../img/notbad.jpg'
) AS profilepicture,
LEFT(`private_message`.`content`, 15) as `content`
FROM
`private_message`,
`friendship`,
`user`
WHERE
(`friendship`.user2ID = `private_message`.`origin` AND
`friendship`.user1ID = `private_message`.`destination` AND
`friendship`.chatLastVisted1 < `private_message`.`creationdate` OR
`friendship`.user1ID = `private_message`.`origin` AND
`friendship`.user2ID = `private_message`.`destination` AND
`friendship`.chatLastVisted2 < `private_message`.`creationdate`) AND
`private_message`.`origin` = `user`.`userID` AND
`private_message`.`destination` = :userID AND
`user`.`role` != 'banned'
GROUP BY `user`.`userID`
");
$stmt->bindParam(':userID', $_SESSION["userID"]);
$stmt->execute();
return json_encode($stmt->fetchAll());
}

View File

@@ -1,35 +1,33 @@
<?php <?php
abstract class AlertMessage extends Exception {
class settingsMessage { public function __construct($message = "", $code = 0, Exception $previous = null)
private $class; {
private $message; parent::__construct($message, $code, $previous);
/**
* settingsMessage constructor.
* @param string $type Happy or angry
* @param string $message The message to display
*/
public function __construct($type, $message) {
$this->message = $message;
switch ($type) {
case "happy":
$this->class = "settings-message-happy";
break;
case "angry":
$this->class = "settings-message-angry";
break;
default:
$this->class = "settings-message";
break;
} }
abstract public function getClass();
}
class HappyAlert extends AlertMessage {
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
} }
public function getClass() { public function getClass() {
return $this->class; return "settings-message-happy";
}
} }
public function getMessage() { class AngryAlert extends AlertMessage {
return $this->message; public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
public function getClass() {
return "settings-message-angry";
} }
} }
@@ -94,24 +92,19 @@ function updateSettings() {
$stmt->bindValue(":bio", test_input($_POST["bio"])); $stmt->bindValue(":bio", test_input($_POST["bio"]));
$stmt->bindValue(":userID", $_SESSION["userID"]); $stmt->bindValue(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
throw new HappyAlert("Instellingen zijn opgeslagen.");
return new settingsMessage("happy", "Instellingen zijn opgeslagen.");
} }
function changePassword() { function changePassword() {
$user = getPasswordHash(); $user = getPasswordHash();
if (password_verify($_POST["password-old"], $user["password"])) { if (password_verify($_POST["password-old"], $user["password"])) {
if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) { if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) {
if (doChangePassword()) { doChangePassword();
return new settingsMessage("happy", "Wachtwoord gewijzigd.");
} else { } else {
return new settingsMessage("angry", "Er is iets mis gegaan."); throw new AngryAlert("Wachtwoorden komen niet overeen.");
} }
} else { } else {
return new settingsMessage("angry", "Wachtwoorden komen niet oveen."); throw new AngryAlert("Oud wachtwoord niet correct.");
}
} else {
return new settingsMessage("angry", "Oud wachtwoord niet correct.");
} }
} }
@@ -129,7 +122,12 @@ function doChangePassword() {
$stmt->bindParam(":new_password", $hashed_password); $stmt->bindParam(":new_password", $hashed_password);
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
return $stmt->rowCount();
if ($stmt->rowCount()) {
throw new HappyAlert("Wachtwoord gewijzigd.");
} else {
throw new AngryAlert();
}
} }
function changeEmail() { function changeEmail() {
@@ -138,20 +136,13 @@ function changeEmail() {
$email = strtolower($_POST["email"]); $email = strtolower($_POST["email"]);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
//check if email exists //check if email exists
if (emailIsAvailableInDatabase($email)) { emailIsAvailableInDatabase($email);
if (doChangeEmail($email)) { doChangeEmail($email);
return new settingsMessage("happy", "Emailadres is veranderd.");
} else { } else {
return new settingsMessage("angry", "Er is iets mis gegaan."); throw new AngryAlert("Geef een geldig emailadres");
} }
} else { } else {
return new settingsMessage("angry", "Emailadres bestaat al."); throw new AngryAlert("Emailadressen komen niet overeen.");
}
} else {
return new settingsMessage("angry", "Geef een geldig emailadres.");
}
} else {
return new settingsMessage("angry", "Emailadressen komen niet overeen.");
} }
} }
@@ -167,7 +158,9 @@ function emailIsAvailableInDatabase($email) {
$stmt->bindParam(":email", $email); $stmt->bindParam(":email", $email);
$stmt->execute(); $stmt->execute();
return !$stmt->rowCount(); if ($stmt->rowCount()) {
throw new AngryAlert("Emailadres wordt al gebruikt.");
}
} }
function doChangeEmail($email) { function doChangeEmail($email) {
@@ -182,18 +175,28 @@ function doChangeEmail($email) {
$stmt->bindParam(":email", $email); $stmt->bindParam(":email", $email);
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
return $stmt->rowCount(); // return $stmt->rowCount();
if ($stmt->rowCount()) {
throw new HappyAlert("Emailadres is veranderd.");
} else {
throw new AngryAlert();
}
} }
function updateProfilePicture() { function updateAvatar() {
$profilePictureDir = "/var/www/html/public/"; $profilePictureDir = "/var/www/html/public/";
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_" . basename($_FILES["pp"]["name"]); $relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.png";
removeOldProfilePicture();
move_uploaded_file($_FILES['pp']['tmp_name'], $profilePictureDir . $relativePath); checkAvatarSize($_FILES["pp"]["tmp_name"]);
setProfilePictureToDatabase("../" . $relativePath); $scaledImg = scaleAvatar($_FILES["pp"]["tmp_name"]);
removeOldAvatar();
imagepng($scaledImg, $profilePictureDir . $relativePath);
setAvatarToDatabase("../" . $relativePath);
throw new HappyAlert("Profielfoto veranderd.");
} }
function removeOldProfilePicture() { function removeOldAvatar() {
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
SELECT SELECT
`profilepicture` `profilepicture`
@@ -205,20 +208,39 @@ function removeOldProfilePicture() {
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
$old_avatar = $stmt->fetch()["profilepicture"]; $old_avatar = $stmt->fetch()["profilepicture"];
if ($old_avatar != NULL) {
unlink("/var/www/html/public/uploads/" . $old_avatar); unlink("/var/www/html/public/uploads/" . $old_avatar);
} }
}
function setProfilePictureToDatabase($url) { function setAvatarToDatabase(string $url) {
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
UPDATE UPDATE
`user` `user`
SET SET
`profilepicture` = :profilePicture `profilepicture` = :avatar
WHERE WHERE
`userID` = :userID `userID` = :userID
"); ");
$stmt->bindParam(":profilePicture", $url); $stmt->bindParam(":avatar", $url);
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
} }
function checkAvatarSize(string $img) {
$minResolution = 200;
$imgSize = getimagesize($img);
if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) {
throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels.");
}
}
function scaleAvatar(string $imgLink, int $newWidth = 600) {
$img = imagecreatefromstring(file_get_contents($imgLink));
if ($img) {
return imagescale($img, $newWidth);
} else {
throw new AngryAlert("Afbeelding wordt niet ondersteund.");
}
}

View File

@@ -23,7 +23,7 @@ function selectUser($userID) {
`username`, `username`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/avatar-standard.png'
) AS profilepicture, ) AS profilepicture,
`bio`, `bio`,
`role`, `role`,
@@ -273,7 +273,8 @@ function selectRandomNotFriendUser($userID) {
return $stmt->fetch(); return $stmt->fetch();
} }
function searchSomeUsers($n, $m, $search) { function searchSomeUsers($n, $m, $search)
{
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
SELECT SELECT
`username`, `username`,
@@ -301,3 +302,25 @@ function searchSomeUsers($n, $m, $search) {
$stmt->execute(); $stmt->execute();
return $stmt; return $stmt;
} }
function countSomeUsers($search) {
$q = $GLOBALS["db"]->prepare("
SELECT
COUNT(*)
FROM
`user`
WHERE
`username` LIKE :keyword OR
`fname` LIKE :keyword OR
`lname` LIKE :keyword
ORDER BY
`fname`,
`lname`,
`username`
");
$search = "%$search%";
$q->bindParam(':keyword', $search);
$q->execute();
return $q;
}

View File

@@ -1,16 +1,8 @@
<!DOCTYPE html> <script src="js/admin.js" charset="utf-8"></script>
<html>
<head>
<meta charset="utf-8">
<title>Admin Panel</title>
<script src="/js/admin.js" charset="utf-8"></script>
<?php <?php
include_once("../queries/user.php"); require_once ("../queries/user.php");
include_once("../queries/group_page.php"); require_once ("../queries/group_page.php");
?> ?>
</head>
<body>
<!-- function test_input taken from http://www.w3schools.com/php/php_form_validation.asp --> <!-- function test_input taken from http://www.w3schools.com/php/php_form_validation.asp -->
<?php <?php
$search = ""; $search = "";
@@ -66,48 +58,81 @@ $listm = $currentpage * $perpage;
<div class="content"> <div class="content">
<div class="platform admin-panel"> <div class="platform admin-panel">
<div class="admin-title"> <h5>Zoek naar gebruikers of groepen:</h5>
<h1>User Management Panel</h1>
</div> <br>
<div class="admin-options"> <div class="admin-options">
<form class="admin-searchform" <form class="admin-searchform"
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"
method="get"> method="get">
<div class="admin-searchbar"> <div class="admin-searchbar">
<h2>Search</h2> Zoek: <input type="text"
<input type="text"
name="search" name="search"
class="admin-searchinput" class="admin-searchinput"
value="<?php echo $search;?>"> <br> placeholder="Naam"
<input type="submit" value="Search"> value="<?php echo $search;?>">
Op: <select name="pagetype" id="pagetype" onchange="changeFilter()">
<option value="user"
<?php if (isset($pagetype) && $pagetype=="user") echo "selected";?>>
Gerbuiker
</option>
<option value="group"
<?php if (isset($pagetype) && $pagetype=="group") echo "selected";?>>
Groep
</option>
</select>
<button type="submit"><i class="fa fa-search"></i></button>
</div> </div>
<div id="admin-filter">
<div class="admin-filter" id="admin-filter"> <h5>Type gebruiker:</h5>
<h2>Show:</h2> <input type="checkbox"
name="status[]"
<input type="checkbox" name="status[]" id="normal" value="1" id="all"
<?php if (in_array("1", $status)) echo "checked";?>> value="all"
<?php if (in_array("all", $status)) echo "checked";?>>
<label for="normal">Allemaal</label><br>
<input type="checkbox"
name="status[]"
id="normal"
value="user"
<?php if (in_array("user", $status)) echo "checked";?>>
<label for="normal">Normal</label><br> <label for="normal">Normal</label><br>
<input type="checkbox" name="status[]" id="frozen" value="2" <input type="checkbox"
<?php if (in_array("2", $status)) echo "checked";?>> name="status[]"
id="frozen"
value="frozen"
<?php if (in_array("frozen", $status)) echo "checked";?>>
<label for="frozen">Frozen</label><br> <label for="frozen">Frozen</label><br>
<input type="checkbox" name="status[]" id="banned" value="3" <input type="checkbox"
<?php if (in_array("3", $status)) echo "checked";?>> name="status[]"
id="banned"
value="banned"
<?php if (in_array("banned", $status)) echo "checked";?>>
<label for="banned">Banned</label><br> <label for="banned">Banned</label><br>
<input type="checkbox" name="status[]" id="admin" value="5" <input type="checkbox"
<?php if (in_array("5", $status)) echo "checked";?>> name="status[]"
id="admin"
value="admin"
<?php if (in_array("admin", $status)) echo "checked";?>>
<label for="admin">Admin</label><br> <label for="admin">Admin</label><br>
<input type="checkbox" name="status[]" id="unvalidated" value="0" <input type="checkbox"
<?php if (in_array("0", $status)) echo "checked";?>> name="status[]"
id="unvalidated"
value="unconfirmed"
<?php if (in_array("unconfirmed", $status)) echo "checked";?>>
<label for="unvalidated">Unvalidated</label><br> <label for="unvalidated">Unvalidated</label><br>
<input type="checkbox" name="status[]" id="owner" value="42" <input type="checkbox"
<?php if (in_array("42", $status)) echo "checked";?>> name="status[]"
id="owner"
value="owner"
<?php if (in_array("owner", $status)) echo "checked";?>>
<label for="owner">Owner</label> <label for="owner">Owner</label>
</div> </div>
<div class="admin-groupfilter" id="admin-groupfilter"> <div id="admin-groupfilter">
<h2>Show:</h2> <h5>Type groep:</h5>
<input type="checkbox" name="groupstatus[]" id="all" value="all"
<?php if (in_array("all", $groupstatus)) echo "checked";?>>
<label for="hidden">Allemaal</label><br>
<input type="checkbox" name="groupstatus[]" id="hidden" value="0" <input type="checkbox" name="groupstatus[]" id="hidden" value="0"
<?php if (in_array("0", $groupstatus)) echo "checked";?>> <?php if (in_array("0", $groupstatus)) echo "checked";?>>
<label for="hidden">Hidden</label><br> <label for="hidden">Hidden</label><br>
@@ -118,60 +143,12 @@ $listm = $currentpage * $perpage;
<?php if (in_array("2", $groupstatus)) echo "checked";?>> <?php if (in_array("2", $groupstatus)) echo "checked";?>>
<label for="membersonly">Members-only</label><br> <label for="membersonly">Members-only</label><br>
</div> </div>
<div class="admin-filtertype">
<h2>Page Type:</h2>
<input type="radio" name="pagetype" id="user" value="user"
<?php if (isset($pagetype) && $pagetype=="user") echo "checked";?>
onchange="changeFilter()">
<label for="user">Users</label><br>
<input type="radio" name="pagetype" id="group" value="group"
<?php if (isset($pagetype) && $pagetype=="group") echo "checked";?>
onchange="changeFilter()">
<label for="group">Groups</label>
</div>
</form>
<div class="admin-batchactions" id="admin-batchactions">
<h2>Batch Actions: </h2>
<form class="admin-batchform"
id="admin-batchform"
action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>"
method="post">
<input type="radio" name="batchactions" id="freeze" value="2">
<label for="freeze">Freeze</label><br>
<input type="radio" name="batchactions" id="ban" value="3">
<label for="ban">Ban</label><br>
<input type="radio" name="batchactions" id="restore" value="1">
<label for="restore">Restore</label><br><br>
<input type="submit" value="Confirm">
</form> </form>
</div> </div>
<div class="admin-groupbatchactions" id="admin-groupbatchactions">
<h2>Batch Actions: </h2>
<form class="admin-groupbatchform"
id="admin-groupbatchform"
action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>"
method="post">
<input type="radio" name="groupbatchactions" id="hide" value="0">
<label for="hide">Hide</label><br>
<input type="radio" name="groupbatchactions" id="public" value="1">
<label for="public">Public</label><br>
<input type="radio" name="groupbatchactions" id="membersonly" value="2">
<label for="membersonly">Member</label><br><br>
<input type="submit" value="Confirm">
</form>
</div>
</div>
<br>
<div class="admin-users"> <div class="admin-users">
<div class="admin-usertitle"> <div class="admin-usertitle">
<div class="admin-userheading"> <h4>Resultaat:</h4>
<h2>Users:</h2> <span style="float: right">
</div>
<div class="admin-pageui">
<?php <?php
if ($pagetype == "user") { if ($pagetype == "user") {
$pages = countSomeUsersByStatus($search, $status); $pages = countSomeUsersByStatus($search, $status);
@@ -182,8 +159,7 @@ $listm = $currentpage * $perpage;
$mincount = min($listm, $countresults); $mincount = min($listm, $countresults);
$minlist = min($listn + 1, $countresults); $minlist = min($listn + 1, $countresults);
?> ?>
<p class="pagenumber">Current page:</p> Pagina: <form class="admin-pageselector"
<form class="admin-pageselector"
action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>" action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>"
method="post"> method="post">
<select class="admin-pageselect" <select class="admin-pageselect"
@@ -201,22 +177,27 @@ $listm = $currentpage * $perpage;
?> ?>
</select> </select>
</form> </form>
<p class="entriesshown">
<?php <?php
echo "Showing results $minlist to $mincount out of $countresults"; echo "$minlist tot $mincount ($countresults totaal)";
?> ?>
</div> </span>
</div> <br> <form
id="admin-batchform"
action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>"
method="post">
<button type="submit" name="batchactions" id="freeze" value="frozen">Bevries</button>
<button type="submit" name="batchactions" id="ban" value="banned">Ban</button>
<button type="submit" name="batchactions" id="restore" value="user">Activeer</button>
</form>
</div>
<table class="usertable"> <table class="usertable">
<tr> <tr>
<th class="table-checkbox"> <th><input type="checkbox" id="checkall" name="checkall" onchange="checkAll(this)"></th>
<input type="checkbox" id="checkall" name="checkall" onchange="checkAll(this)"> <th class="table-username">Gebruikersnaam</th>
</th>
<th class="table-username">User</th>
<th class="table-status">Status</th> <th class="table-status">Status</th>
<th class="table-comment">Comment</th> <th class="table-comment">Aantekening</th>
<th class="table-action">Action</th> <th class="table-action">Actie</th>
</tr> </tr>
<!-- Table construction via php PDO. --> <!-- Table construction via php PDO. -->
@@ -226,7 +207,6 @@ $listm = $currentpage * $perpage;
if ($pagetype == 'user') { if ($pagetype == 'user') {
$q = searchSomeUsersByStatus($listn, $listm, $search, $status); $q = searchSomeUsersByStatus($listn, $listm, $search, $status);
while($user = $q->fetch(PDO::FETCH_ASSOC)) { while($user = $q->fetch(PDO::FETCH_ASSOC)) {
$userID = $user['userID']; $userID = $user['userID'];
$username = $user['username']; $username = $user['username'];
@@ -252,9 +232,9 @@ $listm = $currentpage * $perpage;
action='$thispage' action='$thispage'
method='post'> method='post'>
<select class='action' name='actions'> <select class='action' name='actions'>
<option value='2'>Freeze</option> <option value='frozen'>Bevries</option>
<option value='3'>Ban</option> <option value='banned'>Ban</option>
<option value='1'>Restore</option> <option value='user'>Activeer</option>
</select> </select>
<input type='hidden' name='userID' value='$userID'> <input type='hidden' name='userID' value='$userID'>
<input type='submit' value='Confirm'> <input type='submit' value='Confirm'>

View File

@@ -1,6 +1,6 @@
<div class="content"> <div class="content">
<div class="chat"> <div class="chat">
<nav class="nav-list chat-left left platform chat-recent"> <nav class="nav-list platform" id="chat-recent-panel">
<h5>Chats</h5> <h5>Chats</h5>
<ul> <ul>
<?php <?php
@@ -17,7 +17,7 @@
// Set default values of a friend. // Set default values of a friend.
$username = $friend["username"]; $username = $friend["username"];
$userID = $friend["userID"]; $userID = $friend["userID"];
$pf = "img/notbad.jpg"; $pf = "img/avatar-standard.png";
// Change values if needed. // Change values if needed.
if (!empty($friend["profilepicture"])) if (!empty($friend["profilepicture"]))
@@ -28,7 +28,10 @@
<li class='friend-item' id='friend-item-$userID' onclick='switchUser(\"$userID\")'> <li class='friend-item' id='friend-item-$userID' onclick='switchUser(\"$userID\")'>
<div class='friend'> <div class='friend'>
<img alt='PF' class='profile-picture' src='$pf'/> <img alt='PF' class='profile-picture' src='$pf'/>
$username <div class='friend-name'>
$name<br/>
<span style='color: #666'>$username</span>
</div>
</div> </div>
</li> </li>
"; ";
@@ -36,9 +39,9 @@
?> ?>
</ul> </ul>
</nav> </nav>
<div class="chat-right">
<div id="chat-history" class="chat-history platform"> <div id="chat-history" class="chat-history platform">
</div> </div>
<div>
<form id="lastIDForm"> <form id="lastIDForm">
<input type="hidden" <input type="hidden"
id="lastID" id="lastID"

View File

@@ -14,8 +14,9 @@ $userinfo = getHeaderInfo();
placeholder="Zoek naar wat je wil" placeholder="Zoek naar wat je wil"
required required
/> />
<input type="submit" <button type="submit">
value="Zoek"/> <i class="fa fa-search"></i>
</button>
</form> </form>
</div> </div>
<div class="right profile-menu"> <div class="right profile-menu">

View File

@@ -35,6 +35,7 @@
foreach ($friends as $i => $friend) { foreach ($friends as $i => $friend) {
$username = $friend["username"]; $username = $friend["username"];
$name = $friend["name"];
$extraItem = ""; $extraItem = "";
$pf = $friend["profilepicture"]; $pf = $friend["profilepicture"];
@@ -49,7 +50,10 @@
value='$username'> value='$username'>
<div class='friend'> <div class='friend'>
<img alt='PF' class='profile-picture' src='$pf'/> <img alt='PF' class='profile-picture' src='$pf'/>
$username <div class='friend-name'>
$name<br/>
<span style='color: #666'>$username</span>
</div>
</div> </div>
</button> </button>
</form> </form>

View File

@@ -5,12 +5,20 @@
<a href="profile.php"><i class="fa fa-user" data-title="Profiel"></i></a> <a href="profile.php"><i class="fa fa-user" data-title="Profiel"></i></a>
<a href="logout.php"><i class="fa fa-sign-out" data-title="Uitloggen"></i></a> <a href="logout.php"><i class="fa fa-sign-out" data-title="Uitloggen"></i></a>
</section> </section>
<section id="notifocationCenter"> <section>
<h4> <h4>
Vriendchapsverzoeken Vriendchapsverzoeken
</h4> </h4>
<ul class="nav-list" id="friendrequestslist"> <ul class="nav-list" id="friendrequestslist">
</ul>
</section>
<section>
<h4>
Nieuwe berichten
</h4>
<ul class="nav-list" id="unreadChatlist">
</ul> </ul>
</section> </section>
</nav> </nav>

View File

@@ -1,6 +1,16 @@
<?php <?php
$search = ""; $search = "";
$filter = "all"; $filter = "all";
$user_perpage = $group_perpage = 20;
$user_currentpage = $group_currentpage = 1;
if (isset($_GET['user-pageselect'])) {
$user_currentpage = $_GET['user-pageselect'];
}
if (isset($_GET['group-pageselect'])) {
$group_currentpage = $_GET['group-pageselect'];
}
if (isset($_GET['search'])) { if (isset($_GET['search'])) {
$search = test_input($_GET['search']); $search = test_input($_GET['search']);
@@ -9,18 +19,26 @@ if (isset($_GET['search'])) {
if (isset($_GET['filter'])) { if (isset($_GET['filter'])) {
$filter = $_GET['filter']; $filter = $_GET['filter'];
} }
$user_n = ($user_currentpage - 1) * $user_perpage;
$user_count = countSomeUsers($search)->fetchColumn();
$group_n = ($group_currentpage - 1) * $group_perpage;
$group_count = countSomeGroups($search)->fetchColumn();
?> ?>
<div class="content"> <div class="content">
<div class="platform"> <div class="platform">
<form class="search-form" action="search.php" method="get"> <form class="search-form"
id="search-form"
action="search.php"
method="get">
<label> <label>
Zoek: Zoek:
</label> </label>
<input type="text" <input type="text"
name="search" name="search"
placeholder="zoek" placeholder="zoek"
required
value=<?php echo "$search";?> value=<?php echo "$search";?>
> >
<label for="filter"> <label for="filter">
@@ -40,17 +58,36 @@ if (isset($_GET['filter'])) {
<?php if ($filter == "friends") echo "selected";?>> <?php if ($filter == "friends") echo "selected";?>>
Vrienden</option> Vrienden</option>
</select> </select>
<input type="submit" <input onclick="document.getElementById('user-pageselect').value = 1;
document.getElementById('group-pageselect').value = 1"
type="submit"
value="Zoek" value="Zoek"
/> >
</form> </form>
</div> </div>
<div class="platform item-box searchleft" id="search-friends-output"> <div class="platform item-box searchleft" id="search-friends-output">
<h4>Gebruikers</h4> <h4>Gebruikers</h4>
<select class="user-pageselect"
name="user-pageselect"
id="user-pageselect"
form="search-form"
onchange="this.form.submit()">
<?php
for ($i=1; $i <= ceil($user_count / $user_perpage); $i++) {
if ($user_currentpage == $i) {
echo "<option value='$i' selected>$i</option>";
} else {
echo "<option value='$i'>$i</option>";
}
}
?>
</select>
<ul class='nav-list'> <ul class='nav-list'>
<?php <?php
$q = searchSomeUsers(0, 20, $search); $q = searchSomeUsers($user_n, $user_perpage, $search);
while ($user = $q->fetch(PDO::FETCH_ASSOC)) { while ($user = $q->fetch(PDO::FETCH_ASSOC)) {
$username = $user['username']; $username = $user['username'];
@@ -59,7 +96,7 @@ if (isset($_GET['filter'])) {
$lname = $user['lname']; $lname = $user['lname'];
echo(" echo("
<a href='https://myhyvesbookplus.nl/profile/$username/'> <a href='https://myhyvesbookplus.nl/profile?username=$username'>
<li class='search-item'> <li class='search-item'>
<div class='friend'> <div class='friend'>
<img class='profile-picture' <img class='profile-picture'
@@ -77,17 +114,34 @@ if (isset($_GET['filter'])) {
<div class="platform item-box searchright" id="search-group-output"> <div class="platform item-box searchright" id="search-group-output">
<h4>Groepen</h4> <h4>Groepen</h4>
<select class="group-pageselect"
name="group-pageselect"
id="group-pageselect"
form="search-form"
onchange="this.form.submit()">
<?php
for ($i=1; $i <= ceil($group_count / $group_perpage); $i++) {
if ($group_currentpage == $i) {
echo "<option value='$i' selected>$i</option>";
} else {
echo "<option value='$i'>$i</option>";
}
}
?>
</select>
<ul class="nav-list"> <ul class="nav-list">
<?php <?php
$q = searchSomeGroups(0, 20, $search); $q = searchSomeGroups($group_n, $user_perpage, $search);
while ($group = $q->fetch(PDO::FETCH_ASSOC)) { while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
$groupname = $group['name']; $groupname = $group['name'];
$grouppic = $group['picture']; $grouppic = $group['picture'];
echo(" echo("
<a href='https://myhyvesbookplus.nl/group/$groupname/'> <a href='https://myhyvesbookplus.nl/group?groupName=$groupname'>
<li class='search-item'> <li class='search-item'>
<div class='group'> <div class='group'>
<img class='group-picture' <img class='group-picture'

View File

@@ -6,8 +6,8 @@ $settings = getSettings();
<div class="settings"> <div class="settings">
<?php <?php
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<div class='platform settings-message ". $result->getClass()."'>". echo "<div class='platform settings-message ". $alertClass ."'>".
$result->getMessage(). $alertMessage .
"</div>"; "</div>";
} }
?> ?>