diff --git a/php/03_todolist/actions.php b/php/03_todolist/actions.php new file mode 100644 index 0000000..b0026ad --- /dev/null +++ b/php/03_todolist/actions.php @@ -0,0 +1,32 @@ +prepare("INSERT INTO + tasks (task_text) VALUES (:task_text)"); + $pripravaDatNaOdeslani->execute(["task_text"=>$taskText]); +} +if($action =="complete" && $id > 0) { + //Aktualizovani úkolu na splněný + $pripravaDatNaOdeslani = $db->prepare("UPDATE tasks + SET is_completed = 1 WHERE id = :id"); + $pripravaDatNaOdeslani->execute(["id"=>$id]); +} + +if($action =="delete" && $id > 0) { + //odebraní úkolu na uspěšný + $pripravaDatNaOdeslani = $db->prepare("DELETE FROM tasks + WHERE id = :id"); + $pripravaDatNaOdeslani->execute(["id"=>$id]); +} + + +header("Location: index.php"); +exit; +?> \ No newline at end of file diff --git a/php/03_todolist/db.php b/php/03_todolist/db.php new file mode 100644 index 0000000..47ef4fb --- /dev/null +++ b/php/03_todolist/db.php @@ -0,0 +1,14 @@ +setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); +//vytvoření tabulky pokud neexistuje +$query = "CREATE TABLE IF NOT EXISTS tasks( + id INTEGER PRIMARY KEY AUTOINCREMENT, + task_text TEXT NOT NULL, + is_completed INTEGER DEFAULT 0, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +)"; +$db->exec($query); +?> \ No newline at end of file diff --git a/php/03_todolist/index.php b/php/03_todolist/index.php new file mode 100644 index 0000000..63127b7 --- /dev/null +++ b/php/03_todolist/index.php @@ -0,0 +1,46 @@ +query("SELECT * FROM tasks +ORDER BY created_at DESC"); +$ukoly = $rawDataZDatabaze->fetchAll(PDO::FETCH_ASSOC); +?> + + + +
+ + +