issue: display assignments in overview
[minimedit.git] / issue / index.php
index 3d62ced075f98f34c04285e6d2c1bb83b828e8ad..419156f70c6ed0909b171223755d1caeb21eaa69 100644 (file)
@@ -1,24 +1,37 @@
 <?php
 global $User, $Db;
 require_once 'database.inc.php';
-$id = trim($Args, '/');
+@list ($id, $title) = explode('/', ltrim($Args, '/'));
 
 if ($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;
-       if ($row->closed) {
-               printf('<p><strong>%s</strong> <small class=date>%s</small></p>'."\n",
-                       'Opgelost', showdate(preg_split('/\D/', $row->closed))
+       print $Issue->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',
+               $author ? " door <strong>{$author->name}</strong>" : '',
+               showdate(preg_split('/\D/', $Issue->created))
+       );
+       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/', $Issue->closed))
                );
        }
+       $Args = "/$id";  # minimal reference
        print placeholder_include('reply');
        return;
 }
@@ -26,7 +39,7 @@ if ($id) {
 if ($_POST) {
                $html = nl2br(htmlspecialchars($_POST['body']));
                $html = empty($html) ? NULL : "<p>$html</p>";
-               $query = $Db->insert('issues', [
+               $query = $Db->set('issues', [
                        'page'    => $Page,
                        'subject' => $_POST['subject'],
                        'body'    => $html,
@@ -38,16 +51,22 @@ if ($_POST) {
                $_POST = [];
 }
 
-$query = $Db->query('SELECT * FROM issues ORDER BY created DESC');
+$sql = 'SELECT * FROM issues WHERE page = ?';
+if (isset($_GET['open'])) {
+       $sql .= ' AND closed IS NULL';
+}
+$sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
+$query = $Db->query($sql, [$Page]);
 
 ob_start();
 print '<ul>';
 while ($row = $query->fetch()) {
-       printf('<li><a href="%s">%s <small class="date">%s</small></a>',
-               "/$Page/{$row->id}",
+       printf('<li><a href="%s">%s <small class="date">%s</small>%s</a>',
+               "/$Page/{$row->id}/{$row->link}",
                sprintf($row->closed ? '<strike>%s</strike>' : '%s',
                        htmlspecialchars($row->subject)),
-               showdate(array_slice(preg_split('/\D/', $row->created), 0, 3))
+               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
+               isset($row->assign) ? ' <em class="right">'.$row->assign.'</em>' : ''
        );
        print "</li>\n";
 }