public function test()
 {
     $this->client = new Google_Client();
     $this->client->setApplicationName('Hangout Schedule');
     $this->client->setClientId('191072902750-o87q963i0t05pkb96mvfusb3gsutpsmv.apps.googleusercontent.com');
     $this->client->setClientSecret('KfLw32e9BM9GxfaGjUAOL3I2');
     $this->client->setRedirectUri('http://local.youniqueproducts.com/api/oauth2/responseFrom/Google');
     $this->client->setScopes("https://www.googleapis.com/auth/calendar");
     $service = new Google_Service_Calendar($this->client);
     $this->getAccessToken();
     $this->setTestData();
     $event = new Google_Event();
     $event->setSummary($this->testData['summary']);
     $event->setLocation('Younique Virtual Party!');
     $start = new Google_EventDateTime();
     $start->setDateTime($this->testData['start']['dateTime'] . '.000-00:00');
     $event->setStart($start);
     $end = new Google_EventDateTime();
     $end->setDateTime($this->testData['end']['dateTime'] . '.000-00:00');
     $event->setEnd($end);
     //        $attendee1 = new Google_EventAttendee();
     //        $attendee1->setEmail('*****@*****.**');
     //        $attendees = array($attendee1);
     //        $event->attendees = $attendees;
     $createdEvent = $service->events->insert('primary', $event);
     var_dump($createdEvent);
 }
Esempio n. 2
0
 private function _process(Google_Event $event)
 {
     $event->setSummary($this->_getReservationSummary());
     $event->setDescription($this->_getReservationDescription());
     $timeBegin = DateTime::createFromTimestamp($this->_reservation->getFinalVisitTime());
     $timeEnd = DateTime::createFromTimestamp($this->_reservation->getVisitEndTime());
     $timeEventBegin = new Google_EventDateTime();
     $timeEventEnd = new Google_EventDateTime();
     $timeEventBegin->setDateTime($timeBegin->getGoogleApiDatetime());
     $timeEventEnd->setDateTime($timeEnd->getGoogleApiDatetime());
     $event->setStart($timeEventBegin);
     $event->setEnd($timeEventEnd);
     return $event;
 }
Esempio n. 3
0
 public function AddActivitat($id, $timestamp_inici, $timestamp_fi, $organitzador, $email, $titol, $link, $location, $summary, $description, $calendarid, $color_id, $idS)
 {
     date_default_timezone_set('Europe/Madrid');
     //echo date(DateTime::RFC3339,mktime(17,30,00,1,14,2013));
     $E = new Google_Event();
     $O = new Google_EventOrganizer();
     $O->setDisplayName($titol);
     $O->setEmail($email);
     $E->setOrganizer($O);
     $E->setSummary($titol);
     $E->setHtmlLink($link);
     $E->setLocation($location);
     $E->setDescription(html_entity_decode(strip_tags($description)));
     $start = new Google_EventDateTime();
     $start->setDateTime(date(DateTime::RFC3339, $timestamp_inici));
     $E->setStart($start);
     $end = new Google_EventDateTime();
     $end->setDateTime(date(DateTime::RFC3339, $timestamp_fi));
     $E->setEnd($end);
     $E->setColorId($color_id);
     $this->cal->events->insert(OptionsPeer::getString('GOOGLE_CALENDAR_ID', $idS), $E);
 }
Esempio n. 4
0
 /**
  * Update Google Calendar unavailable period event.
  * 
  * @param array $provider Contains the provider record data.
  * @param array $unavailable Contains the unavailable period data.
  * @return Google_Event Returns the Google_Event object.
  */
 public function update_unavailable($provider, $unavailable)
 {
     $this->CI->load->helper('general');
     $event = $this->service->events->get($provider['settings']['google_calendar'], $unavailable['id_google_calendar']);
     $event->setDescription($unavailable['notes']);
     $start = new Google_EventDateTime();
     $start->setDateTime(date3339(strtotime($unavailable['start_datetime'])));
     $event->setStart($start);
     $end = new Google_EventDateTime();
     $end->setDateTime(date3339(strtotime($unavailable['end_datetime'])));
     $event->setEnd($end);
     $updated_event = $this->service->events->update($provider['settings']['google_calendar'], $event->getId(), $event);
     return $updated_event;
 }
