-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedit.php
71 lines (60 loc) · 1.82 KB
/
edit.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
<?php
include 'include/context.php';
if (!$auth) { redirect(); }
$notes = get_notes();
$id = isset($_GET['id']) ? $_GET['id'] : 0;
$new = array('url' => '', 'title' => '', 'quote' => '', 'note' => '');
if ($id) {
$new = $notes[$id];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$note['url'] = $_POST['url'];
$note['title'] = $_POST['title'];
$note['quote'] = $_POST['quote'];
$note['note'] = $_POST['note'];
$id = $_POST['id'] ? $_POST['id'] : time();
$path = '/note.php?id='.$id;
$notes[$id] = $note;
put_notes($notes);
header('Location: '.$path);
exit;
}
?>
<?php include 'include/header.php'; ?>
<?php include 'include/menu.php'; ?>
<script>
function load() {
var desc = document.getElementById('desc');
var note = document.getElementById('note');
expand(desc);
expand(note);
}
function expand(element) {
element.style.height = 'auto';
element.style.height = (element.scrollHeight - 10) + 'px';
}
function prevent(event) {
if (event.keyCode === 13) {
event.preventDefault();
}
}
</script>
<div class="main">
<div class="center">
<form action="<?= $self ?>" method="post" autocomplete="off">
<input type="url" name="url" placeholder="URL"
value="<?= $new['url'] ?>" required />
<input type="text" name="title" placeholder="Title"
value="<?= $new['title'] ?>" required />
<textarea id="desc" name="quote" placeholder="Quote"
rows="4" cols="80" oninput="expand(this)"
onkeydown="prevent(event)"><?= $new['quote'] ?></textarea>
<textarea id="note" class="last" name="note" placeholder="Note"
rows="1" cols="80" oninput="expand(this)"
onkeydown="prevent(event)"><?= $new['note'] ?></textarea>
<input type="hidden" name="id" value="<?= $id ?>" />
<input type="submit" value="Update" />
</form>
</div>
</div>
<?php include 'include/footer.php'; ?>