We need the DAVPrincipal module here in some situations.
[davical.git] / inc / tz / list.php
blob74075c8fcf674ebb1524a5251cfd10fd9cf6a98b
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('vComponent.php');
14 $response = new XMLDocument( array("urn:ietf:params:xml:ns:timezone-service" => "") );
15 $tzlist = $response->NewXMLElement('timezone-list');
16 $qry = new AwlQuery('SELECT to_char(max(last_modified),\'YYYY-MM-DD\"T\"HH24:MI:SS"Z"\') AS dtstamp FROM timezones');
17 if ( $qry->Exec('tz/list',__LINE__,__FILE__) && $qry->rows() > 0 ) {
18 $row = $qry->Fetch();
19 $tzlist->NewElement('dtstamp', $row->dtstamp);
21 else {
22 $tzlist->NewElement('dtstamp', gmdate('Y-m-d\TH:i:s\Z'));
25 $sql = 'SELECT our_tzno, tzid, active, to_char(last_modified,\'YYYY-MM-DD\"T\"HH24:MI:SS"Z"\') AS last_modified, olson_name, vtimezone FROM timezones';
26 $params = array();
27 $where = '';
28 if ( $returnall !== true ) {
29 $where = 'active';
31 if ( !empty($changedsince) ) {
32 if ( !empty($where) ) $where .= ' AND ';
33 $where .= 'last_modified > :changedsince';
34 $params[':changedsince'] = $changedsince;
36 if ( !empty($tzid) ) {
37 if ( !empty($where) ) $where .= ' AND ';
38 $where .= '(tzid = :tzid OR our_tzno IN (SELECT our_tzno FROM tz_aliases WHERE tzalias = :tzid))';
39 $params[':tzid'] = $tzid;
41 if ( !empty($where)) $sql .= ' WHERE '.$where;
43 if ( !empty($c->strict_result_ordering) && $c->strict_result_ordering ) {
44 $sql .= ' ORDER BY tzid';
47 <dtstamp>2009-10-11T09:32:11Z</dtstamp>
48 <summary>
49 <tzid>America/New_York</tzid>
50 <last-modified>2009-09-17T01:39:34Z</last-modified>
51 <alias>US/Eastern</alias>
52 <local-name lang="en_US">America/New_York</local-name>
53 <summary>
55 $q2 = new AwlQuery();
56 $qry = new AwlQuery($sql,$params);
57 if ( $qry->Exec('tz/list',__LINE__,__FILE__) && $qry->rows() > 0 ) {
58 while( $tz = $qry->Fetch() ) {
59 $elements = array(
60 new XMLElement('tzid', $tz->tzid),
61 new XMLElement('last-modified', $tz->last_modified)
63 if ( $tz->active != 't' ) {
64 $elements[] = new XMLElement('inactive' );
66 if ( $tz->tzid != $tz->olson_name ) {
67 $elements[] = new XMLElement('alias', $tz->olson_name );
69 if ( $q2->QDo('SELECT * FROM tz_aliases WHERE our_tzno = ?', array($tz->our_tzno)) ) {
70 while( $alias = $q2->Fetch() ) {
71 $elements[] = new XMLElement('alias', $alias->tzalias );
74 if ( !empty($lang) && $q2->QDo('SELECT * FROM tz_localnames WHERE our_tzno = ? AND locale = ?', array($tz->our_tzno, $lang)) && $q2->rows() > 0 ) {
75 while( $local = $q2->Fetch() ) {
76 $attr = array( 'lang' => $local->locale );
77 if ( $local->preferred == 't' ) $attr['preferred'] = 'true';
78 $elements[] = new XMLElement('local-name', $local->localised_name, $attr );
81 else {
82 $elements[] = new XMLElement('local-name', $tz->tzid, ( empty($lang) ? null : array( 'lang' => $lang ) ) );
84 $tzlist->NewElement('summary', $elements);
88 header('Content-Type: application/xml; charset="utf-8"');
90 echo $response->Render($tzlist);
91 exit(0);