You are here

function weather_custom_block in Weather 5.6

Same name and namespace in other branches
  1. 5 weather.module \weather_custom_block()
  2. 6.5 weather.module \weather_custom_block()

Show a configuration page for a custom weather block

1 string reference to 'weather_custom_block'
weather_menu in ./weather.module
Implementation of hook_menu().

File

./weather.module, line 571
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function weather_custom_block($uid, $cid = 0) {

  // Include the ICAO codes
  require_once drupal_get_path('module', 'weather') . '/icao_codes.inc';

  // Include a nice Javascript which makes the settings easier
  drupal_add_js(drupal_get_path('module', 'weather') . '/helper.js');

  // if there's no configuration id provided, we get the first in use or 1
  if ($cid == 0) {
    $cid = _weather_get_first_valid_config($uid);
  }

  // if the provided config id is not currently used, we want the lowest
  // free configuration id. This avoid cases like 56271 for config ids
  $config_in_use = _weather_get_configs_in_use($uid);
  $cid_found = FALSE;
  foreach ($config_in_use as $index) {
    if ($index['cid'] == $cid) {
      $cid_found = TRUE;
      break;
    }
  }
  if (!$cid_found) {
    $cid = _weather_get_free_config($uid);
  }

  // get the previously determined configuration
  $config = _weather_get_config($uid, $cid);
  $config['country'] = _weather_get_country_from_icao($config['icao']);
  $config['countries'] = _weather_get_countries();
  $config['places'] = _weather_get_places($config['country']);
  $output = drupal_get_form('weather_custom_block_form', $uid, $cid, $config);
  return $output;
}