181d5b73e6380fec368787929fe291dace82030b
[minimedit.git] / issue / index.php
1 <?php
2 global $User, $Db;
3 require_once 'database.inc.php';
4 @list ($id, $title) = explode('/', ltrim($Page->path, '/'));
5
6 if ($id and ctype_digit($id)) {
7         $Page->title = "Issue #$id";
8         $Page->path = "/$id";  # minimal reference
9         $Issue = $Db->query(
10                 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id]
11         )->fetch();
12         if (!$Issue) throw new Exception('Issuenummer niet gevonden');
13
14         $replies = $Page->widget('reply');  # handle updates
15
16         $Page->title .= ': '.htmlspecialchars($Issue->subject);
17         $Page->teaser = $Issue->body;
18         $Page->body = $replies;  # find image
19
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);
26         }
27         if ($Issue->assign) {
28                 print '<dt>Toegewezen aan</dt>';
29                 printf('<dd>%s</dd>'."\n", htmlspecialchars($Issue->assign));
30         }
31         if ($Issue->closed) {
32                 print '<dt>Opgelost</dt>';
33                 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->closed)));
34         }
35         print "</dl></aside>\n\n";
36
37         print '<div>';
38         print $Issue->body;
39         print $replies;
40         print "</div>\n";
41         return;
42 }
43
44 if ($_POST) {
45                 require_once 'upload.inc.php';
46                 $query = $Db->set('issues', [
47                         'page'    => $Page->handler,
48                         'subject' => $_POST['subject'],
49                         'body'    => messagehtml($_POST['body']),
50                         'author'  => $User->login,
51                 ]);
52                 if (!$query->rowCount()) {
53                         throw new Exception('Issue niet opgeslagen.');
54                 }
55                 $_POST = [];
56 }
57
58 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
59 $cols = "*, ($subsql AND message IS NOT NULL) AS replycount";
60 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
61 $sql = "SELECT $cols FROM issues i WHERE page = ?";
62 if (isset($_GET['open'])) {
63         $sql .= ' AND closed IS NULL';
64 }
65 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
66 $query = $Db->query($sql, [$Page->handler]);
67
68 if ($id == 'feed') {
69         require 'issue/feed.inc.php';
70 }
71
72 ob_start();
73 print '<ul>';
74 while ($row = $query->fetch()) {
75         printf('<li%s><div><a href="%s">',
76                 $row->closed ? ' class="disabled"' : '',
77                 "/{$Page->handler}/{$row->id}/{$row->link}"
78         );
79         printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
80         {
81                 printf(' <small class="date">%s</small>',
82                         showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
83                 );
84         }
85         if ($row->replycount) {
86                 printf(' <span class=right>%s %d</span>',
87                         '<span class="icon icon-comment" title="reacties">&#x1F5E8;</span>',
88                         $row->replycount
89                 );
90         }
91         if ($row->imagecount) {
92                 print ' <span class="right icon icon-camera" title="afbeeldingen">&#x1F4F7;</span>';
93         }
94         if (isset($row->assign)) {
95                 print ' <em class="right">'.$row->assign.'</em>';
96         }
97         print "</a></div></li>\n";
98 }
99 print "</ul>\n";
100 $Place['issuelist'] = ob_get_clean();