forked from pipiscrew/fullcalendar-php-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_events.php
70 lines (59 loc) · 1.82 KB
/
get_events.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
<?php
$isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
if(!$isAjax) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Python - SyntaxError: invalid syntax, visit pipiscrew.com', true, 500);
exit;
}
if (!isset($_GET["start"]) || !isset($_GET["end"]) || !isset($_GET["_"])) {
echo json_encode(3);
exit;
}
include 'config.php';
$db = connect();
$rows = getSet($db, "select * from day_offs left join users on users.user_id=day_offs.user_id where date_occur between ? and ?",array($_GET["start"],$_GET["end"]));
//create an array
$record = array();
//for each record
foreach($rows as $row) {
$datetime = new DateTime($row['date_occur']);
$event_type = $row['day_off_type'];
//give to calendar bar the proper color
switch ($event_type) {
case 1 :
$color = "#9B26AF";
break;
case 2 :
$color = "#2095F2";
break;
case 3 :
$color = "#009587";
break;
case 4 :
$color = "#FE5621";
break;
case 5 :
$color = "#5CB85C";
break;
case 6 :
$color = "#FEEA3A";
break;
case 7 :
$color = "#785447";
break;
case 8 :
$color = "#5F7C8A";
break;
case 9 :
$color = "#212121";
break;
default:
$color = "#212121";
}
//https://fullcalendar.io/docs/agenda/allDaySlot/
//https://fullcalendar.io/docs/event_data/Event_Object/
//convert datetime to ISO8601 format FullCalendar compatible
$record[] = array("id" => $row['day_off_id'],"title" => $row['user_mail'].$row['comment'],"color" => $color, "allDay" => true, "start" => $datetime->format(DateTime::ISO8601));
//add it to array
}
echo json_encode($record);
?>