function addEvent($title = 'Новый заказ', $desc = 'Описание заказа', $where = 'интернет-магазин', $startDate, $endDate, $sms_reminder)
 {
     try {
         set_include_path('.' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/modules/gcalendar/' . PATH_SEPARATOR . get_include_path());
         include_once 'Zend/Loader.php';
         Zend_Loader::loadClass('Zend_Gdata');
         Zend_Loader::loadClass('Zend_Gdata_AuthSub');
         Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
         Zend_Loader::loadClass('Zend_Gdata_HttpClient');
         Zend_Loader::loadClass('Zend_Gdata_Calendar');
         $client = Zend_Gdata_ClientLogin::getHttpClient($this->_user, $this->_pass, "cl");
         $gdataCal = new Zend_Gdata_Calendar($client);
         $newEvent = $gdataCal->newEventEntry();
         $newEvent->title = $gdataCal->newTitle($title);
         $newEvent->where = array($gdataCal->newWhere($where));
         $newEvent->content = $gdataCal->newContent($desc);
         $when = $gdataCal->newWhen();
         $when->startTime = $startDate;
         $when->endTime = $endDate;
         if (intval($sms_reminder)) {
             $reminder = $gdataCal->newReminder();
             $reminder->method = "sms";
             $reminder->minutes = "0";
             $when->reminders = array($reminder);
         }
         $newEvent->when = array($when);
         $createdEvent = $gdataCal->insertEvent($newEvent);
         return $createdEvent->id->text;
     } catch (Exception $ex) {
         // Report the exception to the user
     }
 }
function g_cal_createEvent($client, $title = 'Untitled', $desc = '', $where = '', $startDate = '2008-01-01', $startTime = '0', $endDate = '2008-01-01', $endTime = '0', $tzOffset = '-08')
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $newEvent = $gdataCal->newEventEntry();
    $newEvent->title = $gdataCal->newTitle($title);
    $newEvent->where = array($gdataCal->newWhere($where));
    $newEvent->content = $gdataCal->newContent("{$desc}");
    if ($startTime == '0' || $startTime == '') {
        //Make this an All-Day Event
        $when = $gdataCal->newWhen();
        $when->startTime = "{$startDate}";
        $when->endTime = "{$endDate}";
    } else {
        $when = $gdataCal->newWhen();
        $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
        $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    }
    $newEvent->when = array($when);
    // Upload the event to the calendar server
    // A copy of the event as it is recorded on the server is returned
    $createdEvent = $gdataCal->insertEvent($newEvent);
    /*
      //Store the new eventID in the cohelitack database
    	//g_cal_updateEvent($client, $createdEvent->id, "New Title");
    	echo "\$event->getLink('edit')->href: " . $createdEvent->getLink('edit')->href . "<br>\n";
    	echo "\$event->getId(): " . $createdEvent->getId() . "<br>\n";
    	
    	$myEvent = getEvent($client,$createdEvent->getId());
    	echo "\$myEvent->getId(): " . $myEvent->getId() . "<br>\n";
    	
    	//g_cal_deleteEventByUrl($client,$createdEvent->getLink('edit')->href);
    	//g_cal_deleteEventById($client,$createdEvent->getId());
    */
    return $createdEvent->getLink('edit')->href;
}
 public function setPlanning($startDate, $endDate, $title, $content)
 {
     // Parameters for ClientAuth authentication
     ProjectConfiguration::registerZend();
     Zend_Loader::loadClass('Zend_Gdata');
     Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
     Zend_Loader::loadClass('Zend_Gdata_Calendar');
     $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
     $user = sfConfig::get('app_gmail_user');
     $pass = sfConfig::get('app_gmail_pwd');
     // Create an authenticated HTTP client
     $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
     // Create an instance of the Calendar service
     $service = new Zend_Gdata_Calendar($client);
     // Create a new entry using the calendar service's magic factory method
     $event = $service->newEventEntry();
     // Populate the event with the desired information
     // Note that each attribute is crated as an instance of a matching class
     $event->title = $service->newTitle($title);
     $event->where = array($service->newWhere("Paris, France"));
     $event->content = $service->newContent($content);
     // Set the date using RFC 3339 format.
     $tzOffset = "+02";
     $when = $service->newWhen();
     //$when->startTime = "{$start_date}.000{$tzOffset}:00";
     //$when->endTime = "{$end_date}.000{$tzOffset}:00";
     $when->startTime = "{$startDate}:00.000{$tzOffset}:00";
     $when->endTime = "{$endDate}:00.000{$tzOffset}:00";
     $event->when = array($when);
     // Upload the event to the calendar server
     // A copy of the event as it is recorded on the server is returned
     $newEvent = $service->insertEvent($event);
 }
 /**
  * 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           $where
  * @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           $endDate   The end date of the event in YYYY-MM-DD 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 string The ID URL for the event.
  */
 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')
 {
     $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';
     $when = $gc->newWhen();
     $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
     $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
     $newEntry->when = array($when);
     $createdEntry = $gc->insertEvent($newEntry);
     return $createdEntry->id->text;
 }
