2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
6 'assign' => 'Toegewezen aan',
7 'subject' => 'Onderwerp',
11 require_once 'upload.inc.php';
13 $html = messagehtml($_POST['reply']);
14 if ($_FILES and !empty($_FILES['image'])) {
15 $target = 'data/upload';
16 if (!file_exists($target)) {
17 throw new Exception("er is geen uploadmap aanwezig op $target");
19 $target .= '/' . $User->login;
20 if ($result = userupload($_FILES['image'], $target)) {
21 if (preg_match('(^image/)', $_FILES['image']['type'])) {
22 $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
25 $html .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
26 $result, basename($result)
31 $query = $Db->set('comments', [
32 'page' => $Page->link,
34 'author' => $User->login,
36 if (!$query->rowCount()) {
37 throw new Exception('Fout bij opslaan');
39 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
43 foreach (array_keys($journalcol) as $col) {
44 if (!isset($_POST[$col])) continue;
45 $row[$col] = $_POST[$col] ?: NULL;
47 if (isset($_POST['status'])) {
48 $reset = !empty($_POST['status']);
49 if (isset($Issue->closed) !== $reset) {
50 $row['closed'] = $reset ? ['now()'] : NULL;
53 $derived = ['updated' => ['now()']];
54 $filter = ['id = ? RETURNING *', $Issue->id];
55 $subquery = $Db->set('issues', $row + $derived, $filter);
57 if ($updated = $subquery->fetch()) {
58 foreach (array_keys($row) as $col) {
59 if ($updated->$col === $Issue->$col) continue; # unaltered
61 'comment_id' => $newcomment,
64 'old_value' => $Issue->$col,
65 'value' => $updated->$col,
72 $target = "/{$Page->link}/$newcomment#$newcomment";
73 abort($target, ($Page->api ? 200 : 303) . ' reply success');
74 $_POST['reply'] = NULL;
76 catch (Exception $e) {
78 abort(ucfirst($e->getMessage()), '500 reply error');
80 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
84 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
85 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
87 print '<ul class="replies">';
89 while ($row = $query->fetch()) {
90 $rowuser = new User("profile/{$row->author}");
91 printf('<li id="%d">', $row->id);
92 printf('<strong>%s</strong> <small class=date>%s</small>',
93 $rowuser->html, showdate(preg_split('/\D/', $row->created))
95 printf("<blockquote>\n%s</blockquote>\n", $row->message);
96 if ($changes = json_decode($row->journal)) {
98 foreach ($changes as $change) {
100 if ($change->col == 'closed') {
101 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
104 printf("<em>%s</em> %s",
105 $journalcol[$change->col], sprintf(
106 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
107 (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
108 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
109 $change->old_value, $change->value
122 print '<form method="post" action="" enctype="multipart/form-data">';
123 if (isset($Issue) and $User->admin("edit {$Page->link}")) {
126 '<label for="%s">%s:</label> '
127 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
129 $journalcol['assign'],
130 htmlspecialchars($Issue->assign ?? '')
133 '<input type="hidden" name="%s" value="" />' .
134 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
135 . '<label for="%1$s"> %s</label>'."\n",
138 isset($Issue->closed) ? ' checked' : '',
145 '<p><label for="%s">%s:</label> '
146 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
147 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
150 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
152 "Bericht van {$User->login}",
155 print '<input type="submit" value="Plaatsen" />'."\n";
157 print '<script src="/upload/progress.js"></script>';