2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
7 $html = nl2br(htmlspecialchars($_POST['reply']));
8 $html = "<p>$html</p>";
9 $query = $Db->set('comments', [
12 'author' => $User->login,
14 if (!$query->rowCount()) {
15 throw new Exception('Fout bij opslaan');
17 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
21 foreach (['assign'] as $col) {
22 if (!isset($_POST[$col])) continue;
23 $row[$col] = $_POST[$col] ?: NULL;
25 if (isset($_POST['status'])) {
26 $reset = !empty($_POST['status']);
27 if (isset($Issue->closed) !== $reset) {
28 $row['closed'] = $reset ? ['now()'] : NULL;
31 $derived = ['updated' => ['now()']];
32 $filter = ['id = ? RETURNING *', $Issue->id];
33 $subquery = $Db->set('issues', $row + $derived, $filter);
35 if ($updated = $subquery->fetch()) {
36 foreach (array_keys($row) as $col) {
37 if ($updated->$col === $Issue->$col) continue; # unaltered
39 'comment_id' => $newcomment,
42 'old_value' => $Issue->$col,
43 'value' => $updated->$col,
48 $_POST['reply'] = NULL;
50 catch (Exception $e) {
51 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
55 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
57 print '<ul class="replies">';
59 while ($row = $query->fetch()) {
60 $rowuser = new User("profile/{$row->author}");
62 printf('<strong>%s</strong> <small class=date>%s</small>',
63 $rowuser->html, showdate(preg_split('/\D/', $row->created))
65 printf("<blockquote>%s</blockquote>\n", $row->message);
71 print '<form method="post" action="">';
72 if (isset($Issue) and $User->admin("edit $Page")) {
75 '<label for="%s">%s:</label> '
76 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
79 htmlspecialchars($Issue->assign ?? '')
82 '<input type="hidden" name="%s" value="" />' .
83 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
84 . '<label for="%1$s"> %s</label>'."\n",
87 isset($Issue->closed) ? ' checked' : '',
92 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
94 "Bericht van {$User->login}",
97 print '<input type="submit" value="Plaatsen" />'."\n";
98 print "</form></li>\n";