You are here

function analytics_dashboard_form in Google Chart Tools 7

Provide a simple form to change time periods

1 string reference to 'analytics_dashboard_form'
analytics_dashboard_page in analytics_dashboard/analytics_dashboard.module
Page callback for report page.

File

analytics_dashboard/analytics_dashboard.forms.inc, line 10
Provides the filtering form on the analytics dashboard page.

Code

function analytics_dashboard_form() {
  $form = array();

  // Load some javascript for datepicker
  drupal_add_library('system', 'ui.datepicker');
  drupal_add_js('jQuery(document).ready(function(){jQuery( ".pickadate" ).datepicker({
      dateFormat: "dd.mm.yy",
      autoSize: true
    });});', 'inline');
  $period_options = array(
    '1_week' => t('1 week'),
    '2_weeks' => t('2 weeks'),
    '1_month' => t('1 month'),
    '3_months' => t('3 months'),
    '6_months' => t('6 months'),
    '1_year' => t('1 year'),
    '2_years' => t('2 years'),
  );
  $period = isset($_GET['period']) ? filter_xss($_GET['period']) : NULL;
  if (!$period || !array_key_exists($period, $period_options)) {
    $period = '1_month';

    // Default value
  }
  $form['option'] = array(
    '#type' => 'radios',
    '#options' => array(
      'period' => '',
      'custom' => '',
    ),
    '#default_value' => isset($_GET['option']) ? filter_xss($_GET['option']) : 'period',
  );
  $form['period'] = array(
    '#type' => 'select',
    '#options' => $period_options,
    '#default_value' => $period,
  );
  $form['custom_from'] = array(
    '#type' => 'textfield',
    '#size' => 10,
    '#attributes' => array(
      'class' => array(
        'pickadate',
      ),
    ),
    '#default_value' => isset($_GET['from']) ? filter_xss($_GET['from']) : '',
  );
  $form['custom_to'] = array(
    '#type' => 'textfield',
    '#size' => 10,
    '#attributes' => array(
      'class' => array(
        'pickadate',
      ),
    ),
    '#default_value' => isset($_GET['to']) ? filter_xss($_GET['to']) : '',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  return $form;
}