Ejemplo n.º 5
0
 function updateEvent($recordid, $eventOld, $Data, $tzOffset = '+00:00')
 {
     set_include_path($this->root_directory . "modules/Calendar4You/");
     $startDate = $Data["date_start"];
     $endDate = $Data["due_date"];
     $startTime = $Data["time_start"];
     $endTime = $Data["time_end"];
     $GCalClass = new Zend_Gdata_Calendar($this->gClient);
     $eventOld->title = $GCalClass->newTitle(trim($Data["subject"]));
     $eventOld->where = array($GCalClass->newWhere(trim($Data["location"])));
     $eventOld->content = $GCalClass->newContent($Data["description"]);
     $when = $GCalClass->newWhen();
     $when->startTime = $startDate . 'T' . $this->removeLastColon($startTime) . ':00.000' . $tzOffset;
     $when->endTime = $endDate . 'T' . $this->removeLastColon($endTime) . ':00.000' . $tzOffset;
     $eventOld->when = array($when);
     $whos = $this->getInvitedUsersEmails($GCalClass, $recordid);
     if (count($whos) > 0) {
         $eventOld->setWho($whos);
     }
     try {
         $eventOld->save();
         $status = true;
     } catch (Zend_Gdata_App_Exception $e) {
         $status = null;
     }
     set_include_path($this->root_directory);
     return $status;
 }
Ejemplo n.º 6
0
 /**
  * Creates an event on the authenticated users default calendar with the
  * specified event details.
  *
  * @return string The id URL for the event.
  */
 public function createEvent(TA_Model_Resource_Db_Table_Row_Abstract $values)
 {
     $values = $this->_modifyValues($values);
     $gc = new Zend_Gdata_Calendar($this->_client);
     $newEntry = $gc->newEventEntry();
     // set event properties
     $newEntry->title = $gc->newTitle(trim($values['title']));
     $newEntry->where = array($gc->newWhere($values['location']));
     $newEntry->content = $gc->newContent($values['description']);
     $newEntry->content->type = 'text';
     $when = $gc->newWhen();
     $start = date_create($values['start']);
     $end = date_create($values['end']);
     $when->startTime = date_format($start, 'Y-m-d\\TH:i:s.000P');
     $when->endTime = date_format($end, 'Y-m-d\\TH:i:s.000P');
     $newEntry->when = array($when);
     $createdEntry = $gc->insertEvent($newEntry);
     return $createdEntry->id->text;
 }
