-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.php
327 lines (296 loc) · 10.4 KB
/
calendar.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
<!DOCTYPE html>
<?php
require_once 'includes/header.php';
$sql = "SELECT * FROM calevents";
$result = $connect->query($sql);
$output = array();
while($row = $result->fetch_array())
{
$temp = array($row[0],$row[1],$row[2]);
array_push($output, $temp);
}
?>
<script>
var events = [
<?php for ($i=0; $i <count($output); $i++) { ?>
{
title: '<?php echo $output[$i][0]; ?>',
start: '<?php echo $output[$i][1]; ?>',
end: '<?php echo $output[$i][2]; ?>'
},
<?php } ?>
]
</script>
<html lang='en'>
<head>
<meta charset='utf-8' />
<link href='custom/fullcalendar/packages/core/main.css' rel='stylesheet' />
<link href='custom/fullcalendar/packages/daygrid/main.css' rel='stylesheet' />
<script src='custom/fullcalendar/packages/core/main.js'></script>
<script src='custom/fullcalendar/packages/daygrid/main.js'></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 40px auto;
}
</style>
<!---Modal starts-->
<?php if(isset($_SESSION['userId']) && $_SESSION['userId']==-2) { ?>
<div class="modal fade" id="returnBrandModel" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" id="returnBrandForm" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Add Event</h4>
</div>
<div class="modal-body">
<div id="return-brand-messages"></div>
<div id="return-brand-result">
<div class="form-group">
<label for="returnNo" class="col-sm-3 control-label">Enter Event Name </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnNo" placeholder="Event Name" name="returnNo" autocomplete="off">
</div>
</div>
<div class="form-group">
<label for="returnFine" class="col-sm-3 control-label">Start date </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnFine" placeholder="Enter a date in YYYY-MM-DD format" name="returnFine" autocomplete="off">
</div>
</div>
<div class="form-group">
<label for="returnFine2" class="col-sm-3 control-label">End date </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnFine2" placeholder="Enter a date in YYYY-MM-DD format" name="returnFine2" autocomplete="off">
</div>
</div>
</div>
</div>
<div class="modal-footer returnBrandFooter">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" id="returnBrandBtn" data-loading-text="Loading..." autocomplete="off">Add event</button>
</div>
</form>
</div>
</div>
</div>
<?php } ?>
<!--Modal ends-->
<!---Modal starts-->
<?php if(isset($_SESSION['userId']) && $_SESSION['userId']==-2) { ?>
<div class="modal fade" id="returnBrandModel2" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" id="returnBrandForm" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Add Event</h4>
</div>
<div class="modal-body">
<div id="return-brand-messages"></div>
<div id="return-brand-result">
<div class="form-group">
<label for="returnNo" class="col-sm-3 control-label">Enter Event Name </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnNo" placeholder="Event Name" name="returnNo1" autocomplete="off">
</div>
</div>
<div class="form-group">
<label for="returnFine" class="col-sm-3 control-label">Start date </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnFine" placeholder="Enter a date in YYYY-MM-DD format" name="returnFine1" autocomplete="off">
</div>
</div>
<div class="form-group">
<label for="returnFine2" class="col-sm-3 control-label">End date </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="returnFine2" placeholder="Enter a date in YYYY-MM-DD format" name="returnFine21" autocomplete="off">
</div>
</div>
</div>
</div>
<div class="modal-footer returnBrandFooter">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" id="returnBrandBtn2" data-loading-text="Loading..." autocomplete="off">Delete event</button>
</div>
</form>
</div>
</div>
</div>
<?php } ?>
<!--Modal ends-->
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid', 'timeGrid' ],
defaultView: 'dayGridMonth',
defaultDate: '2019-11-07',
header: {
left: 'prev,next today',
center: 'addEventButton deleteEventButton',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
<?php if ($_SESSION['userId'] == -2 && $_SESSION['access'] >=4 ) {
echo "
customButtons: {
addEventButton: {
text: 'Add event',
click: function() {
//var dateStr = prompt('Enter a date in YYYY-MM-DD format');
$('#returnBrandModel').modal('show');
$('#returnBrandBtn').click(function () {
var textFieldVal = $('input[name=\"returnNo\"]').val();
var textFieldVal2 = $('input[name=\"returnFine\"]').val();
var textFieldVal3 = $('input[name=\"returnFine2\"]').val();
$.ajax({
url: 'php_action/addCalendar.php',
type: 'post',
data: {a:textFieldVal,b:textFieldVal2,c:textFieldVal3},
dataType: 'json',
success:function(response) {
console.log(response.output);
var a = response.output;
for(var i = 0; i < a.length; i++)
{
var ename = a[i][0];
var sdate = new Date(a[i][1] + 'T00:00:00');
var edate = new Date(a[i][2] + 'T00:00:00');
calendar.addEvent({
title: ename,
start: sdate,
end: edate
});
}
}
});
});
}
},
deleteEventButton: {
text: 'Delete event',
click: function() {
$('#returnBrandModel2').modal('show');
$('#returnBrandBtn2').click(function () {
var textFieldVal = $('input[name=\"returnNo1\"]').val();
var textFieldVal2 = $('input[name=\"returnFine1\"]').val();
var textFieldVal3 = $('input[name=\"returnFine21\"]').val();
$.ajax({
url: 'php_action/deleteCalendar.php',
type: 'post',
data: {a:textFieldVal,b:textFieldVal2,c:textFieldVal3},
dataType: 'json',
success:function(response) {
console.log(response);
var a = response.output;
for(var i = 0; i < a.length; i++)
{
var ename = a[i][0];
var sdate = new Date(a[i][1] + 'T00:00:00');
var edate = new Date(a[i][2] + 'T00:00:00');
calendar.addEvent({
title: ename,
start: sdate,
end: edate
});
}
}
});
});
}
}
},
events: events,
});";
}
else
{
$roll_no = $_SESSION['userId'];
$sql = "SELECT name from student WHERE rollno = '$roll_no'";
//echo $sql;
$result = $connect->query($sql);
$studname = $result->fetch_array();
if($result->num_rows == 0)
{
$studname = array(0 => $_SESSION['aname']);
}
echo "
customButtons: {
addEventButton: {
text: 'Hi, ".$studname[0]."'
}
},
events: events,
});";
}
?>
calendar.render();
});
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
<?php require_once 'includes/footer.php'; ?>
<!--,
events: [
{
title: 'All Day Event',
start: '2019-11-01'
},
{
title: 'Small Day Event',
start: '2019-11-02',
end: '2019-11-02T14:30:00'
},
{
title: 'Long Event',
start: '2019-11-07',
end: '2019-11-10'
},
{
groupId: '999',
title: 'Repeating Event',
start: '2019-11-09T16:00:00'
},
{
groupId: '999',
title: 'Repeating Event',
start: '2019-11-16T16:00:00'
},
{
title: 'Conference',
start: '2019-11-11',
end: '2019-11-13'
},
{
title: 'Meeting',
start: '2019-11-12T10:30:00',
end: '2019-11-12T12:30:00'
},
{
title: 'Lunch',
start: '2019-11-12T12:00:00'
},
{
title: 'Meeting',
start: '2019-11-12T14:30:00'
},
{
title: 'Birthday Party',
start: '2019-11-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2019-11-28'
}
]-->