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 printf('<form method="post" action="%s" enctype="multipart/form-data">',
27 print "<h2>{$Page->title}</h2>\n";
28 printf('<input type="hidden" name="%s" value="%s" />'."\n", 'id', $row->id);
30 '<input type="hidden" name="%s" value="" />'
31 . '<input type="checkbox" id="%1$s" name="%1$s" value="1"%s />'
32 . '<label for="%1$s"> %s</label>'."\n<p>",
33 'announce', $row->announced ? ' checked' : '', 'Aangekondigd'
35 printf('<input type="text" name="%s" value="%s" /><p>'."\n", 'page', $row->page);
36 printf('<textarea id="%s" name="%1$s" cols=60 rows=3>%s</textarea>'."\n",
38 htmlspecialchars($row->raw)
40 print '<input type="submit" value="Aanpassen" />'."\n";
45 $replies = $Page->widget('reply'); # handle updates
46 $Page->body = $replies; # find image
47 if ($Page->api) return;
49 print "<h2>{$Page->title}</h2>\n";
50 print '<aside class="metadata"><dl>'."\n";
51 print '<dt>Geplaatst</dt>';
52 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->created)));
53 if ($Issue->author and $author = new User('profile/'.$Issue->author, FALSE)) {
54 printf('<dd>%s</dd>'."\n", $author->html);
57 print '<dt>Toegewezen aan</dt>';
58 printf('<dd>%s</dd>'."\n", htmlspecialchars($Issue->assign));
61 print '<dt>Opgelost</dt>';
62 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->closed)));
64 print "</dl></aside>\n\n";
72 if ($Page->api) return;
73 if ($_POST and isset($_POST['subject'])) {
74 require_once 'upload.inc.php';
75 if (strlen($_POST['subject']) < 2) {
76 throw new Exception('Vul een onderwerp in om de issue te kunnen benoemen.');
78 if (!preg_match('/\S/', $_POST['reply'])) {
79 throw new Exception('Een korte beschrijving is verplicht om een issue aan te maken.');
81 $query = $Db->set('issues', [
82 'page' => $Page->handler,
83 'subject' => $_POST['subject'],
84 'link' => preg_replace('/\b(?:de|het|een)\s+|\W+/', '-', strtolower($_POST['subject'])),
85 'author' => $User->login,
87 if (!$query->rowCount()) {
88 throw new Exception('Issue niet opgeslagen.');
90 $row = $query->fetch();
92 throw new Exception('Issue niet goed opgeslagen.');
95 createcomment($_POST, $row);
97 catch (Exception $e) {
98 throw new Exception("Issueinhoud niet opgeslagen: {$e->getMessage()}.");
103 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
104 $cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
105 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
106 $sql = "SELECT $cols FROM issues i WHERE page = ?";
107 if (isset($_GET['open'])) {
108 $sql .= ' AND closed IS NULL';
110 $sql .= ' ORDER BY updated DESC';
111 $query = $Db->query($sql, [$Page->handler]);
114 require 'issue/feed.inc.php';
119 "SELECT count(*) AS total, count(closed) AS closed FROM issues"
121 printf("<h4>%s, %s opgelost</h4>\n",
123 sprintf('%d lopende zaken', $stats->total - $stats->closed),
124 isset($_GET['open']) ? FALSE : '?open'
129 while ($row = $query->fetch()) {
130 printf('<li%s><div><a href="%s">',
131 $row->closed ? ' class="disabled"' : '',
132 "/{$Page->handler}/{$row->id}/{$row->link}"
134 printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
136 printf(' <small class="date">%s</small>',
137 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
140 if ($row->replycount) {
141 printf(' <span class=right>%s %d</span>',
142 '<span class="icon icon-comment" title="reacties">🗨</span>',
146 if ($row->imagecount) {
147 print ' <span class="right icon icon-camera" title="afbeeldingen">📷</span>';
149 if (isset($row->assign)) {
150 print ' <em class="right">'.$row->assign.'</em>';
152 print "</a></div></li>\n";
155 $Page->place['issuelist'] = ob_get_clean();