ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCalendarAuthenticationToken.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
13{
14 const SELECTION_NONE = 0;
15 const SELECTION_PD = 1;
18
19 private $user = null;
20
21 private $token = '';
22 private $selection_type = 0;
23 private $calendar = 0;
24
25 private $ical = null;
26 private $ical_ctime = null;
27
34 public function __construct($a_user_id,$a_token = '')
35 {
36 $this->user = $a_user_id;
37 $this->token = $a_token;
38
39 $this->read();
40 }
41
42 public static function lookupAuthToken($a_user_id, $a_selection,$a_calendar = 0)
43 {
44 global $ilDB;
45
46 $query = "SELECT * FROM cal_auth_token ".
47 "WHERE user_id = ".$ilDB->quote($a_user_id,'integer').' '.
48 "AND selection = ".$ilDB->quote($a_selection,'integer').' '.
49 "AND calendar = ".$ilDB->quote($a_calendar,'integer');
50 $res = $ilDB->query($query);
51 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
52 {
53 return $row->hash;
54 }
55 return false;
56 }
57
63 public static function lookupUser($a_token)
64 {
65 global $ilDB;
66
67 $query = "SELECT * FROM cal_auth_token ".
68 "WHERE hash = ".$ilDB->quote($a_token,'text');
69 $res = $ilDB->query($query);
70 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
71 {
72 return $row->user_id;
73 }
74 return 0;
75 }
76
81 public function getSelectionType()
82 {
84 }
85
86
91 public function getUserId()
92 {
93 return $this->user;
94 }
95
101 public function setSelectionType($a_type)
102 {
103 $this->selection_type = $a_type;
104 }
105
111 public function setCalendar($a_cal)
112 {
113 $this->calendar = $a_cal;
114 }
115
116 public function getCalendar()
117 {
118 return $this->calendar;
119 }
120
121 public function setIcal($ical)
122 {
123 $this->ical = $ical;
124 }
125
130 public function getIcal()
131 {
132 return $this->ical;
133 }
134
135
140 public function getToken()
141 {
142 return $this->token;
143 }
144
149 public function storeIcal()
150 {
151 global $ilDB;
152
153 $ilDB->update(
154 'cal_auth_token',
155 array(
156 'ical' => array('clob',$this->getIcal()),
157 'c_time' => array('integer',time())
158 ),
159 array(
160 'user_id' => array('integer',$this->getUserId()),
161 'hash' => array('text',$this->getToken())
162 )
163 );
164 }
165
170 public function isIcalExpired()
171 {
172 return true;
173
174 include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
175
176 if(!ilCalendarSettings::_getInstance()->isSynchronisationCacheEnabled())
177 {
178 return true;
179 }
180 if(!ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes())
181 {
182 return true;
183 }
184 return time() > ($this->ical_ctime + 60 * ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes());
185 }
186
191 public function add()
192 {
193 global $ilDB;
194
195 $this->createToken();
196
197 $query = "INSERT INTO cal_auth_token (user_id,hash,selection,calendar) ".
198 "VALUES ( ".
199 $ilDB->quote($this->getUserId(),'integer').', '.
200 $ilDB->quote($this->getToken(),'text').', '.
201 $ilDB->quote($this->getSelectionType(),'integer').', '.
202 $ilDB->quote($this->getCalendar(),'integer').' '.
203 ')';
204 $ilDB->manipulate($query);
205
206 return $this->getToken();
207 }
208
213 protected function createToken()
214 {
215 $this->token = md5($this->getUserId().$this->getSelectionType().rand());
216 }
217
222 protected function read()
223 {
224 global $ilDB;
225
226 if(!$this->getToken())
227 {
228 $query = "SELECT * FROM cal_auth_token ".
229 "WHERE user_id = ".$ilDB->quote($this->getUserId(),'integer');
230 }
231 else
232 {
233 $query = 'SELECT * FROM cal_auth_token '.
234 'WHERE user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
235 'AND hash = '.$ilDB->quote($this->getToken(),'text');
236
237 }
238
239 $res = $ilDB->query($query);
240 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
241 {
242 $this->token = $row->hash;
243 $this->selection_type = $row->selection;
244 $this->calendar = $row->calendar;
245 $this->ical = $row->ical;
246 $this->ical_ctime = $row->c_time;
247 }
248 return true;
249 }
250}
251?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
Handles calendar authentication tokens for external calendar subscriptions.
static lookupAuthToken($a_user_id, $a_selection, $a_calendar=0)
__construct($a_user_id, $a_token='')
Constructor.
isIcalExpired()
Check if cache is disabled or expired.
static lookupUser($a_token)
Lookup user by hash.
static _getInstance()
get singleton instance
global $ilDB