added powermate css
[dylansserver.git] / model / archive.php
1 <?php
2
3 class archive extends model {
4
5 public function __construct() {
6 parent::__construct();
7 }
8
9 private function check_exists() {
10 $sql = "SELECT COUNT(*) FROM notes
11 WHERE url = ?";
12 $results = $this->query($sql, "s", $_GET['note']);
13 if ($results[0]["COUNT(*)"] != 1) {
14 $this->not_found();
15 }
16 }
17
18 public function display() {
19 require_once("view/archive.php");
20 }
21
22 public function display_notes() {
23 switch (true) {
24 case (isset($_GET['year']) && !isset($_GET['month'])
25 && !isset($_GET['day'])):
26 $sql = "SELECT title, url, date_posted, text
27 FROM notes WHERE YEAR(date_posted) = ?
28 ORDER BY date_posted DESC";
29 $result = $this->query($sql, "d",
30 $_GET['year']);
31 break;
32 case (isset($_GET['year']) && isset($_GET['month'])
33 && !isset($_GET['day'])):
34 $sql = "SELECT title, url, date_posted, text
35 FROM notes WHERE YEAR(date_posted) = ?
36 AND MONTH(date_posted) = ?
37 ORDER BY date_posted DESC";
38 $result = $this->query($sql, "dd",
39 $_GET['year'], $_GET['month']);
40 break;
41 case (isset($_GET['year']) && isset($_GET['month'])
42 && isset($_GET['day'])):
43 $sql = "SELECT title, url, date_posted, text
44 FROM notes WHERE YEAR(date_posted) = ?
45 AND MONTH(date_posted) = ?
46 AND DAY(date_posted) = ?
47 ORDER BY date_posted DESC";
48 $result = $this->query($sql, "ddd",
49 $_GET['year'], $_GET['month'],
50 $_GET['day']);
51 break;
52 }
53 if (count($result) >= 1) {
54 echo "<div id='notes'>";
55 foreach ($result as $row => $entry) {
56 $title = $entry['title'];
57 $url = '/note/' . $entry['url'];
58 $date_posted = explode("-", $entry['date_posted']);
59 $year_posted = $date_posted[0];
60 $month_posted = $date_posted[1];
61 $datetime_posted = explode(' ', $date_posted[2]);
62 $day_posted = $datetime_posted[0];
63 echo "<div class='note'>";
64 echo "<h1><span class='date'>";
65 echo "$year_posted/$month_posted/$day_posted/";
66 echo "</span><a href='$url'>$title</a></h1>";
67 echo $entry['text'];
68 echo "</div>";
69 }
70 echo "</div>";
71 } else {
72 echo "<br>";
73 echo "<h1>sorry, nothing here</h2>";
74 echo "<pre>Empty set (0.00 sec)</pre>";
75 }
76 }
77
78 }
79
80 ?>