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.');
63 createcomment($_POST, $row);
65 catch (Exception $e) {
66 throw new Exception("Issueinhoud niet opgeslagen: {$e->getMessage()}.");
71 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
72 $cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
73 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
74 $sql = "SELECT $cols FROM issues i WHERE page = ?";
75 if (isset($_GET['open'])) {
76 $sql .= ' AND closed IS NULL';
78 $sql .= ' ORDER BY updated DESC';
79 $query = $Db->query($sql, [$Page->handler]);
82 require 'issue/feed.inc.php';
87 "SELECT count(*) AS total, count(closed) AS closed FROM issues"
89 printf("<h4>%d lopende zaken, %s opgelost</h4>\n",
90 $stats->total - $stats->closed, $stats->closed
93 while ($row = $query->fetch()) {
94 printf('<li%s><div><a href="%s">',
95 $row->closed ? ' class="disabled"' : '',
96 "/{$Page->handler}/{$row->id}/{$row->link}"
98 printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
100 printf(' <small class="date">%s</small>',
101 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
104 if ($row->replycount) {
105 printf(' <span class=right>%s %d</span>',
106 '<span class="icon icon-comment" title="reacties">🗨</span>',
110 if ($row->imagecount) {
111 print ' <span class="right icon icon-camera" title="afbeeldingen">📷</span>';
113 if (isset($row->assign)) {
114 print ' <em class="right">'.$row->assign.'</em>';
116 print "</a></div></li>\n";
119 $Page->place['issuelist'] = ob_get_clean();