{$lang['account']['log_in']}"; $q = "SELECT count(*) FROM users LIMIT 1;"; if ($signups !== false || ($signups === false && pg_fetch_array(pg_query($db, $q))["count"] !== 0)) { echo " - {$lang['account']['sign_up']}"; } include "boilerplate/foot.php"; exit(); } else if ($_SERVER["REQUEST_METHOD"] === "POST") { $intent = $_POST["intent"]; if ($intent === "create-item") { $row_id = $_POST["row"]; $date = strtotime($_POST["date"]); $description = $_POST["description"]; if (strlen($row_id) !== 64 || !preg_match("/[a-f0-9]{64}/", $row_id)) { $err = lang["add"]["errors"]["invalid_id"]; } else if ($date === false) { $err = lang["add"]["errors"]["date"]; } else if (strlen($description) === 0 || strlen($description) > 256) { $err = lang["add"]["errors"]["description_length"]; } else { $repopulate = array( "row_id" => $row_id, "date" => $date ); pg_insert( $db, "item", array( "id" => generate_id(), "row" => $row_id, "description" => $description, "date" => date("Y-m-d", $date) ) ); } } else if ($intent === "change-password") { $old_pw = $_POST["old"]; $new_pw = $_POST["new"]; $confirm_pw = $_POST["confirm"]; if (!($old_pw && $new_pw && $confirm_pw)) { $err = $lang["account"]["errors"]["bad_request"]; } else if ($new_pw !== $confirm_pw) { $err = $lang["account"]["errors"]["password_match"]; } else if (password_verify($old_pw, $user["password_hash"])) { $pw_hash = password_hash($new_pw, PASSWORD_DEFAULT); pg_update( $db, "users", array("password_hash" => $pw_hash), array("id" => $user["id"]) ); $token = get_token($user["username"], $pw_hash); setcookie( "token", $token, time() + 60 * 60 * 24 * 365 ); $conf = $lang["account"]["errors"]["password_changed"]; } else { $err = $lang["account"]["errors"]["incorrect_password"]; } } } else if ($_GET["del"] && strlen($_GET["del"]) === 64 && preg_match("/[a-f0-9]{64}/", $_GET["del"])) { pg_query($db, "DELETE FROM item WHERE id='{$_GET['del']}';"); } include "boilerplate/head.php"; $select_options = ""; $todo_list = ""; $q = "SELECT * FROM section WHERE users='{$user['id']}' ORDER BY LOWER(name) ASC;"; $sections = pg_fetch_all(pg_query($db, $q)); foreach ($sections as $section) { $q = "SELECT * FROM row WHERE section='{$section['id']}' ORDER BY LOWER(name) ASC;"; $rows = pg_fetch_all(pg_query($db, $q)); $show_subtitle = $section["show_subtitle"] === "t"; $enable_optgroup = $show_subtitle || count($rows) !== 1; $todo_list .= "

" . htmlspecialchars($section["name"]) . "

"; if ($enable_optgroup) { $select_options .= ""; } $first = true; foreach ($rows as $row) { if ($repopulate["row_id"] == $row["id"]) { $select_options .= ""; $first = false; } if ($enable_optgroup) { $select_options .= ""; } } ?>

type="date" name="date" id="date" required>
" name="description" id="description" required>
">

{$user['username']}", $lang["settings"]["account"]["current"]); ?>

">
">
">
">