2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
6 'assign' => 'Toegewezen aan',
10 require_once 'upload.inc.php';
12 $html = messagehtml($_POST['reply']);
13 if ($_FILES and isset($_FILES['image'])) {
14 $target = 'data/upload';
15 if (!file_exists($target)) {
16 throw new Exception("er is geen uploadmap aanwezig op $target");
18 $target .= '/' . $User->login;
19 $result = userupload($_FILES['image'], $target);
20 $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
22 $query = $Db->set('comments', [
25 'author' => $User->login,
27 if (!$query->rowCount()) {
28 throw new Exception('Fout bij opslaan');
30 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
34 foreach (array_keys($journalcol) as $col) {
35 if (!isset($_POST[$col])) continue;
36 $row[$col] = $_POST[$col] ?: NULL;
38 if (isset($_POST['status'])) {
39 $reset = !empty($_POST['status']);
40 if (isset($Issue->closed) !== $reset) {
41 $row['closed'] = $reset ? ['now()'] : NULL;
44 $derived = ['updated' => ['now()']];
45 $filter = ['id = ? RETURNING *', $Issue->id];
46 $subquery = $Db->set('issues', $row + $derived, $filter);
48 if ($updated = $subquery->fetch()) {
49 foreach (array_keys($row) as $col) {
50 if ($updated->$col === $Issue->$col) continue; # unaltered
52 'comment_id' => $newcomment,
55 'old_value' => $Issue->$col,
56 'value' => $updated->$col,
62 $_POST['reply'] = NULL;
64 catch (Exception $e) {
65 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
69 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
70 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
72 print '<ul class="replies">';
74 while ($row = $query->fetch()) {
75 $rowuser = new User("profile/{$row->author}");
77 printf('<strong>%s</strong> <small class=date>%s</small>',
78 $rowuser->html, showdate(preg_split('/\D/', $row->created))
80 printf("<blockquote>\n%s</blockquote>\n", $row->message);
81 if ($changes = json_decode($row->journal)) {
83 foreach ($changes as $change) {
85 if ($change->col == 'closed') {
86 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
89 printf("<em>%s</em> %s",
90 $journalcol[$change->col], sprintf(
91 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
92 (!isset($change->value) ? 'verwijderd (<strike>%s</strike>)' :
93 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
94 $change->old_value, $change->value
107 print '<form method="post" action="" enctype="multipart/form-data">';
108 if (isset($Issue) and $User->admin("edit $Page")) {
111 '<label for="%s">%s:</label> '
112 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
114 $journalcol['assign'],
115 htmlspecialchars($Issue->assign ?? '')
118 '<input type="hidden" name="%s" value="" />' .
119 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
120 . '<label for="%1$s"> %s</label>'."\n",
123 isset($Issue->closed) ? ' checked' : '',
130 '<p><label for="%s">%s:</label> '
131 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
132 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
135 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
137 "Bericht van {$User->login}",
140 print '<input type="submit" value="Plaatsen" />'."\n";
141 print "</form></li>\n";