issue: assignment text field for admins
[minimedit.git] / widget / reply.php
1 <?php
2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
4
5 print '<h3>Reacties</h3>'."\n";
6
7 if ($_POST) {
8         try {
9                 $html = nl2br(htmlspecialchars($_POST['reply']));
10                 $html = "<p>$html</p>";
11                 $query = $Db->set('comments', [
12                         'page'    => $Page,
13                         'message' => $html,
14                         'author'  => $User->login,
15                 ]);
16                 if (!$query->rowCount()) {
17                         throw new Exception('Fout bij opslaan');
18                 }
19
20                 if (isset($Issue)) {
21                         $row = ['updated' => ['now()']];
22                         foreach (['assign'] as $col) {
23                                 if (!isset($_POST[$col])) continue;
24                                 $row[$col] = $_POST[$col] ?: NULL;
25                         }
26                         $Db->set('issues', $row, ['id = ?', $Issue->id]);
27                 }
28                 $_POST['reply'] = NULL;
29         }
30         catch (Exception $e) {
31                 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
32         }
33 }
34
35 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
36
37 print '<ul class="replies">';
38
39 while ($row = $query->fetch()) {
40         $rowuser = new User("profile/{$row->author}");
41         print '<li>';
42         printf('<strong>%s</strong> <small class=date>%s</small>',
43                 $rowuser->html, showdate(preg_split('/\D/', $row->created))
44         );
45         printf("<blockquote>%s</blockquote>\n", $row->message);
46         print "</li>\n";
47 }
48
49 if ($User) {
50         print '<li>';
51         print '<form method="post" action="">';
52         if (isset($Issue) and $User->admin("edit $Page")) {
53                 print '<p>';
54                 printf(
55                         '<label for="%s">%s:</label> '
56                         . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
57                         'assign',
58                         'Toegewezen aan',
59                         htmlspecialchars($Issue->assign ?? '')
60                 );
61                 print "</p>\n";
62         }
63         printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
64                 'reply',
65                 "Bericht van {$User->login}",
66                 ''
67         );
68         print '<input type="submit" value="Plaatsen" />'."\n";
69         print "</form></li>\n";
70 }
71
72 print "</ul>\n\n";