issue: assignment text field for admins
[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) {
7         $Article->title = "Issue #$id";
8
9         $Issue = $Db->query(
10                 'SELECT * FROM issues WHERE id = ?', [$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 $Issue->body;
17         printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
18                 'Geplaatst',
19                 $Issue->author ? " door <strong>{$Issue->author}</strong>" : '',
20                 showdate(preg_split('/\D/', $Issue->created))
21         );
22         if ($Issue->assign) {
23                 printf('<p><em>%s</em> aan <strong>%s</strong></p>'."\n",
24                         'Toegewezen', htmlspecialchars($Issue->assign)
25                 );
26         }
27         if ($Issue->closed) {
28                 printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
29                         'Opgelost', '',
30                         showdate(preg_split('/\D/', $Issue->closed))
31                 );
32         }
33         $Args = "/$id";  # minimal reference
34         print placeholder_include('reply');
35         return;
36 }
37
38 if ($_POST) {
39                 $html = nl2br(htmlspecialchars($_POST['body']));
40                 $html = empty($html) ? NULL : "<p>$html</p>";
41                 $query = $Db->set('issues', [
42                         'page'    => $Page,
43                         'subject' => $_POST['subject'],
44                         'body'    => $html,
45                         'author'  => $User->login,
46                 ]);
47                 if (!$query->rowCount()) {
48                         throw new Exception('Issue niet opgeslagen.');
49                 }
50                 $_POST = [];
51 }
52
53 $sql = 'SELECT * FROM issues';
54 if (isset($_GET['open'])) {
55         $sql .= ' WHERE closed IS NULL';
56 }
57 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
58 $query = $Db->query($sql);
59
60 ob_start();
61 print '<ul>';
62 while ($row = $query->fetch()) {
63         printf('<li><a href="%s">%s <small class="date">%s</small></a>',
64                 "/$Page/{$row->id}/{$row->link}",
65                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
66                         htmlspecialchars($row->subject)),
67                 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
68         );
69         print "</li>\n";
70 }
71 print "</ul>\n";
72 $Place['issuelist'] = ob_get_clean();