Path: blob/master/web-gui/buildyourownbotnet/assets/js/fullcalendar-2/demos/php/get-events.php
1296 views
<?php12//--------------------------------------------------------------------------------------------------3// This script reads event data from a JSON file and outputs those events which are within the range4// supplied by the "start" and "end" GET parameters.5//6// An optional "timezone" GET parameter will force all ISO8601 date stings to a given timezone.7//8// Requires PHP 5.2.0 or higher.9//--------------------------------------------------------------------------------------------------1011// Require our Event class and datetime utilities12require dirname(__FILE__) . '/utils.php';1314// Short-circuit if the client did not give us a date range.15if (!isset($_GET['start']) || !isset($_GET['end'])) {16die("Please provide a date range.");17}1819// Parse the start/end parameters.20// These are assumed to be ISO8601 strings with no time nor timezone, like "2013-12-29".21// Since no timezone will be present, they will parsed as UTC.22$range_start = parseDateTime($_GET['start']);23$range_end = parseDateTime($_GET['end']);2425// Parse the timezone parameter if it is present.26$timezone = null;27if (isset($_GET['timezone'])) {28$timezone = new DateTimeZone($_GET['timezone']);29}3031// Read and parse our events JSON file into an array of event data arrays.32$json = file_get_contents(dirname(__FILE__) . '/../json/events.json');33$input_arrays = json_decode($json, true);3435// Accumulate an output array of event data arrays.36$output_arrays = array();37foreach ($input_arrays as $array) {3839// Convert the input array into a useful Event object40$event = new Event($array, $timezone);4142// If the event is in-bounds, add it to the output43if ($event->isWithinDayRange($range_start, $range_end)) {44$output_arrays[] = $event->toArray();45}46}4748// Send JSON to the client.49echo json_encode($output_arrays);5051