-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathedit-tag.php
More file actions
64 lines (49 loc) · 2.01 KB
/
Copy pathedit-tag.php
File metadata and controls
64 lines (49 loc) · 2.01 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
53
54
55
56
57
58
59
60
61
62
63
64
<?php
if(DB_READONLY) showReadonlyPage();
if (empty($user)) {
header('Location: /login');
exit();
}
if ($user['roleCode'] !== 'admin' && $user['roleCode'] !== 'moderator') showErrorPage(HTTP_FORBIDDEN);
$tagId = $_REQUEST['tagid'] ?? 0;
$save = !empty($_POST['save']);
$delete = !empty($_POST['delete']);
if ($save || $delete) {
validateActionToken();
}
if ($save) {
$isNew = false;
$color = intval(substr($_POST['color'], 1), 16) << 8 | 0x000000FF;
$name = strip_tags($_POST['name']);
$text = strip_tags($_POST['text']);
if (!$tagId) {
$isNew = true;
$con->execute('INSERT INTO tags (name, text, color, kind) VALUES (?, ?, ?, 2)', [$name, $text, $color]);
addMessage(MSG_CLASS_OK, 'Tag created.');
if (!empty($_POST['saveandback'])) header('Location: /list/tag?saved=1');
else header("Location: /edit/tag?tagid=$tagId");
exit();
} else {
$con->execute('UPDATE tags SET name = ?, text = ?, color = ? WHERE tagId = ?', [$name, $text, $color, $tagId]);
addMessage(MSG_CLASS_OK, 'Tag saved.');
if (!empty($_POST['saveandback'])) header('Location: /list/tag?saved=1');
else forceRedirectAfterPOST();
exit();
}
}
else if ($delete) {
$con->execute('DELETE FROM tags WHERE tagId = ?', [$tagId]);
header('Location: /list/tag?deleted=1');
exit();
}
if ($tagId) {
$row = $con->getRow("SELECT *, LPAD(HEX(color), 8, '0') as color FROM tags WHERE tagId = ?", [$_REQUEST['tagid']]);
} else {
$row = ['tagId' => 0, 'name' => '', 'text' => '', 'color' => '000000'];
}
cspPushAllowedInlineHandlerHash('sha256-nTlTeikEEupAQmSPlHWFcoJvMdPCIBu+Zu+G64E7uC4='); // javascript:submitForm(0)
cspPushAllowedInlineHandlerHash('sha256-XKuSPEJjbu3T+mAY9wlP6dgYQ4xJL1rP4m3GrDwZ68c='); // javascript:submitForm(1)
cspPushAllowedInlineHandlerHash('sha256-HAn3sRp/DKqkhccjWmi+mt2NzQCTHLzeSlhZ0T2cDuY='); // javascript:submitDelete()
$view->assign('row', $row);
$view->assign('headerHighlight', HEADER_HIGHLIGHT_ADMIN_TOOLS, null, true);
$view->display("edit-tag");