issue: inline ticket body like replies
[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         $Issue = $Db->query(
10                 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
11         )->fetch();
12         if (!$Issue) throw new Exception('Issuenummer niet gevonden');
13
14         $Article->title .= ': '.htmlspecialchars($Issue->subject);
15         print "<h2>{$Article->title}</h2>\n";
16         $author = $Issue->author ? new User('profile/'.$Issue->author, FALSE) : NULL;
17         printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
18                 'Geplaatst',
19                 $author ? " door <strong>{$author->name}</strong>" : '',
20                 showdate(preg_split('/\D/', $Issue->created))
21         );
22         if ($Issue->assign) {
23                 printf('<p><em>%s</em> aan <strong>%s</strong></p>'."\n",
24                         'Toegewezen', htmlspecialchars($Issue->assign)
25                 );
26         }
27         if ($Issue->closed) {
28                 printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
29                         'Opgelost', '',
30                         showdate(preg_split('/\D/', $Issue->closed))
31                 );
32         }
33         print $Issue->body;
34         $Args = "/$id";  # minimal reference
35         print placeholder_include('reply');
36         return;
37 }
38
39 if ($_POST) {
40                 $html = nl2br(htmlspecialchars($_POST['body']));
41                 $html = empty($html) ? NULL : "<p>$html</p>";
42                 $query = $Db->set('issues', [
43                         'page'    => $Page,
44                         'subject' => $_POST['subject'],
45                         'body'    => $html,
46                         'author'  => $User->login,
47                 ]);
48                 if (!$query->rowCount()) {
49                         throw new Exception('Issue niet opgeslagen.');
50                 }
51                 $_POST = [];
52 }
53
54 $sql = 'SELECT * FROM issues WHERE page = ?';
55 if (isset($_GET['open'])) {
56         $sql .= ' AND closed IS NULL';
57 }
58 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
59 $query = $Db->query($sql, [$Page]);
60
61 ob_start();
62 print '<ul>';
63 while ($row = $query->fetch()) {
64         printf('<li><a href="%s">%s <small class="date">%s</small>%s</a>',
65                 "/$Page/{$row->id}/{$row->link}",
66                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
67                         htmlspecialchars($row->subject)),
68                 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
69                 isset($row->assign) ? ' <em class="right">'.$row->assign.'</em>' : ''
70         );
71         print "</li>\n";
72 }
73 print "</ul>\n";
74 $Place['issuelist'] = ob_get_clean();