]> git.mjollnir.org Git - moodle.git/commitdiff
+ fsockopen to file_get_contents
authorethem <ethem>
Fri, 18 Jan 2008 10:43:21 +0000 (10:43 +0000)
committerethem <ethem>
Fri, 18 Jan 2008 10:43:21 +0000 (10:43 +0000)
+ no more student

enrol/authorize/authorizenetlib.php
enrol/authorize/enrol.php
enrol/authorize/localfuncs.php

index 71fdcdc234d5b355c5efd60b6561f9e691a5f9c5..987a324fc707ee76951b0bb4d51cc4ed0b532cba 100644 (file)
@@ -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";
index d558376ec1916e571bfa7a27f2a1d4a8b50608e9..82f288a42a1a7b1064ee0c2774b53952369011b9 100755 (executable)
@@ -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;
         }
 
index 24d80b98af219925b8b62a3b29107d8926424cf9..9b63f1f4ebfc6c14a60b3afe7464c3b4debd70ac 100644 (file)
@@ -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);
+    }
 }
 
 ?>