issue: ordered overview including closed tickets
[minimedit.git] / issue / index.php
index 87b22a39d876ac8774a1a1a512e52e025e9176b0..35a1116b153b72cd26de0973b8e64842ecc5dad3 100644 (file)
@@ -1,11 +1,11 @@
 <?php
-global $User, $Db;
+global $User, $Db, $Issue;
 require_once 'database.inc.php';
 @list ($id, $title) = explode('/', ltrim($Page->path, '/'));
 
 if ($id and ctype_digit($id)) {
        $Page->title = "Issue #$id";
-       $Page->path = "/$id";  # minimal reference
+       $Page->link = $Page->handler . ($Page->path = "/$id");  # minimal reference
        $Issue = $Db->query(
                'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id]
        )->fetch();
@@ -14,9 +14,8 @@ if ($id and ctype_digit($id)) {
        $replies = $Page->widget('reply');  # handle updates
 
        $Page->title .= ': '.htmlspecialchars($Issue->subject);
-       $Page->teaser = $Issue->body;
-       if ($Page->api) return;
        $Page->body = $replies;  # find image
+       if ($Page->api) return;
 
        print "<h2>{$Page->title}</h2>\n";
        print '<aside class="metadata"><dl>'."\n";
@@ -36,35 +35,47 @@ if ($id and ctype_digit($id)) {
        print "</dl></aside>\n\n";
 
        print '<div>';
-       print $Issue->body;
        print $replies;
        print "</div>\n";
        return;
 }
 
-if ($_POST) {
+if ($Page->api) return;
+if ($_POST and isset($_POST['subject'])) {
                require_once 'upload.inc.php';
+               if (strlen($_POST['subject']) < 2) {
+                       throw new Exception('Een minimaal onderwerp is verplicht om een issue aan te maken.');
+               }
                $query = $Db->set('issues', [
                        'page'    => $Page->handler,
                        'subject' => $_POST['subject'],
-                       'body'    => messagehtml($_POST['body']),
+                       'link'    => preg_replace('/\b(?:de|het|een)\s+|\W+/', '-', strtolower($_POST['subject'])),
                        'author'  => $User->login,
                ]);
                if (!$query->rowCount()) {
                        throw new Exception('Issue niet opgeslagen.');
                }
+               $row = $query->fetch();
+               if (!$row->id) {
+                       throw new Exception('Issue niet goed opgeslagen.');
+               }
+               try {
+                       createcomment($_POST, $row);
+               }
+               catch (Exception $e) {
+                       throw new Exception("Issueinhoud niet opgeslagen: {$e->getMessage()}.");
+               }
                $_POST = [];
 }
-if ($Page->api) return;
 
 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
-$cols = "*, ($subsql AND message IS NOT NULL) AS replycount";
+$cols = "*, ($subsql AND message IS NOT NULL) - 1 AS replycount";
 $cols .= ", ($subsql AND message ~ '<img') AS imagecount";
 $sql = "SELECT $cols FROM issues i WHERE page = ?";
 if (isset($_GET['open'])) {
        $sql .= ' AND closed IS NULL';
 }
-$sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
+$sql .= ' ORDER BY updated DESC';
 $query = $Db->query($sql, [$Page->handler]);
 
 if ($id == 'feed') {