reply: share parent data from issue page
[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                         $Db->set('issues', $row, ['id = ?', $Issue->id]);
23                 }
24                 $_POST['reply'] = NULL;
25         }
26         catch (Exception $e) {
27                 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
28         }
29 }
30
31 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
32
33 print '<ul class="replies">';
34
35 while ($row = $query->fetch()) {
36         $rowuser = new User("profile/{$row->author}");
37         print '<li>';
38         printf('<strong>%s</strong> <small class=date>%s</small>',
39                 $rowuser->html, showdate(preg_split('/\D/', $row->created))
40         );
41         printf("<blockquote>%s</blockquote>\n", $row->message);
42         print "</li>\n";
43 }
44
45 if ($User) {
46         print '<li>';
47         print '<form method="post" action="">';
48         printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
49                 'reply',
50                 "Bericht van {$User->login}",
51                 ''
52         );
53         print '<input type="submit" value="Plaatsen" />'."\n";
54         print "</form></li>\n";
55 }
56
57 print "</ul>\n\n";