Date picker in bday

This commit is contained in:
Marijn Jansen
2017-01-30 21:48:18 +01:00
parent b30ef0d0cf
commit 422e2d1308
2 changed files with 54 additions and 13 deletions

View File

@@ -110,20 +110,30 @@ function updateSettings() {
WHERE WHERE
`userID` = :userID `userID` = :userID
"); ");
$bday = new DateTime(test_input($_POST["year"] . $_POST["month"] . $_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", test_input($_POST["showEmail"]));
$stmt->bindValue(":showBday", test_input($_POST["showBday"])); $stmt->bindValue(":showBday",test_input($_POST["showBday"]));
$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

@@ -44,37 +44,68 @@ $settings = getSettings();
</li> </li>
<li> <li>
<label for="bday">Geboortedatum</label> <label for="bday">Geboortedatum</label>
<input type="date" <?php $currentbday = new DateTime($settings["birthdate"]);?>
name="bday" <select name='day'>";
id="bday" <?php for ($day = 1; $day < 32; $day++):
placeholder="yyyy-mm-dd" $day = sprintf("%02d", $day); ?>
value="<?= $settings["birthdate"]?>" <option value='<?=$day?>'
> <?= ($day == $currentbday->format("d")) ? "selected" : ""?>
><?=$day?></option>";
<?php endfor; ?>
</select>
<select name='month'>
<option value='01' <?=('01' == $currentbday->format("m")) ? "selected" : ""?>>januari</option>
<option value='02' <?=('02' == $currentbday->format("m")) ? "selected" : ""?>>februari</option>
<option value='03' <?=('03' == $currentbday->format("m")) ? "selected" : ""?>>maart</option>
<option value='04' <?=('04' == $currentbday->format("m")) ? "selected" : ""?>>april</option>
<option value='05' <?=('05' == $currentbday->format("m")) ? "selected" : ""?>>mei</option>
<option value='06' <?=('06' == $currentbday->format("m")) ? "selected" : ""?>>juni</option>
<option value='07' <?=('07' == $currentbday->format("m")) ? "selected" : ""?>>juli</option>
<option value='08' <?=('08' == $currentbday->format("m")) ? "selected" : ""?>>augustus</option>
<option value='09' <?=('09' == $currentbday->format("m")) ? "selected" : ""?>>september</option>
<option value='10' <?=('10' == $currentbday->format("m")) ? "selected" : ""?>>oktober</option>
<option value='11' <?=('11' == $currentbday->format("m")) ? "selected" : ""?>>november</option>
<option value='12' <?=('12' == $currentbday->format("m")) ? "selected" : ""?>>december</option>
</select>
<select name='year'>";
<?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="radio"
name="showBday" name="showBday"
id="showBday"
value="1" value="1"
<?php echo ($settings["showBday"] ? "checked" : "")?> <?= ($settings["showBday"] ? "checked" : "")?>
> Ja > Ja
<input type="radio" <input type="radio"
name="showBday" name="showBday"
id="showBday"
value="0" value="0"
<?php echo ($settings["showBday"] ? "" : "checked")?> <?= ($settings["showBday"] ? "" : "checked")?>
> Nee > Nee
</li> </li>
<li> <li>
<label for="showEmail">Toon Email</label> <label for="showEmail">Toon Email</label>
<input type="radio" <input type="radio"
name="showEmail" name="showEmail"
id="showEmail"
value="1" value="1"
<?php echo ($settings["showEmail"] ? "checked" : "")?> <?= ($settings["showEmail"] ? "checked" : "")?>
> Ja > Ja
<input type="radio" <input type="radio"
name="showEmail" name="showEmail"
id="showEmail"
value="0" value="0"
<?php echo ($settings["showEmail"] ? "" : "checked")?> <?= ($settings["showEmail"] ? "" : "checked")?>
> Nee > Nee
</li> </li>
<li> <li>