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 !empty($_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 if ($result = userupload($_FILES['image'], $target)) {
20 if (preg_match('(^image/)', $_FILES['image']['type'])) {
21 $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
24 $html .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
25 $result, basename($result)
30 $query = $Db->set('comments', [
31 'page' => $Page->link,
33 'author' => $User->login,
35 if (!$query->rowCount()) {
36 throw new Exception('Fout bij opslaan');
38 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
42 foreach (array_keys($journalcol) as $col) {
43 if (!isset($_POST[$col])) continue;
44 $row[$col] = $_POST[$col] ?: NULL;
46 if (isset($_POST['status'])) {
47 $reset = !empty($_POST['status']);
48 if (isset($Issue->closed) !== $reset) {
49 $row['closed'] = $reset ? ['now()'] : NULL;
52 $derived = ['updated' => ['now()']];
53 $filter = ['id = ? RETURNING *', $Issue->id];
54 $subquery = $Db->set('issues', $row + $derived, $filter);
56 if ($updated = $subquery->fetch()) {
57 foreach (array_keys($row) as $col) {
58 if ($updated->$col === $Issue->$col) continue; # unaltered
60 'comment_id' => $newcomment,
63 'old_value' => $Issue->$col,
64 'value' => $updated->$col,
71 $target = "/{$Page->link}/$newcomment#$newcomment";
72 abort($target, ($Page->api ? 200 : 303) . ' reply success');
73 $_POST['reply'] = NULL;
75 catch (Exception $e) {
77 abort(ucfirst($e->getMessage()), '500 reply error');
79 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
83 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
84 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
86 print '<ul class="replies">';
88 while ($row = $query->fetch()) {
89 $rowuser = new User("profile/{$row->author}");
90 printf('<li id="%d">', $row->id);
91 printf('<strong>%s</strong> <small class=date>%s</small>',
92 $rowuser->html, showdate(preg_split('/\D/', $row->created))
94 printf("<blockquote>\n%s</blockquote>\n", $row->message);
95 if ($changes = json_decode($row->journal)) {
97 foreach ($changes as $change) {
99 if ($change->col == 'closed') {
100 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
103 printf("<em>%s</em> %s",
104 $journalcol[$change->col], sprintf(
105 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
106 (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
107 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
108 $change->old_value, $change->value
121 print '<form method="post" action="" enctype="multipart/form-data">';
122 if (isset($Issue) and $User->admin("edit {$Page->link}")) {
125 '<label for="%s">%s:</label> '
126 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
128 $journalcol['assign'],
129 htmlspecialchars($Issue->assign ?? '')
132 '<input type="hidden" name="%s" value="" />' .
133 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
134 . '<label for="%1$s"> %s</label>'."\n",
137 isset($Issue->closed) ? ' checked' : '',
144 '<p><label for="%s">%s:</label> '
145 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
146 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
149 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
151 "Bericht van {$User->login}",
154 print '<input type="submit" value="Plaatsen" />'."\n";
156 print '<script src="/upload/progress.js"></script>';