-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistholidays.php
106 lines (103 loc) · 4.2 KB
/
listholidays.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
<?php include('admin/config.php');
//Connect to database
$con = mysqli_connect(databasehost, databaseuser, databasepassword, databasename);
if (!$con) {
die('Could not connect: ' . mysqli_error());}
//
$totallocations = totallocations; //How many libraries have regular hours set
function returnjson($json) {
if(array_key_exists('callback', $_GET)){
header('Content-Type: text/javascript; charset=utf8');
$http_origin = $_SERVER['HTTP_ORIGIN'];
if ($http_origin == "https://jmrl.org" || $http_origin == "https://www.jmrl.org" || $http_origin == "http://10.0.8.54" || $http_origin == "http://69.16.201.28" || $http_origin == "https://69.16.201.28" || $http_origin == "https://10.0.8.54" || $http_origin == "http://hestia.jmrl.org" || $http_origin == "https://hestia.jmrl.org")
{
header("Access-Control-Allow-Origin: $http_origin");
}
header('Access-Control-Allow-Methods: GET, POST');
$callback = $_GET['callback'];
echo $callback.'('.$json.');';
} else{
// normal JSON string
header('Content-Type: application/json; charset=utf8');
$http_origin = $_SERVER['HTTP_ORIGIN'];
if ($http_origin == "https://jmrl.org" || $http_origin == "https://www.jmrl.org" || $http_origin == "http://10.0.8.54" || $http_origin == "http://69.16.201.28" || $http_origin == "https://69.16.201.28" || $http_origin == "https://10.0.8.54" || $http_origin == "http://hestia.jmrl.org" || $http_origin == "https://hestia.jmrl.org")
{
header("Access-Control-Allow-Origin: $http_origin");
}
header('Access-Control-Allow-Methods: GET, POST');
echo $json;
}
}
if (array_key_exists('limit', $_GET)) {
$conditions = "AND `SpecialDate` < (CURDATE() + INTERVAL " . $_GET['limit'] . " DAY)";
}
if (array_key_exists('lib', $_GET)) {
$conditions .= " AND `LibID` = " . $_GET['lib'];
}
$holidayinfoquery = "SELECT GROUP_CONCAT(`LibID` ORDER BY `LibID`), `HolName`, `SpecialDate`, GROUP_CONCAT(DISTINCT `Closed` ORDER BY `Closed`), `Notes`, `OpenTime`, `CloseTime` FROM `Special` WHERE `SpecialDate` >= CURDATE() " . $conditions . " GROUP BY `HolName`,`SpecialDate` ORDER BY `SpecialDate`;";
$holidayinforesult = mysqli_query($con, $holidayinfoquery);
$branchnames = shortnames; //Get short branch names from Config
if (array_key_exists('json', $_GET)) {
$json = json_encode(mysqli_fetch_all($holidayinforesult));
returnjson($json);
} else {
header('Content-Type: text/javascript; charset=utf8');
$html = "<ul class='holidaylist'>";
while ($row = mysqli_fetch_row($holidayinforesult)) {
$html .= "<li><b>" . htmlentities($row[1], ENT_QUOTES, 'UTF-8') . "</b> (" . date("F j, Y", strtotime($row[2])) . ")";
$branches = explode(",", $row[0]);
if (($row[3] == 0 || $row[3] == "0,1") && $row[4] == "") {
$html .= " <i>- Special hours";
if (array_key_exists('lib', $_GET)) {
$html .= " " . date("g:i a", strtotime($row[5])) . " - " . date("g:i a", strtotime($row[6]));
} else if (count($branches) < $totallocations) {
$html .= " at ";
$counter = 1;
foreach($branches as $branch) {
if ($counter > 1 && $counter < count($branches)) {
$html .= ", ";
} else if ($counter > 1 && $counter == count($branches)) {
$html .= ", and ";
}
$html .= $branchnames[($branch - 1)];
$counter ++;
}
}
$html .= "</i>";
}
else if ($row[3] == 0) {
$html .= " <i>- " . htmlentities($row[4], ENT_QUOTES, 'UTF-8') . "</i>";
}
else if (!array_key_exists('lib', $_GET) && $row[3] == 1 && count($branches) < $totallocations && $row[4] == "") {
$html .= " <i>- ";
$counter = 1;
foreach($branches as $branch) {
if ($counter > 1 && $counter < count($branches)) {
$html .= ", ";
} else if ($counter > 1 && $counter == count($branches)) {
$html .= ", and ";
}
$html .= $branchnames[($branch - 1)];
$counter ++;
}
$html .= " closed</i>";
}
else {
if ($row[4] == "") {
$html .= " <i>- Closed</i>";
}
else {
$html .= "<i>- " . htmlentities($row[4], ENT_QUOTES, 'UTF-8') . "</i>";
}
}
$html .= "</li>";
}
$html .= "</ul>";
if (array_key_exists('divid', $_GET)) {
$divid = preg_replace("/[^a-zA-Z0-9]/", "", $_GET['divid']);
} else {
$divid = "holidaylistdiv";
}
echo "jQuery('#$divid').html(\"$html\");";
}
?>