Esempio n. 5
0
 /**
  * Creates a Google Event object and set its parameters
  * @param app: Appointment object to be set as event
  */
 function set_event_parameters($app, $worker_id = 0)
 {
     global $appointments;
     $a = $appointments;
     $summary = sprintf(__('%s Appointment', 'appointments'), $a->get_service_name($app->service));
     if (isset($this->options["gcal_location"]) && '' != trim($this->options["gcal_location"])) {
         $location = str_replace(array('ADDRESS', 'CITY'), array($app->address, $app->city), $this->options["gcal_location"]);
     } else {
         $location = get_bloginfo('description');
     }
     // Find time difference from Greenwich as GCal asks UTC
     if (!current_time('timestamp')) {
         $tdif = 0;
     } else {
         $tdif = current_time('timestamp') - time();
     }
     $start = new Google_EventDateTime();
     $start->setDateTime(date("Y-m-d\\TH:i:s\\Z", strtotime($app->start) - $tdif));
     $end = new Google_EventDateTime();
     $end->setDateTime(date("Y-m-d\\TH:i:s\\Z", strtotime($app->end) - $tdif));
     // An email is always required
     if (!$app->email) {
         $email = $a->get_worker_email($app->worker);
     } else {
         $email = $app->email;
     }
     if (!$email) {
         $email = $a->get_admin_email();
     }
     $attendee1 = new Google_EventAttendee();
     $attendee1->setEmail($email);
     $attendees = array($attendee1);
     $this->event = new Google_Event();
     $this->event->setSummary($summary);
     $this->event->setLocation($location);
     $this->event->setStart($start);
     $this->event->setEnd($end);
     $this->event->setSummary(apply_filters('app-gcal-set_summary', $a->_replace($this->get_summary($worker_id), $app->name, $a->get_service_name($app->service), $a->get_worker_name($app->worker), $app->start, $app->price, $a->get_deposit($app->price), $app->phone, $app->note, $app->address, $app->email, $app->city), $app));
     $this->event->setDescription(apply_filters('app-gcal-set_description', $a->_replace($this->get_description($worker_id), $app->name, $a->get_service_name($app->service), $a->get_worker_name($app->worker), $app->start, $app->price, $a->get_deposit($app->price), $app->phone, $app->note, $app->address, $app->email, $app->city), $app));
     $this->event->attendees = $attendees;
     // Alright, now deal with event sequencing
     if (!empty($app->gcal_ID)) {
         $tmp = $this->service->events->get($this->get_selected_calendar($worker_id), $app->gcal_ID);
         $sequence = is_object($tmp) && !empty($tmp->sequence) ? $tmp->sequence : (is_array($tmp) && !empty($tmp['sequence']) ? $tmp['sequence'] : false);
         if (!empty($sequence)) {
             $this->event->sequence = $sequence;
         }
         // Add sequence if we have it
     }
 }
