2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
5 print '<h3>Reacties</h3>'."\n";
9 $html = nl2br(htmlspecialchars($_POST['reply']));
10 $html = "<p>$html</p>";
11 $query = $Db->set('comments', [
14 'author' => $User->login,
16 if (!$query->rowCount()) {
17 throw new Exception('Fout bij opslaan');
19 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
23 foreach (['assign'] as $col) {
24 if (!isset($_POST[$col])) continue;
25 $row[$col] = $_POST[$col] ?: NULL;
27 if (isset($_POST['status'])) {
28 $reset = !empty($_POST['status']);
29 if (isset($Issue->closed) !== $reset) {
30 $row['closed'] = $reset ? ['now()'] : NULL;
33 $derived = ['updated' => ['now()']];
34 $filter = ['id = ? RETURNING *', $Issue->id];
35 $subquery = $Db->set('issues', $row + $derived, $filter);
37 if ($updated = $subquery->fetch()) {
38 foreach (array_keys($row) as $col) {
39 if ($updated->$col === $Issue->$col) continue; # unaltered
41 'comment_id' => $newcomment,
44 'old_value' => $Issue->$col,
45 'value' => $updated->$col,
50 $_POST['reply'] = NULL;
52 catch (Exception $e) {
53 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
57 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
59 print '<ul class="replies">';
61 while ($row = $query->fetch()) {
62 $rowuser = new User("profile/{$row->author}");
64 printf('<strong>%s</strong> <small class=date>%s</small>',
65 $rowuser->html, showdate(preg_split('/\D/', $row->created))
67 printf("<blockquote>%s</blockquote>\n", $row->message);
73 print '<form method="post" action="">';
74 if (isset($Issue) and $User->admin("edit $Page")) {
77 '<label for="%s">%s:</label> '
78 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
81 htmlspecialchars($Issue->assign ?? '')
84 '<input type="hidden" name="%s" value="" />' .
85 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
86 . '<label for="%1$s"> %s</label>'."\n",
89 isset($Issue->closed) ? ' checked' : '',
94 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
96 "Bericht van {$User->login}",
99 print '<input type="submit" value="Plaatsen" />'."\n";
100 print "</form></li>\n";