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 $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
23 $query = $Db->set('comments', [
24 'page' => $Page->link,
26 'author' => $User->login,
28 if (!$query->rowCount()) {
29 throw new Exception('Fout bij opslaan');
31 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
35 foreach (array_keys($journalcol) as $col) {
36 if (!isset($_POST[$col])) continue;
37 $row[$col] = $_POST[$col] ?: NULL;
39 if (isset($_POST['status'])) {
40 $reset = !empty($_POST['status']);
41 if (isset($Issue->closed) !== $reset) {
42 $row['closed'] = $reset ? ['now()'] : NULL;
45 $derived = ['updated' => ['now()']];
46 $filter = ['id = ? RETURNING *', $Issue->id];
47 $subquery = $Db->set('issues', $row + $derived, $filter);
49 if ($updated = $subquery->fetch()) {
50 foreach (array_keys($row) as $col) {
51 if ($updated->$col === $Issue->$col) continue; # unaltered
53 'comment_id' => $newcomment,
56 'old_value' => $Issue->$col,
57 'value' => $updated->$col,
64 $target = "/{$Page->link}/$newcomment#$newcomment";
65 abort($target, ($Page->api ? 200 : 303) . ' reply success');
66 $_POST['reply'] = NULL;
68 catch (Exception $e) {
70 abort(ucfirst($e->getMessage()), '500 reply error');
72 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
76 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
77 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
79 print '<ul class="replies">';
81 while ($row = $query->fetch()) {
82 $rowuser = new User("profile/{$row->author}");
83 printf('<li id="%d">', $row->id);
84 printf('<strong>%s</strong> <small class=date>%s</small>',
85 $rowuser->html, showdate(preg_split('/\D/', $row->created))
87 printf("<blockquote>\n%s</blockquote>\n", $row->message);
88 if ($changes = json_decode($row->journal)) {
90 foreach ($changes as $change) {
92 if ($change->col == 'closed') {
93 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
96 printf("<em>%s</em> %s",
97 $journalcol[$change->col], sprintf(
98 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
99 (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
100 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
101 $change->old_value, $change->value
114 print '<form method="post" action="" enctype="multipart/form-data">';
115 if (isset($Issue) and $User->admin("edit {$Page->link}")) {
118 '<label for="%s">%s:</label> '
119 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
121 $journalcol['assign'],
122 htmlspecialchars($Issue->assign ?? '')
125 '<input type="hidden" name="%s" value="" />' .
126 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
127 . '<label for="%1$s"> %s</label>'."\n",
130 isset($Issue->closed) ? ' checked' : '',
137 '<p><label for="%s">%s:</label> '
138 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
139 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
142 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
144 "Bericht van {$User->login}",
147 print '<input type="submit" value="Plaatsen" />'."\n";
149 print '<script src="/upload/progress.js"></script>';