Esempio n. 6
0
function insertGoogleCalendarEvent($resrvation_id)
{
    if ($resrvation_id) {
        try {
            $resrvation_details = getReservationDetailFromId($resrvation_id);
            $calendar_id = getCalendarIdFromProperty($resrvation_details['PropertyID']);
            $row_credential = getGoogleCredential();
            $eventstartdate = date('Y-m-d', strtotime($resrvation_details['ArrivalDate']));
            $eventenddate = date('Y-m-d', strtotime($resrvation_details['DepartureDate']) + 86400);
            $esd = $eventstartdate . ' 00:00:00';
            $eed = $eventenddate . ' 10:00:00';
            $pst = new DateTimeZone('America/Los_Angeles');
            $gmt = new DateTimeZone('GMT');
            $dates = new DateTime($esd, $pst);
            $dates->setTimezone($gmt);
            $eventstartdate = $dates->format('Y-m-d') . 'T' . $dates->format('H:i:s') . 'Z';
            $datee = new DateTime($eed, $pst);
            $datee->setTimezone($gmt);
            $eventenddate = $datee->format('Y-m-d') . 'T' . $datee->format('H:i:s') . 'Z';
            //change as per client requirement to display full period from checkin to checkout on google calender
            //$eventenddate = date('Y-m-d',(strtotime($resrvation_details['DepartureDate']) + 172800)); // 86400 122400
            $tenantname = stripslashes($resrvation_details['FirstName']);
            if ($resrvation_details['MiddleName']) {
                $tenantname .= ' ' . stripslashes($resrvation_details['MiddleName']);
            }
            $tenantname .= ' ' . stripslashes($resrvation_details['LastName']);
            $tenantemail = stripslashes($resrvation_details['Email']);
            $tenantphone = stripslashes($resrvation_details['TelephoneNumber']);
            $tenantdayphone = stripslashes($resrvation_details['DaytimePhone']);
            $tenantstaypurpose = stripslashes($resrvation_details['StayPurpose']);
            //Event Summery i.e. Event Title
            $summery = 'Reservation Period - ' . $tenantname;
            //Event Description
            $description = "Tenant Details:\n\r Name: {$tenantname}\n\r Email: {$tenantemail}\n\r Phone: {$tenantphone}\n\r Day Phone: {$tenantdayphone}\n\r Stay Purpose: {$tenantstaypurpose}";
            include_once 'src/Google_Client.php';
            include_once 'src/contrib/Google_CalendarService.php';
            $client = new Google_Client();
            $client->setClientId($row_credential['ClientId']);
            $client->setClientSecret($row_credential['ClientSecret']);
            $client->setRedirectUri($row_credential['RedirectUri']);
            $client->setDeveloperKey($row_credential['DeveloperKey']);
            $cal = new Google_CalendarService($client);
            $client->setAccessToken($row_credential['AccessToken']);
            if ($client->getAccessToken()) {
                $eventendtime = new Google_EventDateTime();
                $eventendtime->setDateTime($eventenddate);
                $eventstarttime = new Google_EventDateTime();
                $eventstarttime->setDateTime($eventstartdate);
                $addevent = new Google_Event();
                $addevent->setEnd($eventendtime);
                $addevent->setStart($eventstarttime);
                $addevent->setDescription($description);
                $addevent->setSummary($summery);
                $eventadresp = $cal->events->insert($calendar_id, $addevent);
                updateEventId($resrvation_id, $eventadresp['id']);
            }
        } catch (Exception $e) {
            /* echo '<pre>';
            			print_r($e);
            			echo '</pre>';
            			exit; */
            //log error for debbug
            $response = json_encode($e);
            $insert_errsql = "INSERT INTO debug_calendarerr SET Response='" . mysql_real_escape_string($response) . "', ReservePropertyId='" . $resrvation_id . "'";
            $result_errsql = mysql_query($insert_errsql);
        }
    }
}
Esempio n. 7
0
 public function updateGoogleCalendarEvent($action)
 {
     try {
         // catch google exceptions so the whole app doesn't crash if google has a problem syncing
         $admin = Yii::app()->settings;
         if ($admin->googleIntegration) {
             if (isset($this->syncGoogleCalendarId) && $this->syncGoogleCalendarId) {
                 //                    // Google Calendar Libraries
                 //                    $timezone = date_default_timezone_get();
                 //                    require_once "protected/extensions/google-api-php-client/src/Google_Client.php";
                 //                    require_once "protected/extensions/google-api-php-client/src/contrib/Google_CalendarService.php";
                 //                    date_default_timezone_set($timezone);
                 //
                 //                    $client = new Google_Client();
                 //                    $client->setClientId($admin->googleClientId);
                 //                    $client->setClientSecret($admin->googleClientSecret);
                 //                    //$client->setDeveloperKey($admin->googleAPIKey);
                 //                    $client->setAccessToken($this->syncGoogleCalendarAccessToken);
                 //                    $client->setUseObjects(true); // return objects instead of arrays
                 //                    $googleCalendar = new Google_CalendarService($client);
                 $auth = new GoogleAuthenticator();
                 $googleCalendar = $auth->getCalendarService();
                 // check if the access token needs to be refreshed
                 // note that the google library automatically refreshes the access token if we need a new one,
                 // we just need to check if this happend by calling a google api function that requires authorization,
                 // and, if the access token has changed, save this new access token
                 $testCal = $googleCalendar->calendars->get($this->syncGoogleCalendarId);
                 //                    if($this->syncGoogleCalendarAccessToken != $client->getAccessToken()){
                 //                        $this->syncGoogleCalendarAccessToken = $client->getAccessToken();
                 //                        $this->update(array('syncGoogleCalendarAccessToken'));
                 //                    }
                 $summary = $action->actionDescription;
                 if ($action->associationType == 'contacts' || $action->associationType == 'contact') {
                     $summary = $action->associationName . ' - ' . $action->actionDescription;
                 }
                 $event = $googleCalendar->events->get($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId);
                 if (is_array($event)) {
                     $event = new Google_Event($event);
                 }
                 $event->setSummary($summary);
                 if (empty($action->dueDate)) {
                     $action->dueDate = time();
                 }
                 if ($action->allDay) {
                     $start = new Google_EventDateTime();
                     $start->setDate(date('Y-m-d', $action->dueDate));
                     $event->setStart($start);
                     if (!$action->completeDate) {
                         $action->completeDate = $action->dueDate;
                     }
                     $end = new Google_EventDateTime();
                     $end->setDate(date('Y-m-d', $action->completeDate + 86400));
                     $event->setEnd($end);
                 } else {
                     $start = new Google_EventDateTime();
                     $start->setDateTime(date('c', $action->dueDate));
                     $event->setStart($start);
                     if (!$action->completeDate) {
                         $action->completeDate = $action->dueDate;
                     }
                     // if no end time specified, make event 1 hour long
                     $end = new Google_EventDateTime();
                     $end->setDateTime(date('c', $action->completeDate));
                     $event->setEnd($end);
                 }
                 if ($action->color && $action->color != '#3366CC') {
                     $colorTable = array(10 => 'Green', 11 => 'Red', 6 => 'Orange', 8 => 'Black');
                     if (($key = array_search($action->color, $colorTable)) != false) {
                         $event->setColorId($key);
                     }
                 }
                 $newEvent = $googleCalendar->events->update($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId, $event);
             }
         }
     } catch (Exception $e) {
     }
 }
