-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
75 lines (73 loc) · 2.84 KB
/
add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require './includes/init.php';
if (isset($_POST['new_outline']) && !empty($_POST['new_outline'])) {
$outline_name = $_POST['new_outline'];
$table_name = 'outlines';
$data = array('name' => $outline_name);
$outline_exists = Db::query("SELECT * FROM " . $table_name . " WHERE name=?", $outline_name);
if (!$outline_exists) {
Db::insert($table_name, $data);
} else {
$error = "outline under that name already exists";
}
}
if (isset($_POST['parent_text']) && isset($_POST['outline_text'])) {
$table = 'outline_texts';
$data = array('outline_id' => $_GET['outline'], 'parent_id' => $_POST['parent_text'], 'text' => $_POST['outline_text']);
$insert = Db::insert($table, $data);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Learn - home</title>
<?php require 'includes/head.php'; ?>
</head>
<body id="learn">
<nav>
<?php require 'includes/nav.php'; ?>
</nav>
<main class="main">
<?php if (isset($_GET['outline'])): ?>
<form action="" class="add-outline-text" method="post">
<select name="parent_text">
<?php
$parent = intval($_GET['outline']);
$texts = Db::queryAll('SELECT * FROM outline_texts WHERE outline_id=?', $parent);
$text_array = array();
foreach ($texts as $text) {
$item = "<option value='" . $text['id'] . "'>" . $text['text'] . "</option>";
array_push($text_array, $item);
}
$text_array = array_reverse($text_array);
foreach ($text_array as $texta) {
echo $texta;
}
?>
<option value="0">-- first item --</option>
</select>
<input type="text" name="outline_text">
<input type="submit" value="add">
</form>
<?php else ?>
<form action="" method="get" class="add-outline">
<select name="outline">
<option value="">select outline</option>
<?php
$outlines = Db::queryAll('SELECT * FROM outlines');
foreach ($outlines as $outline) {
echo "<option value='" . $outline['id'] . "'>" . $outline['name'] . "</option>";
}
?>
</select>
<input type="submit" value="add">
</form>
<form class="add-outline" action="" method="post">
<label for="new_outline">new outline:</label>
<input type="text" name="new_outline">
<input type="submit" value="submit">
</form>
<?php endif ?>
</main>
</body>
</html>