Permalink
Browse files

+ fsockopen to file_get_contents

+ no more student
  • Loading branch information...
1 parent 3980c30 commit 3309cb829f68033a70779f66b6a4a617dec87e6b ethem committed Jan 18, 2008
Showing with 33 additions and 51 deletions.
  1. +13 −30 enrol/authorize/authorizenetlib.php
  2. +2 −8 enrol/authorize/enrol.php
  3. +18 −13 enrol/authorize/localfuncs.php
@@ -243,46 +243,29 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
}
}
- $referer = '';
+ $header = 'Connection: close' . "\r\n" .
+ 'Content-type: application/x-www-form-urlencoded' . "\r\n" .
+ 'Content-length: ' . strlen($poststring);
+
if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
- $referer = "Referer: $CFG->an_referer\r\n";
+ $header .= "\r\n" . 'Referer: ' . $CFG->an_referer;
}
- $errno = 0; $errstr = '';
- $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
- $fp = fsockopen("ssl://$host", 443, $errno, $errstr, 60);
- if (!$fp) {
- $message = "no connection: $errstr ($errno)";
- return AN_RETURNZERO;
- }
+ $contextopts = array('http' => array('method' => 'POST',
+ 'header' => $header,
+ 'content' => $poststring));
- // critical section
+ $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
+ $context = stream_context_create($contextopts);
@ignore_user_abort(true);
if (intval(ini_get('max_execution_time')) > 0) {
@set_time_limit(300);
}
-
- fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" .
- "Host: $host\r\n" . $referer .
- "Content-type: application/x-www-form-urlencoded\r\n" .
- "Connection: close\r\n" .
- "Content-length: " . strlen($poststring) . "\r\n\r\n" .
- $poststring . "\r\n"
- );
-
- $tmpstr = '';
- while(!feof($fp) && !stristr($tmpstr, 'content-length')) {
- $tmpstr = fgets($fp, 4096);
- }
- if (!stristr($tmpstr, 'content-length')) {
- $message = "content-length error";
- @fclose($fp);
+ $data = file_get_contents("https://$host:443/gateway/transact.dll", false, $context);
+ if (!$data) {
+ $message = "no connection to https://$host:443/gateway/transact.dll";
return AN_RETURNZERO;
}
- $length = trim(substr($tmpstr, strpos($tmpstr,'content-length')+15));
- fgets($fp, 4096);
- $data = fgets($fp, $length);
- @fclose($fp);
$response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
if ($response === false) {
$message = "response error";
View
@@ -436,14 +436,8 @@ public function config_form($frm)
return; // notice breaks the form and xhtml later
}
- if (optional_param('verifyaccount', 0, PARAM_INT))
- {
- $message = '';
- if (AN_APPROVED == authorize_verify_account($message)) {
- notify(get_string('verifyaccountresult', 'enrol_authorize', get_string('success')));
- } else {
- notify(get_string('verifyaccountresult', 'enrol_authorize', $message));
- }
+ if (optional_param('verifyaccount', 0, PARAM_INT)) {
+ notify(authorize_verify_account());
return;
}
@@ -148,21 +148,22 @@ function send_welcome_messages($orderdata)
$sender = get_admin();
}
- $ei = reset($emailinfo);
- while ($ei !== false) {
+ for($ei = reset($emailinfo); $ei !== false; ) {
$usercourses = array();
$lastuserid = $ei->userid;
- for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
+ for($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
$usercourses[] = $current->fullname;
}
$ei = $current;
- $a = new stdClass;
- $a->courses = implode("\n", $usercourses);
- $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
- $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
- $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
- $user = get_record('user', 'id', $lastuserid);
- @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
+ if ($user = get_record('user', 'id', $lastuserid)) {
+ $a = new stdClass;
+ $a->name = $user->firstname;
+ $a->courses = implode("\n", $usercourses);
+ $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
+ $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
+ $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
+ @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
+ }
}
}
@@ -173,7 +174,7 @@ function check_openssl_loaded()
}
-function authorize_verify_account(&$message)
+function authorize_verify_account()
{
global $CFG, $USER, $SITE;
require_once('authorizenetlib.php');
@@ -207,8 +208,12 @@ function authorize_verify_account(&$message)
$extra->x_invoice_num = $order->id;
$extra->x_description = 'Verify Account';
- $message = '';
- return authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis');
+ if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis')) {
+ return get_string('verifyaccountresult', 'enrol_authorize', get_string('success'));
+ }
+ else {
+ return get_string('verifyaccountresult', 'enrol_authorize', $message);
+ }
}
?>

0 comments on commit 3309cb8

Please sign in to comment.