diff --git a/website/public/img/avatar-standard.png b/website/public/img/avatar-standard.png new file mode 100644 index 0000000..21ab818 Binary files /dev/null and b/website/public/img/avatar-standard.png differ diff --git a/website/public/img/notbad.jpg b/website/public/img/notbad.jpg deleted file mode 100644 index eeea126..0000000 Binary files a/website/public/img/notbad.jpg and /dev/null differ diff --git a/website/public/settings.php b/website/public/settings.php index b473f99..e40f042 100644 --- a/website/public/settings.php +++ b/website/public/settings.php @@ -12,23 +12,28 @@ getClass(); + $alertMessage = $w->getMessage(); } } include("../views/main.php"); diff --git a/website/public/styles/search.css b/website/public/styles/search.css index b54723d..86fd41d 100644 --- a/website/public/styles/search.css +++ b/website/public/styles/search.css @@ -14,4 +14,16 @@ .searchleft, .searchright { display: inline-block; 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; } \ No newline at end of file diff --git a/website/queries/friendship.php b/website/queries/friendship.php index fff3754..dc1ce46 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -8,7 +8,7 @@ function selectAllFriends($userID) { LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`, IFNULL( `profilepicture`, - '../img/notbad.jpg' + '../img/avatar-standard.png' ) AS profilepicture, `onlinestatus`, `role` @@ -40,7 +40,7 @@ function selectAllFriendRequests() { LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`, IFNULL( `profilepicture`, - '../img/notbad.jpg' + '../img/avatar-standard.png' ) AS profilepicture, `onlinestatus`, `role` diff --git a/website/queries/group_page.php b/website/queries/group_page.php index d704e8c..9a3461d 100644 --- a/website/queries/group_page.php +++ b/website/queries/group_page.php @@ -194,4 +194,22 @@ function searchSomeGroups($n, $m, $search) { $stmt->execute(); 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; +} ?> \ No newline at end of file diff --git a/website/queries/header.php b/website/queries/header.php index e6bc8ac..b0dd42c 100644 --- a/website/queries/header.php +++ b/website/queries/header.php @@ -6,7 +6,7 @@ function getHeaderInfo() { `lname`, IFNULL( `profilepicture`, - 'img/notbad.jpg' + 'img/avatar-standard.png' ) AS profilepicture FROM `user` diff --git a/website/queries/settings.php b/website/queries/settings.php index 1a5dacf..965665a 100644 --- a/website/queries/settings.php +++ b/website/queries/settings.php @@ -1,35 +1,33 @@ 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; - } +class HappyAlert extends AlertMessage { + + public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null) + { + parent::__construct($message, $code, $previous); } public function getClass() { - return $this->class; + return "settings-message-happy"; + } +} + +class AngryAlert extends AlertMessage { + public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null) + { + parent::__construct($message, $code, $previous); } - public function getMessage() { - return $this->message; + public function getClass() { + return "settings-message-angry"; } } @@ -94,24 +92,19 @@ function updateSettings() { $stmt->bindValue(":bio", test_input($_POST["bio"])); $stmt->bindValue(":userID", $_SESSION["userID"]); $stmt->execute(); - - return new settingsMessage("happy", "Instellingen zijn opgeslagen."); + throw new HappyAlert("Instellingen zijn opgeslagen."); } function changePassword() { $user = getPasswordHash(); if (password_verify($_POST["password-old"], $user["password"])) { if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) { - if (doChangePassword()) { - return new settingsMessage("happy", "Wachtwoord gewijzigd."); - } else { - return new settingsMessage("angry", "Er is iets mis gegaan."); - } + doChangePassword(); } else { - return new settingsMessage("angry", "Wachtwoorden komen niet oveen."); + throw new AngryAlert("Wachtwoorden komen niet overeen."); } } else { - return new settingsMessage("angry", "Oud wachtwoord niet correct."); + throw new AngryAlert("Oud wachtwoord niet correct."); } } @@ -129,7 +122,12 @@ function doChangePassword() { $stmt->bindParam(":new_password", $hashed_password); $stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->execute(); - return $stmt->rowCount(); + + if ($stmt->rowCount()) { + throw new HappyAlert("Wachtwoord gewijzigd."); + } else { + throw new AngryAlert(); + } } function changeEmail() { @@ -138,20 +136,13 @@ function changeEmail() { $email = strtolower($_POST["email"]); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { //check if email exists - if (emailIsAvailableInDatabase($email)) { - if (doChangeEmail($email)) { - return new settingsMessage("happy", "Emailadres is veranderd."); - } else { - return new settingsMessage("angry", "Er is iets mis gegaan."); - } - } else { - return new settingsMessage("angry", "Emailadres bestaat al."); - } + emailIsAvailableInDatabase($email); + doChangeEmail($email); } else { - return new settingsMessage("angry", "Geef een geldig emailadres."); + throw new AngryAlert("Geef een geldig emailadres"); } } else { - return new settingsMessage("angry", "Emailadressen komen niet overeen."); + throw new AngryAlert("Emailadressen komen niet overeen."); } } @@ -167,7 +158,9 @@ function emailIsAvailableInDatabase($email) { $stmt->bindParam(":email", $email); $stmt->execute(); - return !$stmt->rowCount(); + if ($stmt->rowCount()) { + throw new AngryAlert("Emailadres wordt al gebruikt."); + } } function doChangeEmail($email) { @@ -182,18 +175,28 @@ function doChangeEmail($email) { $stmt->bindParam(":email", $email); $stmt->bindParam(":userID", $_SESSION["userID"]); $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/"; - $relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_" . basename($_FILES["pp"]["name"]); - removeOldProfilePicture(); - move_uploaded_file($_FILES['pp']['tmp_name'], $profilePictureDir . $relativePath); - setProfilePictureToDatabase("../" . $relativePath); + $relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.png"; + + checkAvatarSize($_FILES["pp"]["tmp_name"]); + $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(" SELECT `profilepicture` @@ -205,20 +208,39 @@ function removeOldProfilePicture() { $stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->execute(); $old_avatar = $stmt->fetch()["profilepicture"]; - unlink("/var/www/html/public/uploads/" . $old_avatar); + if ($old_avatar != NULL) { + unlink("/var/www/html/public/uploads/" . $old_avatar); + } } -function setProfilePictureToDatabase($url) { +function setAvatarToDatabase(string $url) { $stmt = $GLOBALS["db"]->prepare(" UPDATE `user` SET - `profilepicture` = :profilePicture + `profilepicture` = :avatar WHERE `userID` = :userID "); - $stmt->bindParam(":profilePicture", $url); + $stmt->bindParam(":avatar", $url); $stmt->bindParam(":userID", $_SESSION["userID"]); $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."); + } } \ No newline at end of file diff --git a/website/queries/user.php b/website/queries/user.php index 114d673..18cd3f6 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -23,7 +23,7 @@ function selectUser($userID) { `username`, IFNULL( `profilepicture`, - '../img/notbad.jpg' + '../img/avatar-standard.png' ) AS profilepicture, `bio`, `role`, @@ -273,7 +273,8 @@ function selectRandomNotFriendUser($userID) { return $stmt->fetch(); } -function searchSomeUsers($n, $m, $search) { +function searchSomeUsers($n, $m, $search) +{ $stmt = $GLOBALS["db"]->prepare(" SELECT `username`, @@ -301,3 +302,25 @@ function searchSomeUsers($n, $m, $search) { $stmt->execute(); 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; +} diff --git a/website/views/chat-view.php b/website/views/chat-view.php index 135f7f4..9b40f71 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -17,7 +17,7 @@ // Set default values of a friend. $username = $friend["username"]; $userID = $friend["userID"]; - $pf = "img/notbad.jpg"; + $pf = "img/avatar-standard.png"; // Change values if needed. if (!empty($friend["profilepicture"])) diff --git a/website/views/menu.php b/website/views/menu.php index 521a8c8..d360e77 100644 --- a/website/views/menu.php +++ b/website/views/menu.php @@ -131,4 +131,4 @@ - + \ No newline at end of file diff --git a/website/views/search-view.php b/website/views/search-view.php index 0d650d4..ad93659 100644 --- a/website/views/search-view.php +++ b/website/views/search-view.php @@ -1,6 +1,16 @@ fetchColumn(); + +$group_n = ($group_currentpage - 1) * $group_perpage; +$group_count = countSomeGroups($search)->fetchColumn(); ?>
-
+ >

Gebruikers

+ + +