+ fsockopen to file_get_contents

+ no more student
This commit is contained in:
ethem 2008-01-18 10:43:21 +00:00
parent 3980c306b1
commit 3309cb829f
3 changed files with 33 additions and 51 deletions

@ -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 = '';
$contextopts = array('http' => array('method' => 'POST',
'header' => $header,
'content' => $poststring));
$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;
}
// critical section
$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";

@ -436,14 +436,8 @@ class enrolment_plugin_authorize
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);
}
}
?>