You are here

function autologout_block in Automated Logout 6.2

Same name and namespace in other branches
  1. 5 autologout.module \autologout_block()
  2. 6.4 autologout.module \autologout_block()
  3. 6 autologout.module \autologout_block()
  4. 6.3 autologout.module \autologout_block()

Implementation of hook_block().

File

./autologout.module, line 54
Used to automagically log out a user after a preset time, AjK May 2006

Code

function autologout_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;

  // Turn block off if module turned off, anonymous user, or exluded by role.
  if (!_autologout_local_settings('enabled') || $user->uid == 0 || _autologout_exclude_by_role()) {
    return;
  }
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Automated Logout info');
      return $block;
      break;
    case 'configure':
      if (module_exists('jstimer')) {
        if (!module_exists('jst_timer')) {
          drupal_set_message(t('The "Widget: timer" module must also be enabled for the dynamic countdown to work in the automated logout block.'), 'error');
        }
        if (variable_get('jstimer_js_load_option', 0) != 1) {
          drupal_set_message(t('The Javascript timer module\'s "Javascript load options" setting should be set to "Every page" for the dynamic countdown to work in the automated logout block.'), 'error');
        }
      }
    case 'save':
      break;
    case 'view':
      $refresh = (int) _autologout_local_settings('refresh_delta');
      $timeout = _autologout_local_settings('timeout');
      $block['subject'] = filter_xss_admin(_autologout_local_settings('block_title'));
      if (module_exists('jstimer') && module_exists('jst_timer')) {
        $logout_message = filter_xss_admin(_autologout_local_settings('logout_message'));
        $block['content'] = theme('jstimer', 'jst_timer', array(
          'interval' => $timeout,
          'threshold' => 5,
          'format_txt' => filter_xss_admin(variable_get('autologout_jstimer_format', '%hours%:%mins%:%secs%')),
          'complete' => $logout_message . ' ' . ($refresh ? ' ' . t('This page will refresh in %refresh seconds.', array(
            '%refresh' => $refresh,
          )) : ''),
          'no_js_txt' => t('You will be logged out in !time if this page is not refreshed before then.', array(
            '!time' => format_interval($timeout),
          )),
        ));
      }
      else {
        $block['content'] = t('You will be logged out in !time if this page is not refreshed before then.', array(
          '!time' => format_interval($timeout),
        ));
      }
      $logout_message = filter_xss_admin(_autologout_local_settings('logout_message'));
      if ($logout_message != '') {
        $block['content'] .= '<span style="display:none" class="tc_msg">' . $logout_message . '</span>';
      }
      break;
  }
  return $block;
}