/**
  * Get calendar info after a PROPFIND
  */
 function parse_calendar_info()
 {
     $calendars = array();
     if (isset($this->xmltags['urn:ietf:params:xml:ns:caldav:calendar'])) {
         $calendar_urls = array();
         foreach ($this->xmltags['urn:ietf:params:xml:ns:caldav:calendar'] as $k => $v) {
             $calendar_urls[$this->HrefForProp('urn:ietf:params:xml:ns:caldav:calendar', $k)] = 1;
         }
         foreach ($this->xmltags['DAV::href'] as $i => $hnode) {
             $href = rawurldecode($this->xmlnodes[$hnode]['value']);
             if (!isset($calendar_urls[$href])) {
                 continue;
             }
             //        printf("Seems '%s' is a calendar.\n", $href );
             $calendar = new CalDAVCalendar($href);
             /*
              *  Transform href into calendar
              * /xxxxx/yyyyy/caldav.php/principal/resource/
              *                          t-3       t-2
              */
             $pieces = preg_split('/\\//', $href);
             $total = count($pieces);
             $calendar_id = $pieces[$total - 2];
             $calendar->setCalendarID($calendar_id);
             $ok_props = $this->GetOKProps($hnode);
             foreach ($ok_props as $v) {
                 switch ($v['tag']) {
                     case 'http://calendarserver.org/ns/:getctag':
                         $calendar->setCtag(isset($v['value']) ? $v['value'] : '-');
                         break;
                     case 'DAV::displayname':
                         $calendar->setDisplayName(isset($v['value']) ? $v['value'] : '-');
                         break;
                     case 'http://apple.com/ns/ical/:calendar-color':
                         $calendar->setRBGcolor(isset($v['value']) ? $this->_rgba2rgb($v['value']) : '-');
                         break;
                     case 'http://apple.com/ns/ical/:calendar-order':
                         $calendar->setOrder(isset($v['value']) ? $v['value'] : '-');
                         break;
                 }
             }
             $calendars[$calendar->getCalendarID()] = $calendar;
         }
     }
     return $calendars;
 }
 /**
  * function setCalendar()
  *
  * Sets the actual calendar to work with
  *
  * Debugging:
  * @throws CalDAVException
  * For debugging purposes, just sorround everything with try { ... } catch (Exception $e) { echo $e->__toString(); exit(-1); }
  */
 function setCalendar(CalDAVCalendar $calendar)
 {
     if (!isset($this->client)) {
         throw new Exception('No connection. Try connect().');
     }
     $this->client->SetCalendar($this->client->first_url_part . $calendar->getURL());
     // Is there a '/' at the end of the calendar_url?
     if (!preg_match('#^.*?/$#', $this->client->calendar_url, $matches)) {
         $this->url = $this->client->calendar_url . '/';
     } else {
         $this->url = $this->client->calendar_url;
     }
 }