ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSessionReminderCheck.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10{
15 public function getJsonResponse($sessionId)
16 {
23 global $ilDB, $ilUser, $lng, $ilClientIniFile;
24
25 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
26
27
28 $GLOBALS['DIC']->logger()->auth()->debug('Session reminder call for: ' . $sessionId);
29
30 // disable session writing and extension of expire time
31 include_once './Services/Authentication/classes/class.ilSession.php';
33
34 $response = array('remind' => false);
35
36 $res = $ilDB->queryF('
37 SELECT expires, user_id, data
38 FROM usr_session
39 WHERE session_id = %s',
40 array('text'),
41 array($sessionId)
42 );
43
44 $num = $ilDB->numRows($res);
45
46 if($num > 1)
47 {
48 $response['message'] = 'The determined session data is not unique.';
49 return ilJsonUtil::encode($response);
50 }
51
52 if($num == 0)
53 {
54 $response['message'] = 'ILIAS could not determine the session data.';
55 return ilJsonUtil::encode($response);
56 }
57
58 $data = $ilDB->fetchAssoc($res);
60 {
61 $response['message'] = 'ILIAS could not fetch the session data or the corresponding user is no more authenticated.';
62 return ilJsonUtil::encode($response);
63 }
64
69 $expiretime = $data['expires'];
70 if($this->isSessionAlreadyExpired($expiretime))
71 {
72 $response['message'] = 'The session is already expired. The client should have received a remind command before.';
73 return ilJsonUtil::encode($response);
74 }
75
80
81 if(null === $expiretime)
82 {
83 $response['message'] = 'ILIAS could not determine the expire time from the session data.';
84 return ilJsonUtil::encode($response);
85 }
86
87 if($this->isSessionAlreadyExpired($expiretime))
88 {
89 $response['message'] = 'The session is already expired. The client should have received a remind command before.';
90 return ilJsonUtil::encode($response);
91 }
92
97
98 include_once './Services/Authentication/classes/class.ilSessionReminder.php';
99 $remind_time = $expiretime - max(ilSessionReminder::MIN_LEAD_TIME, (float)$ilUser->getPref('session_reminder_lead_time')) * 60;
100 if($remind_time > time())
101 {
102 // session will expire in <lead_time> minutes
103 $response['message'] = 'Lead time not reached, yet. Current time: ' . date('Y-m-d H:i:s', time()) . ', Reminder time: ' . date('Y-m-d H:i:s', $remind_time);
104 return ilJsonUtil::encode($response);
105 }
106
107 $dateTime = new ilDateTime($expiretime, IL_CAL_UNIX);
108 switch($ilUser->getTimeFormat())
109 {
111 $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
112 break;
113
115 default:
116 $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
117 break;
118 }
119
120 $response = array(
121 'extend_url' => './ilias.php?baseClass=ilPersonalDesktopGUI',
122 'txt' => str_replace("\\n", '%0A', sprintf($lng->txt('session_reminder_alert'), ilDatePresentation::secondsToString($expiretime - time()), $formatted_expiration_time, $ilClientIniFile->readVariable('client', 'name') . ' | ' . ilUtil::_getHttpPath())),
123 'remind' => true
124 );
125
126 return ilJsonUtil::encode($response);
127 }
128
133 protected function isSessionAlreadyExpired($expiretime)
134 {
135 return $expiretime < time();
136 }
137
143 {
144 return is_array($data) && isset($data['user_id']) && $data['user_id'] > 0 && $data['user_id'] != ANONYMOUS_USER_ID;
145 }
146}
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
@classDescription Date and time handling
static encode($mixed, $suppress_native=false)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static enableWebAccessWithoutSession($enable_web_access_without_session)
static _getHttpPath()
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $lng
Definition: privfeed.php:17
global $ilDB
$ilUser
Definition: imgupload.php:18