Ejemplo n.º 7
0
    /**
     * Get the user notes from Google calendar (Gdata Zend functions are necessary)
     */
    public function gCalendar() {
        // Security check
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ));

        // get user uid
        $user = (UserUtil::getVar('uid') == '') ? '-1' : UserUtil::getVar('uid');
        $usability = ModUtil::func('IWagendas', 'user', 'getGdataFunctionsUsability');
        if ($usability !== true) {
            throw new Zikula_Exception_Forbidden();
        }
        //Load required classes
        require_once 'Zend/Loader.php';
        Zend_Loader::loadClass('Zend_Gdata');
        Zend_Loader::loadClass('Zend_Gdata_AuthSub');
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
        Zend_Loader::loadClass('Zend_Gdata_HttpClient');
        Zend_Loader::loadClass('Zend_Gdata_Calendar');
        //@var string Location of AuthSub key file.  include_path is used to find this
        $_authSubKeyFile = null; // Example value for secure use: 'mykey.pem'
        //@var string Passphrase for AuthSub key file.
        $_authSubKeyFilePassphrase = null;
        $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
        $userSettings = ModUtil::func('IWagendas', 'user', 'getUserGCalendarSettings');
        if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
            try {
                $client = Zend_Gdata_ClientLogin::getHttpClient($userSettings['gUserName'], base64_decode($userSettings['gUserPass']), $service);
            } catch (exception $e) {
                $authSubUrl = ModUtil::func('IWagendas', 'user', 'getAuthSubUrl');
                return System::redirect(ModUtil::url('IWwebbox', 'user', 'main', array('url' => str_replace('&', '*', str_replace('?', '**', $authSubUrl)))));
            }
        } else
            $client = ModUtil::func('IWagendas', 'user', 'getAuthSubHttpClient');
        try {
            $gdataCal = new Zend_Gdata_Calendar($client);
        } catch (exception $e) {
            LogUtil::registerError($this->__('Connection with Google failed. Imposible to synchronize the agenda'));
            return false;
        }
        //get user calendars
        try {
            $calFeed = $gdataCal->getCalendarListFeed();
        } catch (exception $e) {
            LogUtil::registerError($this->__('Connection with Google failed. Imposible to synchronize the agenda'));
            return false;
        }
        $gCalendarsIdsArray = array();
        foreach ($calFeed as $calendar) {
            $gCalendarsIdsArray[] = $calendar->id;
        }
        // Get all existing google calendars stored in database. We need them to know if the received google calendars exists or not
        $gAgendas = ModUtil::apiFunc('IWagendas', 'user', 'getAllAgendas', array('gAgendas' => 1,
                    'gCalendarsIdsArray' => $gCalendarsIdsArray));
        $gCalendarsIdsArray = array();
        foreach ($gAgendas as $g) {
            $gIds[$g['gCalendarId']] = $g;
        }
        $existingCalendar = array();
        // Create or edit the calendars if it were necessary
        foreach ($calFeed as $calendar) {
            //sincronize calendars
            $id = $calendar->id;
            $resp = '$' . $user . '$';
            $accessLevel = '$' . substr($calendar->accessLevel->value, 0, 4) . '|' . $user . '$';
            $color = '$' . $calendar->color->value . '|' . $user . '$';
            // Create a calendar array based on the calendar id
            $existingCalendar["$id"] = 1;
            if (!array_key_exists("$id", $gIds)) {
                $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                $agenda = ModUtil::apiFunc('IWagendas', 'admin', 'create', array('nom_agenda' => $calendar->title,
                            'descriu' => $calendar->summary->text,
                            'c1' => $this->__('What'),
                            'c2' => $this->__('End'),
                            'c3' => $this->__('Where'),
                            'c4' => $this->__('Content'),
                            'c5' => $this->__('Author'),
                            'tc1' => 1,
                            'tc2' => 1,
                            'tc3' => 1,
                            'tc4' => 2,
                            'tc5' => 1,
                            'activa' => 1,
                            'adjunts' => 0,
                            'protegida' => 1,
                            'gColor' => '$' . $color,
                            'color' => '',
                            'gCalendarId' => $id,
                            'gAccessLevel' => '$' . $accessLevel,
                            'resp' => '$' . $resp,
                            'sv' => $sv));
                // add new agenda into the array in case the agenda is created recently
                $gIds["$id"] = $agenda;
            } else {
                if ($gIds["$id"]['nom_agenda'] != $calendar->title ||
                        $gIds["$id"]['descriu'] != $calendar->summary->text ||
                        strpos($gIds["$id"]['gColor'], $color) === false ||
                        strpos($gIds["$id"]['resp'], $resp) === false ||
                        strpos($gIds["$id"]['gAccessLevel'], $accessLevel) === false) {
                    if (strpos($gIds["$id"]['gAccessLeve l'], $accessLevel) === false) {
                        // Change the gCalendar access level
                        $pos = strpos($gIds["$id"]['gAccessLevel'], '|' . $user . '$');
                        $userAccessLevel = ($pos > 0) ? substr($gIds["$id"]['gAccessLevel'], $pos - 5, (int) strlen($user) + 7) : '';
                        $newAccessLevelString = ($pos > 0) ? str_replace($userAccessLevel, $accessLevel, $gIds["$id"]['gAccessLevel']) : $gIds["$id"]['gAccessLevel'] . $accessLevel;
                    }
                    if (strpos($gIds["$id"]['gColor'], $color) === false) {
                        // Change the gCalendar access level
                        $pos = strpos($gIds["$id"]['gColor'], '|' . $user . '$');
                        $userColor = ($pos > 0) ? substr($gIds["$id"]['gColor'], $pos - 8, (int) strlen($user) + 10) : '';
                        $newColorString = ($pos > 0) ? str_replace($userColor, $color, $gIds["$id"]['gColor']) : $gIds["$id"]['gColor'] . $color;
                    }
                    $resp = (strpos($gIds["$id"]['resp'], $resp) === false) ? $resp : '';
                    $items = array('nom_agenda' => $calendar->title,
                        'descriu' => $calendar->summary->text,
                        'gColor' => $newColorString,
                        'resp' => $gIds["$id"]['resp'] . $resp,
                        'gAccessLevel' => $newAccessLevelString);
                    $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                    ModUtil::apiFunc('IWagendas', 'admin', 'editAgenda', array('daid' => $gIds["$id"]['daid'],
                        'items' => $items,
                        'sv' => $sv));
                }
            }
        }
        // Get data from google for 2 months ago and 4 future months more or less
        $time = time();
        $beginDate = $time - 2 * 30 * 24 * 60 * 60;
        $endDate = $time + 4 * 30 * 24 * 60 * 60;
        $beginOndate = date('Y-m-d', $beginDate);
        $endOnDate = date('Y-m-d', $endDate);
        //get all the google notes
        $gCalendarNotes = ModUtil::apiFunc('IWagendas', 'user', 'getAllGCalendarNotes', array('beginDate' => $beginDate,
                    'endDate' => $endDate,
                    'gIds' => $gIds));
        foreach ($calFeed as $calendar) {
            $id = $calendar->id;
            $query = $gdataCal->newEventQuery();
            $calFeed = $gdataCal->getCalendarListFeed();
            $gUser = str_replace(Zend_Gdata_Calendar::CALENDAR_FEED_URI . '/default/', "", $id); // kind of dirty way to get the info, nut it lokks working :)
            $query->setUser($gUser);
            $query->setVisibility('private');
            $query->setProjection('full');
            $query->setOrderby('starttime');
            $query->setStartMin($beginOndate);
            $query->setStartMax($endOnDate);
            $eventFeed = array();
            if ($calendar->accessLevel->value == 'owner' ||
                    $calendar->accessLevel->value == 'editor' ||
                    $calendar->accessLevel->value == 'read') {
                $eventFeed = $gdataCal->getCalendarEventFeed($query);
            }
            foreach ($eventFeed as $event) {
                foreach ($event->when as $when) {
                    $startTime = $when->startTime;
                    $day = substr($startTime, 8, 2);
                    $month = substr($startTime, 5, 2);
                    $year = substr($startTime, 0, 4);
                    $hour = substr($startTime, 11, 2);
                    $minute = substr($startTime, 14, 2);
                    $startTime = gmmktime($hour, $minute, 0, $month, $day, $year);
                    $day = date('d', $startTime);
                    $month = date('m', $startTime);
                    $year = date('Y', $startTime);
                    $hour = date('H', $startTime);
                    $minute = date('i', $startTime);
                    $endTime = $when->endTime;
                    $dayEnd = substr($endTime, 8, 2);
                    $monthEnd = substr($endTime, 5, 2);
                    $yearEnd = substr($endTime, 0, 4);
                    $hourEnd = substr($endTime, 11, 2);
                    $minuteEnd = substr($endTime, 14, 2);
                    $endTime = gmmktime($hourEnd, $minuteEnd, 0, $monthEnd, $dayEnd, $yearEnd);
                    $dayEnd = date('d', $endTime);
                    $monthEnd = date('m', $endTime);
                    $yearEnd = date('Y', $endTime);
                    $hourEnd = date('H', $endTime);
                    $minuteEnd = date('i', $endTime);
                    $allDay = (($minute == '' || $minute == '00') && ($hour == '' || $hour == '23') && ($minuteEnd == '' || $minuteEnd == '00') && ($hourEnd == '' || $hourEnd == '00')) ? 1 : 0;
                    $end = ($allDay == 0) ? $this->__('Foreseen time to finish') . ': ' . $hourEnd . ':' . $minuteEnd : $this->__('All day');
                    if (!array_key_exists("$event->id", $gCalendarNotes)) {
                        //create item
                        $lid = ModUtil::apiFunc('IWagendas', 'user', 'crear', array('dia' => $day,
                                    'mes' => $month,
                                    'any' => $year,
                                    'c1' => $event->title,
                                    'c2' => $end,
                                    'c3' => $event->where[0]->valueString,
                                    'c4' => $event->content,
                                    'c5' => $event->author[0]->email->text,
                                    'c6' => '',
                                    'minut' => $minute,
                                    'hora' => $hour,
                                    'totdia' => $allDay,
                                    'tasca' => 0,
                                    'nivell' => 0,
                                    'rid' => '-1',
                                    'daid' => $gIds["$id"]['daid'],
                                    'nova' => '$$' . $user . '$',
                                    'oculta' => 0,
                                    'fitxer' => '',
                                    'origen' => '',
                                    'gCalendarEventId' => $event->id,
                                    'protegida' => 0));
                    } else {
                        $existing["$event->id"] = 1;
                        $item = $gCalendarNotes["$event->id"];
                        if ($allDay) {
                            $hour = 23;
                            $minute = 59;
                        }
                        $data = mktime($hour, $minute, 0, $month, $day, $year);
                        //check if item has changed. If it has changed it is updated
                        if ($item['c1'] != $event->title ||
                                $item['data'] != $data ||
                                $item['c2'] != $end ||
                                $item['c3'] != $event->where[0]->valueString ||
                                $item['c4'] != $event->content) {
                            $items = array('c1' => $event->title,
                                'c2' => $end,
                                'c3' => $event->where[0]->valueString,
                                'c4' => $event->content,
                                'data' => $data,
                                'totdia' => $allDay,
                                'origen' => $calendar->title,
                                'totdia' => $allDay);
                            //modify of a simple entry
                            $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $item['aid'],
                                        'items' => $items,
                                        'daid' => $item['daid']));
                        }
                        //delete event from gCalendar if it were necessary
                        if ($item['deleted'] == 1) {
                            //delete of a simple entry
                            try {
                                $event->delete();
                            } catch (Zend_Gdata_App_Exception $e) {
                                return $this->__('You are not allowed to administrate the agendas');
                            }
                        }
                    }
                }
            }
        }
        // Delete the calendars where user can't access any more
        $diff = array_diff_key($gIds, $existingCalendar);
        foreach ($diff as $d) {
            if ($resp == '$') {
                // Nobody else needs the calendar and it is deleted
                $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                ModUtil::apiFunc('IWagendas', 'admin', 'delete', array('daid' => $d['daid'],
                    'sv' => $sv));
            } else {
                // The user access to the calendar is deleted
                $items = array('gColor' => $newColorString,
                    'resp' => $resp,
                    'gAccessLevel' => $newAccessLevelString);
                $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                ModUtil::apiFunc('IWagendas', 'admin', 'editAgenda', array('daid' => $d['daid'],
                    'items' => $items,
                    'sv' => $sv));
            }
        }
        // set as deleted the not existing gCalendar notes
        $diff = array_diff_key($gCalendarNotes, $existing);
        foreach ($diff as $d) {
            if (strpos($gAgendas[$d['daid']]['gAccessLevel'], '$free|' . $user . '$') === false) {
                $items = array('deleted' => 1,
                    'protegida' => 0);
                $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $d['aid'],
                            'daid' => $d['daid'],
                            'items' => $items));
            }
        }
        //save that the sincronization has been made
        $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
        ModUtil::func('IWmain', 'user', 'userSetVar', array('uid' => $user,
            'name' => 'sincroGCalendar',
            'module' => 'IWagendas',
            'sv' => $sv,
            'value' => '1',
            'lifetime' => $userSettings['gRefreshTime'] * 60));
        //get all notes from gCalendar that has been created without connexion and create them
        $notesNotInGCalendar = ModUtil::apiFunc('IWagendas', 'user', 'getAllGCalendarNotes', array('beginDate' => $beginDate,
                    'endDate' => $endDate,
                    'gIds' => $gIds,
                    'notInGCalendar' => 1));
        foreach ($notesNotInGCalendar as $note) {
            $data = $note['data'];
            $data1 = $note['data1'];
            //Protect correct format for dateStart and dataEnd
            if ($data1 < $data)
                $data1 = $data;
            // Create a new entry using the calendar service's magic factory method
            $event = $gdataCal->newEventEntry();
            // Populate the event with the desired information
            // Note that each attribute is crated as an instance of a matching class
            $event->title = $gdataCal->newTitle($note['c1']);
            $event->where = array($gdataCal->newWhere($note['c3']));
            $event->content = $gdataCal->newContent($note['c4']);
            // Set the date using RFC 3339 format.
            $startDate = date('Y-m-d', $data);
            $endDate = date('Y-m-d', $data1);
            $when = $gdataCal->newWhen();
            if ($note['totdia'] == 0) {
                $tzOffset = ($userSettings['tzOffset'] == '') ? '+02' : $userSettings['tzOffset'];
                //protect correct time format
                $startTime = date('H:i', $data);
                $endTime = date('H:i', $data1);
                $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
                $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
            } else {
                $when->startTime = "$startDate";
                $when->endTime = "$endDate";
            }
            $event->when = array($when);
            $calendarURL = str_replace(Zend_Gdata_Calendar::CALENDAR_FEED_URI . '/default/', "", $gAgendas[$note['daid']]['gCalendarId']);
            $calendarURL = 'http://www.google.com/calendar/feeds/' . $calendarURL . '/private/full';
            // Upload the event to the calendar server
            // A copy of the event as it is recorded on the server is returned
            try {
                $newEvent = $gdataCal->insertEvent($event, $calendarURL);
            } catch (Zend_Gdata_App_Exception $e) {
                return $this->__('Error produced during gCalendar\'s event creation');
            }
            $gCalendarEventId = $newEvent->id;
            // Edit note gCalendarEventId
            $items = array('gCalendarEventId' => $gCalendarEventId);
            //modify of a simple entry
            $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $note['aid'],
                        'items' => $items,
                        'daid' => $note['daid']));
        }
        return true;
    }