/**
 * up to date event recently created
*/
function updateDateEvent($_service, $_event, $_tampon) {
	try {
		//actual date
		$datetime = new DateTime('now');

		//end event date
		$end = new Google_EventDateTime();
		$end->setDateTime($datetime->format("Y-m-d\TH:i:s"));
		$end->setTimeZone('Europe/Paris');
		$_event->setEnd($end);				

		//event description (cronjob output)
		$_event->setDescription($_tampon);

		//update event
		$_service->events->update(SolrSafeOperatorHelper::clusterIni('ConfigCalendar', 'CalendarId', 'calendar.ini'), $_event->getId(), $_event);

		$cli = eZCLI::instance();
		$cli->output('Event id : ' . $_event->getId() . ' updated');	
	} catch(Exception $e) {
		$cli = eZCLI::instance();
		$cli->output($e->getMessage());
	}
}
Esempio n. 9
0
function cloud_scrivi_calendar($evento_descr, $evento_start, $evento_durata = '+2 hours', $evento_location = '', $event_id = null)
{
    $evento_descr = $evento_descr;
    $evento_start1 = strtotime($evento_start);
    $evento_end1 = strtotime($evento_start . $evento_durata);
    $evento_location = $evento_location;
    /*************** DA QUI IN GIU NON TOCCHEREI PIU NULLA...  ******************/
    $app_name = 'allarrembaggio';
    $client_id = '1034795448812-gghclbbghnvnmotg6as7524fraeojfnh.apps.googleusercontent.com';
    $email_address = '*****@*****.**';
    $key_file = plugin_dir_path(__FILE__) . 'google-api-php-client/allarrembaggio-85318f0a4e9d.p12';
    $calendar_id = '*****@*****.**';
    $evento_start = gmdate('Y-m-d\\TH:i:s', $evento_start1);
    $evento_end = gmdate('Y-m-d\\TH:i:s', $evento_end1);
    require_once "google-api-php-client/src/Google_Client.php";
    require_once "google-api-php-client/src/contrib/Google_CalendarService.php";
    $client = new Google_Client();
    $client->setUseObjects(true);
    $client->setApplicationName($app_name);
    $client->setClientId($client_id);
    $client->setAssertionCredentials(new Google_AssertionCredentials($email_address, array("https://www.googleapis.com/auth/calendar"), file_get_contents($key_file)));
    //setAssertionCredentials
    $service = new Google_CalendarService($client);
    $event = new Google_Event();
    $event->setSummary($evento_descr);
    $event->setLocation($evento_location);
    $start = new Google_EventDateTime();
    $start->setDateTime($evento_start);
    $start->setTimeZone('Europe/Rome');
    $event->setStart($start);
    $end = new Google_EventDateTime();
    $end->setDateTime($evento_end);
    $end->setTimeZone('Europe/Rome');
    $event->setEnd($end);
    //--prima di crearlo, elimino eventuali eventi
    if ($event_id != null) {
        $service->events->delete($calendar_id, $event_id);
    }
    //--creo l'evento
    $new_event = null;
    try {
        $new_event = $service->events->insert($calendar_id, $event);
        $new_event_id = $new_event->getId();
    } catch (Google_ServiceException $e) {
        syslog(LOG_ERR, $e->getMessage());
    }
    $output = null;
    $output = $service->events->get($calendar_id, $new_event->getId());
    $output = $output->getId();
    return $output;
}
Esempio n. 10
0
 if ($seevent->address != '') {
     $sLocation .= ', ' . html_entity_decode($seevent->address, ENT_QUOTES, 'UTF-8');
 }
 if ($seevent->city != '') {
     $sLocation .= ', ' . html_entity_decode($seevent->city, ENT_QUOTES, 'UTF-8');
 }
 $event->setLocation($sLocation);
 $strStart = Engine_Api::_()->ynevent()->getDateStringForCalendar($seevent->starttime);
 $strEnd = Engine_Api::_()->ynevent()->getDateStringForCalendar($seevent->endtime);
 #Set Start time
 $start = new Google_EventDateTime();
 $start->setDateTime($strStart);
 $event->setStart($start);
 #Set End time
 $end = new Google_EventDateTime();
 $end->setDateTime($strEnd);
 $event->setEnd($end);
 #Get Calendar list
 $calendarList = $cal->calendarList->listCalendarList();
 #Check main Calendar
 if (count($calendarList)) {
     foreach ($calendarList['items'] as $calendar) {
         if ($calendar['accessRole'] == 'owner') {
             #Post event to Google Calendar
             $cal->events->insert($calendar['id'], $event);
         }
     }
 }
 $_SESSION['accesstoken'] = $client->getAccessToken();
 #Redirect to event
 $_SESSION['google_calendar_message'] = Zend_Registry::get("Zend_Translate")->_("Added successfully!");
