-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnotices.php
154 lines (125 loc) · 4.74 KB
/
notices.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
require_once "../../resources/autoload.php";
if (!$USER->isAdmin()) {
die();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
switch ($_POST["form_type"]) {
case "newNotice":
$SQL->addNotice($_POST["title"], $_POST["date"], $_POST["content"], $_POST["expiry"], $USER);
break;
case "editNotice":
$SQL->editNotice($_POST["id"], $_POST["title"], $_POST["date"], $_POST["content"], $_POST["expiry"]);
break;
case "delNotice":
$SQL->deleteNotice($_POST["id"]);
break;
}
}
include $LOC_HEADER;
?>
<h1>Cluster Notice Management</h1>
<hr>
<h5>Create/Edit Cluster Notice</h5>
<button style='display: none;' class='btnClear'>Create New Notice Instead</button>
<form action="" method="POST" id="noticeForm">
<input type="hidden" name=id>
<input type="hidden" name="form_type" value="newNotice">
<input type="text" name="title" placeholder="Notice Title">
<input type="date" name="date">
<textarea name="content" id="editor" form="noticeForm"></textarea>
<input style='display: inline-block;' type="submit" value="Create Notice">
</form>
<div class='example notice'>
<span class='noticeTitle'>Edit Title To Change</span>
<span class='noticeDate'>Edit Date to Change</span>
<div class='noticeText'><p>Edit Message to Change</p></div>
</div>
<hr>
<h5>Existing Notices</h5>
<?php
$notices = $SQL->getNotices();
foreach ($notices as $notice) {
echo "<div class='notice' data-id='" . $notice["id"] . "'>";
echo "<span class='noticeTitle'>" . $notice["title"] . "</span>";
echo "<span class='noticeDate'>" . date('Y-m-d', strtotime($notice["date"])) . "</span>";
echo "<div class='noticeText'>" . $notice["message"] . "</div>";
echo "<button class='btnEdit'>Edit</button>";
echo
"<form style='display: inline-block; margin-left: 10px;' method='POST' action=''>
<input type='hidden' name='form_type' value='delNotice'>
<input type='hidden' name='id' value='" . $notice["id"] . "'>
<input type='submit' value='Delete'>
</form>";
echo "</div>";
}
?>
<script>
ClassicEditor
.create(document.querySelector('#editor'), {
//toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo', 'numberedList', 'bulletedList' ]
removePlugins: ['image']
})
.then(editor => {
mainEditor = editor;
editor.model.document.on('change:data', () => {
$("div.example > div").html(editor.getData());
});
})
.catch(error => {
console.error(error)
});
$('input[name=title]').on('input', function(e) {
$("div.example > span.noticeTitle").text($(this).val());
});
$('input[name=date]').on('input', function(e) {
$("div.example > span.noticeDate").text($(this).val());
});
$('button.btnEdit').on('click', function(e) {
let cur_id = $("#noticeForm > input[name=id]").val();
let cur_title = $("#noticeForm > input[name=title]").val();
let cur_date = $("#noticeForm > input[name=date]").val();
let cur_text = mainEditor.getData();
var hasUnsavedWork =
cur_id != "" ||
cur_title != "" ||
cur_date != "" ||
cur_text != "";
if (hasUnsavedWork) {
if (!confirm("Are you sure you want to clear your unsaved work?")) {
return;
}
}
var id = $(this).parent().attr("data-id");
var title = $(this).siblings("span.noticeTitle").text();
var date = $(this).siblings("span.noticeDate").text();
var text = $(this).siblings("div.noticeText").html();
$("#noticeForm > input[name=id]").val(id);
$("#noticeForm > input[name=title]").val(title);
$("#noticeForm > input[name=date]").val(date);
$("#noticeForm > input[name=form_type").val("editNotice")
mainEditor.setData(text);
$("#noticeForm > input[type=submit]").val("Edit Notice");
$("button.btnClear").show();
});
$('button.btnClear').on('click', function(e) {
if (!confirm("Are you sure you want to clear this edit?")) {
return;
}
$("#noticeForm > input[name=id]").val("");
$("#noticeForm > input[name=title]").val("");
$("#noticeForm > input[name=date]").val("");
$("#noticeForm > input[name=form_type").val("newNotice")
mainEditor.setData("");
$("#noticeForm > input[type=submit]").val("Create Notice");
$(this).hide();
});
$("#noticeForm").on("submit", function(e) {
if (!confirm("Are you sure you want to add/edit notice?")) {
e.preventDefault();
return;
}
});
</script>
<?php
include $LOC_FOOTER;