= '$today'"; $r = MYSQL_QUERY($delete_query); print "
Attempting Delete Query: $delete_query
"; if ($r) { print "
Result of Delete: Success
";} else { print "Result of Delete: Failure
";} $r2 = MYSQL_QUERY($query); // Print out the SQL, for everyone's edification print "Attempting Insert Query: $query
"; if ($r2) { print "Result of Insert: Success
";} else { print "Result of Insert: Failure. Are you sure you have data in your Google Calendar to be extracted?
" ;} /////////////// /* Functions */ /////////////// // Function to convert our 24 hour time into twelve hour with am/pm, for friendlier display on HTML pages function miltoampm($hour, $minute="00") { $ampm = ($hour >=12 && $hour <24) ? "pm" : "am"; $newhour = ($hour % 12 === 0) ? 12 : $hour % 12; if ($minute != "00") {$newhour .= ":$minute";} return $newhour . ' ' . $ampm; } // Function to generate the SQL to update our calendar function outputCalendarByDateRange($client, $startDate, $endDate) { $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser('default'); // we're looking at the default calendar $query->setVisibility('private'); // is this a public or private feed? $query->setProjection('full'); // Select which projection of the data you want $query->setOrderby('starttime'); // Select how you want the results ordered $query->setStartMin($startDate); $query->setStartMax($endDate); $eventFeed = $gdataCal->getCalendarEventFeed($query); global $debugger; foreach ($eventFeed as $event) { foreach ($event->when as $when) { // suck out the date $start = $when->startTime; $start2 = explode("T", $start); list($startHour, $startMinute) = split(":", $start2[1]); $dmy = explode("-", $start2[0]); $day = $dmy[2]; $month = $dmy[1]; $year = $dmy[0]; $end = $when->endTime; $end2 = explode("T", $end); list($endHour, $endMinute) = split(":", $end2[1]); $the_date = $start2[0]; $day_of_week = date("l",mktime(0,0,0,$month, $day, $year)); $date[$the_date] = array("$event->title", $day_of_week, $startHour, $startMinute, $endHour, $endMinute, "$event->content"); } } // Make sure there is a result if ($date != "") { // Sort the array by the date field (key) ksort($date); if ($debugger == "yes") {print ""; print_r($date); print "";} $i=1; foreach($date as $date_label => $date_item) { $event_title = $date_item[0]; $dow = $date_item[1]; $startHr = $date_item[2]; $startMin = $date_item[3]; $endHr = $date_item[4]; $endMin = $date_item[5]; // If you wanted to get the description information, you could uncomment the following line // (and then add a field to the database to store the info + to the sql) // $event_content = $date_item[6]; // Look for the word "Closed" in the event title field (case-insensitive) to determine if // the library is closed that day if (preg_match("/closed/i", $event_title)) {$closed = 1; } else {$closed = 0;} $newStart = miltoampm($startHr, $startMin); $newEnd = miltoampm($endHr, $endMin); $sql .= "('$date_label', '$dow', '$newStart', '$newEnd', '$closed'), "; $i++; } } return $sql; } ?>