-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcontent.php
More file actions
74 lines (58 loc) · 1.75 KB
/
content.php
File metadata and controls
74 lines (58 loc) · 1.75 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
65
66
67
68
69
70
71
72
73
74
<?php
require_once __DIR__ . "/../../resources/autoload.php";
use UnityWebPortal\lib\UnityHTTPD;
if (!$USER->isAdmin()) {
UnityHTTPD::forbidden("not an admin");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
UnityHTTPD::validatePostCSRFToken();
if (!empty($_POST["pageSel"])) {
$SQL->editPage($_POST["pageSel"], $_POST["content"], $USER);
}
}
require $LOC_HEADER;
?>
<h1>Page Content Management</h1>
<hr>
<form id="pageForm" method="POST" action="">
<?php echo UnityHTTPD::getCSRFTokenHiddenFormInput(); ?>
<select name="pageSel" required>
<option value="" selected disabled hidden>Select page...</option>
<?php
$pages = $SQL->getPages();
foreach ($pages as $page) {
echo "<option value='" . $page["page"] . "'>" . $page["page"] . "</option>";
}
?>
</select>
<br><br>
<textarea name="content" id="editor" form="pageForm"></textarea>
<br><br>
<input type="submit" value="Edit Page">
</form>
<script>
ClassicEditor
.create(document.querySelector('#editor'), {})
.then(editor => {
mainEditor = editor;
})
.catch(error => {
console.error(error)
});
const url = '<?php echo getURL("admin/ajax/get_page_contents.php"); ?>';
$("#pageForm > select[name=pageSel]").change(function(e) {
$.ajax({
url: `${url}?pageid=` + $(this).val(),
dataType: "json",
success: function(result) {
mainEditor.setData(result.content);
}});
});
$("#pageForm").on("submit", function(e) {
if (!confirm("Are you sure you want to edit this page?")) {
e.preventDefault();
}
})
</script>
<?php
require $LOC_FOOTER;