You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.1 KiB
85 lines
3.1 KiB
<?php
|
|
require "header.php";
|
|
function html_escape($text){
|
|
return htmlspecialchars((string)$text,ENT_QUOTES, "UTF-8");
|
|
}
|
|
$tasks = [];
|
|
try {
|
|
$query = $pdo->prepare("SELECT id, task_desc
|
|
FROM tasks ORDER BY created ASC");
|
|
$query->execute();
|
|
$tasks = $query->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
echo '<div class="alert alert-danger"> Chyba při
|
|
načítní úkolů' . html_escape($e->getMessage());
|
|
}
|
|
?>
|
|
<h4 class="display-4">Moje úkoly</h4>
|
|
|
|
<form action="add_task.php" method="post" class="card card-body
|
|
bg-light mb-3">
|
|
<div class="m-3">
|
|
<label for="task_desc" class="form-label">Nový úkol:</label>
|
|
<input type="text" class="form-control"
|
|
id="task_desc" name="task_desc"
|
|
required placeholder="Nový úkol..">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Přidat úkol</button>
|
|
</form>
|
|
|
|
<?php if (isset($_GET["status"])): ?>
|
|
<?php if ($_GET["status"]=="deleted"): ?>
|
|
<div class="alert alert-info alert-dismissible
|
|
fade show" role="alert">
|
|
Úkol byl smazán
|
|
<button type="button" class="btn-close"
|
|
data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php elseif ($_GET["status"]=="added"): ?>
|
|
<div class="alert alert-success alert-dismissible
|
|
fade show" role="alert">
|
|
Úkol byl přidán
|
|
<button type="button" class="btn-close"
|
|
data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php elseif ($_GET["status"]=="add_error"): ?>
|
|
<div class="alert alert-danger alert-dismissible
|
|
fade show" role="alert">
|
|
Chyba: popis úkolu nesmí být prázdný.
|
|
<button type="button" class="btn-close"
|
|
data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php elseif ($_GET["status"]=="delete_error"): ?>
|
|
<div class="alert alert-danger alert-dismissible
|
|
fade show" role="alert">
|
|
Chyb při mazání úkolu
|
|
<button type="button" class="btn-close"
|
|
data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php elseif ($_GET["status"]=="db_error"): ?>
|
|
<div class="alert alert-danger alert-dismissible
|
|
fade show" role="alert">
|
|
Chyba databáze. Zkuste to prosím znovu.
|
|
<button type="button" class="btn-close"
|
|
data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
|
|
<ul class="list-group">
|
|
<?php foreach($tasks as $task):?>
|
|
<li class="list-group-item d-flex
|
|
justify-content-between align-items-center">
|
|
<span><?= html_escape($task["task_desc"])?></span>
|
|
<form action="delete_task.php" method="post">
|
|
<input type="hidden" name="task_id"
|
|
value=<?= html_escape($task["id"])?> >
|
|
<button type="submit"
|
|
class="btn btn-outline-danger">SMAZAT</button>
|
|
</form>
|
|
</li>
|
|
<?php endforeach?>
|
|
</ul>
|
|
|
|
<?php include "footer.php"?>
|