ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCalendarRemoteAccessHandler.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Calendar/classes/class.ilCalendarAuthenticationToken.php';
25
35{
36 private $token_handler = null;
37
42 public function __construct()
43 {
44 }
45
49 public function getTokenHandler()
50 {
52 }
53
58 public function parseRequest()
59 {
60 if($_GET['client_id'])
61 {
62 $_COOKIE['ilClientId'] = $_GET['client_id'];
63
64 }
65 else
66 {
67 $path_info_components = explode('/',$_SERVER['PATH_INFO']);
68 $_COOKIE['ilClientId'] = $path_info_components[1];
69 }
70 }
71
76 public function handleRequest()
77 {
78 session_name('ILCALSESSID');
79 $this->initIlias();
80 $logger = $GLOBALS['DIC']->logger()->cal();
81 $this->initTokenHandler();
82
83 if(!$this->initUser())
84 {
85 $logger->warning('Calendar token is invalid. Authentication failed.');
86 return false;
87 }
88
89 if($this->getTokenHandler()->getIcal() and !$this->getTokenHandler()->isIcalExpired())
90 {
91 $GLOBALS['DIC']['ilAuthSession']->logout();
92 ilUtil::deliverData($this->getTokenHandler(),'calendar.ics','text/calendar','utf-8');
93 exit;
94 }
95
96 include_once './Services/Calendar/classes/Export/class.ilCalendarExport.php';
97 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
99 {
101 $cats->initialize(ilCalendarCategories::MODE_REMOTE_SELECTED, $this->getTokenHandler()->getCalendar());
102 $logger->dump($cats->getCategories(true), ilLogLevel::DEBUG);
103 $export = new ilCalendarExport($cats->getCategories(true));
104 }
105 else
106 {
109 $logger->dump($cats->getCategories(true), ilLogLevel::DEBUG);
110 $export = new ilCalendarExport($cats->getCategories(true));
111 }
112
113 $export->export();
114
115 $this->getTokenHandler()->setIcal($export->getExportString());
116 $this->getTokenHandler()->storeIcal();
117
118 $GLOBALS['DIC']['ilAuthSession']->logout();
119 ilUtil::deliverData($export->getExportString(),'calendar.ics','text/calendar','utf-8');
120 exit;
121 }
122
123 protected function initTokenHandler()
124 {
125 $GLOBALS['DIC']->logger()->cal()->info('Authentication token: ' . $_GET['token']);
126 $this->token_handler = new ilCalendarAuthenticationToken(
128 $_GET['token']
129 );
130 return true;
131 }
132
133 protected function initIlias()
134 {
135 include_once "Services/Context/classes/class.ilContext.php";
137
138 include_once './Services/Authentication/classes/class.ilAuthFactory.php';
140
141 require_once("Services/Init/classes/class.ilInitialisation.php");
143
144 $GLOBALS['lng']->loadLanguageModule('dateplaner');
145 }
146
151 protected function initUser()
152 {
153 if(!$this->getTokenHandler() instanceof ilCalendarAuthenticationToken)
154 {
155 $GLOBALS['DIC']->logger()->cal()->info('Initialisation of authentication token failed');
156 return false;
157 }
158 if(!$this->getTokenHandler()->getUserId())
159 {
160 $GLOBALS['DIC']->logger()->cal()->info('No user id found for calendar synchronisation');
161 return false;
162 }
163 include_once './Services/User/classes/class.ilObjUser.php';
164 if(!ilObjUser::_exists($this->getTokenHandler()->getUserId()))
165 {
166 $GLOBALS['DIC']->logger()->cal()->notice('No valid user id found for calendar synchronisation');
167 return false;
168 }
169
170 include_once './Services/Init/classes/class.ilInitialisation.php';
171 $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, $this->getTokenHandler()->getUserId());
172 ilInitialisation::initUserAccount();
173
174 if(!$GLOBALS['DIC']->user() instanceof ilObjUser)
175 {
176 $GLOBALS['DIC']->logger()->cal()->debug('no user object defined');
177 }
178 else
179 {
180 $GLOBALS['DIC']->logger()->cal()->debug('Current user is: ' . $GLOBALS['DIC']->user()->getId());
181 }
182 return true;
183 }
184}
185?>
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static setContext($a_context)
set context
Handles calendar authentication tokens for external calendar subscriptions.
static lookupUser($a_token)
Lookup user by hash.
static _getInstance($a_usr_id=0)
get singleton instance
@classDescription Export calendar(s) to ical format
@classDescription Handles requests from external calendar applications
parseRequest()
Fetch client id, the chosen calendar...
static init($a_type)
Init context by type.
const CONTEXT_ICAL
static initILIAS()
ilias initialisation
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$path_info_components
Definition: webdav.php:20