auth: append login to formatted user names
[minimedit.git] / issue / index.php
index 10efc5ebcc87537a549c056f3ca9b2cbe81031a4..bb556f2019d6e259d70ca8a943cdc40757b75c50 100644 (file)
@@ -3,28 +3,34 @@ global $User, $Db;
 require_once 'database.inc.php';
 @list ($id, $title) = explode('/', ltrim($Args, '/'));
 
-if ($id) {
+if ($id and ctype_digit($id)) {
        $Article->title = "Issue #$id";
 
-       $row = $Db->query(
-               'SELECT * FROM issues WHERE id = ?', [$id]
+       $Issue = $Db->query(
+               'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
        )->fetch();
-       if (!$row) throw new Exception('Issuenummer niet gevonden');
+       if (!$Issue) throw new Exception('Issuenummer niet gevonden');
 
-       $Article->title .= ': '.htmlspecialchars($row->subject);
+       $Article->title .= ': '.htmlspecialchars($Issue->subject);
        print "<h2>{$Article->title}</h2>\n";
-       print $row->body;
+       $author = $Issue->author ? new User('profile/'.$Issue->author, FALSE) : NULL;
        printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
                'Geplaatst',
-               $row->author ? " door <strong>{$row->author}</strong>" : '',
-               showdate(preg_split('/\D/', $row->created))
+               $author ? " door <strong>{$author->html}</strong>" : '',
+               showdate(preg_split('/\D/', $Issue->created))
        );
-       if ($row->closed) {
+       if ($Issue->assign) {
+               printf('<p><em>%s</em> aan <strong>%s</strong></p>'."\n",
+                       'Toegewezen', htmlspecialchars($Issue->assign)
+               );
+       }
+       if ($Issue->closed) {
                printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
                        'Opgelost', '',
-                       showdate(preg_split('/\D/', $row->closed))
+                       showdate(preg_split('/\D/', $Issue->closed))
                );
        }
+       print $Issue->body;
        $Args = "/$id";  # minimal reference
        print placeholder_include('reply');
        return;
@@ -45,21 +51,32 @@ if ($_POST) {
                $_POST = [];
 }
 
-$sql = 'SELECT * FROM issues';
+$cols = "*, (SELECT count(*) FROM comments WHERE"
+       . " page=i.page||'/'||i.id AND message IS NOT NULL) AS replycount";
+$sql = "SELECT $cols FROM issues i WHERE page = ?";
 if (isset($_GET['open'])) {
-       $sql .= ' WHERE closed IS NULL';
+       $sql .= ' AND closed IS NULL';
 }
 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
-$query = $Db->query($sql);
+$query = $Db->query($sql, [$Page]);
+
+if ($id == 'feed') {
+       require 'issue/feed.inc.php';
+}
 
 ob_start();
 print '<ul>';
 while ($row = $query->fetch()) {
-       printf('<li><a href="%s">%s <small class="date">%s</small></a>',
+       printf('<li%s><a href="%s">%s <small class="date">%s</small>%s</a>',
+               $row->closed ? ' class="disabled"' : '',
                "/$Page/{$row->id}/{$row->link}",
-               sprintf($row->closed ? '<strike>%s</strike>' : '%s',
+               sprintf($row->closed ? '<s>%s</s>' : '%s',
                        htmlspecialchars($row->subject)),
-               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
+               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
+               implode(' ', [
+                       $row->replycount ? sprintf('<span class=right>+%d</span>', $row->replycount) : '',
+                       isset($row->assign) ? '<em class="right">'.$row->assign.'</em>' : '',
+               ])
        );
        print "</li>\n";
 }