Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move card validation to validate_enrol_form function.

  • Loading branch information...
commit c5c56ae00d5e13801f36042acd516da11a4f6f8d 1 parent cc56643
ethem authored
Showing with 22 additions and 20 deletions.
  1. +22 −20 enrol/authorize/enrol.php
View
42 enrol/authorize/enrol.php
@@ -101,7 +101,6 @@ function check_entry($form, $course) {
function cc_submit($form, $course)
{
global $CFG, $USER, $SESSION;
- require_once $CFG->dirroot.'/enrol/authorize/ccval.php';
require_once $CFG->dirroot.'/enrol/authorize/action.php';
if (!$this->validate_enrol_form($form)) {
@@ -110,21 +109,9 @@ function cc_submit($form, $course)
$this->prevent_double_paid($course);
- $exp_date = ($form->ccexpiremm < 10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm);
- $exp_date .= $form->ccexpireyyyy;
- $valid_cc = CCVal($form->cc, $form->cctype, $exp_date);
+ $useripno = getremoteaddr();
$curcost = $this->get_course_cost($course);
- $useripno = getremoteaddr(); // HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR
-
- if (!$valid_cc) {
- if ($valid_cc === 0) {
- $this->ccerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize');
- }
- else {
- $this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize');
- }
- return;
- }
+ $exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy;
// NEW ORDER
$timenow = time();
@@ -286,12 +273,24 @@ function cc_submit($form, $course)
function validate_enrol_form($form)
{
global $CFG;
+ require_once $CFG->dirroot.'/enrol/authorize/ccval.php';
- $return = true;
+ $ccexpiremm = intval($form->ccexpiremm);
+ $ccexpireyyyy = intval($form->ccexpireyyyy);
- if (empty($form->ccexpiremm) || empty($form->ccexpireyyyy)) {
+ if (empty($ccexpiremm) || empty($ccexpireyyyy)) {
$this->ccerrors['ccexpire'] = get_string('missingccexpire', 'enrol_authorize');
}
+ $expdate = sprintf("%02d", $ccexpiremm) . strval($ccexpireyyyy);
+ $validcc = CCVal($form->cc, $form->cctype, $expdate);
+ if (!$validcc) {
+ if ($validcc === 0) {
+ $this->ccerrors['ccexpire'] = get_string('ccexpired', 'enrol_authorize');
+ }
+ else {
+ $this->ccerrors['cc'] = get_string('ccinvalid', 'enrol_authorize');
+ }
+ }
if (empty($form->ccfirstname) || empty($form->cclastname)) {
$this->ccerrors['ccfirstlast'] = get_string('missingfullname');
}
@@ -318,12 +317,13 @@ function validate_enrol_form($form)
if (empty($form->cczip) || !is_numeric($form->cczip)) {
$this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize');
}
+
if (!empty($this->ccerrors)) {
$this->ccerrors['header'] = get_string('someerrorswerefound');
- $return = false;
+ return false;
}
- return $return;
+ return true;
}
/**
@@ -533,7 +533,9 @@ function prevent_double_paid($course)
{
global $CFG, $SESSION, $USER;
- if ($rec=get_record('enrol_authorize','userid',$USER->id,'courseid',$course->id,'status',AN_STATUS_AUTH,'id')) {
+ $status = empty($CFG->an_test) ? AN_STATUS_AUTH : AN_STATUS_NONE;
+
+ if ($rec=get_record('enrol_authorize','userid',$USER->id,'courseid',$course->id,'status',$status,'id')) {
$a->orderid = $rec->id;
redirect($CFG->wwwroot, get_string("paymentpending", "enrol_authorize", $a), '20');
return;
Please sign in to comment.
Something went wrong with that request. Please try again.