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('Een minimaal onderwerp is verplicht om een issue aan te maken.');
71 $query = $Db->set('issues', [
72 'page' => $Page->handler,
73 'subject' => $_POST['subject'],
74 'link' => preg_replace('/\b(?:de|het|een)\s+|\W+/', '-', strtolower($_POST['subject'])),
75 'author' => $User->login,
77 if (!$query->rowCount()) {
78 throw new Exception('Issue niet opgeslagen.');
80 $row = $query->fetch();
82 throw new Exception('Issue niet goed opgeslagen.');
85 createcomment($_POST, $row);
87 catch (Exception $e) {
88 throw new Exception("Issueinhoud niet opgeslagen: {$e->getMessage()}.");
93 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
94 $cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
95 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
96 $sql = "SELECT $cols FROM issues i WHERE page = ?";
97 if (isset($_GET['open'])) {
98 $sql .= ' AND closed IS NULL';
100 $sql .= ' ORDER BY updated DESC';
101 $query = $Db->query($sql, [$Page->handler]);
104 require 'issue/feed.inc.php';
109 "SELECT count(*) AS total, count(closed) AS closed FROM issues"
111 printf("<h4>%d lopende zaken, %s opgelost</h4>\n",
112 $stats->total - $stats->closed, $stats->closed
115 while ($row = $query->fetch()) {
116 printf('<li%s><div><a href="%s">',
117 $row->closed ? ' class="disabled"' : '',
118 "/{$Page->handler}/{$row->id}/{$row->link}"
120 printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
122 printf(' <small class="date">%s</small>',
123 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
126 if ($row->replycount) {
127 printf(' <span class=right>%s %d</span>',
128 '<span class="icon icon-comment" title="reacties">🗨</span>',
132 if ($row->imagecount) {
133 print ' <span class="right icon icon-camera" title="afbeeldingen">📷</span>';
135 if (isset($row->assign)) {
136 print ' <em class="right">'.$row->assign.'</em>';
138 print "</a></div></li>\n";
141 $Page->place['issuelist'] = ob_get_clean();