Esempio n. 11
0
 protected function createGoogleEventFromTermin($termin, $event = null)
 {
     // 'id' => '761',
     // 'datum' => '10.10.2012',
     // 'titel' => 'Dynamische Meditation',
     // 'untertitel' => 'mit Milam Horn --Anm: 0175-86 57 233',
     // 'zeit' => '06:00 Uhr',
     // 'url' => '',
     // 'from' => '1349848800',
     // 'to' => '1349848801',
     // 'gId' => '',
     if (!$event) {
         $event = new Google_Event();
     }
     $event->setSummary($termin->titel);
     $untertitel = str_replace('--', '<br/>', $termin->untertitel);
     $untertitel .= '<hr/>' . str_replace('--', '<br/>', $termin->datum) . ' ' . str_replace('--', '<br/>', $termin->zeit);
     if ($termin->url) {
         $untertitel .= '<hr/><a href="' . $termin->url . '">Weitere Informationen</a>';
     }
     $event->setDescription($untertitel);
     $to = $termin->to;
     $from = $termin->from;
     $days = 1;
     while ($to - $from > 60 * 60 * 24) {
         $to -= 60 * 60 * 24;
         $days++;
     }
     $start = new Google_EventDateTime();
     $start->setDateTime(date('Y-m-d\\TH:i:s', $from));
     $start->setTimezone('Europe/Berlin');
     $event->setStart($start);
     $end = new Google_EventDateTime();
     $end->setDateTime(date('Y-m-d\\TH:i:s', $to));
     $end->setTimezone('Europe/Berlin');
     $event->setEnd($end);
     if ($days > 1) {
         $freq = "RRULE:FREQ=DAILY;COUNT=" . $days;
         $event->setRecurrence(array($freq));
     }
     return $event;
 }
Esempio n. 12
0
function newDateTime($date, $time)
{
    date_default_timezone_set('America/Los_Angeles');
    $datetime = new Google_EventDateTime();
    $date = date('c', strtotime("{$date} {$time}"));
    $datetime->setDateTime($date);
    $datetime->setTimeZone('America/Los_Angeles');
    return $datetime;
}