Ejemplo n.º 1
0
/**
 * Returns an entry object representing the event with the specified ID.
 *
 * @param  Zend_Http_Client $client  The authenticated client object
 * @param  string           $eventId The event ID string
 * @return Zend_Gdata_Calendar_EventEntry|null if the event is found, null if it's not
 */
function getEvent(Zend_Http_Client $client, $eventId)
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $query = $gdataCal->newEventQuery();
    $query->setUser('default');
    $query->setVisibility('private');
    $query->setProjection('full');
    $query->setEvent($eventId);
    try {
        $eventEntry = $gdataCal->getCalendarEventEntry($query);
        return $eventEntry;
    } catch (Zend_Gdata_App_Exception $e) {
        return null;
    }
}
Ejemplo n.º 2
0
    /**
     * Delete a note
     *
     * @param array $args Information about the anotation
     *
     * @return True if success and false otherwise
     */
    public function deleteNote($args) {
        // Security check
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ));

        $aid = FormUtil::getPassedValue('aid', isset($args['aid']) ? $args['aid'] : null, 'REQUEST');
        $daid = FormUtil::getPassedValue('daid', isset($args['daid']) ? $args['daid'] : null, 'REQUEST');

        $uid = UserUtil::getVar('uid');
        // Get the note
        $note = ModUtil::apiFunc('IWagendas', 'user', 'get', array('aid' => $aid));
        if ($note == false) {
            return $this->__('Event not found');
        }
        // Check if user can access the note
        if ($daid != 0) {
            // Shared agenda
            // Get agenda information
            $agenda = ModUtil::apiFunc('IWagendas', 'user', 'getAgenda', array('daid' => $daid));

            // Check whether the user can access the agenda for this action
            $te_acces = ModUtil::func('IWagendas', 'user', 'te_acces', array('daid' => $daid,
                        'grup' => $agenda['grup'],
                        'resp' => $agenda['resp'],
                        'activa' => $agenda['activa']));
            // If the user has no access, show an error message and stop execution
            if ($te_acces < 3 || ($te_access == 3 && $note['usuari'] != $uid)) {
                return $this->__('You are not allowed to administrate the agendas');
            }
        } else {
            if ($note['daid'] > 0) {
                // Get agenda information
                $agenda = ModUtil::apiFunc('IWagendas', 'user', 'getAgenda', array('daid' => $note['daid']));
            }
        }
        $deleted = '';
        if ($note['daid'] == $daid) {
            if ($daid == 0) {
                // Check if user is trying to delete an ouw note
                if ($note['usuari'] != UserUtil::getVar('uid')) {
                    return $this->__('You are not allowed to administrate the agendas');
                }
                // Only in personal agendas the notes are deleted from database
                if (ModUtil::apiFunc('IWagendas', 'user', 'delete', array('aid' => $aid))) {
                    // Success
                    $deleted = $aid;
                }
                // Check if it has got attached file and if it is needed in other notes
                if ($note['fitxer'] != '') {
                    $n_fitxers = ModUtil::apiFunc('IWagendas', 'user', 'n_fitxers', array('fitxer' => $note['fitxer']));
                    if ($n_fitxers == 0 && file_exists(ModUtil::getVar('IWmain', 'documentRoot') . '/' . ModUtil::getVar('IWagendas', 'urladjunts') . '/' . $note['fitxer'])) {
                        $folder = ModUtil::getVar('IWagendas', 'urladjunts');
                        $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                        $delete = ModUtil::func('IWmain', 'user', 'deleteFile', array('sv' => $sv,
                                    'folder' => $folder,
                                    'fileName' => $note['fitxer']));
                    }
                }
            } else {
                // in this case the note is deleted wend it expires
                // with the value deleted = 1 users can see the label deleted in personal agendas but the note is not
                // visible in shared agenda
                if (strpos($agenda['gAccessLevel'], '$owne|' . $uid . '$') !== false || $agenda['gAccessLevel'] == '') {
                    $deletedByUser = ($note['deletedByUser'] == '') ? '$' : $note['deletedByUser'];
                    $deletedByUser .= ( strpos($agenda['gAccessLevel'], '$owne|' . $uid . '$') !== false) ? '$' . $uid . '$' : $deletedByUser;
                    $items = array('deleted' => 1,
                        'deletedByUser' => $deletedByUser,
                        'protegida' => 0);
                    $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $aid,
                                'daid' => $daid,
                                'items' => $items));
                    if ($lid != false)
                        $deleted = $aid; //success
                } else {
                    return $this->__('You are not allowed to administrate the agendas');
                }
            }
        } else {
            $deletedShared = ($note['gCalendarEventId'] != '' && strpos($agenda['gAccessLevel'], '$owne|' . $uid . '$') !== false) ? 1 : 0;
            $deletedByUser = ($note['deletedByUser'] == '') ? '$' : $note['deletedByUser'];
            $deletedByUser .= '$' . $uid . '$';
            $items = array('deletedByUser' => $deletedByUser,
                'deleted' => $deletedShared,
                'protegida' => 0);
            $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $aid,
                        'daid' => $daid,
                        'items' => $items));
            if ($lid != false)
                $deleted = $aid; // success
        }
        //delete the gCalendar notes
        $usability = ModUtil::func('IWagendas', 'user', 'getGdataFunctionsUsability');
        if ($usability === true && $note['gCalendarEventId'] != '' && strpos($agenda['gAccessLevel'], '$owne|' . $uid . '$') !== false) {
            $userSettings = ModUtil::func('IWagendas', 'user', 'getUserGCalendarSettings');
            // 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;
            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');
            $gdataCal = new Zend_Gdata_Calendar($client);
            try {
                $event = $gdataCal->getCalendarEventEntry($note['gCalendarEventId']);
            } catch (Zend_Gdata_App_Exception $e) {
                $error = true;
            }
            if (!$error) {
                try {
                    $event->delete();
                } catch (Zend_Gdata_App_Exception $e) {
                    return $this->__('You are not allowed to administrate the agendas');
                }
            } else {
                //LogUtil::registerError(_AGENDESERRORDELETINGGCALENDARNOTE);
            }
        }
        return $aid;
    }
