/** * Handles the download the calendar data as iCalendar for the * user identified by $key. * * * @global Seminar_User $user * @global Seminar_Perm $perm * @param string $key * @param string $type type of export */ function index_action($key = '') { if (strlen($key)) { $user_id = IcalExport::getUserIdByKey($key); } else { $username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (isset($username) && isset($password)) { $result = StudipAuthAbstract::CheckAuthentication($username, $password); } if (isset($result) && $result['uid'] !== false) { $user_id = $result['uid']; } else { $this->response->add_header('WWW-Authenticate', 'Basic realm="Stud.IP Login"'); $this->set_status(401); $this->render_text('authentication failed'); return; } } if ($user_id) { $GLOBALS['user'] = new Seminar_User($user_id); $GLOBALS['perm'] = new Seminar_Perm(); $extype = 'ALL_EVENTS'; $export = new CalendarExport(new CalendarWriterICalendar()); $export->exportFromDatabase($user_id, strtotime('-4 week'), 2114377200, 'ALL_EVENTS'); if ($GLOBALS['_calendar_error']->getMaxStatus(ErrorHandler::ERROR_CRITICAL)) { $this->set_status(500); $this->render_nothing(); return; } $content = join($export->getExport()); if (stripos($_SERVER['HTTP_USER_AGENT'], 'google-calendar') !== false) { $content = str_replace(array('CLASS:PRIVATE', 'CLASS:CONFIDENTIAL'), 'CLASS:PUBLIC', $content); } $this->response->add_header('Content-Type', 'text/calendar;charset=utf-8'); $this->response->add_header('Content-Disposition', 'attachment; filename="studip.ics"'); $this->response->add_header('Content-Transfer-Encoding', 'binary'); $this->response->add_header('Pragma', 'public'); $this->response->add_header('Cache-Control', 'private'); $this->response->add_header('Content-Length', strlen($content)); $this->render_text($content); } else { // delayed response to prevent brute force attacks ??? $this->set_status(400); $this->render_nothing(); } }
function exportFromDatabase($range_id = null, $start = 0, $end = Calendar::CALENDAR_END, $event_types = null, $except = null) { $this->_createFile(); parent::exportFromDatabase($range_id, $start, $end, $event_types, $sem_ids, $except); $this->_closeFile(); }