2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
4 @list ($id, $title) = explode('/', ltrim($Page->path, '/'));
6 if ($id and ctype_digit($id)) {
7 $Page->title = "Issue #$id";
8 $Page->link = $Page->handler . ($Page->path = "/$id"); # minimal reference
10 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id]
12 if (!$Issue) throw new Exception('Issuenummer niet gevonden');
14 $replies = $Page->widget('reply'); # handle updates
16 $Page->title .= ': '.htmlspecialchars($Issue->subject);
17 $Page->body = $replies; # find image
18 if ($Page->api) return;
20 print "<h2>{$Page->title}</h2>\n";
21 print '<aside class="metadata"><dl>'."\n";
22 print '<dt>Geplaatst</dt>';
23 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->created)));
24 if ($Issue->author and $author = new User('profile/'.$Issue->author, FALSE)) {
25 printf('<dd>%s</dd>'."\n", $author->html);
28 print '<dt>Toegewezen aan</dt>';
29 printf('<dd>%s</dd>'."\n", htmlspecialchars($Issue->assign));
32 print '<dt>Opgelost</dt>';
33 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->closed)));
35 print "</dl></aside>\n\n";
43 if ($Page->api) return;
44 if ($_POST and isset($_POST['subject'])) {
45 require_once 'upload.inc.php';
46 if (strlen($_POST['subject']) < 2) {
47 throw new Exception('Een minimaal onderwerp is verplicht om een issue aan te maken.');
49 $query = $Db->set('issues', [
50 'page' => $Page->handler,
51 'subject' => $_POST['subject'],
52 'link' => preg_replace('/\b(?:de|het|een)\s+|\W+/', '-', strtolower($_POST['subject'])),
53 'author' => $User->login,
55 if (!$query->rowCount()) {
56 throw new Exception('Issue niet opgeslagen.');
58 $row = $query->fetch();
60 throw new Exception('Issue niet goed opgeslagen.');
62 $query = $Db->set('comments', [
63 'page' => "{$Page->handler}/{$row->id}",
64 'raw' => $_POST['body'],
65 'message' => messagehtml($_POST['body']),
66 'author' => $User->login,
68 if (!$query->rowCount()) {
69 throw new Exception('Issueinhoud niet opgeslagen.');
74 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
75 $cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
76 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
77 $sql = "SELECT $cols FROM issues i WHERE page = ?";
78 if (isset($_GET['open'])) {
79 $sql .= ' AND closed IS NULL';
81 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
82 $query = $Db->query($sql, [$Page->handler]);
85 require 'issue/feed.inc.php';
90 while ($row = $query->fetch()) {
91 printf('<li%s><div><a href="%s">',
92 $row->closed ? ' class="disabled"' : '',
93 "/{$Page->handler}/{$row->id}/{$row->link}"
95 printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
97 printf(' <small class="date">%s</small>',
98 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
101 if ($row->replycount) {
102 printf(' <span class=right>%s %d</span>',
103 '<span class="icon icon-comment" title="reacties">🗨</span>',
107 if ($row->imagecount) {
108 print ' <span class="right icon icon-camera" title="afbeeldingen">📷</span>';
110 if (isset($row->assign)) {
111 print ' <em class="right">'.$row->assign.'</em>';
113 print "</a></div></li>\n";
116 $Page->place['issuelist'] = ob_get_clean();