/
setnotify.php
326 lines (326 loc) · 18.2 KB
/
setnotify.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
require_once("res/utils.php");
session_start();
$res = Client::installResult();
if (!isset($_SESSION["client"])) {
header("Location: unauthenticated.php");
}
$client = $_SESSION["client"];
if(isset($_POST['ntype'])) {
$option = $_POST['ntype'];
if($option == 'addcategory') $res = $client->addCategory($_POST["name"], $_POST["summary"]);
else if ($option == 'editcategory') $res = $client->editCategory($_POST["id"], $_POST["summary"]);
else if ($option == 'delcategory') $res = $client->delCategory($_POST["todel"]);
else if ($option == 'adddaily') $res = $client->addDaily($_POST["name"], $_POST["summary"], $_POST["category_id"]);
else if ($option == 'editdaily') $res = $client->editDaily($_POST["id"], $_POST["summary"], $_POST["category_id"]);
else if ($option == 'deldaily') $res = $client->delDaily($_POST["todel"]);
else if ($option == 'addweekly') $res = $client->addWeekly($_POST["name"], $_POST["day"], $_POST["summary"], $_POST["category_id"]);
else if ($option == 'editweekly') $res = $client->editWeekly($_POST["id"], $_POST["day"], $_POST["summary"], $_POST["category_id"]);
else if ($option == 'delweekly') $res = $client->delWeekly($_POST["todel"]);
}
const NOTI_EMPTY = '<div class="nempty"><div>You have not added any notifiers here.</div> <div>Please add some.</div></div>';
function addRow($arr) {
echo '<tr>';
foreach($arr as $val) {
echo "<td>$val</td>";
}
echo '</tr>';
}
function addOption($id, $val, $selectedId = -1) {
$sel = $id === $selectedId ? 'selected="selected"' : "";
echo "<option value='$id' $sel>$val</option>";
}
function addCheckbox($id, $val, $name) {
echo "<input type='checkbox' name=".$name."[]' value='$id'>$val</input><br />";
}
$day = Array(
'sun' => 'Sunday',
'mon' => 'Monday',
'tue' => 'Tuesday',
'wed' => 'Wednesday',
'thu' => 'Thursday',
'fri' => 'Friday',
'sat' => 'Saturday',
);
$client->loadNotifiers();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="scripts/jquery.js"></script>
<link type="image/icon-x" href="favicon.png" rel="shortcut icon" />
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<link href="styles/commpane.css" rel="stylesheet" type="text/css" />
<link href="styles/setnotify.css" rel="stylesheet" type="text/css" />
<title>Notifier</title>
<script type="text/javascript">
var ndat = [];
<?php
echo 'ndat["category"] = '.json_encode($client->category).";\n";
echo 'ndat["dailynots"] = '.json_encode($client->dailynots)."\n";
echo 'ndat["weeklynots"] = '.json_encode($client->weeklynots)."\n";
echo 'ndat["yearlynots"] = '.json_encode($client->yearlynots)."\n";
?>
$(document).ready(function(e) {
$(".selectall").change(function(e) {
var chk = $(this).attr("checked");
$(this).siblings("input:checkbox").prop('checked', $(this).prop("checked"));
});
$(".notioption .button").click(function(e) {
$elem = $(this).siblings(".body");
$(".notioption .body").not($elem).slideUp(250);
$elem.slideToggle(250);
});
});
function findWithId(matcher, type, todo) {
var id = matcher;
var arr = ndat[type];
for(var i = 0; i < arr.length; i++) {
var obj = arr[i];
if(obj["id"] == id) {
todo(obj);
break;
}
}
}
</script>
</head>
<body>
<?php $tab="Set Notifier"; include("templateinpre.php"); ?>
<div id="inrem">
<?php
if($res["process"] != Client::PROCESS_NONE) {
echo '<div id="message" class="'.(($res["code"] != Client::CODE_SUCCESS) ?
"failure":"success").'" >'.$res["message"].'</div>';
}
if(count($client->category) != 0) { ?>
<div id="dailynot" class="nblock">
<div class="nblockhead"> Daily notifiers </div>
<div class="nblockrem"><div class="notielems">
<?php
if (count($client->dailynots) == 0) {
echo NOTI_EMPTY;
} else {
?>
<table class="noti" width="100%">
<tr><th>Name</th><th>Category</th><th>Summary</th></tr>
<?php foreach($client->dailynots as $r){addRow(Array($r['name'], $r['category_name'], $r['summary']));} ?>
</table>
<?php } ?>
<div class="notioptions">
<div class="notiadd notioption">
<div class="button">Add</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="adddaily" />
<label for="name">Name</label>
<input type="text" name="name" placeholder="Newspaper etc" required="required" />
<label for="summary">Summary</label>
<textarea name="summary" placeholder="Read news paper on time etc."></textarea>
<label for="category_id">Category</label>
<select name="category_id">
<?php foreach($client->category as $r) addOption($r['id'], $r['name']); ?>
</select>
<input type="submit" value="Add" />
</form>
</div>
</div>
<?php if(count($client->dailynots) != 0) { ?>
<div class="notiedit notioption">
<div class="button">Edit</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="editdaily" />
<label for="id">Name</label>
<select name="id" class="editor">
<?php foreach($client->dailynots as $r) addOption($r['id'], $r['name']); ?>
</select>
<label for="summary">Summary</label>
<textarea name="summary"><?php echo $client->dailynots[0]["summary"] ?></textarea>
<select name="category_id">
<?php foreach($client->category as $r) addOption($r['id'], $r['name']); ?>
</select>
<input type="submit" value="Edit" />
</form>
<script type="text/javascript">
$("#dailynot select.editor").change(function(e) {
var elem = $(this);
findWithId($(elem).val(), "dailynots", function(obj){
$(elem).siblings("textarea[name='summary']").val(obj["summary"]);
$(elem).siblings("select[name='category_id']").val(obj["category_id"]);
});
});
</script>
</div>
</div>
<div class="notidel notioption">
<div class="button">Delete</div>
<div class="body">
<form method="post" onsubmit="return confirm('Are you sure you want to delete this notifier? \nDeleting it will also delete all the entries related to it.');">
<input type="hidden" name="ntype" value="deldaily" />
<?php foreach($client->dailynots as $r) addCheckbox($r['id'], $r['name'], "todel"); ?>
<input type="checkbox" class="selectall">Select all</input>
<input type="submit" value="Delete" />
</form>
</div>
</div>
<?php } ?>
</div>
</div></div>
</div>
<div id="weeklynot" class="nblock">
<div class="nblockhead"> Weekly notifiers </div>
<div class="nblockrem"><div class="notielems">
<?php
if (count($client->weeklynots) == 0) {
echo NOTI_EMPTY;
} else {
?>
<table class="noti">
<tr><th>Name</th><th>Day</th><th>Category</th><th>Summary</th></tr>
<?php foreach($client->weeklynots as $r){addRow(Array($r['name'], $day[$r['day']], $r['category_name'], $r['summary']));} ?>
</table>
<?php } ?>
<div class="notioptions">
<div class="notiadd notioption">
<div class="button">Add</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="addweekly" />
<label for="name">Name</label>
<input type="text" name="name" placeholder="TV Program etc" required="required" />
<label for="day">Day</label>
<select name="day">
<?php foreach($day as $k => $v) {addOption($k, $v);} ?>
</select>
<label for="summary">Summary</label>
<textarea name="summary" placeholder="Watch TV serial etc."></textarea>
<label for="category_id">Category</label>
<select name="category_id">
<?php foreach($client->category as $r) addOption($r['id'], $r['name']); ?>
</select>
<input type="submit" value="Add" />
</form>
</div>
</div>
<?php if(count($client->weeklynots) != 0) { ?>
<div class="notiedit notioption">
<div class="button">Edit</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="editweekly" />
<label for="id">Name</label>
<select name="id" class="editor">
<?php foreach($client->weeklynots as $r) addOption($r['id'], $r['name']); ?>
</select>
<label for="day">Day</label>
<select name="day">
<?php foreach($day as $k => $v) {addOption($k, $v, $client->weeklynots[0]["day"]);} ?>
</select>
<label for="summary">Summary</label>
<textarea name="summary"><?php echo $client->weeklynots[0]["summary"] ?></textarea>
<select name="category_id">
<?php foreach($client->category as $r) addOption($r['id'], $r['name'], $client->weeklynots[0]["category_id"]); ?>
</select>
<input type="submit" value="Edit" />
</form>
<script type="text/javascript">
$("#weeklynot select.editor").change(function(e) {
var elem = $(this);
findWithId($(elem).val(), "weeklynots", function(obj){
$(elem).siblings("textarea[name='summary']").val(obj["summary"]);
$(elem).siblings("select[name='day']").val(obj["day"]);
$(elem).siblings("select[name='category_id']").val(obj["category_id"]);
});
});
</script>
</div>
</div>
<div class="notidel notioption">
<div class="button">Delete</div>
<div class="body">
<form method="post" onsubmit="return confirm('Are you sure you want to delete this notifier? \nDeleting it will also delete all the entries related to it.');">
<input type="hidden" name="ntype" value="delweekly" />
<?php foreach($client->weeklynots as $r) addCheckbox($r['id'], $r['name'], "todel"); ?>
<input type="checkbox" class="selectall">Select all</input>
<input type="submit" value="Delete" />
</form>
</div>
</div>
<?php } ?>
</div>
</div></div>
</div>
<?php } ?>
<div id="category" class="nblock">
<div class="nblockhead"> Categories </div>
<div class="nblockrem"><div class="notielems">
<?php
if (count($client->category) == 0) {
echo '<div class="nempty">Please add some categories of notifiers before starting up.</div>';
} else {
?>
<table class="noti">
<tr><th>Name</th><th>Summary</th></tr>
<?php foreach($client->category as $r){addRow(Array($r['name'], $r['summary']));} ?>
</table>
<?php } ?>
<div class="notioptions">
<div class="notiadd notioption">
<div class="button">Add</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="addcategory" />
<label for="name">Name</label>
<input type="text" name="name" placeholder="Important, Not necessary, College related etc." required="required" />
<label for="summary">Summary</label>
<textarea name="summary" placeholder="Must do, It is important etc." required="required"></textarea>
<input type="submit" value="Add" />
</form>
</div>
</div>
<?php if(count($client->category) != 0) { ?>
<div class="notiedit notioption">
<div class="button">Edit</div>
<div class="body">
<form method="post">
<input type="hidden" name="ntype" value="editcategory" />
<label for="id">Name</label>
<select name="id" class="editor">
<?php foreach($client->category as $r) addOption($r['id'], $r['name'], $client->category[0]["id"]); ?>
</select>
<label for="summary">Summary</label>
<textarea name="summary"><?php echo $client->category[0]["summary"] ?></textarea>
<input type="submit" value="Edit" />
</form>
<script type="text/javascript">
$("#category select.editor").change(function(e) {
var elem = this;
findWithId($(elem).val(), "category", function(obj) {
$(elem).siblings("textarea").html(obj["summary"]);
});
});
</script>
<div id="log"></div>
</div>
</div>
<div class="notidel notioption">
<div class="button">Delete</div>
<div class="body">
<form method="post" onsubmit="return confirm('Are you sure? Deleting category will also delete all the entries related to it.');">
<input type="hidden" name="ntype" value="delcategory" />
<?php foreach($client->category as $r) addCheckbox($r['id'], $r['name'], "todel"); ?>
<input type="checkbox" class="selectall">Select all</input>
<input type="submit" value="Delete" />
</form>
</div>
</div>
<?php } ?>
</div>
</div></div>
</div>
</div>
<?php include("templateinpost.php"); ?>
</body>
</html>