ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
24 include_once './Services/Calendar/classes/class.ilCalendarAuthenticationToken.php';
25 
35 {
36  protected const LIMITED_QUERY_PARAM = 'limited';
37  private $token_handler = null;
41  protected $limit_enabled;
42 
46  public function __construct()
47  {
48  }
49 
53  public function getTokenHandler()
54  {
55  return $this->token_handler;
56  }
57 
62  public function parseRequest()
63  {
64  if ($_GET['client_id']) {
65  $_COOKIE['ilClientId'] = $_GET['client_id'];
66  } else {
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  $this->initLimitEnabled();
83 
84  if (!$this->initUser()) {
85  $logger->warning('Calendar token is invalid. Authentication failed.');
86  return false;
87  }
88 
89  if ($this->getTokenHandler()->getIcal() and !$this->getTokenHandler()->isIcalExpired()) {
90  $GLOBALS['DIC']['ilAuthSession']->logout();
91  ilUtil::deliverData($this->getTokenHandler(), 'calendar.ics', 'text/calendar', 'utf-8');
92  exit;
93  }
94 
95  include_once './Services/Calendar/classes/Export/class.ilCalendarExport.php';
96  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
97  if ($this->getTokenHandler()->getSelectionType() == ilCalendarAuthenticationToken::SELECTION_CALENDAR) {
98  #$export = new ilCalendarExport(array($this->getTokenHandler()->getCalendar()));
100  $cats->initialize(ilCalendarCategories::MODE_REMOTE_SELECTED, $this->getTokenHandler()->getCalendar());
101  $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
102  } else {
104  $cats->initialize(ilCalendarCategories::MODE_REMOTE_ACCESS);
105  $export = new ilCalendarExport($cats->getCategories(true), $this->limit_enabled);
106  }
107 
108  $export->export();
109 
110  $this->getTokenHandler()->setIcal($export->getExportString());
111  $this->getTokenHandler()->storeIcal();
112 
113  $GLOBALS['DIC']['ilAuthSession']->logout();
114  ilUtil::deliverData($export->getExportString(), 'calendar.ics', 'text/calendar', 'utf-8');
115  exit;
116  }
117 
118  protected function initTokenHandler()
119  {
120  $GLOBALS['DIC']->logger()->cal()->info('Authentication token: ' . $_GET['token']);
121  $this->token_handler = new ilCalendarAuthenticationToken(
123  $_GET['token']
124  );
125  return true;
126  }
127 
128  protected function initLimitEnabled()
129  {
130  $this->limit_enabled = (bool) $_GET[self::LIMITED_QUERY_PARAM];
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['DIC']['lng']->loadLanguageModule('dateplaner');
145  }
146 
151  protected function initUser()
152  {
153  if (!$this->getTokenHandler() instanceof ilCalendarAuthenticationToken) {
154  $GLOBALS['DIC']->logger()->cal()->info('Initialisation of authentication token failed');
155  return false;
156  }
157  if (!$this->getTokenHandler()->getUserId()) {
158  $GLOBALS['DIC']->logger()->cal()->info('No user id found for calendar synchronisation');
159  return false;
160  }
161  include_once './Services/User/classes/class.ilObjUser.php';
162  if (!ilObjUser::_exists($this->getTokenHandler()->getUserId())) {
163  $GLOBALS['DIC']->logger()->cal()->notice('No valid user id found for calendar synchronisation');
164  return false;
165  }
166 
167  include_once './Services/Init/classes/class.ilInitialisation.php';
168  $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, $this->getTokenHandler()->getUserId());
170 
171  if (!$GLOBALS['DIC']->user() instanceof ilObjUser) {
172  $GLOBALS['DIC']->logger()->cal()->debug('no user object defined');
173  } else {
174  $GLOBALS['DIC']->logger()->cal()->debug('Current user is: ' . $GLOBALS['DIC']->user()->getId());
175  }
176  return true;
177  }
178 }
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
exit
Definition: login.php:29
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
parseRequest()
Fetch client id, the chosen calendar...
$_GET["client_id"]
$path_info_components
Definition: webdav.php:16
user()
Definition: user.php:4
static initILIAS()
ilias initialisation
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
Export calendar(s) to ical format
const CONTEXT_ICAL
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static setContext($a_context)
set context
static _getInstance($a_usr_id=0)
get singleton instance
static init($a_type)
Init context by type.
static lookupUser($a_token)
Lookup user by hash.
Handles calendar authentication tokens for external calendar subscriptions.
Handles requests from external calendar applications
static initUserAccount()
Init user with current account id.
$_COOKIE[session_name()]
Definition: xapitoken.php:37