You are here

function ad_notify_overview_form_validate in Advertisement 6

Validate ad notifications before saving to database.

File

notify/ad_notify.module, line 458
Receive email notifications regarding ads.

Code

function ad_notify_overview_form_validate($form, &$form_state) {
  $redirect = FALSE;
  if ($form_state['values']['event'] == 'regular' && $form_state['values']['delay'] < 3600) {
    drupal_set_message(t('You are not allowed to schedule a regular notification more frequently than once an hour.'), 'error');
    $redirect = TRUE;
  }
  else {
    if (!isset($form_state['values']['notid'])) {
      if (db_result(db_query("SELECT notid FROM {ad_notify} WHERE oid = %d AND event = '%s' AND delay = %d", $form_state['values']['oid'], $form_state['values']['event'], $form_state['values']['delay']))) {
        drupal_set_message(t('You have already scheduled that notification.'), 'error');
        $redirect = TRUE;
      }
    }
    else {
      if ($form_state['values']['locked'] && !ad_adaccess($form_state['values']['aid'], 'manage owners')) {
        $redirect = TRUE;
        drupal_set_message(t('This notification is locked, you will need to contact the site administrator to edit this notification for you.'), 'error');
      }
    }
  }
  if ($redirect) {
    if (arg(2) == 'adowners' && arg(4) == 'notifications') {
      drupal_goto('node/' . $form_state['values']['aid'] . '/adowners/' . $form_state['values']['uid'] . '/notifications');
    }
    else {
      drupal_goto('node/' . $form_state['values']['aid'] . '/notifications');
    }
  }
}