/**
 * Creates an event on the authenticated user's default calendar with the
 * specified event details.
 *
 * @param Zend_Http_Client $client The authenticated client object
 * @param string $title The event title
 * @param string $desc The detailed description of the event
 * @param string $startDate The start date of the event in YYYY-MM-DD format
 * @param string $startTime The start time of the event in HH:MM 24hr format
 * @param string $endTime The end time of the event in HH:MM 24hr format
 * @param string $tzOffset The offset from GMT/UTC in [+-]DD format (eg -08)
 * @return void
 */
function createEvent($client, $title = 'Tennis with Beth', $desc = 'Meet for a quick lesson', $where = 'On the courts', $startDate = '2008-01-20', $startTime = '10:00', $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    Zend_Feed::registerNamespace('gd', 'http://schemas.google.com/g/2005');
    $newEntry = new Zend_Feed_EntryAtom();
    $newEntry->title = trim($title);
    $newEntry->{'gd:where'}['valueString'] = $where;
    $newEntry->content = $desc;
    $newEntry->content['type'] = 'text';
    $when = $newEntry->{'gd:when'};
    $when['startTime'] = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
    $when['endTime'] = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    $gdataCal->post($newEntry->saveXML());
}
 */
if (isset($_GET['deleteUri'])) {
    $gdataCal = new Zend_Gdata_Calendar($client);
    $gdataCal->delete($_GET['deleteUri']);
    header('Location: ' . $php_self);
    exit;
}
/**
 * Copy an item from the shared calendar to my calendar.
 */
if (isset($_POST['save'])) {
    $gdataCal = new Zend_Gdata_Calendar($client);
    if (get_magic_quotes_gpc()) {
        $_POST['save'] = stripslashes($_POST['save']);
    }
    $gdataCal->post(html_entity_decode($_POST['save']));
    header('Location: ' . $php_self);
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Google Calendar Demo</title>
<style>
body{ font-family: Arial; }
</style>
</head>
<body>
<table border="1">
/**
 * Creates a recurring event on the authenticated user's default calendar with
 * the specified event details.  
 *
 * @param  Zend_Http_Client $client    The authenticated client object
 * @param  string           $title     The event title
 * @param  string           $desc      The detailed description of the event
 * @param  string           $recurData The iCalendar recurring event syntax (RFC2445)
 * @return void
 */
function createRecurringEvent(Zend_Http_Client $client, $title = 'Tennis with Beth', $desc = 'Meet for a quick lesson', $where = 'On the courts', $recurData = null)
{
    $gc = new Zend_Gdata_Calendar($client);
    $newEntry = $gc->newEventEntry();
    $newEntry->title = $gc->newTitle(trim($title));
    $newEntry->where = array($gc->newWhere($where));
    $newEntry->content = $gc->newContent($desc);
    $newEntry->content->type = 'text';
    /**
     * Due to the length of this recurrence syntax, we did not specify
     * it as a default parameter value directly
     */
    if ($recurData == null) {
        $recurData = "DTSTART;VALUE=DATE:20070501\r\n" . "DTEND;VALUE=DATE:20070502\r\n" . "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904\r\n";
    }
    $newEntry->recurrence = $gc->newRecurrence($recurData);
    $gc->post($newEntry->saveXML());
}
        $gdataCal->insertEvent($appCal, $own_cal);
        $calFeed = $gdataCal->getCalendarListFeed();
        foreach ($calFeed as $calendar) {
            if ($calendar->title->text == $abbreviation . $i) {
                //This is the money, you need to use '->content-src'
                //Anything else and you have to manipulate it to get it right.
                $appCalUrl = $calendar->content->src;
            }
        }
        extract($_POST);
        //set POST variables
        $calurl = substr($appCalUrl, 38, strlen($appCalUrl) - 51);
        $url = "http://www.google.com/calendar/feeds/" . $calurl . "/acl/full";
        $post_fields = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'>\n            <category scheme='http://schemas.google.com/g/2005#kind'\n            term='http://schemas.google.com/acl/2007#accessRule'/>\n            <gAcl:scope type='default'></gAcl:scope>\n            <gAcl:role value='http://schemas.google.com/gCal/2005#read'></gAcl:role>\n            </entry>";
        $gdataCal = new Zend_Gdata_Calendar($client);
        $gdataCal->post($post_fields, $url);
        query("INSERT INTO calendarLinks (id, link) \n                    VALUES(?, ?)", $clubID . "." . $i, $appCalUrl);
        //            query("INSERT INTO calendarLinks (id, link)
        //                    VALUES(?, ?)", $clubID.".".$i, substr($appCalUrl,38,strlen($appCalUrl)-51));
    }
    // redirect to home
    redirect("/");
} else {
    // pass the createClub_form the list of possible club types
    $rows = query("SELECT * FROM clubTypes");
    $categories = array();
    foreach ($rows as $row) {
        // since we want the "Other" category to be at the end of our form,
        // we will add this on the form separately
        //if($row["description"] != "Other")
        $categories[$row["id"]] = $row["description"];