You are here

function yr_verdata_add_location in Yr Weatherdata 6

Function for adding locations.

Return value

Returns a form array, to be processed by drupal_get_form().

1 string reference to 'yr_verdata_add_location'
yr_verdata_menu in ./yr_verdata.module
Implementation of hook_menu().

File

./yr_verdata.module, line 535
yr_verdata.module This file provides the yr_verdata forecast module.

Code

function yr_verdata_add_location() {
  $form = array();
  $form['add_new'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add new location'),
    '#collapsible' => TRUE,
  );
  $form['add_new']['language'] = array(
    '#type' => 'select',
    '#title' => t('Language'),
    '#options' => array(
      'place' => t('English'),
      'sted' => t('Norwegian Bokmål'),
      'stad' => t('Norwegian Nynorsk'),
    ),
    '#default_value' => variable_get('yr_verdata_lang', 'place'),
    '#description' => t('Select the language you want this forecast delivered in.'),
    '#required' => TRUE,
  );
  $form['add_new']['country'] = array(
    '#type' => 'textfield',
    '#title' => t('Country'),
    '#description' => t('The first part of the url at <a href="!yrl">yr.no</a> (after <em>http://yr.no/place/</em>). For example: http://yr.no/place/<strong>Norway</strong>/Vest-Agder/Kristiansand/Hamresanden.', array(
      '!yrl' => 'http://yr.no',
    )),
    '#required' => TRUE,
  );
  $form['add_new']['region'] = array(
    '#type' => 'textfield',
    '#title' => t('Region'),
    '#description' => t('The second part of the url at <a href="!yrl">yr.no</a> (after <em>http://yr.no/place/</em>). For example: http://yr.no/place/Norway/<strong>Vest-Agder</strong>/Kristiansand/Hamresanden.', array(
      '!yrl' => 'http://yr.no',
    )),
    '#required' => TRUE,
  );
  $form['add_new']['subregion'] = array(
    '#type' => 'textfield',
    '#title' => t('Subregion/City'),
    '#description' => t('The third part of the url at <a href="!yrl">yr.no</a> (after <em>http://yr.no/place/</em>). For example: http://yr.no/place/Norway/Vest-Agder/<strong>Kristiansand</strong>/Hamresanden.', array(
      '!yrl' => 'http://yr.no',
    )),
    '#required' => TRUE,
  );
  $form['add_new']['location'] = array(
    '#type' => 'textfield',
    '#title' => t('Location'),
    '#description' => t('The fourth part of the url at <a href="!yrl">yr.no</a> (after <em>http://yr.no/place/</em>). For example: http://yr.no/place/Norway/Vest-Agder/Kristiansand/<strong>Hamresanden</strong>.<br />Note that some locations do not have this part of the url and for those, this part is not required.', array(
      '!yrl' => 'http://yr.no',
    )),
  );
  $form['add_new']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save location'),
  );

  // Get all existing locations for display in a table.
  $order = variable_get('yr_verdata_order', 'subregion');
  $result = db_query("SELECT * FROM {yr_verdata} ORDER BY '%s', 'location' ASC", $order);
  $rows = array();
  while ($row = db_fetch_array($result)) {
    $tmp = explode('/', $row['url']);
    $row['title'] = $tmp[3];
    $row['title'] .= isset($tmp[4]) ? ' - ' . $tmp[4] : '';
    $row['title'] .= ', ' . $tmp[2] . ', ' . $tmp[1];
    $row['title'] = str_replace('_', ' ', $row['title']);
    $rows[] = array(
      $row['yid'],
      l($row['title'], 'yr_verdata/' . $row['yid']),
      l('X', 'admin/content/yr_verdata/delete/' . $row['yid']),
    );
  }
  if (count($rows) == 0) {
    $rows = array(
      'data' => array(
        t('No locations are stored in the database.'),
        array(
          'colspan' => 3,
        ),
      ),
    );
  }
  $headers = array(
    t('YID'),
    t('Location'),
    t('Delete'),
  );
  $form['existing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Existing locations'),
    '#collapsible' => TRUE,
  );
  $form['existing']['table'] = array(
    '#type' => 'item',
    '#value' => theme('table', $headers, $rows),
  );
  return $form;
}