issue: track messages in database
[minimedit.git] / issue / index.php
1 <?php
2 global $User, $Db;
3 require_once 'database.inc.php';
4 $id = trim($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         if ($row->closed) {
18                 printf('<p><strong>%s</strong> <small class=date>%s</small></p>'."\n",
19                         'Opgelost', showdate(preg_split('/\D/', $row->closed))
20                 );
21         }
22         print placeholder_include('reply');
23         return;
24 }
25
26 if ($_POST) {
27                 $html = nl2br(htmlspecialchars($_POST['body']));
28                 $html = empty($html) ? NULL : "<p>$html</p>";
29                 $query = $Db->insert('issues', [
30                         'page'    => $Page,
31                         'subject' => $_POST['subject'],
32                         'body'    => $html,
33                         'author'  => $User->login,
34                 ]);
35                 if (!$query->rowCount()) {
36                         throw new Exception('Issue niet opgeslagen.');
37                 }
38                 $_POST = [];
39 }
40
41 $query = $Db->query('SELECT * FROM issues ORDER BY created DESC');
42
43 ob_start();
44 print '<ul>';
45 while ($row = $query->fetch()) {
46         printf('<li><a href="%s">%s <small class="date">%s</small></a>',
47                 "/$Page/{$row->id}",
48                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
49                         htmlspecialchars($row->subject)),
50                 showdate(array_slice(preg_split('/\D/', $row->created), 0, 3))
51         );
52         print "</li>\n";
53 }
54 print "</ul>\n";
55 $Place['issuelist'] = ob_get_clean();