Ejemplo n.º 8
0
/**
 * 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());
}
Ejemplo n.º 9
0
 /**
 * Create an event
 * @param String $client Access token
 * @param Associative Array $eventArray
 *                          'desc'      =>  'This is a description for the event',
 								'where'     =>  'Location',
 								'startDate' =>  'YYYY-MM-DD',
 								'startTime' =>  'HH:MM', // 24hr time
 								'endDate'   =>  'YYYY-MM-DD',
 								'endTime'   =>  'HH:MM', // 24hr time
 								'tzOffset'  =>  '00' // timezone offset from GMT
 * @return String - ID of created event
 */
 function createEvent($client, $eventArray)
 {
     $gdataCal = new Zend_Gdata_Calendar($client);
     $newEvent = $gdataCal->newEventEntry();
     $newEvent->title = $gdataCal->newTitle($eventArray['title']);
     $newEvent->where = array($gdataCal->newWhere($eventArray['where']));
     $newEvent->content = $gdataCal->newContent($eventArray['desc']);
     $when = $gdataCal->newWhen();
     $when->startTime = "{$eventArray['startDate']}T{$eventArray['startTime']}:00.000{$eventArray['tzOffset']}:00";
     $when->endTime = "{$eventArray['endDate']}T{$eventArray['endTime']}:00.000{$eventArray['tzOffset']}:00";
     $newEvent->when = array($when);
     //upload the even to the calendar server
     //a copy of the event as it is recorded on the server is returned
     $createdEvent = $gdataCal->insertEvent($newEvent);
     return $createdEvent->id->text;
 }
