Exemplo n.º 1
0
function core_dimensions_after_add_to_members($object, &$ignored)
{
    if ($object instanceof Report || $object instanceof Timeslot) {
        return;
    }
    // Add to persons and users dimensions
    $user_ids = array();
    if (logged_user() instanceof Contact) {
        $user_ids[] = logged_user()->getId();
    }
    if ($object instanceof ProjectTask) {
        /* @var $object ProjectTask */
        if ($object->getAssignedById() > 0) {
            $user_ids[] = $object->getAssignedById();
        }
        if ($object->getAssignedToContactId() > 0) {
            $user_ids[] = $object->getAssignedToContactId();
        }
    }
    if ($object instanceof ProjectEvent) {
        /* @var $object ProjectEvent */
        $invitations = EventInvitations::findAll(array("conditions" => "`event_id` = " . $object->getId()));
        foreach ($invitations as $inv) {
            $user_ids[] = $inv->getContactId();
        }
    }
    if ($object instanceof Contact && !$object->isUser()) {
        $member = Members::findOne(array("conditions" => "`object_id` = (" . $object->getId() . ") AND `dimension_id` = (SELECT `id` FROM `" . TABLE_PREFIX . "dimensions` WHERE `code` = 'feng_persons')"));
        if ($member instanceof Member) {
            $object->addToMembers(array($member));
        }
    }
    $context = active_context();
    if (count($context) > 0) {
        foreach ($context as $selection) {
            if ($selection instanceof Member && $selection->getDimension()->getCode() == 'feng_persons') {
                $object->addToMembers(array($selection));
            }
        }
    }
    core_dim_add_to_person_user_dimensions($object, $user_ids);
}
Exemplo n.º 2
0
 /**
  * Send event notification to the list of users ($people)
  *
  * @param ProjectEvent $event Event
  * @param array $people
  * @return boolean
  * @throws NotifierConnectionError
  */
 static function notifEvent(ProjectEvent $object, $people, $notification, $sender)
 {
     if (!is_array($people) || !count($people) || !$sender instanceof Contact) {
         return;
         // nothing here...
     }
     // if
     $name = $object->getObjectName();
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     tpl_assign('object', $object);
     tpl_assign('title', $name);
     tpl_assign('description', escape_html_whitespace(convert_to_links(clean($object->getDescription()))));
     //descripction
     //context
     $contexts = array();
     $members = $object->getMembers();
     if (count($members) > 0) {
         foreach ($members as $member) {
             $dim = $member->getDimension();
             if ($dim->getIsManageable()) {
                 if ($dim->getCode() == "customer_project" || $dim->getCode() == "customers") {
                     $obj_type = ObjectTypes::findById($member->getObjectTypeId());
                     if ($obj_type instanceof ObjectType) {
                         $contexts[$dim->getCode()][$obj_type->getName()][] = '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                     }
                 } else {
                     $contexts[$dim->getCode()][] = '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                 }
             }
         }
     }
     tpl_assign('contexts', $contexts);
     //folders
     $attachments = array();
     try {
         $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
         if ($content) {
             $file_path = ROOT . "/tmp/logo_empresa.png";
             $handle = fopen($file_path, 'wb');
             if ($handle) {
                 fwrite($handle, $content);
                 fclose($handle);
                 $attachments['logo'] = array('cid' => gen_id() . substr($sender->getEmailAddress(), strpos($sender->getEmailAddress(), '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
             }
         }
     } catch (FileNotInRepositoryError $e) {
         unset($attachments['logo']);
     }
     tpl_assign('attachments', $attachments);
     // attachments
     //invitations
     $invitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $object->getId()));
     if (isset($invitations) && is_array($invitations)) {
         $guests = "";
         $send_link = array();
         foreach ($invitations as $inv) {
             $inv_user = Contacts::findById($inv->getContactId());
             if ($inv_user instanceof Contact) {
                 if (can_access($inv_user, $object->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                     $state_desc = lang('pending response');
                     if ($inv->getInvitationState() == 1) {
                         $state_desc = lang('yes');
                     } else {
                         if ($inv->getInvitationState() == 2) {
                             $state_desc = lang('no');
                         } else {
                             if ($inv->getInvitationState() == 3) {
                                 $state_desc = lang('maybe');
                             }
                         }
                     }
                     $guests .= '<div style="line-height: 20px; clear:both;">';
                     $guests .= '<div style="width: 35%;line-height: 20px; float: left;">' . clean($inv_user->getObjectName()) . '</div>';
                     $guests .= '<div style="line-height: 20px; float: left;">' . $state_desc . '</div></div>';
                 }
                 if ($inv->getInvitationState() == 0) {
                     $send_link[] = $inv_user->getId();
                 }
             }
         }
     }
     tpl_assign('guests', $guests);
     // invitations
     $emails = array();
     foreach ($people as $user) {
         if ($user->getId() != $sender->getId() && !$user->getDisabled()) {
             // send notification on user's locale and with user info
             $locale = $user->getLocale();
             Localization::instance()->loadSettings($locale, ROOT . '/language');
             //ALL SUBSCRIBERS
             if ($object->getSubscribers()) {
                 $subscribers = $object->getSubscribers();
                 $string_subscriber = '';
                 $total_s = count($subscribers);
                 $c = 0;
                 foreach ($subscribers as $subscriber) {
                     $c++;
                     if ($c == $total_s && $total_s > 1) {
                         $string_subscriber .= lang('and');
                     } else {
                         if ($c > 1) {
                             $string_subscriber .= ", ";
                         }
                     }
                     $string_subscriber .= $subscriber->getFirstName();
                     if ($subscriber->getSurname() != "") {
                         $string_subscriber .= " " . $subscriber->getSurname();
                     }
                 }
                 tpl_assign('subscribers', $string_subscriber);
                 // subscribers
             }
             //start
             if ($object->getStart() instanceof DateTimeValue) {
                 $date = Localization::instance()->formatDescriptiveDate($object->getStart(), $user->getTimezone());
                 $time = Localization::instance()->formatTime($object->getStart(), $user->getTimezone());
                 tpl_assign('start', $date);
                 //start
                 if ($object->getTypeId() != 2) {
                     tpl_assign('time', $time);
                     //time
                 }
             }
             if ($object->getTypeId() != 2) {
                 //duration
                 if ($object->getDuration() instanceof DateTimeValue) {
                     $durtime = $object->getDuration()->getTimestamp() - $object->getStart()->getTimestamp();
                     $durhr = $durtime / 3600 % 24;
                     //seconds per hour
                     tpl_assign('duration', $durhr . " hs");
                     //duration
                 }
             } else {
                 tpl_assign('duration', lang('all day event'));
                 //duration
             }
             $links = array();
             if (in_array($user->getId(), $send_link)) {
                 $links = array(array('img' => get_image_url("/16x16/complete.png"), 'text' => lang('accept invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 1, 'e' => $object->getId(), 'u' => $user->getId()))), array('img' => get_image_url("/16x16/del.png"), 'text' => lang('reject invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 2, 'e' => $object->getId(), 'u' => $user->getId()))));
                 $description_title = lang("new notification event invitation", $object->getObjectName(), $sender->getObjectName());
                 $subject_mail = lang("new notification event", $name, $sender->getObjectName());
             } else {
                 $description_title = lang("{$notification} notification event desc", $object->getObjectName(), $sender->getObjectName());
                 $subject_mail = lang("{$notification} notification {$type}", $name, $typename);
             }
             tpl_assign('links', $links);
             tpl_assign('description_title', $description_title);
             //description_title
             $toemail = $user->getEmailAddress();
             if (!$toemail) {
                 continue;
             }
             $emails[] = array("to" => array(self::prepareEmailAddress($toemail, $user->getObjectName())), "from" => self::prepareEmailAddress($sender->getEmailAddress(), $sender->getObjectName()), "subject" => $subject = $subject_mail, "body" => tpl_fetch(get_template_path('general', 'notifier')), "attachments" => $attachments);
         }
     }
     // foreach
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
     self::queueEmails($emails);
 }
 function findSyncByEvent($event_id)
 {
     return EventInvitations::findAll(array('conditions' => array('`synced` = 1 AND `event_id` = ' . $event_id)));
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return EventInvitations 
  */
 function manager()
 {
     if (!$this->manager instanceof EventInvitations) {
         $this->manager = EventInvitations::instance();
     }
     return $this->manager;
 }
Exemplo n.º 5
0
 function findByEvent($event_id)
 {
     return EventInvitations::findAll(array('conditions' => array('`event_id` = ?', $event_id)));
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return EventInvitations 
 */
 function manager() {
   if(!($this->manager instanceof EventInvitations)) $this->manager = EventInvitations::instance();
   return $this->manager;
 } // manager
Exemplo n.º 7
0
 function cloneEvent($new_st_date, $new_due_date)
 {
     $new_event = new ProjectEvent();
     $new_event->setObjectName($this->getObjectName());
     $new_event->setDescription($this->getDescription());
     $new_event->setTypeId($this->getTypeId());
     if ($this->getDuration() instanceof DateTimeValue) {
         $new_event->setDuration(new DateTimeValue($this->getDuration()->getTimestamp()));
     }
     if ($this->getStart() instanceof DateTimeValue) {
         $new_event->setStart(new DateTimeValue($this->getStart()->getTimestamp()));
     }
     $new_event->setOriginalEventId($this->getObjectId());
     $new_event->save();
     // set next values for repetetive task
     if ($new_event->getStart() instanceof DateTimeValue) {
         $new_event->setStart($new_st_date);
     }
     if ($new_event->getDuration() instanceof DateTimeValue) {
         $new_event->setDuration($new_due_date);
     }
     $invitations = EventInvitations::findByEvent($this->getId());
     if ($invitations) {
         foreach ($invitations as $invitation) {
             $invit = new EventInvitation();
             $invit->setEventId($new_event->getId());
             $invit->setContactId($invitation->getContactId());
             $invit->setInvitationState(logged_user() instanceof Contact && logged_user()->getId() == $invitation->getContactId() ? 1 : 0);
             $invit->save();
         }
     }
     $subscriptions = ObjectSubscriptions::findByEvent($this->getId());
     if ($subscriptions) {
         foreach ($subscriptions as $subscription) {
             $subscrip = new ObjectSubscription();
             $subscrip->setObjectId($new_event->getId());
             $subscrip->setContactId($subscription->getContactId());
             $subscrip->save();
         }
     }
     $reminders = ObjectReminders::findByEvent($this->getId());
     if ($reminders) {
         foreach ($reminders as $reminder) {
             $remind = new ObjectReminder();
             $remind->setObjectId($new_event->getId());
             $remind->setMinutesBefore($reminder->getMinutesBefore());
             $remind->setType($reminder->getType());
             $remind->setContext($reminder->getContext());
             $remind->setUserId(0);
             $date = $new_event->getStart();
             if ($date instanceof DateTimeValue) {
                 $rdate = new DateTimeValue($date->getTimestamp() - $reminder->getMinutesBefore() * 60);
                 $remind->setDate($rdate);
             }
             $remind->save();
         }
     }
     $member_ids = array();
     $context = active_context();
     foreach ($context as $selection) {
         if ($selection instanceof Member) {
             $member_ids[] = $selection->getId();
         }
     }
     $object_controller = new ObjectController();
     $object_controller->add_to_members($new_event, $member_ids);
     return $new_event;
 }
Exemplo n.º 8
0
 /**
  * Delete this object
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     if ($this->isAccountOwner()) {
         return false;
     }
     // if
     $this->deleteAvatar();
     //$this->deletePersonalProject();
     MailAccountUsers::deleteByUser($this);
     GroupUsers::clearByUser($this);
     Contacts::updateUserIdOnUserDelete($this->getId());
     ProjectUsers::clearByUser($this);
     ObjectSubscriptions::clearByUser($this);
     ObjectReminders::clearByUser($this);
     EventInvitations::clearByUser($this);
     UserPasswords::clearByUser($this);
     return parent::delete();
 }
 function allowed_users_view_events()
 {
     $comp_array = array();
     $actual_user_id = isset($_GET['user']) ? $_GET['user'] : logged_user()->getId();
     $wspace_id = isset($_GET['ws_id']) ? $_GET['ws_id'] : 0;
     $ws = Projects::findByCSVIds($wspace_id);
     $evid = array_var($_GET, 'evid');
     $companies = Companies::findAll();
     $i = 0;
     foreach ($companies as $comp) {
         $users = $comp->getUsersOnWorkspaces($ws);
         if (is_array($users)) {
             foreach ($users as $k => $user) {
                 // removing event creator from notification list
                 $keep = false;
                 foreach ($ws as $w) {
                     if (can_read_type($user, $w, 'ProjectEvents')) {
                         $keep = true;
                     }
                 }
                 if (!$keep) {
                     unset($users[$k]);
                 }
             }
             if (count($users) > 0) {
                 $comp_data = array('id' => $i++, 'object_id' => $comp->getId(), 'name' => $comp->getName(), 'logo_url' => $comp->getLogoUrl(), 'users' => array());
                 foreach ($users as $user) {
                     $comp_data['users'][] = array('id' => $user->getId(), 'name' => $user->getDisplayName(), 'avatar_url' => $user->getAvatarUrl(), 'invited' => $evid == 0 ? $user->getId() == $actual_user_id : EventInvitations::findOne(array('conditions' => "`event_id` = {$evid} and `user_id` = " . $user->getId())) != null, 'mail' => $user->getEmail());
                 }
                 $comp_array[] = $comp_data;
             }
         }
     }
     $object = array("totalCount" => count($comp_array), "start" => 0, "companies" => array());
     $object['companies'] = $comp_array;
     ajx_extra_data($object);
     ajx_current("empty");
 }
 static function addInvitations(&$result_events, $user_id = -1)
 {
     if ($user_id == -1) {
         $user_id = logged_user()->getId();
     }
     if (isset($result_events) && is_array($result_events) && count($result_events)) {
         $event_ids = array();
         foreach ($result_events as $event) {
             $event_ids[] = $event->getId();
         }
         $invitations_res = EventInvitations::findAll(array('conditions' => 'contact_id = ' . $user_id));
         $invitations = array();
         foreach ($invitations_res as $i) {
             if (!isset($invitations[$i->getEventId()])) {
                 $invitations[$i->getEventId()] = array();
             }
             $invitations[$i->getEventId()][] = $i;
         }
         foreach ($result_events as $event) {
             $event_invitations = array_var($invitations, $event->getId(), array());
             foreach ($event_invitations as $inv) {
                 $event->addInvitation($inv);
             }
         }
     }
 }
 /**
 * 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, 'EventInvitations')) {
     return parent::paginate($arguments, $items_per_page, $current_page);
   } else {
     return EventInvitations::instance()->paginate($arguments, $items_per_page, $current_page);
     //$instance =& EventInvitations::instance();
     //return $instance->paginate($arguments, $items_per_page, $current_page);
   } // if
 } // paginate
Exemplo n.º 12
0
 function icalendar_import()
 {
     @set_time_limit(0);
     if (isset($_GET['from_menu']) && $_GET['from_menu'] == 1) {
         unset($_SESSION['history_back']);
     }
     if (isset($_SESSION['history_back'])) {
         if ($_SESSION['history_back'] > 0) {
             $_SESSION['history_back'] = $_SESSION['history_back'] - 1;
         }
         if ($_SESSION['history_back'] == 0) {
             unset($_SESSION['history_back']);
         }
         ajx_current("back");
     } else {
         $ok = false;
         $this->setTemplate('cal_import');
         $filedata = array_var($_FILES, 'cal_file');
         if (is_array($filedata)) {
             $filename = $filedata['tmp_name'] . 'vcal';
             copy($filedata['tmp_name'], $filename);
             $events_data = CalFormatUtilities::decode_ical_file($filename);
             if (count($events_data)) {
                 try {
                     DB::beginWork();
                     foreach ($events_data as $ev_data) {
                         $event = new ProjectEvent();
                         $event->setFromAttributes($ev_data);
                         $event->save();
                         ApplicationLogs::createLog($event, ApplicationLogs::ACTION_ADD);
                         $conditions = array('event_id' => $event->getId(), 'contact_id' => logged_user()->getId());
                         //insert only if not exists
                         if (EventInvitations::findById($conditions) == null) {
                             $invitation = new EventInvitation();
                             $invitation->setEventId($event->getId());
                             $invitation->setContactId(logged_user()->getId());
                             $invitation->setInvitationState(1);
                             $invitation->save();
                         }
                         //insert only if not exists
                         if (ObjectSubscriptions::findBySubscriptions($event->getId()) == null) {
                             $subscription = new ObjectSubscription();
                             $subscription->setObjectId($event->getId());
                             $subscription->setContactId(logged_user()->getId());
                             $subscription->save();
                         }
                         $member_ids = array();
                         $context = active_context();
                         foreach ($context as $selection) {
                             if ($selection instanceof Member) {
                                 $member_ids[] = $selection->getId();
                             }
                         }
                         $object_controller = new ObjectController();
                         $object_controller->add_to_members($event, $member_ids);
                     }
                     DB::commit();
                     $ok = true;
                     flash_success(lang('success import events', count($events_data)));
                     $_SESSION['history_back'] = 1;
                 } catch (Exception $e) {
                     DB::rollback();
                     flash_error($e->getMessage());
                 }
             } else {
                 flash_error(lang('no events to import'));
             }
             unset($filename);
             if (!$ok) {
                 ajx_current("empty");
             }
         } else {
             if (array_var($_POST, 'atimportform', 0)) {
                 ajx_current("empty");
             }
         }
     }
 }
 private function update_event_on_google_calendar($event, $ext_calendar, $ext_user, $service)
 {
     $insert_event = false;
     //update event
     if ($event->getSpecialID() != "") {
         //First retrieve the event from the google API.
         try {
             $newEvent = $service->events->get($ext_calendar->getOriginalCalendarId(), $event->getSpecialID());
         } catch (Exception $e) {
             Logger::log("Fail to get event from google: " . $event->getId());
             Logger::log($e->getMessage());
             throw $e;
         }
     }
     //insert event
     if (!$newEvent instanceof Google_Service_Calendar_Event) {
         //create google event
         $newEvent = new Google_Service_Calendar_Event();
         $insert_event = true;
     }
     $newEvent->setSummary($event->getObjectName());
     $newEvent->setDescription($event->getDescription());
     $start = new Google_Service_Calendar_EventDateTime();
     $end = new Google_Service_Calendar_EventDateTime();
     //All day event
     if ($event->getTypeId() == 2) {
         $star_time = date("Y-m-d", $event->getStart()->getTimestamp());
         $end_time = date("Y-m-d", $event->getDuration()->getTimestamp());
         $start->setDate($star_time);
         $end->setDate($end_time);
     } else {
         $star_time = date(DATE_RFC3339, $event->getStart()->getTimestamp());
         $end_time = date(DATE_RFC3339, $event->getDuration()->getTimestamp());
         $start->setDateTime($star_time);
         $end->setDateTime($end_time);
     }
     $newEvent->setStart($start);
     $newEvent->setEnd($end);
     try {
         if ($insert_event) {
             // insert event
             $createdEvent = $service->events->insert($ext_calendar->getOriginalCalendarId(), $newEvent);
         } else {
             // update event
             $createdEvent = $service->events->update($ext_calendar->getOriginalCalendarId(), $newEvent->getId(), $newEvent);
         }
     } catch (Exception $e) {
         Logger::log("Fail to add event: " . $event->getId());
         Logger::log($e->getMessage());
         throw $e;
     }
     $event->setSpecialID($createdEvent->getId());
     $event->setUpdateSync(ExternalCalendarController::date_google_to_sql($createdEvent->getUpdated()));
     $event->setExtCalId($ext_calendar->getId());
     $event->save();
     $invitation = EventInvitations::findOne(array('conditions' => array('contact_id = ' . $ext_user->getContactId() . ' AND event_id =' . $event->getId())));
     if ($invitation) {
         $invitation->setUpdateSync(ExternalCalendarController::date_google_to_sql($createdEvent->getUpdated()));
         $invitation->setSpecialId($createdEvent->getId());
         $invitation->save();
     }
 }
Exemplo n.º 14
0
 static function addInvitations($result_events, $user_id = -1)
 {
     if ($user_id == -1) {
         $user_id = logged_user()->getId();
     }
     if (isset($result_events) && is_array($result_events) && count($result_events)) {
         foreach ($result_events as $event) {
             $inv = EventInvitations::findById(array('event_id' => $event->getId(), 'user_id' => $user_id));
             if ($inv != null) {
                 $event->addInvitation($inv);
             }
         }
     }
 }
Exemplo n.º 15
0
        function import_google_calendar() {
                ajx_current("empty");
                $users = ExternalCalendarUsers::findByContactId();  
                if($users){
                    $calendars = ExternalCalendars::findByExtCalUserId($users->getId());

                    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');

                    $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);

                            //update or insert events for calendars                        
                            foreach ($calendars as $calendar){

                                //check the deleted calendars
                                $delete_calendar = false;
                                $calFeed = $gdataCal->getCalendarListFeed();        
                                foreach ($calFeed as $calF){
                                    $cal_src = explode("/",$calF->content->src);
                                    array_pop($cal_src);
                                    $calendar_visibility = end($cal_src);
                                    array_pop($cal_src);
                                    $calendar_user = end($cal_src); 

                                    if($calendar_user == $calendar->getCalendarUser()){
                                        $delete_calendar = true;
                                    }
                                }

                                if($delete_calendar){
                                    $calendar_user = $calendar->getCalendarUser();
                                    $calendar_visibility = $calendar->getCalendarVisibility();
                                    $start_sel = date('Y-m-d', strtotime('-1 week'));
                                    $end_sel = date('Y-m-d', strtotime('+2 year'));

                                    $query = $gdataCal->newEventQuery();
                                    $query->setUser($calendar_user);
                                    $query->setVisibility($calendar_visibility);
                                    $query->setSingleEvents(true);
                                    $query->setProjection('full');
                                    $query->setOrderby('starttime');
                                    $query->setSortOrder('ascending'); 
                                    $query->setStartMin($start_sel);
                                    $query->setStartMax($end_sel);
                                    $query->setMaxResults(50);
                                    // execute and get results
                                    $event_list = $gdataCal->getCalendarEventFeed($query);

                                    $array_events_google = array();
                                    foreach ($event_list as $event){                                        
                                        $event_id = explode("/",$event->id->text);
                                        $special_id = end($event_id); 
                                        $event_name = lang("untitle event");
                                        if($event->title->text != ""){
                                            $event_name = $event->title->text;
                                        }
                                        $array_events_google[] = $special_id;
                                        $new_event = ProjectEvents::findBySpecialId($special_id);
                                        if($new_event){
                                            if(strtotime(ProjectEvents::date_google_to_sql($event->updated)) > $new_event->getUpdateSync()->getTimestamp()){
                                                $start = strtotime(ProjectEvents::date_google_to_sql($event->when[0]->startTime));
                                                $fin = strtotime(ProjectEvents::date_google_to_sql($event->when[0]->endTime));
                                                if(($fin - $start) == 86400){
                                                    $new_event->setStart(date("Y-m-d H:i:s",$start));
                                                    $new_event->setDuration(date("Y-m-d H:i:s",$start));
                                                    $new_event->setTypeId(2);
                                                }elseif(($fin - $start) > 86400){                                                
                                                    $t_s = explode(' ', date("Y-m-d H:i:s",$start));
                                                    $t_f = explode(' ', date("Y-m-d H:i:s",$fin));

                                                    $date_s = new DateTimeValue(strtotime($t_s[0]."00:00:00") - logged_user()->getTimezone() * 3600);
                                                    $date_f = new DateTimeValue(strtotime($t_f[0]."23:59:59 -1 day") - logged_user()->getTimezone() * 3600);

                                                    $new_event->setStart(date("Y-m-d H:i:s",$date_s->getTimestamp()));
                                                    $new_event->setDuration(date("Y-m-d H:i:s",$date_f->getTimestamp()));
                                                    $new_event->setTypeId(2);
                                                }else{
                                                    $new_event->setStart(ProjectEvents::date_google_to_sql($event->when[0]->startTime));
                                                    $new_event->setDuration(ProjectEvents::date_google_to_sql($event->when[0]->endTime));
                                                }

                                                $new_event->setObjectName($event_name);
                                                $new_event->setDescription($event->content->text);
                                                $new_event->setUpdateSync(ProjectEvents::date_google_to_sql($event->updated));
                                                $new_event->setExtCalId($calendar->getId());
                                                $new_event->save(); 
                                            }
                                        }else{
                                            $new_event = new ProjectEvent();
                                            
                                            $start = strtotime(ProjectEvents::date_google_to_sql($event->when[0]->startTime));
                                            $fin = strtotime(ProjectEvents::date_google_to_sql($event->when[0]->endTime));
                                            if(($fin - $start) == 86400){
                                                $new_event->setStart(date("Y-m-d H:i:s",$start));
                                                $new_event->setDuration(date("Y-m-d H:i:s",$start));
                                                $new_event->setTypeId(2);
                                            }elseif(($fin - $start) > 86400){
                                                $t_s = explode(' ', date("Y-m-d H:i:s",$start));
                                                $t_f = explode(' ', date("Y-m-d H:i:s",$fin));
                                                
                                                $date_s = new DateTimeValue(strtotime($t_s[0]."00:00:00") - logged_user()->getTimezone() * 3600);
                                                $date_f = new DateTimeValue(strtotime($t_f[0]."23:59:59 -1 day") - logged_user()->getTimezone() * 3600);
                                                
                                                $new_event->setStart(date("Y-m-d H:i:s",$date_s->getTimestamp()));
                                                $new_event->setDuration(date("Y-m-d H:i:s",$date_f->getTimestamp()));
                                                $new_event->setTypeId(2);
                                            }else{
                                                $new_event->setStart(ProjectEvents::date_google_to_sql($event->when[0]->startTime));
                                                $new_event->setDuration(ProjectEvents::date_google_to_sql($event->when[0]->endTime));
                                                $new_event->setTypeId(1);
                                            }
                                            
                                            $new_event->setObjectName($event_name);
                                            $new_event->setDescription($event->content->text);
                                            $new_event->setSpecialID($special_id);
                                            $new_event->setUpdateSync(ProjectEvents::date_google_to_sql($event->updated));
                                            $new_event->setExtCalId($calendar->getId());                                            
                                            $new_event->save(); 
                                            
                                            $conditions = array('event_id' => $new_event->getId(), 'contact_id' => logged_user()->getId());
                                            //insert only if not exists 
                                            if (EventInvitations::findById($conditions) == null) { 
                                                $invitation = new EventInvitation();
                                                $invitation->setEventId($new_event->getId());
                                                $invitation->setContactId(logged_user()->getId());
                                                $invitation->setInvitationState(1);
                                                $invitation->save();
                                            }
                                            
                                            //insert only if not exists 
                                            if (ObjectSubscriptions::findBySubscriptions($new_event->getId()) == null) { 
                                                $subscription = new ObjectSubscription();
                                                $subscription->setObjectId($new_event->getId());
                                                $subscription->setContactId(logged_user()->getId());
                                                $subscription->save();
                                            }

                                            if($users->getRelatedTo()){
                                                $member = array();
                                                $member_ids = explode(",",$users->getRelatedTo());
                                                foreach ($member_ids as $member_id){
                                                    $member[] = $member_id;
                                                }
                                                $object_controller = new ObjectController();
                                                $object_controller->add_to_members($new_event, $member); 
                                            }else{
                                                $member_ids = array();
                                                $context = active_context();
                                                foreach ($context as $selection) {
                                                    if ($selection instanceof Member) $member_ids[] = $selection->getId();
                                                }		        
                                                $object_controller = new ObjectController();
                                                $object_controller->add_to_members($new_event, $member_ids); 
                                            }                                            
                                        }           
                                    }// foreach event list 

                                    //check the deleted events
                                    $events_delete = ProjectEvents::findByExtCalId($calendar->getId());
                                    if($events_delete){
                                        foreach($events_delete as $event_delete){  
                                            if(!in_array($event_delete->getSpecialID(), $array_events_google)){
                                                $event_delete->trash();

                                                $event_delete->setSpecialID("");
                                                $event_delete->setExtCalId(0);
                                                $event_delete->save();    
                                            }                                        
                                        }  
                                    }
                                }else{                
                                    $events = ProjectEvents::findByExtCalId($calendar->getId());
                                    if($calendar->delete()){
                                        if($events){
                                            foreach($events as $event){                            
                                                $event->trash();

                                                $event->setSpecialID("");
                                                $event->setExtCalId(0);
                                                $event->save();
                                            }  
                                        }
                                    }
                                }
                            }//foreach calendars
                    }
                    catch(Exception $e)
                    {
                    		Logger::log($e->getMessage());
                            flash_error(lang('could not connect to calendar'));
                            ajx_current("empty");
                    }
                }
	}
Exemplo n.º 16
0
                 $options[] = option_tag(lang('decide later'), 0, $event_inv_state == 0 ? array('selected' => 'selected') : null);
             }
             $att_form = '<form style="height:100%;background-color:white" class="internalForm" action="' . get_url('event', 'change_invitation_state') . '" method="post">';
             $att_form .= '<table><tr><td style="padding-right:6px;"><b>' . lang('attendance') . '<b></td><td>';
             $att_form .= select_box('event_attendance', $options, array('id' => 'viewEventFormComboAttendance')) . '</td><td>';
             $att_form .= input_field('event_id', $event->getId(), array('type' => 'hidden'));
             $att_form .= input_field('user_id', logged_user()->getId(), array('type' => 'hidden'));
             $att_form .= submit_button(lang('Save'), null, array('style' => 'margin-top:0px;margin-left:10px')) . '</td></tr></table></form>';
         }
     }
     //if
 }
 // if
 $otherInvitationsTable = '';
 if (!$event->isNew()) {
     $otherInvitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $event->getId()));
     if (isset($otherInvitations) && is_array($otherInvitations)) {
         $otherInvitationsTable .= '<div class="coInputMainBlock adminMainBlock" style="width:70%;">';
         $otherInvitationsTable .= '<table style="width:100%;"><col width="50%" /><col width="50%" />';
         $otherInvitationsTable .= '<tr><th><b>' . lang('name') . '</b></th><th><b>' . lang('participate') . '</b></th></tr>';
         $isAlt = false;
         $cant = 0;
         foreach ($otherInvitations as $inv) {
             $inv_user = Contacts::findById($inv->getContactId());
             if ($inv_user instanceof Contact) {
                 if (can_access($inv_user, $event->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                     if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_update_other_users_invitations')) {
                         // only show status
                         $state_desc = lang('pending response');
                         if ($inv->getInvitationState() == 1) {
                             $state_desc = lang('yes');
Exemplo n.º 17
0
 function clearInvitations()
 {
     $this->event_invitations = array();
     EventInvitations::delete(array('`event_id` = ?', $this->getId()));
 }