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"); } }
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(); $project = active_or_personal_project(); if ($ev_data['subject'] == '') { $ev_data['subject'] = lang('no subject'); } $event->setFromAttributes($ev_data); $event->save(); $event->addToWorkspace($project); $object_controller = new ObjectController(); $object_controller->add_subscribers($event); ApplicationLogs::createLog($event, null, ApplicationLogs::ACTION_ADD); $this->registerInvitations($ev_data, $event); if (isset($ev_data['confirmAttendance'])) { if ($event->getCreatedBy() instanceof User) { $this->change_invitation_state($ev_data['confirmAttendance'], $event->getId(), $event->getCreatedBy()->getId()); } } } 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"); } } } }