summaryrefslogtreecommitdiff
path: root/forum/utils/googlecalendar.php
blob: e6305f804a667bf564ac5ee9be5ca0ad538a8898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

include_once($UTIL_DIR . "/events.php");

function googleCalendarEvent($event)
{
	global $ZEND_DIR, $GOOGLE_CALENDAR_USER, $GOOGLE_CALENDAR_PASSWD;

	set_include_path(get_include_path() . PATH_SEPARATOR . $ZEND_DIR);

	// load classes
	require_once 'Zend/Loader.php';
	Zend_Loader::loadClass('Zend_Gdata');
	Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
	Zend_Loader::loadClass('Zend_Gdata_Calendar');
	Zend_Loader::loadClass('Zend_Http_Client');
      
	// connect to service
	$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
	$user = $GOOGLE_CALENDAR_USER;
	$pass = $GOOGLE_CALENDAR_PASSWD;
	$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
	$gcal = new Zend_Gdata_Calendar($client);
      
	/*
	// validate input
	if (empty($_POST['title'])) {
		die('ERROR: Missing title');
	} 
      
	if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])) {
		die('ERROR: Invalid start date/time');        
	}
      
	if (!checkdate($_POST['edate_mm'], $_POST['edate_dd'], $_POST['edate_yy'])) {
		die('ERROR: Invalid end date/time');        
	}
	*/  
	$title = htmlentities(utf8_decode($event->title . "\n" . $event->description));
	$start = date(DATE_ATOM, $event->starttime);
	$end = date(DATE_ATOM, $event->starttime + $event->duration);

	// construct event object
	// save to server      

	try {
		$gevent = $gcal->newEventEntry();        
		$gevent->title = $gcal->newTitle($title);        
		$when = $gcal->newWhen();
		$when->startTime = $start;
		$when->endTime = $end;
		$gevent->when = array($when);        
		$gcal->insertEvent($gevent);   
	} catch (Zend_Gdata_App_Exception $e) {
		echo "Error: " . $e->getResponse();
	}

	//	echo 'Event successfully added!';      
}
?>