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');
13 $Page->title .= ': '.htmlspecialchars($Issue->subject);
15 if ($title and ctype_digit($title)) {
16 $Page->title = "Antwoord op {$Page->title}";
17 $Page->handler = $Page->link;
18 $Page->link .= "/$title";
20 'SELECT * FROM comments WHERE id = ?', [$title]
22 if (!$row) throw new Exception('Antwoordnummer niet gevonden');
24 print "<h2>{$Page->title}</h2>\n";
25 printf('<form method="post" action="%s" enctype="multipart/form-data">',
28 printf('<input type="hidden" name="%s" value="%s" />'."\n", 'id', $row->id);
29 printf('<textarea id="%s" name="%1$s" cols=60 rows=3>%s</textarea>'."\n",
31 htmlspecialchars($row->raw)
33 print '<input type="submit" value="Aanpassen" />'."\n";
38 $replies = $Page->widget('reply'); # handle updates
39 $Page->body = $replies; # find image
40 if ($Page->api) return;
42 print "<h2>{$Page->title}</h2>\n";
43 print '<aside class="metadata"><dl>'."\n";
44 print '<dt>Geplaatst</dt>';
45 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->created)));
46 if ($Issue->author and $author = new User('profile/'.$Issue->author, FALSE)) {
47 printf('<dd>%s</dd>'."\n", $author->html);
50 print '<dt>Toegewezen aan</dt>';
51 printf('<dd>%s</dd>'."\n", htmlspecialchars($Issue->assign));
54 print '<dt>Opgelost</dt>';
55 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->closed)));
57 print "</dl></aside>\n\n";
65 if ($Page->api) return;
66 if ($_POST and isset($_POST['subject'])) {
67 require_once 'upload.inc.php';
68 if (strlen($_POST['subject']) < 2) {
69 throw new Exception('Vul een onderwerp in om de issue te kunnen benoemen.');
71 if (!preg_match('/\S/', $_POST['reply'])) {
72 throw new Exception('Een korte beschrijving is verplicht om een issue aan te maken.');
74 $query = $Db->set('issues', [
75 'page' => $Page->handler,
76 'subject' => $_POST['subject'],
77 'link' => preg_replace('/\b(?:de|het|een)\s+|\W+/', '-', strtolower($_POST['subject'])),
78 'author' => $User->login,
80 if (!$query->rowCount()) {
81 throw new Exception('Issue niet opgeslagen.');
83 $row = $query->fetch();
85 throw new Exception('Issue niet goed opgeslagen.');
88 createcomment($_POST, $row);
90 catch (Exception $e) {
91 throw new Exception("Issueinhoud niet opgeslagen: {$e->getMessage()}.");
96 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
97 $cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
98 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
99 $sql = "SELECT $cols FROM issues i WHERE page = ?";
100 if (isset($_GET['open'])) {
101 $sql .= ' AND closed IS NULL';
103 $sql .= ' ORDER BY updated DESC';
104 $query = $Db->query($sql, [$Page->handler]);
107 require 'issue/feed.inc.php';
112 "SELECT count(*) AS total, count(closed) AS closed FROM issues"
114 printf("<h4>%s, %s opgelost</h4>\n",
116 sprintf('%d lopende zaken', $stats->total - $stats->closed),
117 isset($_GET['open']) ? FALSE : '?open'
122 while ($row = $query->fetch()) {
123 printf('<li%s><div><a href="%s">',
124 $row->closed ? ' class="disabled"' : '',
125 "/{$Page->handler}/{$row->id}/{$row->link}"
127 printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
129 printf(' <small class="date">%s</small>',
130 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
133 if ($row->replycount) {
134 printf(' <span class=right>%s %d</span>',
135 '<span class="icon icon-comment" title="reacties">🗨</span>',
139 if ($row->imagecount) {
140 print ' <span class="right icon icon-camera" title="afbeeldingen">📷</span>';
142 if (isset($row->assign)) {
143 print ' <em class="right">'.$row->assign.'</em>';
145 print "</a></div></li>\n";
148 $Page->place['issuelist'] = ob_get_clean();