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', [
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,
63 $_POST['reply'] = NULL;
65 catch (Exception $e) {
66 print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
70 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
71 $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
73 print '<ul class="replies">';
75 while ($row = $query->fetch()) {
76 $rowuser = new User("profile/{$row->author}");
78 printf('<strong>%s</strong> <small class=date>%s</small>',
79 $rowuser->html, showdate(preg_split('/\D/', $row->created))
81 printf("<blockquote>\n%s</blockquote>\n", $row->message);
82 if ($changes = json_decode($row->journal)) {
84 foreach ($changes as $change) {
86 if ($change->col == 'closed') {
87 printf('<em>%s</em>', isset($change->value) ? 'Gesloten' : 'Heropend');
90 printf("<em>%s</em> %s",
91 $journalcol[$change->col], sprintf(
92 !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
93 (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
94 'gewijzigd van <q>%s</q> naar <q>%s</q>'),
95 $change->old_value, $change->value
108 print '<form method="post" action="" enctype="multipart/form-data">';
109 if (isset($Issue) and $User->admin("edit $Page")) {
112 '<label for="%s">%s:</label> '
113 . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
115 $journalcol['assign'],
116 htmlspecialchars($Issue->assign ?? '')
119 '<input type="hidden" name="%s" value="" />' .
120 '<input type="checkbox" id="%1$s" name="%1$s" value="%s"%s />'
121 . '<label for="%1$s"> %s</label>'."\n",
124 isset($Issue->closed) ? ' checked' : '',
131 '<p><label for="%s">%s:</label> '
132 . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
133 'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
136 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
138 "Bericht van {$User->login}",
141 print '<input type="submit" value="Plaatsen" />'."\n";
142 print "</form></li>\n";