You are here

function uc_credit_settings_form_validate in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_credit/uc_credit.module \uc_credit_settings_form_validate()
  2. 7.3 payment/uc_credit/uc_credit.admin.inc \uc_credit_settings_form_validate()

File

payment/uc_credit/uc_credit.module, line 858
Defines the credit card payment method and hooks in payment gateways.

Code

function uc_credit_settings_form_validate($form_id, $form_values) {
  $dir = variable_get('uc_credit_encryption_path', t('Not configured, see below.'));
  $filename = rtrim($dir, '/\\') . '/uc_credit.key';
  if ($form_values['uc_credit_encryption_path'] !== variable_get('uc_credit_encryption_path', t('Not configured, see below.')) || !file_exists($filename)) {
    $dir = rtrim($form_values['uc_credit_encryption_path'], '/\\');
    $_SESSION['update_cc_encrypt_dir'] = TRUE;
    if (!empty($dir) && $dir !== t('Not configured, see below.')) {
      if (!is_dir($dir)) {
        form_set_error('uc_credit_encryption_path', t('You have specified a non-existent directory.'));
        unset($_SESSION['update_cc_encrypt_dir']);
      }
      else {
        $file = fopen($dir . '/encrypt.test', 'w');
        if ($file === FALSE) {
          form_set_error('uc_credit_encryption_path', t('Cannot write to directory, please verify the directory permissions.'));
          unset($_SESSION['update_cc_encrypt_dir']);
        }
        else {
          if (fwrite($file, '0123456789') === FALSE) {
            form_set_error('uc_credit_encryption_path', t('Cannot write to directory, please verify the directory permissions.'));
            unset($_SESSION['update_cc_encrypt_dir']);
            fclose($file);
          }
          else {
            fclose($file);
            $file = fopen($dir . '/encrypt.test', 'r');
            if ($file === FALSE) {
              form_set_error('uc_credit_encryption_path', t('Cannot read from directory, please verify the directory permissions.'));
              unset($_SESSION['update_cc_encrypt_dir']);
            }
            fclose($file);
          }
          unlink($dir . '/encrypt.test');
        }
      }
    }
  }
}