You are here

function autologout_block in Automated Logout 6

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

Implementation of hook_block().

File

./autologout.module, line 85
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;
  _autologout_debug("autologout_block('{$op}')");
  if (!_autologout_local_settings('enabled')) {
    return;
  }
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Automated Logout info');
      return $block;
      break;
    case 'configure':
      if (module_exists("countdowntimer")) {
        if (variable_get('countdowntimer_js_load_option', 0) != 1) {

          //
          // Display the error on the block configure page and log the
          // other times the block is called without the settings enabled
          //
          drupal_set_message(l(t('Countdown Timer admin settings'), 'admin/settings/countdowntimer') . t('  for Javascript load options should be set to EVERY PAGE or this block will not display properly.'), 'error');
        }
      }
      else {
        drupal_set_message(l(t('Javascript Countdown Timer'), 'http://drupal.org/project/countdowntimer') . t(' must be installed for the block to be visable.'), 'error');
      }
    case 'save':
      break;
    case 'view':
      if ($user->uid < 2 || _autologout_by_role()) {
        _autologout_debug("  block doesn't apply");
        return;
      }

      /**
       *  only display the block when the countdowntimer module is installed
       */
      if (module_exists("countdowntimer")) {
        if (variable_get('countdowntimer_js_load_option', 0) != 1) {

          //countdowntimer is not configured for every page, the block

          //won't countdown on all pages otherwise.

          //Log the error
          $error_message = t('Automated Logout block called and Countdown Timer admin settings is not set for EVERY PAGE');
          watchdog('configuration', $error_message);
          if (variable_get('error_level', 1) == 1 || strstr($_SERVER['SCRIPT_NAME'], 'update.php')) {

            /**
             * if permissable in site settings display the error on the page
             */
            drupal_set_message($error_message, 'error');
          }
        }
      }
      $block['subject'] = filter_xss_admin(_autologout_local_settings('block_title'));
      $refresh = (int) _autologout_local_settings('refresh_delta');
      $timeout = _autologout_local_settings('timeout');
      $logout_time = (int) $_SESSION['lastaccess'] + $timeout;
      $tz = drupal_substr(date('O'), 0, 3);

      /**
       * When we port to Drupal 7 we can change the date to date('c', $logout_time)
       * which is the ISO 8601 date used here but support was only added in PHP 5
       */
      $block['content'] = '
      <span class="countdowntimer">' . t('You will be automatically logged out at') . ' ' . date('r', $logout_time) . ' ' . t('if this page is not refreshed before then.') . '
          <span style="display:none" class="datetime">' . date('Y-m-d\\TH:i:s', $logout_time) . $tz . ':00</span>
          <span style="display:none" class="current_server_time">' . date('Y-m-d\\TH:i:s') . $tz . ':00</span>
          <span style="display:none" class="dir">down</span>
          <span style="display:none" class="complete">' . t('You have been automatically logged out due to inactivity.') . ' ' . ($refresh ? ' ' . t('This page will refresh in %refresh seconds.', array(
        '%refresh' => $refresh,
      )) : '') . '</span>
      ';
      $redirect_url = filter_xss_admin(_autologout_local_settings('redirect_url'));
      $logout_message = filter_xss_admin(_autologout_local_settings('logout_message'));
      if ($redirect_url != '') {
        $block['content'] .= '<span style="display:none" class="tc_redir">' . $redirect_url . '</span>';
      }
      if ($logout_message != '') {
        $block['content'] .= '<span style="display:none" class="tc_msg">' . $logout_message . '</span>';
      }
      $block['content'] .= '</span>';

      //_autologout_define_headers();
      break;
  }

  // end switch()
  return $block;
}