/[drupal]/contributions/modules/autologout/autologout.module
ViewVC logotype

Contents of /contributions/modules/autologout/autologout.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Fri Apr 17 14:43:53 2009 UTC (7 months, 1 week ago) by jvandervort
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--3
Changes since 1.8: +80 -609 lines
File MIME type: text/x-php
#341420 by rob loach, a new auto logout lite module.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Used to automagically log out a user after a certain time.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function autologout_help($path, $arg) {
13 switch ($path) {
14 case 'admin/help#autologout':
15 $output = '<p>'. t('The <em>Automated Logout</em> module allows you to force users to log out after a given amount of time. You can configure this in the <a href="@usersettings">User settings administration</a>.', array('@usersettings' => base_path() .'admin/user/settings')) . '</p>';
16 $output .= '<p>'. t('If you have the <a href="@jquerycountdown">jQuery Countdown module</a> enabled, the <a href="@automatedlogoutblock">Automated Logout block</a> will have a live countdown timer.', array('@automatedlogoutblock' => base_path() .'admin/build/block', '@usersettings' => 'http://drupal.org/project/jquery_countdown')) . '</p>';
17 return $output;
18 break;
19 }
20 }
21
22 /**
23 * Implementation of hook_form_alter().
24 */
25 function autologout_form_alter(&$form, $form_state, $form_id) {
26 if ($form_id == 'user_admin_settings') {
27 $form['autologout'] = array(
28 '#type' => 'fieldset',
29 '#title' => t('Automated Logout'),
30 '#weight' => -1,
31 );
32 $form['autologout']['autologout_seconds'] = array(
33 '#type' => 'select',
34 '#title' => t('Time until forced logout'),
35 '#description' => t('Force the user to logout after the given amount of time.'),
36 '#default_value' => variable_get('autologout_seconds', 0),
37 '#options' => array(
38 0 => t('Disabled'),
39 30 => t('30 seconds'),
40 60 => t('One minute'),
41 60 * 2 => t('Two minutes'),
42 60 * 5 => t('Five minutes'),
43 60 * 10 => t('Ten minutes'),
44 60 * 20 => t('Twenty minutes'),
45 60 * 30 => t('Thirty minutes'),
46 60 * 60 => t('One hour'),
47 ),
48 );
49 }
50 }
51
52 /**
53 * Implementation of hook_init().
54 */
55 function autologout_init() {
56 global $user;
57 if ($user->uid > 0) {
58 // See if automatic logout is enabled.
59 $seconds = variable_get('autologout_seconds', 0);
60 if ($seconds > 0) {
61 // Check the session's last access.
62 if (!isset($_SESSION['autologout_lastaccess']) || ((int)$_SESSION['autologout_lastaccess']) > time() - $seconds) {
63 // Update the session's last access.
64 $_SESSION['autologout_lastaccess'] = time();
65 $redirect = base_path() .'logout';
66 drupal_set_html_head("<meta http-equiv='refresh' content='$seconds';url='$redirect'>");
67 }
68 else {
69 // Force the user to log out.
70 module_load_include('inc', 'user', 'user.pages');
71 user_logout();
72 }
73 }
74 }
75 }
76
77 /**
78 * Implementation of hook_block().
79 */
80 function autologout_block($op = 'list', $delta = 0, $edit = array()) {
81 // The $op parameter determines what piece of information is being requested.
82 switch ($op) {
83 case 'list':
84 $blocks['autologout'] = array(
85 'info' => t('Automated Logout'),
86 );
87 return $blocks;
88 break;
89 case 'view':
90 $block = array();
91 switch ($delta) {
92 case 'autologout':
93 $block['subject'] = t('Automated Logout');
94 $block['content'] = theme('autologout_block');
95 break;
96 }
97 return $block;
98 }
99 }
100
101 /**
102 * Implementation of hook_theme().
103 */
104 function autologout_theme() {
105 return array(
106 'autologout_block' => array(),
107 );
108 }
109
110 /**
111 * Themes the automated logout block.
112 */
113 function theme_autologout_block() {
114 global $user;
115 $seconds = (int)variable_get('autologout_seconds', 0);
116 if ($user->uid != 0 && $seconds > 0) {
117 if (module_exists('jquery_countdown')) {
118 jquery_countdown_add(".autologout", array("until" => $seconds, "expiryUrl" => base_path() .'logout'));
119 }
120 return '<div class="autologout">'. t('You will be logged out in !time.', array('!time' => format_interval($seconds))) . '</div>';
121 }
122 }

  ViewVC Help
Powered by ViewVC 1.1.2