Example #1
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);
}