-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnote-act.php
More file actions
52 lines (52 loc) · 1.58 KB
/
Copy pathnote-act.php
File metadata and controls
52 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
$import = ['auth', 'csrf', 'view', 'html', 'note'];
require __DIR__ . '/lib/boot.php';
$app->auth->requireUser();
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !$app->csrf->check()) {
$app->redirect('');
}
$uid = $app->auth->id();
if (isset($_POST['pin'])) {
$app->note->pin((int) $_POST['pin'], $uid, true);
$app->redirect('notes.php');
}
if (isset($_POST['unpin'])) {
$app->note->pin((int) $_POST['unpin'], $uid, false);
$app->redirect('notes.php');
}
if (isset($_POST['undash'])) {
$app->note->pin((int) $_POST['undash'], $uid, false);
$app->redirect('');
}
if (isset($_POST['memosubmit'])) {
if (!$app->auth->atLeast('editor')) {
$app->redirect('');
}
$bid = (int) ($_POST['b'] ?? 0);
$back = $bid > 0 ? 'memos-editor.php?b=' . $bid : 'memos-editor.php';
$op = (string) $_POST['memosubmit'];
if ($op !== 'delete') {
$app->view->setFlash('Nothing was changed. Confirm the action if asked.', false);
$app->redirect($back);
}
$ids = [];
foreach ($_POST as $k => $v) {
if (str_starts_with((string) $k, 'bulk_') && filter_var($v, FILTER_VALIDATE_INT)) {
$ids[] = (int) $v;
}
}
if ($ids === []) {
$app->view->setFlash('Select at least one memo.', false);
$app->redirect($back);
}
$ok = 0;
foreach ($ids as $id) {
if ($app->note->deleteOwned($id, $uid)) {
$ok++;
}
}
$app->view->setFlash($ok === 1 ? 'Memo deleted.' : $ok . ' memos deleted.', false);
$app->redirect($back);
}
$app->redirect('');