Update refresh-alarms script to newer style initialisation.
[davical.git] / inc / tz / get.php
blob13d0785e719adf0570ccf6f52d03893ab752acc0
1 <?php
2 /**
3 * DAViCal Timezone Service handler - capabilitis
5 * @package davical
6 * @subpackage tzservice
7 * @author Andrew McMillan <andrew@morphoss.com>
8 * @copyright Morphoss Ltd
9 * @license http://gnu.org/copyleft/gpl.html GNU GPL v3 or later
12 require_once('vCalendar.php');
14 if ( empty($format) ) $format = 'text/calendar';
15 if ( $format != 'text/calendar' ) {
16 $request->PreconditionFailed(403, 'supported-format', 'This server currently only supports text/calendar format.', 'urn:ietf:params:xml:ns:timezone-service');
19 $sql = 'SELECT our_tzno, tzid, active, olson_name, vtimezone, etag, ';
20 $sql .= 'to_char(last_modified,\'Dy, DD Mon IYYY HH24:MI:SS "GMT"\') AS last_modified ';
21 $sql .= 'FROM timezones WHERE tzid=:tzid';
22 $params = array( ':tzid' => $tzid );
23 $qry = new AwlQuery($sql,$params);
24 if ( !$qry->Exec() ) exit(1);
25 if ( $qry->rows() < 1 ) {
26 $sql = 'SELECT our_tzno, tzid, active, olson_name, vtimezone, etag, ';
27 $sql .= 'to_char(last_modified,\'Dy, DD Mon IYYY HH24:MI:SS "GMT"\') AS last_modified ';
28 $sql .= 'FROM timezones JOIN tz_aliases USING(our_tzno) WHERE tzalias=:tzid';
29 if ( !$qry->Exec() ) exit(1);
30 if ( $qry->rows() < 1 ) $request->DoResponse(404);
33 $tz = $qry->Fetch();
35 $vtz = new vCalendar($tz->vtimezone);
36 $vtz->AddProperty('TZ-URL', $c->protocol_server_port . $_SERVER['REQUEST_URI']);
37 $vtz->AddProperty('TZNAME', $tz->olson_name );
38 if ( $qry->QDo('SELECT * FROM tz_localnames WHERE our_tzno = :our_tzno', array(':our_tzno'=>$tz->our_tzno)) && $qry->rows() ) {
39 while( $name = $qry->Fetch() ) {
40 if ( strpos($_SERVER['QUERY_STRING'], 'lang='.$name->locale) !== false ) {
41 $vtz->AddProperty('TZNAME',$name->localised_name, array('LANGUAGE',str_replace('_','-',$name->locale)));
46 header( 'ETag: "'.$tz->etag.'"' );
47 header( 'Last-Modified: '. $tz->last_modified );
48 header( 'Content-Disposition: Attachment; Filename="'.str_replace('/','-',$tzid . '.ics"' ));
50 $request->DoResponse(200, $vtz->Render(), 'text/calendar; charset=UTF-8');
52 exit(0);