Skip to content

Commit

Permalink
Move card validation to validate_enrol_form function.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethem committed Jan 27, 2006
1 parent cc56643 commit c5c56ae
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions enrol/authorize/enrol.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function check_entry($form, $course) {
function cc_submit($form, $course) function cc_submit($form, $course)
{ {
global $CFG, $USER, $SESSION; global $CFG, $USER, $SESSION;
require_once $CFG->dirroot.'/enrol/authorize/ccval.php';
require_once $CFG->dirroot.'/enrol/authorize/action.php'; require_once $CFG->dirroot.'/enrol/authorize/action.php';


if (!$this->validate_enrol_form($form)) { if (!$this->validate_enrol_form($form)) {
Expand All @@ -110,21 +109,9 @@ function cc_submit($form, $course)


$this->prevent_double_paid($course); $this->prevent_double_paid($course);


$exp_date = ($form->ccexpiremm < 10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm); $useripno = getremoteaddr();
$exp_date .= $form->ccexpireyyyy;
$valid_cc = CCVal($form->cc, $form->cctype, $exp_date);
$curcost = $this->get_course_cost($course); $curcost = $this->get_course_cost($course);
$useripno = getremoteaddr(); // HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR $exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy;

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;
}


// NEW ORDER // NEW ORDER
$timenow = time(); $timenow = time();
Expand Down Expand Up @@ -286,12 +273,24 @@ function cc_submit($form, $course)
function validate_enrol_form($form) function validate_enrol_form($form)
{ {
global $CFG; 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'); $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)) { if (empty($form->ccfirstname) || empty($form->cclastname)) {
$this->ccerrors['ccfirstlast'] = get_string('missingfullname'); $this->ccerrors['ccfirstlast'] = get_string('missingfullname');
} }
Expand All @@ -318,12 +317,13 @@ function validate_enrol_form($form)
if (empty($form->cczip) || !is_numeric($form->cczip)) { if (empty($form->cczip) || !is_numeric($form->cczip)) {
$this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize'); $this->ccerrors['cczip'] = get_string('missingzip', 'enrol_authorize');
} }

if (!empty($this->ccerrors)) { if (!empty($this->ccerrors)) {
$this->ccerrors['header'] = get_string('someerrorswerefound'); $this->ccerrors['header'] = get_string('someerrorswerefound');
$return = false; return false;
} }


return $return; return true;
} }


/** /**
Expand Down Expand Up @@ -533,7 +533,9 @@ function prevent_double_paid($course)
{ {
global $CFG, $SESSION, $USER; 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; $a->orderid = $rec->id;
redirect($CFG->wwwroot, get_string("paymentpending", "enrol_authorize", $a), '20'); redirect($CFG->wwwroot, get_string("paymentpending", "enrol_authorize", $a), '20');
return; return;
Expand Down

0 comments on commit c5c56ae

Please sign in to comment.