You are here

function weather_custom_block in Weather 5

Same name and namespace in other branches
  1. 5.6 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 376
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');
  $places_url .= base_path() . drupal_get_path('module', 'weather');

  // 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, $places_url);

  // Add another location
  if ($uid == 0) {
    $url = 'admin/settings/weather/' . _weather_get_free_config($uid);
  }
  else {
    $url = 'user/' . $uid . '/weather/' . _weather_get_free_config($uid);
  }
  $output .= '<p>';
  $output .= l(t('Add another location to the block'), $url);
  $output .= '</p>';
  if (count($config_in_use)) {
    $output .= '<p>';
    $output .= t('Current locations in the block:');
    $output .= '</p>';
    $output .= '<ul>';
    foreach ($config_in_use as $index) {

      // do not add a link to the current configuration
      $output .= '<li>';
      if ($index['cid'] == $cid) {
        $output .= check_plain($index['real_name']);
      }
      else {
        if ($uid == 0) {
          $url = 'admin/settings/weather/' . $index['cid'];
        }
        else {
          $url = 'user/' . $uid . '/weather/' . $index['cid'];
        }
        $output .= l($index['real_name'], $url);
      }
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}