issue: closed at bottom, option ?open to exclude
[minimedit.git] / issue / index.php
1 <?php
2 global $User, $Db;
3 require_once 'database.inc.php';
4 @list ($id, $title) = explode('/', ltrim($Args, '/'));
5
6 if ($id) {
7         $Article->title = "Issue #$id";
8
9         $row = $Db->query(
10                 'SELECT * FROM issues WHERE id = ?', [$id]
11         )->fetch();
12         if (!$row) throw new Exception('Issuenummer niet gevonden');
13
14         $Article->title .= ': '.htmlspecialchars($row->subject);
15         print "<h2>{$Article->title}</h2>\n";
16         print $row->body;
17         printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
18                 'Geplaatst',
19                 $row->author ? " door <strong>{$row->author}</strong>" : '',
20                 showdate(preg_split('/\D/', $row->created))
21         );
22         if ($row->closed) {
23                 printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
24                         'Opgelost', '',
25                         showdate(preg_split('/\D/', $row->closed))
26                 );
27         }
28         $Args = "/$id";  # minimal reference
29         print placeholder_include('reply');
30         return;
31 }
32
33 if ($_POST) {
34                 $html = nl2br(htmlspecialchars($_POST['body']));
35                 $html = empty($html) ? NULL : "<p>$html</p>";
36                 $query = $Db->insert('issues', [
37                         'page'    => $Page,
38                         'subject' => $_POST['subject'],
39                         'body'    => $html,
40                         'author'  => $User->login,
41                 ]);
42                 if (!$query->rowCount()) {
43                         throw new Exception('Issue niet opgeslagen.');
44                 }
45                 $_POST = [];
46 }
47
48 $sql = 'SELECT * FROM issues';
49 if (isset($_GET['open'])) {
50         $sql .= ' WHERE closed IS NULL';
51 }
52 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
53 $query = $Db->query($sql);
54
55 ob_start();
56 print '<ul>';
57 while ($row = $query->fetch()) {
58         printf('<li><a href="%s">%s <small class="date">%s</small></a>',
59                 "/$Page/{$row->id}/{$row->link}",
60                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
61                         htmlspecialchars($row->subject)),
62                 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
63         );
64         print "</li>\n";
65 }
66 print "</ul>\n";
67 $Place['issuelist'] = ob_get_clean();