Ejemplo n.º 10
0
 function createEvent($client, $title, $desc, $where, $startDate, $startTime, $endDate, $endTime, $tzOffset)
 {
     $gdataCal = new Zend_Gdata_Calendar($client);
     $newEvent = $gdataCal->newEventEntry();
     $newEvent->title = $gdataCal->newTitle($title);
     $newEvent->where = array($gdataCal->newWhere($where));
     $newEvent->content = $gdataCal->newContent("{$desc}");
     $when = $gdataCal->newWhen();
     $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
     $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
     $newEvent->when = array($when);
     $createdEvent = $gdataCal->insertEvent($newEvent);
     return $createdEvent->id->text;
 }
Ejemplo n.º 11
0
 static function updateEvent(&$newEvent, $bean, $user)
 {
     $client = self::getClient($user);
     if ($client != false) {
         $gdataCal = new Zend_Gdata_Calendar($client);
         global $timedate;
         $date_time_start = $bean->date_start . ' ' . $bean->time_start;
         if (toTimestamp($date_time_start) < mktime(0, 0, 0, 1, 1, 2001)) {
             //$date_time_start = DateTime::get_time_start($timedate->to_db_date($bean->date_start,false),$bean->time_start.":00");
             //$date_time_start = $date_time_start->get_mysql_date().' '.$date_time_start->get_mysql_time();
             $date_time_start = date($timedate->get_db_date_time_format(), strtotime($bean->date_start));
         }
         //$date_time_start = $timedate->handle_offset($date_time_start, $timedate->get_db_date_time_format(), true);
         $time = toTimestamp($date_time_start);
         $duration = $bean->duration_hours * 60 * 60 + $bean->duration_minutes * 60;
         $when = $gdataCal->newWhen();
         $when->startTime = strftime("%Y-%m-%dT%H:%M:%S.000+00:00", $time);
         $when->endTime = strftime("%Y-%m-%dT%H:%M:%S.000+00:00", $time + $duration);
         // Tasks
         if (isset($bean->date_due) === true) {
             $date_time_end = $bean->date_due . ' ' . $bean->time_due;
             if (toTimestamp($date_time_start) < mktime(0, 0, 0, 1, 1, 2001)) {
                 $date_time_end = date($timedate->get_db_date_time_format(), strtotime($bean->date_due));
             }
             $time = toTimestamp($date_time_end);
             $when->endTime = strftime("%Y-%m-%dT%H:%M:%S.000+00:00", $time);
         }
         // Tasks
         if ($bean->reminder_time < 0) {
             $when->reminders = array();
         } else {
             $mins = (int) ($bean->reminder_time / 60);
             // reminder_time are seconds
             if ($mins < 5) {
                 $mins = 5;
             }
             $reminder = $gdataCal->newReminder();
             //$reminder->method = "sms";
             $reminder->minutes = $mins;
             $when->reminders = array($reminder);
         }
         $newEvent->when = array($when);
         /** Conditionals **/
         if ($bean->module_dir == "Meetings") {
             $newEvent->where = array($gdataCal->newWhere($bean->location));
             $newEvent->title = $gdataCal->newTitle("Встреча: " . $bean->name);
         } elseif ($bean->module_dir == "Calls") {
             $newEvent->title = $gdataCal->newTitle("Звонок: " . $bean->name);
         } elseif ($bean->module_dir == "Tasks") {
             $newEvent->title = $gdataCal->newTitle("Задача: " . $bean->name);
         }
         $newEvent->content = $gdataCal->newContent($bean->description);
     }
 }
