You are here

function ad_notify_notifications_validate in Advertisement 5

Validate ad notifications before saving to database.

File

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

Code

function ad_notify_notifications_validate($form_id, $form_values) {
  $redirect = FALSE;
  if ($form_values['event'] == 'regular' && $form_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 (!$form_values['notid']) {
      if (db_result(db_query("SELECT notid FROM {ad_notify} WHERE oid = %d AND event = '%s' AND delay = %d", $form_values['oid'], $form_values['event'], $form_values['delay']))) {
        drupal_set_message(t('You have already scheduled that notification.'), 'error');
        $redirect = TRUE;
      }
    }
    else {
      if ($form_values['locked'] && !ad_adaccess($form_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_values['aid'] . '/adowners/' . $form_values['uid'] . '/notifications');
    }
    else {
      drupal_goto('node/' . $form_values['aid'] . '/notifications');
    }
  }
}