Ejemplo n.º 3
0
require_once "data/data.inc.php";
// records stats
require_once "../page_builder/page_header.php";
// libs
require_once "lib/google_calendar.init.php";
require_once "lib/calendar.lib.php";
require_once "lib/textformat.lib.php";
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
// predefined service name for calendar
// the method of building a query based on newEventQuery() just didn't seem to want to work. this did though.
$client = Zend_Gdata_ClientLogin::getHttpClient($username . '@gmail.com', $password, $service);
$gdataCal = new Zend_Gdata_Calendar($client);
$error = false;
try {
    $url = 'http://www.google.com/calendar/feeds/' . $calendars[$_REQUEST['cal']]['user'] . '/private/full/_' . $_REQUEST['id'];
    $event = $gdataCal->getCalendarEventEntry($url);
} catch (Exception $e) {
    $error = true;
}
if ($error == true) {
    // need to create an error handler class
    echo "<div class='error'>Error for details" . $url . "</div>" . $e;
    exit;
} else {
    $when = $event->getWhen();
    $startTime = $when[0]->startTime;
    $endTime = $when[0]->endTime;
    $date_str = strftime('%A, %B %e, %Y', strtotime($startTime));
    $date_str_for_storage = strftime('%D', strtotime($startTime));
    $date_str_for_compare = strftime('%Y%m%d', strtotime($startTime));
    if (!(strlen($startTime) == 10)) {
/****************************************************************/
/**
 * This file is used to reflect changes from ATutor to Google Calendar.
 */
$_user_location = 'public';
require_once 'includes/classes/googlecalendar.class.php';
define('AT_INCLUDE_PATH', '../../../include/');
require AT_INCLUDE_PATH . 'vitals.inc.php';
$gcalobj = new GoogleCalendar();
$client = $gcalobj->getAuthSubHttpClient();
$gdata_cal = new Zend_Gdata_Calendar($client);
$event_url = $_GET['id'];
$command = $_GET['cmd'];
try {
    //Get the event object from its id.
    $event = $gdata_cal->getCalendarEventEntry($event_url);
    if (strcmp($command, 'delete') == 0) {
        //If event is deleted then call delete method.
        $event->delete();
    } else {
        if (strcmp($command, 'update') == 0) {
            //Update event attributes and then save it in Google Calendar.
            $event->title = $gdata_cal->newTitle($_GET['title']);
            $when = $gdata_cal->newWhen();
            $when->startTime = $_GET['start'];
            $when->endTime = $_GET['end'];
            $event->when = array($when);
            $event->save();
        }
    }
    exit;
Ejemplo n.º 5
0
        function delete_event_calendar_extern($event){
            ajx_current("empty");
            if($event->getExtCalId() > 0){
                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_Calendar');

                $users = ExternalCalendarUsers::findByContactId();
                $calendar = ExternalCalendars::findById($event->getExtCalId());

                $user = $users->getAuthUser();
                $pass = $users->getAuthPass();
                $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
				
                try
                {
	                $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);
	
	                $event_id = 'http://www.google.com/calendar/feeds/'.$calendar->getCalendarUser().'/private/full/'.$event->getSpecialID();
	
	                $gcal = new Zend_Gdata_Calendar($client);
	
	                $edit_event = $gcal->getCalendarEventEntry($event_id);
	                $edit_event->delete(); 
	            }
	            catch(Exception $e)
	            {
	                flash_error($e->getMessage());
	                ajx_current("empty");
	            }
            }            
        }
function getEventByUrl($eventEditUrl)
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $query = $gdataCal->newEventQuery();
    $query->setUser('default');
    $query->setVisibility('private');
    $query->setProjection('full');
    $query->setEvent($eventId);
    try {
        $eventEntry = $gdataCal->getCalendarEventEntry($query);
        return $eventEntry;
    } catch (Zend_Gdata_App_Exception $e) {
        var_dump($e);
        return false;
    }
}
Ejemplo n.º 7
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;
 }