ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  private $token_handler = null;
37 
42  public function __construct()
43  {
44  }
45 
49  public function getTokenHandler()
50  {
51  return $this->token_handler;
52  }
53 
58  public function parseRequest()
59  {
60  if ($_GET['client_id']) {
61  $_COOKIE['ilClientId'] = $_GET['client_id'];
62  } else {
63  $path_info_components = explode('/', $_SERVER['PATH_INFO']);
64  $_COOKIE['ilClientId'] = $path_info_components[1];
65  }
66  }
67 
72  public function handleRequest()
73  {
74  session_name('ILCALSESSID');
75  $this->initIlias();
76  $logger = $GLOBALS['DIC']->logger()->cal();
77  $this->initTokenHandler();
78 
79  if (!$this->initUser()) {
80  $logger->warning('Calendar token is invalid. Authentication failed.');
81  return false;
82  }
83 
84  if ($this->getTokenHandler()->getIcal() and !$this->getTokenHandler()->isIcalExpired()) {
85  $GLOBALS['DIC']['ilAuthSession']->logout();
86  ilUtil::deliverData($this->getTokenHandler(), 'calendar.ics', 'text/calendar', 'utf-8');
87  exit;
88  }
89 
90  include_once './Services/Calendar/classes/Export/class.ilCalendarExport.php';
91  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
92  if ($this->getTokenHandler()->getSelectionType() == ilCalendarAuthenticationToken::SELECTION_CALENDAR) {
93  #$export = new ilCalendarExport(array($this->getTokenHandler()->getCalendar()));
95  $cats->initialize(ilCalendarCategories::MODE_REMOTE_SELECTED, $this->getTokenHandler()->getCalendar());
96  $export = new ilCalendarExport($cats->getCategories(true));
97  } else {
100  $export = new ilCalendarExport($cats->getCategories(true));
101  }
102 
103  $export->export();
104 
105  $this->getTokenHandler()->setIcal($export->getExportString());
106  $this->getTokenHandler()->storeIcal();
107 
108  $GLOBALS['DIC']['ilAuthSession']->logout();
109  ilUtil::deliverData($export->getExportString(), 'calendar.ics', 'text/calendar', 'utf-8');
110  exit;
111  }
112 
113  protected function initTokenHandler()
114  {
115  $GLOBALS['DIC']->logger()->cal()->info('Authentication token: ' . $_GET['token']);
116  $this->token_handler = new ilCalendarAuthenticationToken(
118  $_GET['token']
119  );
120  return true;
121  }
122 
123  protected function initIlias()
124  {
125  include_once "Services/Context/classes/class.ilContext.php";
127 
128  include_once './Services/Authentication/classes/class.ilAuthFactory.php';
130 
131  require_once("Services/Init/classes/class.ilInitialisation.php");
133 
134  $GLOBALS['DIC']['lng']->loadLanguageModule('dateplaner');
135  }
136 
141  protected function initUser()
142  {
143  if (!$this->getTokenHandler() instanceof ilCalendarAuthenticationToken) {
144  $GLOBALS['DIC']->logger()->cal()->info('Initialisation of authentication token failed');
145  return false;
146  }
147  if (!$this->getTokenHandler()->getUserId()) {
148  $GLOBALS['DIC']->logger()->cal()->info('No user id found for calendar synchronisation');
149  return false;
150  }
151  include_once './Services/User/classes/class.ilObjUser.php';
152  if (!ilObjUser::_exists($this->getTokenHandler()->getUserId())) {
153  $GLOBALS['DIC']->logger()->cal()->notice('No valid user id found for calendar synchronisation');
154  return false;
155  }
156 
157  include_once './Services/Init/classes/class.ilInitialisation.php';
158  $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, $this->getTokenHandler()->getUserId());
159  ilInitialisation::initUserAccount();
160 
161  if (!$GLOBALS['DIC']->user() instanceof ilObjUser) {
162  $GLOBALS['DIC']->logger()->cal()->debug('no user object defined');
163  } else {
164  $GLOBALS['DIC']->logger()->cal()->debug('Current user is: ' . $GLOBALS['DIC']->user()->getId());
165  }
166  return true;
167  }
168 }
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
$_COOKIE['client_id']
Definition: server.php:9
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
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
Export calendar(s) to ical format
const CONTEXT_ICAL
static setContext($a_context)
set context
static _getInstance($a_usr_id=0)
get singleton instance
static init($a_type)
Init context by type.
exit
Definition: backend.php:16
static lookupUser($a_token)
Lookup user by hash.
Handles calendar authentication tokens for external calendar subscriptions.
Handles requests from external calendar applications
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.