diff --git a/website/queries/calcAge.php b/website/queries/calcAge.php new file mode 100644 index 0000000..c2896b5 --- /dev/null +++ b/website/queries/calcAge.php @@ -0,0 +1,12 @@ +diff($today); + return $interval->y; +} \ No newline at end of file diff --git a/website/queries/settings.php b/website/queries/settings.php index f4c5403..bdc9d38 100644 --- a/website/queries/settings.php +++ b/website/queries/settings.php @@ -110,20 +110,31 @@ function updateSettings() { WHERE `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(":lname", test_input($_POST["lname"])); $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(":showEmail", test_input($_POST["showEmail"])); - $stmt->bindValue(":showBday", test_input($_POST["showBday"])); + $stmt->bindValue(":showEmail", (array_key_exists("showEmail", $_POST) ? "1" : "0")); + $stmt->bindValue(":showBday", (array_key_exists("showBday", $_POST) ? "1" : "0")); $stmt->bindValue(":userID", $_SESSION["userID"]); $stmt->execute(); 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 * @throws AngryAlert diff --git a/website/views/settings-view.php b/website/views/settings-view.php index b6a3b4c..b7f554a 100644 --- a/website/views/settings-view.php +++ b/website/views/settings-view.php @@ -4,13 +4,11 @@ $settings = getSettings();