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,
51 $_POST['reply'] = NULL;
53 catch (Exception $e) {
54 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
58 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
59 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
61 print '<ul class="replies">';
63 while ($row = $query->fetch()) {
64 $rowuser = new User("profile/{$row->author}");
66 printf('<strong>%s</strong> <small class=date>%s</small>',
67 $rowuser->html, showdate(preg_split('/\D/', $row->created))
69 printf("<blockquote>%s</blockquote>\n", $row->message);
70 if ($changes = json_decode($row->journal)) {
72 foreach ($changes as $change) {
74 if ($change->col == 'closed') {
75 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
78 printf("<em>%s</em> %s",
79 $journalcol[$change->col], sprintf(
80 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
81 (!isset($change->value) ? 'verwijderd (<strike>%s</strike>)' :
82 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
83 $change->old_value, $change->value
96 print '<form method="post" action="">';
97 if (isset($Issue) and $User->admin("edit $Page")) {
100 '<label for="%s">%s:</label> '
101 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
103 $journalcol['assign'],
104 htmlspecialchars($Issue->assign ?? '')
107 '<input type="hidden" name="%s" value="" />' .
108 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
109 . '<label for="%1$s"> %s</label>'."\n",
112 isset($Issue->closed) ? ' checked' : '',
117 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
119 "Bericht van {$User->login}",
122 print '<input type="submit" value="Plaatsen" />'."\n";
123 print "</form></li>\n";