2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
6 'assign' => 'Toegewezen aan',
10 require_once 'upload.inc.php';
12 $query = $Db->set('comments', [
14 'message' => messagehtml($_POST['reply']),
15 'author' => $User->login,
17 if (!$query->rowCount()) {
18 throw new Exception('Fout bij opslaan');
20 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
24 foreach (array_keys($journalcol) as $col) {
25 if (!isset($_POST[$col])) continue;
26 $row[$col] = $_POST[$col] ?: NULL;
28 if (isset($_POST['status'])) {
29 $reset = !empty($_POST['status']);
30 if (isset($Issue->closed) !== $reset) {
31 $row['closed'] = $reset ? ['now()'] : NULL;
34 $derived = ['updated' => ['now()']];
35 $filter = ['id = ? RETURNING *', $Issue->id];
36 $subquery = $Db->set('issues', $row + $derived, $filter);
38 if ($updated = $subquery->fetch()) {
39 foreach (array_keys($row) as $col) {
40 if ($updated->$col === $Issue->$col) continue; # unaltered
42 'comment_id' => $newcomment,
45 'old_value' => $Issue->$col,
46 'value' => $updated->$col,
52 $_POST['reply'] = NULL;
54 catch (Exception $e) {
55 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
59 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
60 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
62 print '<ul class="replies">';
64 while ($row = $query->fetch()) {
65 $rowuser = new User("profile/{$row->author}");
67 printf('<strong>%s</strong> <small class=date>%s</small>',
68 $rowuser->html, showdate(preg_split('/\D/', $row->created))
70 printf("<blockquote>%s</blockquote>\n", $row->message);
71 if ($changes = json_decode($row->journal)) {
73 foreach ($changes as $change) {
75 if ($change->col == 'closed') {
76 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
79 printf("<em>%s</em> %s",
80 $journalcol[$change->col], sprintf(
81 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
82 (!isset($change->value) ? 'verwijderd (<strike>%s</strike>)' :
83 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
84 $change->old_value, $change->value
97 print '<form method="post" action="">';
98 if (isset($Issue) and $User->admin("edit $Page")) {
101 '<label for="%s">%s:</label> '
102 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
104 $journalcol['assign'],
105 htmlspecialchars($Issue->assign ?? '')
108 '<input type="hidden" name="%s" value="" />' .
109 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
110 . '<label for="%1$s"> %s</label>'."\n",
113 isset($Issue->closed) ? ' checked' : '',
118 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
120 "Bericht van {$User->login}",
123 print '<input type="submit" value="Plaatsen" />'."\n";
124 print "</form></li>\n";