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: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417:
<?php
require_once('vComponent.php');
class vCalendar extends vComponent {
private $contained_type;
private $primary_component;
private $timezones;
private $organizer;
private $attendees;
private $schedule_agent;
function __construct($content=null) {
$this->contained_type = null;
$this->primary_component = null;
$this->timezones = array();
if ( empty($content) || is_array($content) ) {
parent::__construct();
$this->SetType('VCALENDAR');
$this->AddProperty('PRODID', '-//davical.org//NONSGML AWL Calendar//EN');
$this->AddProperty('VERSION', '2.0');
$this->AddProperty('CALSCALE', 'GREGORIAN');
if ( !empty($content) ) {
foreach( $content AS $k => $v ) {
$this->AddProperty($k,$v);
}
}
}
else {
parent::__construct($content);
$components = $this->GetComponents();
if(isset($components) && count($components) > 0){
foreach( $components AS $k => $comp ) {
if ( $comp->GetType() == 'VTIMEZONE' ) {
$this->AddTimeZone($comp, true);
}
else if ( empty($this->contained_type) ) {
$this->contained_type = $comp->GetType();
$this->primary_component = $comp;
}
}
}
if ( !isset($this->contained_type) && !empty($this->timezones) ) {
$this->contained_type = 'VTIMEZONE';
$this->primary_component = reset($this->timezones);
}
}
}
function AddTimeZone(vComponent $vtz, $in_components=false) {
$tzid = $vtz->GetPValue('TZID');
if ( empty($tzid) ) {
dbg_error_log('ERROR','Ignoring invalid VTIMEZONE with no TZID parameter!');
dbg_log_array('LOG', 'vTimezone', $vtz, true);
return;
}
$this->timezones[$tzid] = $vtz;
if ( !$in_components ) $this->AddComponent($vtz);
}
function GetTimeZone( $tzid ) {
if ( empty($this->timezones[$tzid]) ) return null;
return $this->timezones[$tzid];
}
function GetOrganizer() {
if ( !isset($this->organizer) ) {
$organizers = $this->GetPropertiesByPath('/VCALENDAR/*/ORGANIZER');
$organizer = (count($organizers) > 0 ? $organizers[0] : false);
$this->organizer = (empty($organizer) ? false : $organizer );
if ( $this->organizer ) {
$this->schedule_agent = $organizer->GetParameterValue('SCHEDULE-AGENT');
if ( empty($schedule_agent) ) $this->schedule_agent = 'SERVER';
}
}
return $this->organizer;
}
function GetScheduleAgent() {
if ( !isset($this->schedule_agent) ) $this->GetOrganizer();
return $this->schedule_agent;
}
function GetAttendees() {
if ( !isset($this->attendees) ) {
$this->attendees = array();
$attendees = $this->GetPropertiesByPath('/VCALENDAR/*/ATTENDEE');
$wr_attendees = $this->GetPropertiesByPath('/VCALENDAR/*/X-WR-ATTENDEE');
if ( count ( $wr_attendees ) > 0 ) {
dbg_error_log( 'PUT', 'Non-compliant iCal request. Using X-WR-ATTENDEE property' );
foreach( $wr_attendees AS $k => $v ) {
$attendees[] = $v;
}
}
$this->attendees = $attendees;
}
return $this->attendees;
}
function UpdateAttendeeStatus( $email, vProperty $statusProperty ) {
foreach($this->GetComponents() AS $ck => $v ) {
if ($v->GetType() == 'VEVENT' || $v->GetType() == 'VTODO' ) {
$new_attendees = array();
foreach( $v->GetProperties() AS $p ) {
if ( $p->Name() == 'ATTENDEE' ) {
if ( $p->Value() == $email || $p->Value() == 'mailto:'.$email ) {
$new_attendees[] = $statusProperty;
}
else {
$new_attendees[] = clone($p);
}
}
}
$v->SetProperties($new_attendees,'ATTENDEE');
$this->attendees = null;
$this->rendered = null;
}
}
}
function UpdateOrganizerStatus( vProperty $statusProperty ) {
$this->rendered = null;
foreach($this->GetComponents() AS $ck => $v ) {
if ($v->GetType() == 'VEVENT' || $v->GetType() == 'VTODO' ) {
$v->SetProperties(array($statusProperty), 'ORGANIZER');
$this->organizer = null;
$this->rendered = null;
}
}
}
function StartFilter( $filters ) {
dbg_error_log('vCalendar', ':StartFilter we have %d filters to test', count($filters) );
if ( count($filters) != 1 ) return false;
$tag = $filters[0]->GetNSTag();
$name = $filters[0]->GetAttribute("name");
if ( $tag != "urn:ietf:params:xml:ns:caldav:comp-filter" || $name != 'VCALENDAR' ) return false;
return $this->TestFilter($filters[0]->GetContent());
}
function GetOlsonName( vComponent $vtz ) {
$tzstring = $vtz->GetPValue('TZID');
$tzid = olson_from_tzstring($tzstring);
if ( !empty($tzid) ) return $tzid;
$tzstring = $vtz->GetPValue('X-LIC-LOCATION');
$tzid = olson_from_tzstring($tzstring);
if ( !empty($tzid) ) return $tzid;
$tzcdo = $vtz->GetPValue('X-MICROSOFT-CDO-TZID');
if ( empty($tzcdo) ) return null;
switch( $tzcdo ) {
case 0: return('UTC');
case 1: return('Europe/London');
case 2: return('Europe/Lisbon');
case 3: return('Europe/Paris');
case 4: return('Europe/Berlin');
case 5: return('Europe/Bucharest');
case 6: return('Europe/Prague');
case 7: return('Europe/Athens');
case 8: return('America/Brasilia');
case 9: return('America/Halifax');
case 10: return('America/New_York');
case 11: return('America/Chicago');
case 12: return('America/Denver');
case 13: return('America/Los_Angeles');
case 14: return('America/Anchorage');
case 15: return('Pacific/Honolulu');
case 16: return('Pacific/Apia');
case 17: return('Pacific/Auckland');
case 18: return('Australia/Brisbane');
case 19: return('Australia/Adelaide');
case 20: return('Asia/Tokyo');
case 21: return('Asia/Singapore');
case 22: return('Asia/Bangkok');
case 23: return('Asia/Kolkata');
case 24: return('Asia/Muscat');
case 25: return('Asia/Tehran');
case 26: return('Asia/Baghdad');
case 27: return('Asia/Jerusalem');
case 28: return('America/St_Johns');
case 29: return('Atlantic/Azores');
case 30: return('America/Noronha');
case 31: return('Africa/Casablanca');
case 32: return('America/Argentina/Buenos_Aires');
case 33: return('America/La_Paz');
case 34: return('America/Indiana/Indianapolis');
case 35: return('America/Bogota');
case 36: return('America/Regina');
case 37: return('America/Tegucigalpa');
case 38: return('America/Phoenix');
case 39: return('Pacific/Kwajalein');
case 40: return('Pacific/Fiji');
case 41: return('Asia/Magadan');
case 42: return('Australia/Hobart');
case 43: return('Pacific/Guam');
case 44: return('Australia/Darwin');
case 45: return('Asia/Shanghai');
case 46: return('Asia/Novosibirsk');
case 47: return('Asia/Karachi');
case 48: return('Asia/Kabul');
case 49: return('Africa/Cairo');
case 50: return('Africa/Harare');
case 51: return('Europe/Moscow');
case 53: return('Atlantic/Cape_Verde');
case 54: return('Asia/Yerevan');
case 55: return('America/Panama');
case 56: return('Africa/Nairobi');
case 58: return('Asia/Yekaterinburg');
case 59: return('Europe/Helsinki');
case 60: return('America/Godthab');
case 61: return('Asia/Rangoon');
case 62: return('Asia/Kathmandu');
case 63: return('Asia/Irkutsk');
case 64: return('Asia/Krasnoyarsk');
case 65: return('America/Santiago');
case 66: return('Asia/Colombo');
case 67: return('Pacific/Tongatapu');
case 68: return('Asia/Vladivostok');
case 69: return('Africa/Ndjamena');
case 70: return('Asia/Yakutsk');
case 71: return('Asia/Dhaka');
case 72: return('Asia/Seoul');
case 73: return('Australia/Perth');
case 74: return('Asia/Riyadh');
case 75: return('Asia/Taipei');
case 76: return('Australia/Sydney');
case 57:
case 52:
default:
}
return null;
}
function Confidential() {
static $keep_properties = array( 'DTSTAMP'=>1, 'DTSTART'=>1, 'RRULE'=>1, 'DURATION'=>1, 'DTEND'=>1, 'DUE'=>1, 'UID'=>1, 'CLASS'=>1, 'TRANSP'=>1, 'CREATED'=>1, 'LAST-MODIFIED'=>1 );
static $resource_components = array( 'VEVENT'=>1, 'VTODO'=>1, 'VJOURNAL'=>1 );
$this->MaskComponents(array( 'VTIMEZONE'=>1, 'VEVENT'=>1, 'VTODO'=>1, 'VJOURNAL'=>1 ), false);
$this->MaskProperties($keep_properties, $resource_components );
if ( isset($this->rendered) ) unset($this->rendered);
foreach( $this->GetComponents() AS $comp ) {
if ( isset($resource_components[$comp->GetType()] ) ) {
if ( isset($comp->rendered) ) unset($comp->rendered);
$comp->AddProperty( 'SUMMARY', translate('Busy') );
}
}
return $this;
}
function GetItip($method, $attendee_value ) {
$iTIP = clone($this);
static $keep_properties = array( 'DTSTART'=>1, 'DURATION'=>1, 'DTEND'=>1, 'DUE'=>1, 'UID'=>1,
'SEQUENCE'=>1, 'ORGANIZER'=>1, 'ATTENDEE'=>1 );
static $resource_components = array( 'VEVENT'=>1, 'VTODO'=>1, 'VJOURNAL'=>1 );
$iTIP->MaskComponents($resource_components, false);
$iTIP->MaskProperties($keep_properties, $resource_components );
$iTIP->AddProperty('METHOD',$method);
if ( isset($iTIP->rendered) ) unset($iTIP->rendered);
if ( !empty($attendee_value) ) {
$iTIP->attendees = array();
foreach( $iTIP->GetComponents() AS $comp ) {
if ( isset($resource_components[$comp->GetType()] ) ) {
foreach( $comp->GetProperties() AS $k=> $property ) {
switch( $property->Name() ) {
case 'ATTENDEE':
if ( $property->Value() == $attendee_value )
$iTIP->attendees[] = $property->ClearParameters(array('CUTYPE'=>true, 'SCHEDULE-STATUS'=>true));
else
$comp->clearPropertyAt($k);
break;
case 'SEQUENCE':
$property->Value( $property->Value() + 1);
break;
}
}
$comp->AddProperty('DTSTAMP', date('Ymd\THis\Z'));
}
}
}
return $iTIP;
}
function GetUID() {
if ( empty($this->primary_component) ) return null;
return $this->primary_component->GetPValue('UID');
}
function SetUID( $newUid ) {
if ( empty($this->primary_component) ) return;
$this->primary_component->SetProperties( array( new vProperty('UID', $newUid) ), 'UID');
}
}