Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

+ fsockopen to file_get_contents

+ no more student
  • Loading branch information...
commit 3309cb829f68033a70779f66b6a4a617dec87e6b 1 parent 3980c30
ethem authored
43 enrol/authorize/authorizenetlib.php
@@ -243,46 +243,29 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $
243 243 }
244 244 }
245 245
246   - $referer = '';
  246 + $header = 'Connection: close' . "\r\n" .
  247 + 'Content-type: application/x-www-form-urlencoded' . "\r\n" .
  248 + 'Content-length: ' . strlen($poststring);
  249 +
247 250 if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
248   - $referer = "Referer: $CFG->an_referer\r\n";
  251 + $header .= "\r\n" . 'Referer: ' . $CFG->an_referer;
249 252 }
250 253
251   - $errno = 0; $errstr = '';
252   - $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
253   - $fp = fsockopen("ssl://$host", 443, $errno, $errstr, 60);
254   - if (!$fp) {
255   - $message = "no connection: $errstr ($errno)";
256   - return AN_RETURNZERO;
257   - }
  254 + $contextopts = array('http' => array('method' => 'POST',
  255 + 'header' => $header,
  256 + 'content' => $poststring));
258 257
259   - // critical section
  258 + $host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
  259 + $context = stream_context_create($contextopts);
260 260 @ignore_user_abort(true);
261 261 if (intval(ini_get('max_execution_time')) > 0) {
262 262 @set_time_limit(300);
263 263 }
264   -
265   - fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" .
266   - "Host: $host\r\n" . $referer .
267   - "Content-type: application/x-www-form-urlencoded\r\n" .
268   - "Connection: close\r\n" .
269   - "Content-length: " . strlen($poststring) . "\r\n\r\n" .
270   - $poststring . "\r\n"
271   - );
272   -
273   - $tmpstr = '';
274   - while(!feof($fp) && !stristr($tmpstr, 'content-length')) {
275   - $tmpstr = fgets($fp, 4096);
276   - }
277   - if (!stristr($tmpstr, 'content-length')) {
278   - $message = "content-length error";
279   - @fclose($fp);
  264 + $data = file_get_contents("https://$host:443/gateway/transact.dll", false, $context);
  265 + if (!$data) {
  266 + $message = "no connection to https://$host:443/gateway/transact.dll";
280 267 return AN_RETURNZERO;
281 268 }
282   - $length = trim(substr($tmpstr, strpos($tmpstr,'content-length')+15));
283   - fgets($fp, 4096);
284   - $data = fgets($fp, $length);
285   - @fclose($fp);
286 269 $response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
287 270 if ($response === false) {
288 271 $message = "response error";
10 enrol/authorize/enrol.php
@@ -436,14 +436,8 @@ public function config_form($frm)
436 436 return; // notice breaks the form and xhtml later
437 437 }
438 438
439   - if (optional_param('verifyaccount', 0, PARAM_INT))
440   - {
441   - $message = '';
442   - if (AN_APPROVED == authorize_verify_account($message)) {
443   - notify(get_string('verifyaccountresult', 'enrol_authorize', get_string('success')));
444   - } else {
445   - notify(get_string('verifyaccountresult', 'enrol_authorize', $message));
446   - }
  439 + if (optional_param('verifyaccount', 0, PARAM_INT)) {
  440 + notify(authorize_verify_account());
447 441 return;
448 442 }
449 443
31 enrol/authorize/localfuncs.php
@@ -148,21 +148,22 @@ function send_welcome_messages($orderdata)
148 148 $sender = get_admin();
149 149 }
150 150
151   - $ei = reset($emailinfo);
152   - while ($ei !== false) {
  151 + for($ei = reset($emailinfo); $ei !== false; ) {
153 152 $usercourses = array();
154 153 $lastuserid = $ei->userid;
155   - for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
  154 + for($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
156 155 $usercourses[] = $current->fullname;
157 156 }
158 157 $ei = $current;
159   - $a = new stdClass;
160   - $a->courses = implode("\n", $usercourses);
161   - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
162   - $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
163   - $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
164   - $user = get_record('user', 'id', $lastuserid);
165   - @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
  158 + if ($user = get_record('user', 'id', $lastuserid)) {
  159 + $a = new stdClass;
  160 + $a->name = $user->firstname;
  161 + $a->courses = implode("\n", $usercourses);
  162 + $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
  163 + $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
  164 + $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
  165 + @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage);
  166 + }
166 167 }
167 168 }
168 169
@@ -173,7 +174,7 @@ function check_openssl_loaded()
173 174 }
174 175
175 176
176   -function authorize_verify_account(&$message)
  177 +function authorize_verify_account()
177 178 {
178 179 global $CFG, $USER, $SITE;
179 180 require_once('authorizenetlib.php');
@@ -207,8 +208,12 @@ function authorize_verify_account(&$message)
207 208 $extra->x_invoice_num = $order->id;
208 209 $extra->x_description = 'Verify Account';
209 210
210   - $message = '';
211   - return authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis');
  211 + if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis')) {
  212 + return get_string('verifyaccountresult', 'enrol_authorize', get_string('success'));
  213 + }
  214 + else {
  215 + return get_string('verifyaccountresult', 'enrol_authorize', $message);
  216 + }
212 217 }
213 218
214 219 ?>

0 comments on commit 3309cb8

Please sign in to comment.
Something went wrong with that request. Please try again.