[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <15-Apr-2004 11:25:31 bh> 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 9 // SOFTWARE LICENSE: GNU General Public License v2.0 10 // NOTICE: > 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of version 2.0 of the GNU General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of version 2.0 of the GNU General 21 // Public License along with this program; if not, write to the Free 22 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 // MA 02110-1301, USA. 24 // 25 // 26 include_once ( 'kernel/common/template.php' ); 27 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 28 include_once ( 'lib/ezutils/classes/ezsession.php' ); 29 30 $tpl =& templateInit(); 31 $sessionsRemoved = false; 32 $http =& eZHTTPTool::instance(); 33 34 $module =& $Params["Module"]; 35 $param['limit'] = 50; 36 37 $filterType = 'registered'; 38 if ( $http->hasSessionVariable( 'eZSessionFilterType' ) ) 39 $filterType = $http->sessionVariable( 'eZSessionFilterType' ); 40 $expirationFilterType = 'active'; 41 if ( $http->hasSessionVariable( 'eZSessionExpirationFilterType' ) ) 42 $expirationFilterType = $http->sessionVariable( 'eZSessionExpirationFilterType' ); 43 44 $userID = $Params['UserID']; 45 46 if ( $module->isCurrentAction( 'ShowAllUsers' ) ) 47 { 48 return $module->redirectToView( 'session' ); 49 } 50 else if ( $module->isCurrentAction( 'ChangeFilter' ) ) 51 { 52 $filterType = $module->actionParameter( 'FilterType' ); 53 if ( !in_array( $filterType, array( 'everyone', 'registered', 'anonymous' ) ) ) 54 $filterType = 'registered'; 55 if ( $module->hasActionParameter( 'InactiveUsersCheckExists' ) ) 56 { 57 $expirationFilterType = 'active'; 58 if ( $module->hasActionParameter( 'InactiveUsersCheck' ) ) 59 $expirationFilterType = 'all'; 60 } 61 if ( $module->hasActionParameter( 'ExpirationFilterType' ) ) 62 { 63 $expirationFilterType = $module->actionParameter( 'ExpirationFilterType' ); 64 } 65 if ( !in_array( $expirationFilterType, array( 'all', 'active' ) ) ) 66 $expirationFilterType = 'active'; 67 $http->setSessionVariable( 'eZSessionFilterType', $filterType ); 68 $http->setSessionVariable( 'eZSessionExpirationFilterType', $expirationFilterType ); 69 } 70 else if ( $module->isCurrentAction( 'RemoveAllSessions' ) ) 71 { 72 eZSessionEmpty(); 73 $sessionsRemoved = true; 74 } 75 else if ( $module->isCurrentAction( 'RemoveTimedOutSessions' ) ) 76 { 77 eZSessionGarbageCollector(); 78 $sessionsRemoved = true; 79 } 80 else if ( $module->isCurrentAction( 'RemoveSelectedSessions' ) ) 81 { 82 if ( $userID ) 83 { 84 if ( eZHTTPTool::hasPostVariable( 'SessionKeyArray' ) ) 85 { 86 $sessionKeyArray = eZHTTPTool::postVariable( 'SessionKeyArray' ); 87 foreach ( $sessionKeyArray as $sessionKeyItem ) 88 { 89 eZSessionDestroy( $sessionKeyItem ); 90 } 91 } 92 } 93 else 94 { 95 if ( eZHTTPTool::hasPostVariable( 'UserIDArray' ) ) 96 { 97 $userIDArray = eZHTTPTool::postVariable( 'UserIDArray' ); 98 if ( count( $userIDArray ) > 0 ) 99 { 100 include_once ( 'lib/ezdb/classes/ezdb.php' ); 101 $db =& eZDB::instance(); 102 $userIDArrayString = $db->implodeWithTypeCast( ',', $userIDArray, 'int' ); 103 $rows = $db->arrayQuery( "SELECT session_key FROM ezsession WHERE user_id IN ( " . $userIDArrayString . " )" ); 104 foreach ( $rows as $row ) 105 { 106 eZSessionDestroy( $row['session_key'] ); 107 } 108 } 109 } 110 } 111 } 112 113 $viewParameters = $Params['UserParameters']; 114 if ( isset( $viewParameters['offset'] ) and 115 is_numeric( $viewParameters['offset'] ) ) 116 { 117 $param['offset'] = $viewParameters['offset']; 118 } 119 else 120 { 121 $param['offset'] = 0; 122 $viewParameters['offset'] = 0; 123 } 124 125 126 /* 127 Get all sessions by limit and offset, and returns it 128 */ 129 function &eZFetchActiveSessions( $params = array() ) 130 { 131 if ( isset( $params['limit'] ) ) 132 $limit = $params['limit']; 133 else 134 $limit = 20; 135 136 if ( isset( $params['offset'] ) ) 137 $offset = $params['offset']; 138 else 139 $offset = 0; 140 $orderBy = " expiration_time DESC"; 141 142 switch ( $params['sortby'] ) 143 { 144 case 'login': 145 { 146 $orderBy = "ezuser.login ASC"; 147 } break; 148 149 case 'email': 150 { 151 $orderBy = "ezuser.email ASC"; 152 } break; 153 154 case 'name': 155 { 156 $orderBy = "ezcontentobject.name ASC"; 157 } break; 158 159 case 'idle': 160 { 161 $orderBy = " expiration_time DESC"; 162 } break; 163 } 164 165 $filterType = $params['filter_type']; 166 switch ( $filterType ) 167 { 168 case 'registered': 169 { 170 $filterSQL = 'AND ezsession.user_id != ' . EZ_USER_ANONYMOUS_ID; 171 } break; 172 173 case 'anonymous': 174 { 175 $filterSQL = 'AND ezsession.user_id = ' . EZ_USER_ANONYMOUS_ID; 176 } break; 177 178 case 'everyone': 179 default: 180 { 181 $filterSQL = ''; 182 } break; 183 } 184 185 $expirationFilterType = $params['expiration_filter']; 186 switch ( $expirationFilterType ) 187 { 188 case 'active': 189 { 190 $ini =& eZINI::instance(); 191 $time = mktime(); 192 $activityTimeout = $ini->variable( 'Session', 'ActivityTimeout' ); 193 $sessionTimeout = $ini->variable( 'Session', 'SessionTimeout' ); 194 $time = $time + $sessionTimeout - $activityTimeout; 195 $expirationFilterSQL = ' AND ezsession.expiration_time > ' . $time; 196 } break; 197 198 case 'all': 199 default: 200 { 201 $expirationFilterSQL = ''; 202 } break; 203 } 204 205 $userID = $params['user_id']; 206 $countField = ''; 207 $countGroup = 'GROUP BY ezsession.user_id'; 208 if ( $userID ) 209 { 210 $filterSQL = 'AND ezsession.user_id = ' . (int)$userID; 211 $expirationSQL = 'ezsession.expiration_time'; 212 } 213 else 214 { 215 $countField = ', count( ezsession.user_id ) AS count'; 216 $expirationSQL = 'max( ezsession.expiration_time ) as expiration_time'; 217 } 218 219 include_once ( 'lib/ezdb/classes/ezdb.php' ); 220 $db =& eZDB::instance(); 221 $query = "SELECT ezsession.user_id, $expirationSQL, max(session_key) as session_key $countField 222 FROM ezsession, ezuser, ezcontentobject 223 WHERE ezsession.user_id=ezuser.contentobject_id AND 224 ezsession.user_id=ezcontentobject.id 225 $filterSQL 226 $expirationFilterSQL 227 $countGroup 228 ORDER BY $orderBy"; 229 230 $rows = $db->arrayQuery( $query, array( 'offset' => $offset, 'limit' => $limit ) ); 231 232 $time = mktime(); 233 $ini =& eZINI::instance(); 234 $activityTimeout = $ini->variable( 'Session', 'ActivityTimeout' ); 235 $sessionTimeout = $ini->variable( 'Session', 'SessionTimeout' ); 236 $sessionTimeoutValue = $time - $sessionTimeout; 237 238 $resultArray = array(); 239 foreach ( $rows as $row ) 240 { 241 $sessionUser = eZUser::fetch( $row['user_id'], true ); 242 $session['user_id'] = $row['user_id']; 243 if ( !$userID ) 244 $session['count'] = $row['count']; 245 $session['expiration_time'] = $row['expiration_time']; 246 $session['session_key'] = $row['session_key']; 247 $session['idle_time'] = $row['expiration_time'] - $sessionTimeout; 248 $idleTime = $time - $row['expiration_time'] + $sessionTimeout; 249 $session['idle']['hour'] = (int)( $idleTime / 3600 ); 250 $session['idle']['minute'] = (int)( ( $idleTime / 60 ) % 60 ); 251 $session['idle']['second'] = abs( $idleTime % 60 ); 252 253 if ( $session['idle']['minute'] < 10 && $session['idle']['minute']>=0 ) 254 { 255 $session['idle']['minute'] = "0" . $session['idle']['minute']; 256 } 257 258 if ( $session['idle']['second'] < 10 ) 259 { 260 $session['idle']['second'] = "0" . $session['idle']['second']; 261 } 262 263 $session['email'] = $sessionUser->attribute( 'email' ); 264 $session['login'] = $sessionUser->attribute( 'login' ); 265 $resultArray[] = $session; 266 } 267 return $resultArray; 268 } 269 270 /* 271 Counts active sessions according the filters and returns the count. 272 */ 273 function &eZFetchActiveSessionCount( $params = array() ) 274 { 275 $filterType = $params['filter_type']; 276 switch ( $filterType ) 277 { 278 case 'registered': 279 { 280 $filterSQL = ' ezsession.user_id != ' . EZ_USER_ANONYMOUS_ID; 281 } break; 282 283 case 'anonymous': 284 { 285 $filterSQL = ' ezsession.user_id = ' . EZ_USER_ANONYMOUS_ID; 286 } break; 287 288 case 'everyone': 289 default: 290 { 291 $filterSQL = ''; 292 } break; 293 } 294 295 $expirationFilterType = $params['expiration_filter']; 296 297 $userID = $params['user_id']; 298 if ( $userID ) 299 { 300 $filterSQL = ' ezsession.user_id = ' . (int)$userID; 301 } 302 303 switch ( $expirationFilterType ) 304 { 305 case 'active': 306 { 307 $ini =& eZINI::instance(); 308 $time = mktime(); 309 $activityTimeout = $ini->variable( 'Session', 'ActivityTimeout' ); 310 $sessionTimeout = $ini->variable( 'Session', 'SessionTimeout' ); 311 $time = $time + $sessionTimeout - $activityTimeout; 312 $expirationFilterSQL = ''; 313 if ( strlen( $filterSQL ) > 0 ) 314 $expirationFilterSQL .= ' AND '; 315 $expirationFilterSQL .= ' ezsession.expiration_time > ' . $time; 316 } break; 317 318 case 'all': 319 default: 320 { 321 $expirationFilterSQL = ''; 322 } break; 323 } 324 325 $whereSQL = ''; 326 if ( ( strlen( $filterSQL ) + strlen( $expirationFilterSQL ) ) > 0 ) 327 $whereSQL = 'WHERE'; 328 329 include_once ( 'lib/ezdb/classes/ezdb.php' ); 330 $db =& eZDB::instance(); 331 $query = "SELECT count( * ) AS count 332 FROM ezsession 333 $whereSQL 334 $filterSQL 335 $expirationFilterSQL"; 336 337 $rows = $db->arrayQuery( $query ); 338 339 return $rows[0]['count']; 340 } 341 342 $param['sortby'] = false; 343 $param['filter_type'] = $filterType; 344 $param['expiration_filter'] = $expirationFilterType; 345 $param['user_id'] = $userID; 346 if ( isset( $viewParameters['sortby'] ) ) 347 $param['sortby'] = $viewParameters['sortby']; 348 $sessionsActive = eZSessionCountActive( $param ); 349 $sessionsCount = eZFetchActiveSessionCount( $param ); 350 $sessionsList =& eZFetchActiveSessions( $param ); 351 352 353 if ( $param['offset'] >= $sessionsActive and $sessionsActive != 0 ) 354 { 355 $module->redirectTo( '/setup/session' ); 356 } 357 358 $tpl->setVariable( "sessions_removed", $sessionsRemoved ); 359 $tpl->setVariable( "sessions_active", $sessionsActive ); 360 $tpl->setVariable( "sessions_count", $sessionsCount ); 361 $tpl->setVariable( "sessions_list", $sessionsList ); 362 $tpl->setVariable( "page_limit", $param['limit'] ); 363 $tpl->setVariable( "view_parameters", $viewParameters ); 364 $tpl->setVariable( "form_parameter_string", $viewParameters ); 365 $tpl->setVariable( 'filter_type', $filterType ); 366 $tpl->setVariable( 'expiration_filter_type', $expirationFilterType ); 367 $tpl->setVariable( 'user_id', $userID ); 368 369 $Result = array(); 370 $Result['content'] =& $tpl->fetch( "design:setup/session.tpl" ); 371 $Result['path'] = array( array( 'url' => false, 372 'text' => ezi18n( 'kernel/setup', 'Session admin' ) ) ); 373 374 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |