You are here

function autologout_block in Automated Logout 5

Same name and namespace in other branches
  1. 6.4 autologout.module \autologout_block()
  2. 6 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 82
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');
      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;
      }
      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('autologout 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');
          }
        }
      }
      $refresh = (int) _autologout_local_settings('refresh_delta');
      $timeout = _autologout_local_settings('timeout');
      $logout_time = (int) $_SESSION['lastaccess'] + $timeout;
      $tz = substr(date('O'), 0, 3);
      $block['subject'] = filter_xss_admin(_autologout_local_settings('block_title'));
      $block['content'] = '
      <span class="countdowntimer">' . t('You will be automatically logged out at %this_date if this page is not refreshed before then.', array(
        '%this_date' => date('r', $logout_time),
      )) . '
        <span style="display:none" name="datetime">' . date('Y-m-d\\TH:i:s', $logout_time) . '</span>
        <span style="display:none" name="dir">down</span>
        <span style="display:none" name="format_txt">%hours%:%mins%:%secs%</span>
        <span style="display:none" name="threshold">5</span>
        <span style="display:none" name="tz_hours">' . $tz . '</span>
        <span style="display:none" name="complete">' . t('You have been logged out. ') . ($refresh ? t('This page will refresh in %refresh seconds', array(
        '%refresh' => $refresh,
      )) : '') . '</span>
      </span>
      ';
      break;
  }

  // end switch()
  return $block;
}