/**
  * This function will return paginated result. Result is an array where first element is
  * array of returned object and second populated pagination object that can be used for
  * obtaining and rendering pagination data using various helpers.
  *
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ExternalCalendarUsers')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ExternalCalendarUsers::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& MailAccounts::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ExternalCalendarUsers 
 */
 function manager() {
   if(!($this->manager instanceof ExternalCalendarUsers)) $this->manager = ExternalCalendarUsers::instance();
   return $this->manager;
 } // manager
Ejemplo n.º 3
0
 function created_event_google_calendar($object, $event)
 {
     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;
     $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
     $calendarUrl = 'http://www.google.com/calendar/feeds/' . $calendar->getCalendarUser() . '/private/full';
     $gdataCal = new Zend_Gdata_Calendar($client);
     $newEvent = $gdataCal->newEventEntry();
     $newEvent->title = $gdataCal->newTitle($event->getObjectName());
     $newEvent->content = $gdataCal->newContent($event->getDescription());
     $star_time = explode(" ", $event->getStart()->format("Y-m-d H:i:s"));
     $end_time = explode(" ", $event->getDuration()->format("Y-m-d H:i:s"));
     if ($event->getTypeId() == 2) {
         $when = $gdataCal->newWhen();
         $when->startTime = $star_time[0];
         $when->endTime = $end_time[0];
         $newEvent->when = array($when);
     } else {
         $when = $gdataCal->newWhen();
         $when->startTime = $star_time[0] . "T" . $star_time[1] . ".000-00:00";
         $when->endTime = $end_time[0] . "T" . $end_time[1] . ".000-00:00";
         $newEvent->when = array($when);
     }
     // insert event
     $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl);
     $event_id = explode("/", $createdEvent->id->text);
     $special_id = end($event_id);
     $event->setSpecialID($special_id);
     $event->setExtCalId($calendar->getId());
     $event->save();
 }
 function findByEmail($email)
 {
     return ExternalCalendarUsers::findOne(array('conditions' => array('`auth_user` = ? AND `contact_id` = ?', $email, logged_user()->getId())));
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ExternalCalendarUsers 
  */
 function manager()
 {
     if (!$this->manager instanceof ExternalCalendarUsers) {
         $this->manager = ExternalCalendarUsers::instance();
     }
     return $this->manager;
 }
Ejemplo n.º 6
0
        function export_google_calendar() {
		ajx_current("empty");
                
                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();
                if($users){
                    if($users->getSync() == 1){
                        $sql = "SELECT ec.* FROM `".TABLE_PREFIX."external_calendars` ec,`".TABLE_PREFIX."external_calendar_users` ecu 
                                WHERE ec.calendar_feng = 1 AND ecu.contact_id = ".logged_user()->getId();
                        $calendar_feng = DB::executeOne($sql);
                        $events = ProjectEvents::findNoSync();

                        $user = $users->getAuthUser();
                        $pass = $users->getAuthPass();
                        $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;

                        try
                        {
                                $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);  
                                $gdataCal = new Zend_Gdata_Calendar($client);

                                if ($calendar_feng){
                                    foreach ($events as $event){
                                        $calendarUrl = 'http://www.google.com/calendar/feeds/'.$calendar_feng['calendar_user'].'/private/full';

                                        $newEvent = $gdataCal->newEventEntry();
                                        $newEvent->title = $gdataCal->newTitle($event->getObjectName());
                                        $newEvent->content = $gdataCal->newContent($event->getDescription());

                                        $star_time = explode(" ",$event->getStart()->format("Y-m-d H:i:s"));
                                        $end_time = explode(" ",$event->getDuration()->format("Y-m-d H:i:s"));

                                        if($event->getTypeId() == 2){
                                            $when = $gdataCal->newWhen();
                                            $when->startTime = $star_time[0];
                                            $when->endTime = $end_time[0];
                                            $newEvent->when = array($when);
                                        }else{                                    
                                            $when = $gdataCal->newWhen();
                                            $when->startTime = $star_time[0]."T".$star_time[1].".000-00:00";
                                            $when->endTime = $end_time[0]."T".$end_time[1].".000-00:00";
                                            $newEvent->when = array($when);
                                        }

                                        // insert event
                                        $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl);

                                        $event_id = explode("/",$createdEvent->id->text);
                                        $special_id = end($event_id); 
                                        $event->setSpecialID($special_id);
                                        $event->setUpdateSync(ProjectEvents::date_google_to_sql($createdEvent->updated));
                                        $event->setExtCalId($calendar_feng['id']);
                                        $event->save();
                                    }                             
                                }else{
                                    $appCalUrl = '';
                                    $calFeed = $gdataCal->getCalendarListFeed();        
                                    foreach ($calFeed as $calF){
                                        $instalation = explode("/", ROOT_URL);
                                        $instalation_name = end($instalation);
                                        if($calF->title->text == lang('feng calendar',$instalation_name)){
                                            $appCalUrl = $calF->content->src;
                                            $t_calendario = $calF->title->text;
                                        }
                                    }    

                                    if($appCalUrl != ""){
                                        $title_cal = $t_calendario;
                                    }else{
                                        $instalation = explode("/", ROOT_URL);
                                        $instalation_name = end($instalation);
                                        $appCal = $gdataCal -> newListEntry();
                                        $appCal -> title = $gdataCal-> newTitle(lang('feng calendar',$instalation_name));                         
                                        $own_cal = "http://www.google.com/calendar/feeds/default/owncalendars/full";                        
                                        $new_cal = $gdataCal->insertEvent($appCal, $own_cal);

                                        $title_cal = $new_cal->title->text;
                                        $appCalUrl = $new_cal->content->src;                                
                                    }               

                                    $cal_src = explode("/",$appCalUrl);
                                    array_pop($cal_src);
                                    $calendar_visibility = end($cal_src);
                                    array_pop($cal_src);
                                    $calendar_user = end($cal_src);                            

                                    $calendar = new ExternalCalendar();
                                    $calendar->setCalendarUser($calendar_user);
                                    $calendar->setCalendarVisibility($calendar_visibility);
                                    $calendar->setCalendarName($title_cal);
                                    $calendar->setExtCalUserId($users->getId());
                                    $calendar->setCalendarFeng(1);
                                    $calendar->save();

                                    foreach ($events as $event){                               
                                        $calendarUrl = 'http://www.google.com/calendar/feeds/'.$calendar->getCalendarUser().'/private/full';

                                        $newEvent = $gdataCal->newEventEntry();

                                        $newEvent->title = $gdataCal->newTitle($event->getObjectName());
                                        $newEvent->content = $gdataCal->newContent($event->getDescription());

                                        $star_time = explode(" ",$event->getStart()->format("Y-m-d H:i:s"));
                                        $end_time = explode(" ",$event->getDuration()->format("Y-m-d H:i:s"));

                                        if($event->getTypeId() == 2){
                                            $when = $gdataCal->newWhen();
                                            $when->startTime = $star_time[0];
                                            $when->endTime = $end_time[0];
                                            $newEvent->when = array($when);
                                        }else{                                    
                                            $when = $gdataCal->newWhen();
                                            $when->startTime = $star_time[0]."T".$star_time[1].".000-00:00";
                                            $when->endTime = $end_time[0]."T".$end_time[1].".000-00:00";
                                            $newEvent->when = array($when);
                                        }

                                        // insert event
                                        $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl);

                                        $event_id = explode("/",$createdEvent->id->text);
                                        $special_id = end($event_id); 
                                        $event->setSpecialID($special_id);
                                        $event->setUpdateSync(ProjectEvents::date_google_to_sql($createdEvent->updated));
                                        $event->setExtCalId($calendar->getId());
                                        $event->save();
                                    } 
                                }
                                flash_success(lang('success add sync'));
                                ajx_current("reload");
                        }
                        catch(Exception $e)
                        {
                        		Logger::log($e->getMessage());
                                flash_error(lang('could not connect to calendar'));
                                ajx_current("empty");
                        }
                    }
                }
	}
