Lars chat #107
BIN
website/public/img/avatar-standard.png
Normal file
BIN
website/public/img/avatar-standard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 98 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB |
@@ -12,23 +12,28 @@
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
$notImplemented = new settingsMessage("angry", "Deze functie werkt nog niet :(");
|
||||
|
||||
$alertClass;
|
||||
$alertMessage;
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
switch ($_POST["form"]) {
|
||||
case "profile":
|
||||
$result = updateSettings();
|
||||
break;
|
||||
case "password":
|
||||
$result = changePassword();
|
||||
break;
|
||||
case "email":
|
||||
$result = changeEmail();
|
||||
break;
|
||||
case "picture":
|
||||
updateProfilePicture();
|
||||
$result = new settingsMessage("happy", "Deze melding doet nog niks nuttigs.");
|
||||
break;
|
||||
try {
|
||||
switch ($_POST["form"]) {
|
||||
case "profile":
|
||||
updateSettings();
|
||||
break;
|
||||
case "password":
|
||||
changePassword();
|
||||
break;
|
||||
case "email":
|
||||
changeEmail();
|
||||
break;
|
||||
case "picture":
|
||||
updateAvatar();
|
||||
break;
|
||||
|
||||
}
|
||||
} catch (AlertMessage $w) {
|
||||
$alertClass = $w->getClass();
|
||||
$alertMessage = $w->getMessage();
|
||||
}
|
||||
}
|
||||
include("../views/main.php");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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`
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
?>
|
||||
@@ -6,7 +6,7 @@ function getHeaderInfo() {
|
||||
`lname`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'img/notbad.jpg'
|
||||
'img/avatar-standard.png'
|
||||
) AS profilepicture
|
||||
FROM
|
||||
`user`
|
||||
|
||||
@@ -1,35 +1,33 @@
|
||||
<?php
|
||||
abstract class AlertMessage extends Exception {
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
class settingsMessage {
|
||||
private $class;
|
||||
private $message;
|
||||
abstract public function getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"]))
|
||||
|
||||
@@ -131,4 +131,4 @@
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</nav>
|
||||
</nav>
|
||||
@@ -1,6 +1,16 @@
|
||||
<?php
|
||||
$search = "";
|
||||
$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'])) {
|
||||
$search = test_input($_GET['search']);
|
||||
@@ -9,18 +19,26 @@ if (isset($_GET['search'])) {
|
||||
if (isset($_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="platform">
|
||||
<form class="search-form" action="search.php" method="get">
|
||||
<form class="search-form"
|
||||
id="search-form"
|
||||
action="search.php"
|
||||
method="get">
|
||||
<label>
|
||||
Zoek:
|
||||
</label>
|
||||
<input type="text"
|
||||
name="search"
|
||||
placeholder="zoek"
|
||||
required
|
||||
value=<?php echo "$search";?>
|
||||
>
|
||||
<label for="filter">
|
||||
@@ -40,17 +58,36 @@ if (isset($_GET['filter'])) {
|
||||
<?php if ($filter == "friends") echo "selected";?>>
|
||||
Vrienden</option>
|
||||
</select>
|
||||
<input type="submit"
|
||||
<input onclick="document.getElementById('user-pageselect').value = 1;
|
||||
document.getElementById('group-pageselect').value = 1"
|
||||
type="submit"
|
||||
value="Zoek"
|
||||
/>
|
||||
>
|
||||
</form>
|
||||
</div>
|
||||
<div class="platform item-box searchleft" id="search-friends-output">
|
||||
<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'>
|
||||
|
||||
<?php
|
||||
$q = searchSomeUsers(0, 20, $search);
|
||||
$q = searchSomeUsers($user_n, $user_perpage, $search);
|
||||
|
||||
while ($user = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
$username = $user['username'];
|
||||
@@ -59,7 +96,7 @@ if (isset($_GET['filter'])) {
|
||||
$lname = $user['lname'];
|
||||
|
||||
echo("
|
||||
<a href='https://myhyvesbookplus.nl/profile/$username/'>
|
||||
<a href='https://myhyvesbookplus.nl/profile?username=$username'>
|
||||
<li class='search-item'>
|
||||
<div class='friend'>
|
||||
<img class='profile-picture'
|
||||
@@ -77,17 +114,34 @@ if (isset($_GET['filter'])) {
|
||||
|
||||
<div class="platform item-box searchright" id="search-group-output">
|
||||
<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">
|
||||
|
||||
<?php
|
||||
$q = searchSomeGroups(0, 20, $search);
|
||||
$q = searchSomeGroups($group_n, $user_perpage, $search);
|
||||
|
||||
while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
$groupname = $group['name'];
|
||||
$grouppic = $group['picture'];
|
||||
|
||||
echo("
|
||||
<a href='https://myhyvesbookplus.nl/group/$groupname/'>
|
||||
<a href='https://myhyvesbookplus.nl/group?groupName=$groupname'>
|
||||
<li class='search-item'>
|
||||
<div class='group'>
|
||||
<img class='group-picture'
|
||||
|
||||
@@ -6,8 +6,8 @@ $settings = getSettings();
|
||||
<div class="settings">
|
||||
<?php
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
echo "<div class='platform settings-message ". $result->getClass()."'>".
|
||||
$result->getMessage().
|
||||
echo "<div class='platform settings-message ". $alertClass ."'>".
|
||||
$alertMessage .
|
||||
"</div>";
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user