-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaff.php
464 lines (374 loc) · 15.9 KB
/
staff.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php
session_start();
if (!isset($_SESSION['id']) || $_SESSION['priv'] != "staff") {
header("Location: index.php");
die();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
unset($_SESSION['name']);
unset($_SESSION['id']);
unset($_SESSION['priv']);
session_destroy();
header("Location: index.php");
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="An initiative by CWIT to let students have online access to study material and notes. Find notes by department, year and subject.">
<meta name="author" content="Aniket Bhadane">
<link rel="icon" href="favicon.ico">
<title>CWIT Learning Management System</title>
<!-- Bootstrap core CSS -->
<link href="docs/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="docs/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="docs/ext_css.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">CWIT LMS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<p class="navbar-text">Signed in as <?php echo $_SESSION['name'] . " (" . $_SESSION['priv'] . ")";?></p>
<form class="navbar-form navbar-right" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<button id="btnLogout" type="submit" class="btn btn-success">Logout</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</nav>
<!--Upload-->
<div class="container" id="upload_container">
<div class="jumbotron">
<h2>Upload Notes</h2>
<form id="upload_form" enctype="multipart/form-data">
<div class="row">
<div class="form-group col-md-3">
<select id="dept_select_u" name = "dept" class="form-control">
<option selected disabled>Select Department</option>
<option value="comp">Computer</option>
<option value="electrical">Electrical</option>
<option value="mech">Mechanical</option>
<option value="civil">Civil</option>
<option value="electronics">Electronics</option>
</select>
</div>
<div class="form-group col-md-3">
<select id="year_select_u" name = "year" class="form-control">
<option selected disabled>Select Year</option>
<option value="fy">FY</option>
<option value="sy">SY</option>
<option value="ty">TY</option>
</select>
</div>
<div class="form-group col-md-3">
<select id="subject_select_u" name = "subject" class="form-control">
<option selected disabled>Select Subject</option>
</select>
</div>
<div class="form-group col-md-3">
<select id="chapter_select_u" name = "chapter" class="form-control">
<option selected disabled>Select Chapter</option>
<option value="ch1">Ch1</option>
<option value="ch2">Ch2</option>
<option value="ch3">Ch3</option>
<option value="ch4">Ch4</option>
<option value="ch5">Ch5</option>
<option value="ch6">Ch6</option>
</select>
</div>
</div>
<div class="form-group">
<input type="file" name="myFile" />
</div>
<div class="alert alert-danger hidden" id="missing_select_upload" role="alert"></div>
<input type="submit" name="upload" value="Upload" class="btn btn-primary" />
</form>
</div>
</div>
<!--View-->
<div class="container">
<div class="jumbotron">
<h2>View Notes</h2>
<div class="row">
<div class="form-group col-md-4">
<select id="dept_select" class="form-control">
<option selected disabled>Select Department</option>
<option value="comp">Computer</option>
<option value="electrical">Electrical</option>
<option value="mech">Mechanical</option>
<option value="civil">Civil</option>
<option value="electronics">Electronics</option>
</select>
</div>
<div class="form-group col-md-4">
<select id="year_select" class="form-control">
<option selected disabled>Select Year</option>
<option value="fy">FY</option>
<option value="sy">SY</option>
<option value="ty">TY</option>
</select>
</div>
<div class="form-group col-md-4">
<select id="subject_select" class="form-control">
<option selected disabled>Select Subject</option>
</select>
</div>
</div>
<div class="alert alert-danger hidden" id="missing_select" role="alert"></div>
<button id="btnSubmit" class="btn btn-primary">Submit</button>
</div>
</div>
<div class="container-fluid hidden" id="results_container">
<p id="results_desc"></p>
<div class="alert alert-info ch_results" role="alert">Chapter 1</div>
<div class="results" id="ch1"></div>
<div class="alert alert-info ch_results" role="alert">Chapter 2</div>
<div class="results" id="ch2"></div>
<div class="alert alert-info ch_results" role="alert">Chapter 3</div>
<div class="results" id="ch3"></div>
<div class="alert alert-info ch_results" role="alert">Chapter 4</div>
<div class="results" id="ch4"></div>
<div class="alert alert-info ch_results" role="alert">Chapter 5</div>
<div class="results" id="ch5"></div>
<div class="alert alert-info ch_results" role="alert">Chapter 6</div>
<div class="results" id="ch6"></div>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">Made by <a href="https://in.linkedin.com/in/aniketbhadane" target="_blank">Aniket Bhadane</a> for CWIT.</p>
</div>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="docs/jquery.min.js"><\/script>')</script>
<script src="docs/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="docs/ie10-viewport-bug-workaround.js"></script>
<script>
$(function(){
$("#dept_select_u").change(function () {
var dept = this.value;
var year = $('#year_select_u').val();
get_subjects_list(dept, year, "#subject_select_u");
});
$("#year_select_u").change(function () {
var year = this.value;
var dept = $('#dept_select_u').val();
get_subjects_list(dept, year, "#subject_select_u");
});
$("#dept_select").change(function () {
var dept = this.value;
var year = $('#year_select').val();
get_subjects_list(dept, year, "#subject_select");
});
$("#year_select").change(function () {
var year = this.value;
var dept = $('#dept_select').val();
get_subjects_list(dept, year, "#subject_select");
});
function get_subjects_list(dept, year, dropdown) {
$.ajax({
url: "fetch_subjects.php",
type: "POST",
beforeSend: function() {
$(dropdown).empty();
$(dropdown).append("<option selected disabled>Please Wait</option>");
$(dropdown).prop('disabled', true);
},
data: {
dept: dept,
year: year,
}
}).done(function (data) {
//alert(data);
var arr = JSON.parse(data);
$(dropdown).empty();
$(dropdown).prop('disabled', false);
$(dropdown).append("<option selected disabled>Select Subject</option>");
$.each(arr, function(key, val) {
if(val!="")
$(dropdown).append("<option value='" + val + "'>" + val + "</option>");
});
}).fail(function( jqXHR, textStatus, errorThrown ) {
alert( "Request failed: " + textStatus + " , " + errorThrown );
});
}
$("#btnSubmit").click(function(){
var dept = $('#dept_select').val();
var year = $('#year_select').val();
var subj_code = $('#subject_select').val();
var missing = "Missing";
if(dept == null)
missing = missing + " Department,"
if(year == null)
missing = missing + " Year,"
if(subj_code == null)
missing = missing + " Subject,"
if(missing != "Missing") {
missing = missing.slice(0, -1);
$('#missing_select').empty();
$('#missing_select').removeClass('hidden').addClass('show');
$('#missing_select').append(missing);
return;
}
$.ajax({
url: "fetch_links.php",
type: "POST",
data: {
dept: dept,
year: year,
subj_code: subj_code,
}
}).done(function (data) {
// append(), after(), before()
//alert(data);
$("#results_desc").text("Showing results for " + dept + " " + year + " " + subj_code);
$(".results").empty();
$('#results_container').removeClass('hidden').addClass('show');
$('#missing_select').removeClass('show').addClass('hidden');
var arr = JSON.parse(data);
var i = 0;
while(arr[i].split("\\").slice(-2, -1)[0] == "ch1") {
$("#ch1").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
while(arr[i].split("\\").slice(-2, -1)[0] == "ch2") {
$("#ch2").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
while(arr[i].split("\\").slice(-2, -1)[0] == "ch3") {
$("#ch3").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
while(arr[i].split("\\").slice(-2, -1)[0] == "ch4") {
$("#ch4").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
while(arr[i].split("\\").slice(-2, -1)[0] == "ch5") {
$("#ch5").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
while(arr[i].split("\\").slice(-2, -1)[0] == "ch6") {
$("#ch6").append("<div class='row note'><div class='form-group col-md-offset-1 col-md-9'><a class='btn btn-default' role='button' href = '" + arr[i] + "' target='_blank'>" + arr[i].split("\\").pop() + "</a></div>"
+ "<div class='form-group col-md-2'><button class='deleteNotes btn btn-default' value='" + arr[i] + "'>DELETE</button></div></div>");
i++;
}
/*for(var i = 0; i < arr.length; i++) {
$("#results").append("<a href = '" + arr[i] + "'>" + arr[i].split("\\").pop() + "</a><br />");
}*/
}).fail(function( jqXHR, textStatus, errorThrown ) {
alert( "Request failed: " + textStatus + " , " + errorThrown );
});
});
$(document).on("click", ".deleteNotes", function(){
if(confirm("Do you really want to delete?")) {
var link = $(this).val();
$.ajax({
url: "delete_notes.php",
type: "POST",
data: {
link: link,
}
}).done(function (data) {
if(data == "Success")
$("#btnSubmit").click();
else
alert(data);
}).fail(function( jqXHR, textStatus, errorThrown ) {
alert( "Request failed: " + textStatus + " , " + errorThrown );
});
}
});
// Variable to hold request
var request;
// Bind to the submit event of our form
$("#upload_form").submit(function(event){
// Prevent default posting of form
event.preventDefault();
// Abort any pending request
if (request) {
request.abort();
}
var formData = new FormData($(this)[0]);
// setup some local variables
var $form = $(this);
// Let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// Serialize the data in the form
//var serializedData = $form.serialize();
// Let's disable the inputs for the duration of the Ajax request.
// Note: we disable elements AFTER the form data has been serialized.
// Disabled form elements will not be serialized.
$inputs.prop("disabled", true);
// Fire off the request to upload.php
request = $.ajax({
url: "upload.php",
type: "POST",
data: formData, // earlier was serializedData, but it does not support sending files, hence using formData
contentType: false,
processData: false //jQuery processes the data attribute and converts the values into strings, so make it false
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
if(response == "Success") {
$('#missing_select_upload').removeClass('show').addClass('hidden');
$("#dept_select").prop('selectedIndex',0);
$("#year_select").prop('selectedIndex',0);
$("#subject_select").empty();
$("#subject_select").append("<option selected disabled>Select Subject</option>");
$("#results_desc").empty();
$(".results").empty();
$('#results_container').removeClass('show').addClass('hidden');
alert("File added successfully.");
} else {
$('#missing_select_upload').empty();
$('#missing_select_upload').removeClass('hidden').addClass('show');
$('#missing_select_upload').append(response);
}
});
// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// Log the error to the console
alert(
"The following error occurred: "+
textStatus + errorThrown
);
});
// Callback handler that will be called regardless
// if the request failed or succeeded
request.always(function () {
// Reenable the inputs
$inputs.prop("disabled", false);
});
});
});
</script>
</body>
</html>