issue: order by last update, changed on reply
[minimedit.git] / widget / reply.php
1 <?php
2 global $User, $Db;
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->insert('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                 if (@list ($cat, $issue) = explode('/', $Page) and ctype_digit($issue)) {
20                         $Db->query(
21                                 'UPDATE issues SET updated = now() WHERE page = ? AND id = ?',
22                                 [$cat, $issue]
23                         );
24                 }
25                 $_POST['reply'] = NULL;
26         }
27         catch (Exception $e) {
28                 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
29         }
30 }
31
32 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
33
34 print '<ul class="replies">';
35
36 while ($row = $query->fetch()) {
37         $rowuser = new User("profile/{$row->author}");
38         print '<li>';
39         printf('<strong>%s</strong> <small class=date>%s</small>',
40                 $rowuser->html, showdate(preg_split('/\D/', $row->created))
41         );
42         printf("<blockquote>%s</blockquote>\n", $row->message);
43         print "</li>\n";
44 }
45
46 if ($User) {
47         print '<li>';
48         print '<form method="post" action="">';
49         printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
50                 'reply',
51                 "Bericht van {$User->login}",
52                 ''
53         );
54         print '<input type="submit" value="Plaatsen" />'."\n";
55         print "</form></li>\n";
56 }
57
58 print "</ul>\n\n";