issue: wrap items to allow containment
[minimedit.git] / issue / index.php
1 <?php
2 global $User, $Db;
3 require_once 'database.inc.php';
4 @list ($id, $title) = explode('/', ltrim($Args, '/'));
5
6 if ($id and ctype_digit($id)) {
7         $Article->title = "Issue #$id";
8
9         $Issue = $Db->query(
10                 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
11         )->fetch();
12         if (!$Issue) throw new Exception('Issuenummer niet gevonden');
13
14         $Article->title .= ': '.htmlspecialchars($Issue->subject);
15         print "<h2>{$Article->title}</h2>\n";
16         print "<dl class=\"aside right sidebar\">\n";
17         print '<dt>Geplaatst</dt>';
18         printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->created)));
19         if ($Issue->author and $author = new User('profile/'.$Issue->author, FALSE)) {
20                 printf('<dd>%s</dd>'."\n", $author->html);
21         }
22         if ($Issue->assign) {
23                 print '<dt>Toegewezen aan</dt>';
24                 printf('<dd>%s</dd>'."\n", htmlspecialchars($Issue->assign));
25         }
26         if ($Issue->closed) {
27                 print '<dt>Opgelost</dt>';
28                 printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->closed)));
29         }
30         print "</dl>\n\n";
31
32         print '<div>';
33         print $Issue->body;
34         $Args = "/$id";  # minimal reference
35         print placeholder_include('reply');
36         print "</div>\n";
37         return;
38 }
39
40 if ($_POST) {
41                 require_once 'upload.inc.php';
42                 $query = $Db->set('issues', [
43                         'page'    => $Page,
44                         'subject' => $_POST['subject'],
45                         'body'    => messagehtml($_POST['body']),
46                         'author'  => $User->login,
47                 ]);
48                 if (!$query->rowCount()) {
49                         throw new Exception('Issue niet opgeslagen.');
50                 }
51                 $_POST = [];
52 }
53
54 $cols = "*, (SELECT count(*) FROM comments WHERE"
55         . " page=i.page||'/'||i.id AND message IS NOT NULL) AS replycount";
56 $sql = "SELECT $cols FROM issues i WHERE page = ?";
57 if (isset($_GET['open'])) {
58         $sql .= ' AND closed IS NULL';
59 }
60 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
61 $query = $Db->query($sql, [$Page]);
62
63 if ($id == 'feed') {
64         require 'issue/feed.inc.php';
65 }
66
67 ob_start();
68 print '<ul>';
69 while ($row = $query->fetch()) {
70         printf('<li%s><div><a href="%s">%s <small class="date">%s</small>%s</a>',
71                 $row->closed ? ' class="disabled"' : '',
72                 "/$Page/{$row->id}/{$row->link}",
73                 sprintf($row->closed ? '<s>%s</s>' : '%s',
74                         htmlspecialchars($row->subject)),
75                 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
76                 implode(' ', [
77                         $row->replycount ? sprintf('<span class=right>+%d</span>', $row->replycount) : '',
78                         isset($row->assign) ? '<em class="right">'.$row->assign.'</em>' : '',
79                 ])
80         );
81         print "</div></li>\n";
82 }
83 print "</ul>\n";
84 $Place['issuelist'] = ob_get_clean();