Ejemplo n.º 12
0
 /**
  * Tarsform  Vtiger Records to Google Records
  * @param <array> $vtEvents 
  * @return <array> tranformed vtiger Records
  */
 public function transformToTargetRecord($vtEvents)
 {
     $records = array();
     foreach ($vtEvents as $vtEvent) {
         $gcalendar = new Zend_Gdata_Calendar($this->apiInstance);
         if ($vtEvent->getMode() == WSAPP_SyncRecordModel::WSAPP_UPDATE_MODE || $vtEvent->getMode() == WSAPP_SyncRecordModel::WSAPP_DELETE_MODE) {
             try {
                 $newEntry = $gcalendar->getCalendarEventEntry($vtEvent->get('_id'));
             } catch (Exception $e) {
                 continue;
             }
         } else {
             $newEntry = $gcalendar->newEventEntry();
         }
         $newEntry->title = $gcalendar->newTitle($vtEvent->get('subject'));
         $newEntry->where = array($gcalendar->newWhere($vtEvent->get('location')));
         $newEntry->content = $gcalendar->newContent($vtEvent->get('description'));
         $newEntry->content->type = 'text';
         $oldtz = date_default_timezone_get();
         date_default_timezone_set('GMT');
         $startDate = $vtEvent->get('date_start');
         $startTime = $vtEvent->get('time_start');
         $endDate = $vtEvent->get('due_date');
         $endTime = $vtEvent->get('time_end');
         if (empty($endTime)) {
             $endTime = "00:00";
         }
         $when = $gcalendar->newWhen();
         $when->startTime = date('c', strtotime("{$startDate} {$startTime}"));
         if (!empty($endDate)) {
             $when->endTime = date('c', strtotime("{$endDate} {$endTime}"));
         }
         date_default_timezone_set($oldtz);
         $newEntry->when = array($when);
         $recordModel = Google_Calendar_Model::getInstanceFromValues(array('entity' => $newEntry));
         $recordModel->setType($this->getSynchronizeController()->getSourceType())->setMode($vtEvent->getMode())->setSyncIdentificationKey($vtEvent->get('_syncidentificationkey'));
         $recordModel = $this->performBasicTransformations($vtEvent, $recordModel);
         $recordModel = $this->performBasicTransformationsToTargetRecords($recordModel, $vtEvent);
         $records[] = $recordModel;
     }
     return $records;
 }
