From: ethem Date: Fri, 18 Jan 2008 10:43:21 +0000 (+0000) Subject: + fsockopen to file_get_contents X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3309cb829f68033a70779f66b6a4a617dec87e6b;p=moodle.git + fsockopen to file_get_contents + no more student --- diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index 71fdcdc234..987a324fc7 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.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"; diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index d558376ec1..82f288a42a 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -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; } diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php index 24d80b98af..9b63f1f4eb 100644 --- a/enrol/authorize/localfuncs.php +++ b/enrol/authorize/localfuncs.php @@ -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); + } } ?>