Ejemplo n.º 7
0
 function delete()
 {
     $options = array_var($_GET, 'options');
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     //check auth
     $event = ProjectEvents::findById(get_id());
     if ($event != null) {
         if (!$event->canDelete(logged_user())) {
             flash_error(lang('no access permissions'));
             //$this->redirectTo('event');
             ajx_current("empty");
             return;
         }
         $events = array($event);
     } else {
         $ev_ids = explode(',', array_var($_GET, 'ids', ''));
         if (!is_array($ev_ids) || count($ev_ids) == 0) {
             flash_error(lang('no objects selected'));
             ajx_current("empty");
             return;
         }
         $events = array();
         foreach ($ev_ids as $id) {
             $e = ProjectEvents::findById($id);
             if ($e instanceof ProjectEvent) {
                 $events[] = $e;
             }
         }
     }
     $this->getUserPreferences($view_type, $user_filter, $status_filter, $task_filter);
     $this->setTemplate($view_type);
     try {
         foreach ($events as $event) {
             try {
                 DB::beginWork();
                 // delete event
                 $event->trash();
                 if ($options == "news" || $options == "all") {
                     $this->repetitive_event_related($event, "delete", $options);
                 }
                 DB::commit();
                 ApplicationLogs::createLog($event, ApplicationLogs::ACTION_TRASH);
                 //external calendar sync
                 if ($event->getSpecialID() != "") {
                     $ext_user = ExternalCalendarUsers::findByContactId();
                     if ($ext_user instanceof ExternalCalendarUser) {
                         $externalCalendarController = new ExternalCalendarController();
                         $externalCalendarController->delete_event_calendar_extern($event, $ext_user);
                     }
                 }
             } catch (Exception $e) {
                 flash_error(lang('error delete event'));
                 ajx_current("empty");
                 DB::rollback();
             }
             // try
         }
         flash_success(lang('success delete event', ''));
         ajx_current("reload");
         ajx_add("overview-panel", "reload");
     } catch (Exception $e) {
         flash_error(lang('error delete event'));
         ajx_current("empty");
     }
     // try
 }
 function export_google_calendar()
 {
     $users = ExternalCalendarUsers::findAll(array('conditions' => "sync = 1"));
     foreach ($users as $user) {
         // log user in
         $contact = Contacts::findById($user->getContactId());
         CompanyWebsite::instance()->logUserIn($contact);
         ExternalCalendarController::export_google_calendar_for_user($user);
         CompanyWebsite::instance()->logUserOut();
     }
 }