109 lines
3.2 KiB
PHP
109 lines
3.2 KiB
PHP
<?php
|
|
|
|
include "config.php";
|
|
include "helper.php";
|
|
include "boilerplate/head.php";
|
|
|
|
$user = is_logged_in();
|
|
|
|
if ($user === false) {
|
|
echo "<a href=\"login.php\">{$lang['account']['log_in']}</a>";
|
|
|
|
$q = "SELECT count(*) FROM users LIMIT 1;";
|
|
|
|
if ($signups !== false || ($signups === false && pg_fetch_array(pg_query($db, $q))["count"] !== 0)) {
|
|
echo " - <a href=\"signup.php\">{$lang['account']['sign_up']}</a>";
|
|
}
|
|
|
|
include "boilerplate/foot.php";
|
|
exit();
|
|
}
|
|
|
|
|
|
$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 .= "<h3>" . htmlspecialchars($section["name"]) . "</h3>";
|
|
|
|
if ($enable_optgroup) {
|
|
$select_options .= "<optgroup label=\"" . htmlspecialchars($section["name"]) . "\">";
|
|
}
|
|
|
|
$first = true;
|
|
foreach ($rows as $row) {
|
|
$select_options .= "<option value=\"{$section['id']}-{$row['id']}\">";
|
|
|
|
if ($first && !$show_subtitle) {
|
|
$select_options .= htmlspecialchars($section["name"]);
|
|
} else {
|
|
$select_options .= htmlspecialchars($row["name"]);
|
|
$todo_list .= "<strong>" . htmlspecialchars($row["name"]) . "</strong>";
|
|
}
|
|
|
|
$q = "SELECT * FROM item WHERE row='{$row['id']}' ORDER BY date ASC, LOWER(description) ASC;";
|
|
$items = pg_fetch_all(pg_query($db, $q));
|
|
$todo_list .= "<ul>";
|
|
|
|
if (count($items) === 0) {
|
|
$todo_list .= "<li><i>{$lang['list']['none']}</i></li>";
|
|
} else {
|
|
foreach ($items as $item) {
|
|
$todo_list .= "<li>" . str_replace("%d", htmlspecialchars($item["description"]), $row["display_format"]) . "</li>";
|
|
}
|
|
}
|
|
|
|
$todo_list .= "</ul>";
|
|
$select_options .= "</option>";
|
|
$first = false;
|
|
}
|
|
|
|
if ($enable_optgroup) {
|
|
$select_options .= "</optgroup>";
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<div id="container">
|
|
<h2><?php echo $lang["add"]["title"]; ?></h2>
|
|
<form method="POST">
|
|
<table>
|
|
<tr>
|
|
<td class="right"><label for="section"><?php echo $lang["add"]["section"]; ?></label></td>
|
|
<td>
|
|
<select required id="section" name="section">
|
|
<?php echo $select_options; ?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="right"><label for="date"><?php echo $lang["add"]["date"]; ?></label></td>
|
|
<td><input type="date" name="date" id="date" required></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="right"><label for="description"><?php echo $lang["add"]["description"]; ?></label></td>
|
|
<td><input autofocus maxlength="256" placeholder="<?php echo $lang["add"]["description_placeholder"]; ?>" name="description" id="description" required></td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td><input type="submit" value="<?php echo $lang["add"]["button"]; ?>"></td>
|
|
</tr>
|
|
</table>
|
|
</form>
|
|
|
|
<h2><?php echo $lang["list"]["title"]; ?></h2>
|
|
<?php echo $todo_list; ?>
|
|
</div>
|
|
|
|
<?php
|
|
include "boilerplate/foot.php";
|
|
?>
|