ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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($sessionIdHash)
16  {
23  global $ilDB, $ilUser, $lng, $ilClientIniFile;
24 
25  $GLOBALS['DIC']->logger()->auth()->debug('Session reminder call for session id hash: ' . $sessionIdHash);
26 
27  // disable session writing and extension of expiration time
29 
30  $response = array('remind' => false);
31 
32  $res = $ilDB->queryF(
33  '
34  SELECT expires, user_id, data
35  FROM usr_session
36  WHERE MD5(session_id) = %s
37  ',
38  ['text'],
39  [$sessionIdHash]
40  );
41 
42  $num = $ilDB->numRows($res);
43 
44  if ($num > 1) {
45  $response['message'] = 'The determined session data is not unique.';
47  }
48 
49  if ($num == 0) {
50  $response['message'] = 'ILIAS could not determine the session data.';
52  }
53 
54  $data = $ilDB->fetchAssoc($res);
55  if (!$this->isAuthenticatedUsrSession($data)) {
56  $response['message'] = 'ILIAS could not fetch the session data or the corresponding user is no more authenticated.';
58  }
59 
64  $expiretime = $data['expires'];
65  if ($this->isSessionAlreadyExpired($expiretime)) {
66  $response['message'] = 'The session is already expired. The client should have received a remind command before.';
68  }
69 
73  $ilUser = ilObjectFactory::getInstanceByObjId($data['user_id']);
74 
75  if (null === $expiretime) {
76  $response['message'] = 'ILIAS could not determine the expire time from the session data.';
78  }
79 
80  if ($this->isSessionAlreadyExpired($expiretime)) {
81  $response['message'] = 'The session is already expired. The client should have received a remind command before.';
83  }
84 
88  $ilUser = ilObjectFactory::getInstanceByObjId($data['user_id']);
89 
90  include_once './Services/Authentication/classes/class.ilSessionReminder.php';
91  $remind_time = $expiretime - max(ilSessionReminder::MIN_LEAD_TIME, (float) $ilUser->getPref('session_reminder_lead_time')) * 60;
92  if ($remind_time > time()) {
93  // session will expire in <lead_time> minutes
94  $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);
96  }
97 
98  $dateTime = new ilDateTime($expiretime, IL_CAL_UNIX);
99  switch ($ilUser->getTimeFormat()) {
101  $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
102  break;
103 
105  default:
106  $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
107  break;
108  }
109 
110  $response = array(
111  'extend_url' => './ilias.php?baseClass=ilPersonalDesktopGUI',
112  'txt' => str_replace("\\n", '%0A', sprintf($lng->txt('session_reminder_alert'), ilDatePresentation::secondsToString($expiretime - time()), $formatted_expiration_time, $ilClientIniFile->readVariable('client', 'name') . ' | ' . ilUtil::_getHttpPath())),
113  'remind' => true
114  );
115 
117  }
118 
123  protected function isSessionAlreadyExpired($expiretime)
124  {
125  return $expiretime < time();
126  }
127 
132  protected function isAuthenticatedUsrSession($data)
133  {
134  return is_array($data) && isset($data['user_id']) && $data['user_id'] > 0 && $data['user_id'] != ANONYMOUS_USER_ID;
135  }
136 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_CAL_UNIX
static encode($mixed, $suppress_native=false)
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
foreach($_POST as $key=> $value) $res
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
const IL_CAL_FKT_DATE
Date and time handling
$ilUser
Definition: imgupload.php:18
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
static _getHttpPath()
global $lng
Definition: privfeed.php:17
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$response