You are here

timezone_detect.install in Timezone Detect 6

Same filename and directory in other branches
  1. 8 timezone_detect.install
  2. 7 timezone_detect.install

(Un)installs the Timezone Detect module.

File

timezone_detect.install
View source
<?php

/**
 * @file
 * (Un)installs the Timezone Detect module.
 */

/**
 * Implements hook_enable().
 */
function timezone_detect_enable() {
  drupal_set_message(t('The Timezone Detect module was successfully enabled.'), 'status');

  // Set default user timezone to "none." Otherwise this module will not do
  // anything in its default configuration (set user timezone only if it
  // is not set).
  $user_default_timezone = variable_get('date_default_timezone_name', NULL);
  if (!empty($user_default_timezone)) {
    variable_set('date_default_timezone_name', 0);
    drupal_set_message(t('Default user timezone set to "empty timezone" for best results with Timezone Detect.'), 'status');
  }

  // Disable "remind users at login if their time zone is not set." Otherwise
  // users may be asked to set their timezone on first login even when this
  // module has already set it via ajax callback.
  $empty_timezone_message = variable_get('empty_timezone_message', 0);
  if ($empty_timezone_message != 0) {
    variable_set('empty_timezone_message', 0);
    drupal_set_message(t('"Remind users at login if their time zone is not set" set to FALSE for best results with Timezone Detect.'), 'status');
  }
}

/**
 * Implements hook_requirements().
 */
function timezone_detect_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // Check that default user timezone is set to "empty timezone", or that
  // Timezone Detect is configured to update user timezone on every login
  // (otherwise automatic timezone detection will not work).
  $default_timezone_okay = FALSE;
  $user_default_timezone = variable_get('date_default_timezone', 0);
  $timezone_update_mode = variable_get('timezone_detect_mode', TIMEZONE_DETECT_MODE_DEFAULT);
  if ($timezone_update_mode != TIMEZONE_DETECT_MODE_DEFAULT || $user_default_timezone == 0) {
    $default_timezone_okay = TRUE;
  }
  switch ($phase) {
    case 'runtime':
      if (!$default_timezone_okay) {
        $requirements['timezone_detect'] = array(
          'title' => $t('Timezone Detect'),
          'value' => $t('Incompatible default user timezone'),
          'description' => $t('For automatic timezone detection to work correctly, please change default  timezone to "empty timezone" on your site\'s !regional_settings_url.', array(
            '!regional_settings_url' => l($t('Date time settings page'), 'admin/settings/date-time'),
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      break;
  }
  return $requirements;
}

/**
 * Implements hook_uninstall().
 */
function timezone_detect_uninstall() {
  variable_del('timezone_detect_update_timezone_every_login');
}