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");
             }
         }
     }
 }