diff options
| -rw-r--r-- | views/global/router.php | 12 | ||||
| -rw-r--r-- | views/list/new/index.php | 8 | ||||
| -rw-r--r-- | views/list/update/index.php | 56 | ||||
| -rw-r--r-- | views/styles.css | 4 |
4 files changed, 50 insertions, 30 deletions
diff --git a/views/global/router.php b/views/global/router.php index 9025113..527ad68 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -55,6 +55,18 @@ foreach (glob($MODELS_DIR . '/*.php') as $filename) { $TOKEN = (array_key_exists('token', $_COOKIE)) ? ($_COOKIE['token'] ?? "") : (""); +function redirect(string $href) { + echo '<script type="text/javascript">window.location.href = "' . $href . '";</script>'; + exit; +} + +function require_login() { + global $TOKEN; + if ($TOKEN === '') { + redirect('/login'); + } +} + if (str_ends_with($view, '.php')) { require_once $view; } diff --git a/views/list/new/index.php b/views/list/new/index.php index 7f1aaf5..cc680b5 100644 --- a/views/list/new/index.php +++ b/views/list/new/index.php @@ -1,12 +1,6 @@ <?php - if (isset($list_status) && $list_status === "") { - } + require_login(); ?> -<script type="text/javascript"> - if (!cookieStorage.getItem('token')) { - window.location.href = '/login'; - } -</script> <h1>Create a new list</h1> diff --git a/views/list/update/index.php b/views/list/update/index.php index b3737f0..5366110 100644 --- a/views/list/update/index.php +++ b/views/list/update/index.php @@ -1,30 +1,44 @@ - -<!-- TODO: Redirect when no user --> - <?php - $user = null; + require_login(); + $webpage = null; + $list = null; try { - $user = Database\Cookie::fromDB($TOKEN); + $list = Database\Cookie::fromDB($TOKEN)->archiveLists(); $webpage = Database\Webpage::fromDBwid($_GET['wid']); } catch (Exception $e) {} ?> -<!-- TODO: Redirect when no webpage --> -<!-- TODO: Redirect when lists is empty --> - -<h2>To which list do you want to add "<?= $webpage->URL ?>"?</h2> - -<form action="/list" method="GET"> - <input type="hidden" name="method" value="PATCH"> - <select name="lid"> - <?php foreach ($user->archiveLists() as $list): ?> - <option value="<?= $list->LID ?>"><?= $list->Name ?></option> - <?php endforeach; ?> - </select> - <input type="hidden" name="type" value="add"> - <input type="hidden" name="wid" value="<?= $_GET['wid'] ?>"> - <input type="submit" value="Select"> -</form> +<?php if ($webpage !== null && $list !== null): ?> + <h2> + To which list do you want to add</br> + <?= $webpage->URL ?></br> + from</br> + <?= $webpage->Date ?>? + </h2> + + <form action="/list" method="GET" class="font-125 flex-row width-100 center-margin"> + <input type="hidden" name="method" value="PATCH"> + <select name="lid" class="flex-expand"> + <?php foreach ($list as $list): ?> + <option value="<?= $list->LID ?>"><?= $list->Name ?></option> + <?php endforeach; ?> + </select> + <input type="hidden" name="type" value="add"> + <input type="hidden" name="wid" value="<?= $_GET['wid'] ?>"> + <input type="submit" value="Select"> + </form> + +<?php elseif ($webpage === null): ?> + <h2>No page with identifier <?= $_GET['wid'] ?> exists!</h2> + +<?php else: ?> + <h2>You have no lists!</h2> + + <form action="/list/new" method="GET"> + <input type="submit" value="Create a new list"> + </form> + +<?php endif; ?> diff --git a/views/styles.css b/views/styles.css index e2a712f..ffdd805 100644 --- a/views/styles.css +++ b/views/styles.css @@ -45,7 +45,7 @@ h1 { text-align: center; } -input, button, textarea { +input, button, textarea, select { color: inherit; background-image: url(/paper.jpg); @@ -72,7 +72,7 @@ input[type=text]:focus { outline: 2px solid var(--highlight-border-color); } -input[type=submit]:hover, button:hover { +input[type=submit]:hover, button:hover, select:hover { cursor: pointer; } |
