2 global $User, $Db, $Issue;
3 require_once 'database.inc.php';
6 'assign' => 'Toegewezen aan',
7 'subject' => 'Onderwerp',
11 require_once 'upload.inc.php';
14 if (isset($_POST['reply']) and $body = $_POST['reply']) {
15 $reply['raw'] = $body;
16 $reply['message'] = messagehtml($body);
18 if ($_FILES and !empty($_FILES['image'])) {
19 $target = 'data/upload';
20 if (!file_exists($target)) {
21 throw new Exception("er is geen uploadmap aanwezig op $target");
23 $target .= '/' . $User->login;
24 if ($result = userupload($_FILES['image'], $target)) {
25 $reply['raw'] .= "/$result";
26 if (preg_match('(^image/)', $_FILES['image']['type'])) {
27 $reply['message'] .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
30 $reply['message'] .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
31 $result, basename($result)
36 $query = $Db->set('comments', $reply + [
37 'page' => $Page->link,
38 'author' => $User->login,
40 if (!$query->rowCount()) {
41 throw new Exception('Fout bij opslaan');
43 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
47 foreach (array_keys($journalcol) as $col) {
48 if (!isset($_POST[$col])) continue;
49 $row[$col] = $_POST[$col] ?: NULL;
51 if (isset($_POST['status'])) {
52 $reset = !empty($_POST['status']);
53 if (isset($Issue->closed) !== $reset) {
54 $row['closed'] = $reset ? ['now()'] : NULL;
57 $derived = ['updated' => ['now()']];
58 $filter = ['id = ? RETURNING *', $Issue->id];
59 $subquery = $Db->set('issues', $row + $derived, $filter);
61 if ($updated = $subquery->fetch()) {
62 foreach (array_keys($row) as $col) {
63 if ($updated->$col === $Issue->$col) continue; # unaltered
65 'comment_id' => $newcomment,
68 'old_value' => $Issue->$col,
69 'value' => $updated->$col,
76 $target = "/{$Page->link}/$newcomment#$newcomment";
77 abort($target, ($Page->api ? 200 : 303) . ' reply success');
78 $_POST['reply'] = NULL;
80 catch (Exception $e) {
82 abort(ucfirst($e->getMessage()), '500 reply error');
84 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
88 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
89 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
91 print '<ul class="replies">';
94 while ($row = $query->fetch()) {
95 $rowuser = new User("profile/{$row->author}");
96 printf('<li id="%d">', $row->id);
97 printf('<strong>%s</strong> <small class=date>%s</small>',
98 $rowuser->html, showdate(preg_split('/\D/', $row->created))
100 if ($html = $row->message) {
101 $html = preg_replace('/(?<=<img )/',
102 $imagecount > 2 ? 'loading="lazy" ' : '', $html, -1, $found);
103 $imagecount += $found;
104 printf("<blockquote>\n%s</blockquote>\n", $html);
106 if ($changes = json_decode($row->journal)) {
108 foreach ($changes as $change) {
110 if ($change->col == 'closed') {
111 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
114 printf("<em>%s</em> %s",
115 $journalcol[$change->col], sprintf(
116 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
117 (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
118 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
119 $change->old_value, $change->value
132 print '<form method="post" action="" enctype="multipart/form-data">';
133 if (isset($Issue) and $User->admin("edit {$Page->link}")) {
136 '<label for="%s">%s:</label> '
137 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
139 $journalcol['assign'],
140 htmlspecialchars($Issue->assign ?? '')
143 '<input type="hidden" name="%s" value="" />' .
144 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
145 . '<label for="%1$s"> %s</label>'."\n",
148 isset($Issue->closed) ? ' checked' : '',
155 '<p><label for="%s">%s:</label> '
156 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
157 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
160 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
162 "Bericht van {$User->login}",
165 print '<input type="submit" value="Plaatsen" />'."\n";
167 print '<script src="/upload/progress.js"></script>';