Exemplo n.º 1
0
 /**
  * function connect()
  * Connects to a CalDAV-Server.
  *
  * Arguments:
  * @param $url URL to the CalDAV-server. E.g. http://exam.pl/baikal/cal.php/username/calendername/
  * @param $user Username to login with
  * @param $pass Password to login with
  *
  * Debugging:
  * @throws CalDAVException
  * For debugging purposes, just sorround everything with try { ... } catch (Exception $e) { echo $e->__toString(); }
  */
 function connect($url, $user, $pass)
 {
     //  Connect to CalDAV-Server and log in
     $client = new CalDAVClient($url, $user, $pass);
     // Valid CalDAV-Server? Or is it just a WebDAV-Server?
     if (!$client->isValidCalDAVServer()) {
         if ($client->GetHttpResultCode() == '401') {
             throw new CalDAVException('Login failed', $client);
         } elseif ($client->GetHttpResultCode() == '') {
             throw new CalDAVException('Can\'t reach server', $client);
         } else {
             throw new CalDAVException('Could\'n find a CalDAV-collection under the url', $client);
         }
     }
     // Check for errors
     if ($client->GetHttpResultCode() != '200') {
         if ($client->GetHttpResultCode() == '401') {
             throw new CalDAVException('Login failed', $client);
         } elseif ($client->GetHttpResultCode() == '') {
             throw new CalDAVException('Can\'t reach server', $client);
         } else {
             throw new CalDAVException('Recieved unknown HTTP status while checking the connection after establishing it', $client);
         }
     }
     $this->client = $client;
 }
Exemplo n.º 2
0
function simpleCalDAVconnect($url, $user, $pass)
{
    // Check for missing arguments
    if (!(isset($url) && isset($user) && isset($pass))) {
        return array(1, 'Missing arguments');
    }
    //  Connect to CalDAV-Server and log in
    $client = new CalDAVClient($url, $user, $pass);
    // Check for errors
    if (!$client->CheckValidCalDAV()) {
        if ($client->GetHttpResultCode() == '401') {
            return array(2, 'Login failed', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse());
        } elseif ($client->GetHttpResultCode() == '') {
            return array(3, 'Can\'t reach server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse());
        } else {
            return array(4, 'Recieved unknown HTTP status while checking the connection after establishing it', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse());
        }
    }
    // set url to our calendar (CalDAV-protocol supports multiple calendars)
    $client->SetCalendar($url);
    // Is valid calendar?
    if (count($client->GetCalendarDetailsByURL($url)) == 0) {
        return array(5, 'Can\'t find the calendar on the CalDAV-server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse());
    }
    return array(0, $client);
}