You are here

function ad_report_admin_validate in Advertisement 6.3

Same name and namespace in other branches
  1. 5.2 report/ad_report.module \ad_report_admin_validate()
  2. 6.2 report/ad_report.module \ad_report_admin_validate()
  3. 7 report/ad_report.module \ad_report_admin_validate()

Sanity check the date range.

File

report/ad_report.module, line 176
Provides comprehensive charts and reports about advertising statistics.

Code

function ad_report_admin_validate($form, $form_state) {
  if ($form_state['clicked_button']['#value'] == t('Reset report')) {
    unset($_SESSION['ad_report_start']);
    unset($_SESSION['ad_report_end']);
    unset($_SESSION['ad_report_group']);
  }
  else {
    $start = isset($form_state['values']['start']) ? strtotime($form_state['values']['start']) : 0;
    $end = isset($form_state['values']['start']) ? strtotime($form_state['values']['end']) : 0;
    if (!$start) {
      form_set_error('start', t('You must enter a valid start date.'));
    }
    else {
      if ($start >= time() - 3600) {
        form_set_error('start', t('The report must start at least one hour before the current time.'));
      }
      else {
        if ($start >= $end) {
          form_set_error('start', t('The report must start before it ends.'));
        }
      }
    }
    if (!$end) {
      form_set_error('end', t('You must enter a valid end date.'));
    }
  }
}