You are here

function uc_file_user_form_validate in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_file/uc_file.module \uc_file_user_form_validate()

Validation handler for per-user file download administration.

File

uc_file/uc_file.module, line 273

Code

function uc_file_user_form_validate($form, &$form_state) {
  $edit = $form_state['values'];

  // Determine if any downloads were modified.
  if (isset($edit['file_download'])) {
    foreach ((array) $edit['file_download'] as $key => $download_modification) {

      // We don't care... it's about to be deleted.
      if ($download_modification['remove']) {
        continue;
      }
      if ($download_modification['download_limit'] < 0) {
        form_set_error('file_download][' . $key . '][download_limit', t('A negative download limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
      }
      if ($download_modification['address_limit'] < 0) {
        form_set_error('file_download][' . $key . '][address_limit', t('A negative address limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
      }

      // Some expirations don't need any validation...
      if ($download_modification['time_granularity'] == 'never' || !$download_modification['time_quantity']) {
        continue;
      }

      // Either use the current expiration, or if there's none,
      // start from right now.
      $new_expiration = _uc_file_expiration_date($download_modification, $download_modification['expiration']);
      if ($new_expiration <= time()) {
        form_set_error('file_download][' . $key . '][time_quantity', t('The date %date has already occurred.', array(
          '%date' => format_date($new_expiration, 'small'),
        )));
      }
      if ($download_modification['time_quantity'] < 0) {
        form_set_error('file_download][' . $key . '][time_quantity', t('A negative expiration quantity does not make sense. Use the polarity control to determine if the time should be added or subtracted.'));
      }
    }
  }
}