Example #1
0
	/**
	* GoogleCalendarAdd
	* Uses the Google Calendar API to add an event to Google Calendar
	*
	* @param Array $data An array containing username, password, what, where, description, datefrom, timefrom, dateto, timeto, and allday
	* @param Boolean $test_auth Set to true to test authentication details only. This will throw an exception if authentication fails or will return true
	*
	* @throws Exception If an error occurs this function will throw an exception.
	*
	* @return Void Returns nothing
	*/
	function GoogleCalendarAdd($data,$test_auth = false)
	{
		if (!class_exists('GoogleCalendar', false)) {
			require_once(SENDSTUDIO_LIB_DIRECTORY . "/googlecalendar/googlecalendar.php");
		}

		$googlecalendar = new GoogleCalendar($data['username'],$data['password']);

		if ($test_auth) {
			return;
		}

		// Populate the event with the desired information
		$event['title'] = $data['what'];
		if (isset($data['where'])) {
			$event['where'] = $data['where'];
		}
		if (isset($data['description'])) {
			$event['text'] = $data['description'];
		}

		$user = GetUser();

		$allday = false;
		if (isset($data['allday'])) {
			$allday = true;
		}

		$event['when'] = array();
		$event['when']['from'] = $this->GoogleCalendarDate($data['datefrom'],$data['timefrom'],$allday,false);
		$event['when']['to'] = $this->GoogleCalendarDate($data['dateto'],$data['timeto'],$allday,true);

		if ($event['when']['from'] == $event['when']['to'] && $allday) {
			unset($event['when']['to']);
		}

		$newEvent = $googlecalendar->addSimpleEvent($event);
	}