-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·53 lines (46 loc) · 1.37 KB
/
index.php
File metadata and controls
executable file
·53 lines (46 loc) · 1.37 KB
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
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
require_once "lib/Smarty.class.php";
require_once "database.php";
//connect to our db
$db = new Db();
if(isset($_COOKIE['ACTIVE_NOTE_ID'])) {
if(!$db->isValid($_COOKIE['ACTIVE_NOTE_ID'])) {
setcookie("ACTIVE_NOTE_ID", $db->getMaxId());
$activeNoteId = $db->getMaxId();
} else {
$activeNoteId = $_COOKIE['ACTIVE_NOTE_ID'];
}
}
if(isset($_REQUEST['action'])) {
switch($_REQUEST['action']) {
case 'delete':
$db->deleteNote($activeNoteId);
$newId = $db->getMaxId();
setcookie("ACTIVE_NOTE_ID", $newId);
$activeNoteId = $newId;
break;
case 'update':
$db->updateNote($_COOKIE['ACTIVE_NOTE_ID'], $_REQUEST['content']);
break;
case 'new':
$db->createNote("New note.");
$newId = $db->getMaxId();
setcookie("ACTIVE_NOTE_ID", $newId);
$activeNoteId = $newId;
break;
case 'navigate':
setcookie("ACTIVE_NOTE_ID", $_REQUEST['id']);
$activeNoteId = $_REQUEST['id'];
break;
}
}
$template = new Smarty();
if(isset($activeNoteId))
$template->assign("ACTIVE_NOTE_ID", $activeNoteId);
$template->assign("notes", $db->getNotes());
$template->display('index.tpl');
//disconnect
$db->disconnect();
?>