Ejemplo n.º 13
0
                $mail->AddAddress($user["number"]);
                // Where to send it
                // send mail
                if ($mail->Send() == false) {
                    die($mail->ErrInfo);
                }
            }
        }
    }
    //$maxPrivacy = query("SELECT MAX(level) FROM privacy")[0]["MAX(level)"];
    $maxPrivacy = $_POST["privacy"];
    for ($privacy = $_POST["privacy"]; $privacy <= $maxPrivacy; $privacy++) {
        $gc = new Zend_Gdata_Calendar($_SESSION["client"]);
        $newEntry = $gc->newEventEntry();
        $newEntry->title = $gc->newTitle($_POST["name"]);
        $newEntry->where = array($gc->newWhere($_POST["location"]));
        $newEntry->content = $gc->newContent($_POST["info"]);
        $newEntry->content->type = 'text';
        $when = $gc->newWhen();
        $calStartDate = date('c', strtotime($startDatetime));
        $calEndDate = date('c', strtotime($endDatetime));
        $when->startTime = $calStartDate;
        $when->endTime = $calEndDate;
        $newEntry->when = array($when);
        $url = query("SELECT link FROM calendarLinks WHERE id = ?", $_POST["club"] . "." . $privacy);
        $url = $url[0]["link"];
        $createdEntry = $gc->insertEvent($newEntry, $url);
    }
    //redirect to home page
    redirect("/");
} else {