Merge branch 'marijn-settings' into 'master'

Marijn settings

See merge request !153
This commit was merged in pull request #157.
This commit is contained in:
Marijn Jansen
2017-01-31 10:24:34 +01:00
3 changed files with 88 additions and 43 deletions

View File

@@ -0,0 +1,12 @@
<?php
/**
* calculates the age of a user
* @param string $bdayAsString
* @return int age
*/
function getAge(string $bdayAsString) : int {
$bday = new DateTime($bdayAsString);
$today = new DateTime("now");
$interval = $bday->diff($today);
return $interval->y;
}

View File

@@ -110,20 +110,31 @@ function updateSettings() {
WHERE WHERE
`userID` = :userID `userID` = :userID
"); ");
$bday = new DateTime();
$bday->setDate(test_input($_POST["year"]), test_input($_POST["month"]), test_input($_POST["day"]));
checkBday($bday);
$stmt->bindValue(":fname", test_input($_POST["fname"])); $stmt->bindValue(":fname", test_input($_POST["fname"]));
$stmt->bindValue(":lname", test_input($_POST["lname"])); $stmt->bindValue(":lname", test_input($_POST["lname"]));
$stmt->bindValue(":location", test_input($_POST["location"])); $stmt->bindValue(":location", test_input($_POST["location"]));
$stmt->bindValue(":bday", test_input($_POST["bday"])); $stmt->bindValue(":bday", $bday->format("Ymd"));
$stmt->bindValue(":bio", test_input($_POST["bio"])); $stmt->bindValue(":bio", test_input($_POST["bio"]));
$stmt->bindValue(":showEmail", test_input($_POST["showEmail"])); $stmt->bindValue(":showEmail", (array_key_exists("showEmail", $_POST) ? "1" : "0"));
$stmt->bindValue(":showBday", test_input($_POST["showBday"])); $stmt->bindValue(":showBday", (array_key_exists("showBday", $_POST) ? "1" : "0"));
$stmt->bindValue(":userID", $_SESSION["userID"]); $stmt->bindValue(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
throw new HappyAlert("Instellingen zijn opgeslagen."); throw new HappyAlert("Instellingen zijn opgeslagen.");
} }
function checkBday(DateTime $bday) {
$today = new DateTime();
if ($bday >= $today) {
throw new AngryAlert("Jij bent vast niet in de toekomst geboren toch? ;)");
}
}
/** /**
* Change * Change
* @throws AngryAlert * @throws AngryAlert

View File

@@ -4,13 +4,11 @@ $settings = getSettings();
<div class="content"> <div class="content">
<div class="settings"> <div class="settings">
<?php <?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
if ($_SERVER["REQUEST_METHOD"] == "POST") { <div class='platform settings-message <?=$alertClass?>'>
echo "<div class='platform settings-message $alertClass '> <?=$alertMessage?>
$alertMessage </div>
</div>"; <?php endif; ?>
}
?>
<form class="settings-profile platform" method="post"> <form class="settings-profile platform" method="post">
<h5>Profiel Instellingen</h5> <h5>Profiel Instellingen</h5>
<ul> <ul>
@@ -21,7 +19,7 @@ $settings = getSettings();
id="fname" id="fname"
placeholder="Voornaam" placeholder="Voornaam"
title="Voornaam" title="Voornaam"
value="<?= $settings["fname"]?>" value="<?=$settings["fname"]?>"
> >
</li> </li>
<li> <li>
@@ -30,7 +28,7 @@ $settings = getSettings();
name="lname" name="lname"
id="lname" id="lname"
placeholder="Achternaam" placeholder="Achternaam"
value="<?= $settings["lname"]?>" value="<?=$settings["lname"]?>"
> >
</li> </li>
<li> <li>
@@ -39,43 +37,61 @@ $settings = getSettings();
name="location" name="location"
id="location" id="location"
placeholder="Locatie" placeholder="Locatie"
value="<?= $settings["location"]?>" value="<?=$settings["location"]?>"
> >
</li> </li>
<li> <li>
<?php $currentbday = new DateTime($settings["birthdate"]); ?>
<label for="bday">Geboortedatum</label> <label for="bday">Geboortedatum</label>
<input type="date" <select name='day' id="bday">
name="bday" <?php for ($day = 1; $day <= 31; $day++): ?>
id="bday" <option value='<?=$day?>'
placeholder="yyyy-mm-dd" <?=($day == $currentbday->format("d")) ? "selected" : ""?>
value="<?= $settings["birthdate"]?>" >
> <?=$day?>
</option>
<?php endfor; ?>
</select>
<select name='month' id="bday">
<?php
$months = array ("januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus",
"september", "oktober", "november", "december");
for ($month = 1; $month <= 12; $month++):
?>
<option value='<?=$month?>'
<?=($month == $currentbday->format("m")) ? "selected" : ""?>
>
<?=$months[$month - 1]?>
</option>
<?php endfor; ?>
</select>
<select name='year' id="bday">
<?php
$now = (new DateTime)->format("Y");
for ($year = $now; $year >= 1900; $year--): ?>
<option value='<?=$year?>'
<?=($year == $currentbday->format("Y")) ? "selected" : ""?>
>
<?=$year?>
</option>
<?php endfor; ?>
</select>
</li> </li>
<li> <li>
<label for="showBday">Toon leeftijd</label> <label for="showBday">Toon leeftijd</label>
<input type="radio" <input type="checkbox"
name="showBday" name="showBday"
value="1" id="showBday"
<?php echo ($settings["showBday"] ? "checked" : "")?> <?=($settings["showBday"] ? "checked" : "")?>
> Ja >
<input type="radio"
name="showBday"
value="0"
<?php echo ($settings["showBday"] ? "" : "checked")?>
> Nee
</li> </li>
<li> <li>
<label for="showEmail">Toon Email</label> <label for="showEmail">Toon Email</label>
<input type="radio" <input type="checkbox"
name="showEmail" name="showEmail"
value="1" id="showEmail"
<?php echo ($settings["showEmail"] ? "checked" : "")?> <?=($settings["showEmail"] ? "checked" : "")?>
> Ja >
<input type="radio"
name="showEmail"
value="0"
<?php echo ($settings["showEmail"] ? "" : "checked")?>
> Nee
</li> </li>
<li> <li>
<label for="bio">Bio</label> <label for="bio">Bio</label>
@@ -83,7 +99,7 @@ $settings = getSettings();
rows="5" rows="5"
title="bio" title="bio"
id="bio" id="bio"
><?= $settings["bio"]?></textarea> ><?=$settings["bio"]?></textarea>
</li> </li>
<li> <li>
<label></label> <label></label>
@@ -99,7 +115,7 @@ $settings = getSettings();
<ul> <ul>
<li> <li>
<label>Huidige profielfoto</label> <label>Huidige profielfoto</label>
<img src="<?= $settings["profilepicture"] ?>" <img src="<?=$settings["profilepicture"]?>"
class="profile-picture" class="profile-picture"
> >
</li> </li>
@@ -124,24 +140,30 @@ $settings = getSettings();
<h5>Verander Wachtwoord</h5> <h5>Verander Wachtwoord</h5>
<ul> <ul>
<li> <li>
<label>Oud wachtwoord</label> <label for="password-old">Oud wachtwoord</label>
<input type="password" <input type="password"
name="password-old" name="password-old"
id="password-old"
placeholder="Oud wachtwoord" placeholder="Oud wachtwoord"
autocomplete="current-password"
> >
</li> </li>
<li> <li>
<label>Nieuw wachtwoord</label> <label for="password-new">Nieuw wachtwoord</label>
<input type="password" <input type="password"
name="password-new" name="password-new"
id="password-new"
placeholder="Nieuw wachtwoord" placeholder="Nieuw wachtwoord"
autocomplete="new-password"
> >
</li> </li>
<li> <li>
<label>Bevestig wachtwoord</label> <label for="password-confirm">Bevestig wachtwoord</label>
<input type="password" <input type="password"
name="password-confirm" name="password-confirm"
id="password-confirm"
placeholder="Bevestig wachtwoord" placeholder="Bevestig wachtwoord"
autocomplete="new-password"
> >
</li> </li>
<li> <li>
@@ -160,7 +182,7 @@ $settings = getSettings();
<label for="email-old">Huidig Email </label> <label for="email-old">Huidig Email </label>
<input type="email" <input type="email"
id="email-old" id="email-old"
value="<?= $settings["email"]?>" value="<?=$settings["email"]?>"
disabled disabled
> >
</li> </li>