Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Authorize.net plugin, some fixes.

  • Loading branch information...
commit 425b7741772e9a9505db44837a4ef0f6bb9b8865 1 parent 5d319ac
ethem authored
2  enrol/authorize/ccval.php
... ... @@ -1,4 +1,4 @@
1   -<?php
  1 +<?php // $Id$
2 2 /************************************************************************
3 3 *
4 4 * CCVal - Credit Card Validation function.
225 enrol/authorize/config.html
... ... @@ -1,107 +1,118 @@
1   -<table cellspacing="0" cellpadding="5" border="0" align="center">
2   -
3   -<tr valign="top">
4   - <td align="right">enrol_cost:</td>
5   - <td>
6   - <input type="text" size="5" name="enrol_cost" value="<?php p($frm->enrol_cost) ?>" />
7   - </td>
8   - <td>
9   - <?php print_string("costdefault") ?>
10   - </td>
11   -</tr>
12   -
13   -<tr valign="top">
14   - <td align="right">enrol_currency:</td>
15   - <td>
16   - <?php choose_from_menu ($paypalcurrencies, "enrol_currency", $frm->enrol_currency, "","", "") ?>
17   - </td>
18   - <td>
19   - <?php print_string("currency") ?>
20   - </td>
21   -</tr>
22   -
23   -
24   -
25   -
26   -<tr valign="top">
27   - <td align="right">an_login:</td>
28   - <td>
29   - <input type="text" name="an_login" value="<?php echo $frm->an_login ?>" />
30   - </td>
31   - <td>
32   - <?php print_string("anlogin", "enrol_authorize") ?>
33   - </td>
34   -</tr>
35   -
36   -<tr valign="top">
37   - <td align="right">an_tran_key:</td>
38   - <td>
39   - <input type="text" name="an_tran_key" value="<?php echo $frm->an_tran_key ?>" />
40   - </td>
41   - <td>
42   - <?php print_string("antrankey", "enrol_authorize") ?>
43   - </td>
44   -</tr>
45   -
46   -<tr valign="top">
47   - <td align="right">an_password:</td>
48   - <td>
49   - <input type="text" name="an_password" value="<?php echo $frm->an_password ?>" />
50   - </td>
51   - <td>
52   - <?php print_string("anpassword", "enrol_authorize") ?>
53   - </td>
54   -</tr>
55   -
56   -<tr valign="top">
57   - <td align="right">an_test:</td>
58   - <td>
59   - <input type="checkbox" value=1 name="an_test" <?php if ($frm->an_test) echo "checked=\"true\"" ?> />
60   - </td>
61   - <td>
62   - <?php print_string("antestmode", "enrol_authorize") ?>
63   - </td>
64   -</tr>
65   -
66   -
67   -<tr valign="top">
68   - <td align="right">enrol_mailstudents:</td>
69   - <td>
70   - <input type="checkbox" value=1 name="enrol_mailstudents" <?php if ($frm->enrol_mailstudents) echo "checked=\"true\"" ?> />
71   - </td>
72   - <td>
73   - <?php print_string("mailstudents") ?>
74   - </td>
75   -</tr>
76   -
77   -<tr valign="top">
78   - <td align="right">enrol_mailteachers:</td>
79   - <td>
80   - <input type="checkbox" value=1 name="enrol_mailteachers" <?php if ($frm->enrol_mailteachers) echo "checked=\"true\"" ?> />
81   - </td>
82   - <td>
83   - <?php print_string("mailteachers") ?>
84   - </td>
85   -</tr>
86   -
87   -<tr valign="top">
88   - <td align="right">enrol_mailadmins:</td>
89   - <td>
90   - <input type="checkbox" value=1 name="enrol_mailadmins" <?php if ($frm->enrol_mailadmins) echo "checked=\"true\"" ?> />
91   - </td>
92   - <td>
93   - <?php print_string("mailadmins") ?>
94   - </td>
95   -</tr>
96   -
97   -<tr valign="top">
98   - <td align="right">enrol_allowinternal:</td>
99   - <td>
100   - <input type="checkbox" value="1" name="enrol_allowinternal" <?php if ($frm->enrol_allowinternal) echo "checked=\"true\"" ?> />
101   - </td>
102   - <td>
103   - <?php print_string('allowinternal') ?>
104   - </td>
105   -</tr>
106   -
107   -</table>
  1 +<table cellspacing="0" cellpadding="5" border="0" align="center">
  2 +
  3 +<tr valign="top">
  4 + <td align="right">enrol_cost:</td>
  5 + <td>
  6 + <input type="text" size="5" name="enrol_cost" value="<?php p($frm->enrol_cost) ?>" />
  7 + </td>
  8 + <td>
  9 + <?php print_string("costdefault") ?>
  10 + </td>
  11 +</tr>
  12 +
  13 +<tr valign="top">
  14 + <td align="right">enrol_currency:</td>
  15 + <td>
  16 + <?php choose_from_menu ($ancurrencies, "enrol_currency", $frm->enrol_currency, "","", "") ?>
  17 + </td>
  18 + <td>
  19 + <?php print_string("currency") ?>
  20 + </td>
  21 +</tr>
  22 +
  23 +
  24 +
  25 +
  26 +<tr valign="top">
  27 + <td align="right">an_login:</td>
  28 + <td>
  29 + <input type="text" name="an_login" value="<?php echo $frm->an_login ?>" />
  30 + </td>
  31 + <td>
  32 + <?php print_string("anlogin", "enrol_authorize") ?>
  33 + </td>
  34 +</tr>
  35 +
  36 +<tr valign="top">
  37 + <td align="right">an_tran_key:</td>
  38 + <td>
  39 + <input type="text" name="an_tran_key" value="<?php echo $frm->an_tran_key ?>" />
  40 + </td>
  41 + <td>
  42 + <?php print_string("antrankey", "enrol_authorize") ?>
  43 + </td>
  44 +</tr>
  45 +
  46 +<tr valign="top">
  47 + <td align="right">an_password:</td>
  48 + <td>
  49 + <input type="text" name="an_password" value="<?php echo $frm->an_password ?>" />
  50 + </td>
  51 + <td>
  52 + <?php print_string("anpassword", "enrol_authorize") ?>
  53 + </td>
  54 +</tr>
  55 +
  56 +<tr valign="top">
  57 + <td align="right">an_referer:</td>
  58 + <td>
  59 + <input type="text" name="an_referer" value="<?php echo $frm->an_referer ?>" />
  60 + </td>
  61 + <td>
  62 + <?php print_string("anreferer", "enrol_authorize") ?>
  63 + </td>
  64 +</tr>
  65 +
  66 +<tr valign="top">
  67 + <td align="right">an_test:</td>
  68 + <td>
  69 + <input type="checkbox" value=1 name="an_test" <?php if ($frm->an_test) echo "checked=\"true\"" ?> />
  70 + </td>
  71 + <td>
  72 + <?php print_string("antestmode", "enrol_authorize") ?>
  73 + </td>
  74 +</tr>
  75 +
  76 +<tr valign="top"><td colspan="3"><hr noshade size="1"></td></tr>
  77 +
  78 +<tr valign="top">
  79 + <td align="right">enrol_mailstudents:</td>
  80 + <td>
  81 + <input type="checkbox" value=1 name="enrol_mailstudents" <?php if ($frm->enrol_mailstudents) echo "checked=\"true\"" ?> />
  82 + </td>
  83 + <td>
  84 + <?php print_string("mailstudents") ?>
  85 + </td>
  86 +</tr>
  87 +
  88 +<tr valign="top">
  89 + <td align="right">enrol_mailteachers:</td>
  90 + <td>
  91 + <input type="checkbox" value=1 name="enrol_mailteachers" <?php if ($frm->enrol_mailteachers) echo "checked=\"true\"" ?> />
  92 + </td>
  93 + <td>
  94 + <?php print_string("mailteachers") ?>
  95 + </td>
  96 +</tr>
  97 +
  98 +<tr valign="top">
  99 + <td align="right">enrol_mailadmins:</td>
  100 + <td>
  101 + <input type="checkbox" value=1 name="enrol_mailadmins" <?php if ($frm->enrol_mailadmins) echo "checked=\"true\"" ?> />
  102 + </td>
  103 + <td>
  104 + <?php print_string("mailadmins") ?>
  105 + </td>
  106 +</tr>
  107 +
  108 +<tr valign="top">
  109 + <td align="right">enrol_allowinternal:</td>
  110 + <td>
  111 + <input type="checkbox" value="1" name="enrol_allowinternal" <?php if ($frm->enrol_allowinternal) echo "checked=\"true\"" ?> />
  112 + </td>
  113 + <td>
  114 + <?php print_string('allowinternal') ?>
  115 + </td>
  116 +</tr>
  117 +
  118 +</table>
95 enrol/authorize/enrol.html
... ... @@ -1,44 +1,51 @@
1   -<p align="center"><?php if (! empty($this->errormsg)) {formerr($this->errormsg);} ?></p>
2   -
3   -<div align="center">
4   -
5   -<p><?php print_string("paymentrequired") ?></p>
6   -<p><b><?php echo get_string("cost").": $CFG->enrol_currency $cost"; ?></b></p>
7   -<p><?php print_string("paymentinstant") ?></p>
8   -
9   -<form name="form" method="post" action="enrol.php" autocomplete="off">
10   -<input type="hidden" name="id" value="<?php p($course->id) ?>" />
11   -<table align="center" width="100%" border=0>
12   -<tr>
13   - <td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
14   - <td align="left"><input type="text" name="ccfirstname" size="16" value="<?php p($userfirstname) ?>" />
15   - <input type="text" name="cclastname" size="16" value="<?php p($userlastname) ?>" /></td>
16   -</tr>
17   -<tr>
18   - <td align="right"><?php print_string("ccno", "enrol_authorize") ?>: </td>
19   - <td align="left"><input type="text" name="cc" size="16" value="<?php p($form->cc) ?>" /></td>
20   -</tr>
21   -<tr>
22   - <td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
23   - <td align="left"><?php
24   - for ($i=1; $i<=12; $i++) {
25   - $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
26   - }
27   - choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm, '');
28   - ?> <input type="text" name="ccexpireyyyy" size="4" maxlength="4" value="<?php p($form->ccexpireyyyy) ?>" /></td>
29   -</tr>
30   -<tr>
31   - <td align="right"><?php print_string("ccvv", "enrol_authorize") ?>: </td>
32   - <td align="left"><input type="text" name="cvv" size="4" maxlength="4" value="<?php p($form->cvv) ?>" />
33   - <font size=1><?php print_string("ccvvhelp", "enrol_authorize") ?></font></td>
34   -</tr>
35   -<tr>
36   - <td align="right"><?php print_string("zipcode", "enrol_authorize") ?>: </td>
37   - <td align="left"><input type="text" name="cczip" size="5" value="<?php p($form->cczip) ?>" /></td>
38   -</tr>
39   -
40   -</table>
41   -<input type="submit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
42   -</form>
43   -
44   -</div>
  1 +<p align="center"><?php if (! empty($this->errormsg)) {formerr($this->errormsg);} ?></p>
  2 +
  3 +<div align="center">
  4 +
  5 +<p><?php print_string("paymentrequired") ?></p>
  6 +<p><b><?php echo get_string("cost").": $CFG->enrol_currency $cost"; ?></b></p>
  7 +<p><?php print_string("paymentinstant") ?></p>
  8 +
  9 +<form name="form" method="post" action="enrol.php" autocomplete="off">
  10 +<input type="hidden" name="id" value="<?php p($course->id) ?>" />
  11 +<table align="center" width="100%" border=0>
  12 +<tr>
  13 + <td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
  14 + <td align="left"><input type="text" name="ccfirstname" size="16" value="<?php p($userfirstname) ?>" />
  15 + <input type="text" name="cclastname" size="16" value="<?php p($userlastname) ?>" /></td>
  16 +</tr>
  17 +<tr>
  18 + <td align="right"><?php print_string("ccno", "enrol_authorize") ?>: </td>
  19 + <td align="left"><input type="text" name="cc" size="16" value="<?php p($form->cc) ?>" /></td>
  20 +</tr>
  21 +<tr>
  22 + <td align="right"><?php print_string("ccexpire", "enrol_authorize") ?>: </td>
  23 + <td align="left"><?php
  24 + for ($i=1; $i<=12; $i++) {
  25 + $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
  26 + }
  27 + choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm, '');
  28 + ?> <input type="text" name="ccexpireyyyy" size="4" maxlength="4" value="<?php p($form->ccexpireyyyy) ?>" /></td>
  29 +</tr>
  30 +<tr>
  31 + <td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
  32 + <td align="left"><?php
  33 + choose_from_menu($CCTYPES, 'cctype', $form->cctype);
  34 + ?>
  35 +</td>
  36 +</tr>
  37 +<tr>
  38 + <td align="right"><?php print_string("ccvv", "enrol_authorize") ?>: </td>
  39 + <td align="left"><input type="text" name="cvv" size="4" maxlength="4" value="<?php p($form->cvv) ?>" />
  40 + <font size=1><?php print_string("ccvvhelp", "enrol_authorize") ?></font></td>
  41 +</tr>
  42 +<tr>
  43 + <td align="right"><?php print_string("zipcode", "enrol_authorize") ?>: </td>
  44 + <td align="left"><input type="text" name="cczip" size="5" value="<?php p($form->cczip) ?>" /></td>
  45 +</tr>
  46 +
  47 +</table>
  48 +<input type="submit" value="<?php print_string("sendpaymentbutton", "enrol_authorize") ?>">
  49 +</form>
  50 +
  51 +</div>
469 enrol/authorize/enrol.php
@@ -42,15 +42,14 @@ function print_entry($course) {
42 42 print_course($course, "80%");
43 43 print_simple_box_start("center");
44 44
45   - //Sanitise some fields before building the CC form
46   - $coursefullname = $this->sanitise_for_cc($course->fullname);
47   - $courseshortname= $this->sanitise_for_cc($course->shortname);
48   - $userfirstname = $this->sanitise_for_cc($USER->firstname);
49   - $userlastname = $this->sanitise_for_cc($USER->lastname);
50   - $useraddress = $this->sanitise_for_cc($USER->address);
51   - $usercity = $this->sanitise_for_cc($USER->city);
  45 + $coursefullname = $course->fullname;
  46 + $courseshortname= $course->shortname;
  47 + $userfirstname = $USER->firstname;
  48 + $userlastname = $USER->lastname;
  49 + $useraddress = $USER->address;
  50 + $usercity = $USER->city;
52 51 $cost = $this->get_cource_cost($course);
53   -
  52 +
54 53 $CCTYPES = array(
55 54 'mcd' => 'Master Card',
56 55 'vis' => 'Visa',
@@ -147,7 +146,7 @@ function cc_submit($form, $course)
147 146 } else {
148 147 $formdata['x_password'] = (isset($CFG->an_password)) ? $CFG->an_password : '';
149 148 }
150   -
  149 +
151 150 //build the post string
152 151 $poststring = '';
153 152 foreach($formdata AS $key => $val) {
@@ -155,11 +154,8 @@ function cc_submit($form, $course)
155 154 }
156 155 // strip off trailing ampersand
157 156 $poststring = substr($poststring, 0, -1);
158   - $response = array();
159   - $fp = fsockopen("zip://" . "wwww." . AN_HOST , AN_PORT, $errno, $errstr, $timeout = 60);
160   -
161   - echo isset($fp); exit;
162   -
  157 +
  158 + $fp = fsockopen("ssl://" . AN_HOST, AN_PORT, $errno, $errstr, $timeout = 60);
163 159 if(!$fp) {
164 160 $this->errormsg = "$errstr ($errno)";
165 161 return;
@@ -168,12 +164,12 @@ function cc_submit($form, $course)
168 164 if (isset($CFG->an_referer) && (!empty($CFG->an_referer)) &&
169 165 ($CFG->an_referer != "http://") && ($CFG->an_referer != "https://")) {
170 166 $anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
171   - }
172   -
  167 + }
  168 +
173 169 //send the server request
174 170 fputs($fp,
175 171 "POST " . AN_PATH . " HTTP/1.1\r\n" .
176   - //"Host: " . AN_HOST . "\r\n" .
  172 + "Host: " . AN_HOST . "\r\n" .
177 173 $anrefererheader .
178 174 "Content-type: application/x-www-form-urlencoded\r\n" .
179 175 "Content-length: " . strlen($poststring) . "\r\n" .
@@ -201,297 +197,244 @@ function cc_submit($form, $course)
201 197 $response = explode("|", $data);
202 198 }
203 199
204   - if ($response[0] == AN_APPROVED) {
205   - $SESSION->ccpaid = 1; // security check: don't duplicate payment
206   -
207   - // XXX: Is this valid for paid cources?
208   - //if ($course->enrolperiod) {
209   - // $timestart = time();
210   - // $timeend = $timestart + $course->enrolperiod;
211   - //} else {
212   - // $timestart = $timeend = 0;
213   - //}
214   - // XXX: Is this valid for paid cources?
215   - // if (!enrol_student($USER->id, $course->id, $timestart, $timeend)) {
216   -
217   - if (!enrol_student($USER->id, $course->id)) {
218   - $this->email_cc_error_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $response);
219   - } else {
220   - // begin: send email
221   - $teacher = get_teacher($course->id);
222   - if (!empty($CFG->enrol_mailstudents)) {
223   - $a->coursename = "$course->fullname";
224   - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
225   - email_to_user($USER, $teacher, get_string("enrolmentnew", '', $course->shortname),
226   - get_string('welcometocoursetext', '', $a));
227   - }
228   -
229   - if (!empty($CFG->enrol_mailteachers)) {
230   - $a->course = "$course->fullname";
231   - $a->user = fullname($USER);
232   - email_to_user($teacher, $USER, get_string("enrolmentnew", '', $course->shortname),
233   - get_string('enrolmentnewuser', '', $a));
  200 + if ($response[0] != AN_APPROVED) {
  201 + $this->errormsg = isset($response[3]) ? $response[3] : 'unknown error';
  202 + } else {
  203 + $SESSION->ccpaid = 1; // security check: don't duplicate payment
  204 + if ($course->enrolperiod) {
  205 + $timestart = time();
  206 + $timeend = $timestart + $course->enrolperiod;
  207 + } else {
  208 + $timestart = $timeend = 0;
234 209 }
235   -
236   - if (!empty($CFG->enrol_mailadmins)) {
237   - $a->course = "$course->fullname";
238   - $a->user = fullname($USER);
239   - $admins = get_admins();
240   - foreach ($admins as $admin) {
241   - email_to_user($admin, $USER, get_string("enrolmentnew", '', $course->shortname),
  210 +
  211 + if (!enrol_student($USER->id, $course->id, $timestart, $timeend)) {
  212 + $this->email_cc_error_to_admin("Error while trying to enrol ".fullname($USER)." in '$course->fullname'", $response);
  213 + } else {
  214 + // begin: send email
  215 + $teacher = get_teacher($course->id);
  216 + if (!empty($CFG->enrol_mailstudents)) {
  217 + $a->coursename = "$course->fullname";
  218 + $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
  219 + email_to_user($USER, $teacher, get_string("enrolmentnew", '', $course->shortname),
  220 + get_string('welcometocoursetext', '', $a));
  221 + }
  222 +
  223 + if (!empty($CFG->enrol_mailteachers)) {
  224 + $a->course = "$course->fullname";
  225 + $a->user = fullname($USER);
  226 + email_to_user($teacher, $USER, get_string("enrolmentnew", '', $course->shortname),
242 227 get_string('enrolmentnewuser', '', $a));
243 228 }
244   - }
245   - // end: send email
246   - // begin: authorize_table
247   - $cclast4 = substr($form->cc, -4);
248   - $datax->cclastfour = ($cclast4 === false) ? '0000' : $cclast4;
249   - $datax->ccexp = $formdata['x_exp_date'];
250   - $datax->cvv = $form->cvv;
251   - $datax->ccname = $formdata['x_first_name'] . " " . $formdata['x_last_name'];
252   - $datax->courseid = $course->id;
253   - $datax->userid = $USER->id;
254   - $datax->avscode = strval($response[5]);
255   - $datax->transid = strval($response[6]);
256   -
257   - if (!insert_record("enrol_authorize", $datax)) { // Insert a transaction record
258   - $this->email_cc_error_to_admin("Error while trying to insert valid transaction", $datax);
259   - }
  229 +
  230 + if (!empty($CFG->enrol_mailadmins)) {
  231 + $a->course = "$course->fullname";
  232 + $a->user = fullname($USER);
  233 + $admins = get_admins();
  234 + foreach ($admins as $admin) {
  235 + email_to_user($admin, $USER, get_string("enrolmentnew", '', $course->shortname),
  236 + get_string('enrolmentnewuser', '', $a));
  237 + }
  238 + }
  239 + // end: send email
  240 +
  241 + // begin: authorize_table
  242 + $cclast4 = substr($form->cc, -4);
  243 + $datax->cclastfour = ($cclast4 === false) ? '0000' : $cclast4;
  244 + $datax->ccexp = $formdata['x_exp_date'];
  245 + $datax->cvv = $form->cvv;
  246 + $datax->ccname = $formdata['x_first_name'] . " " . $formdata['x_last_name'];
  247 + $datax->courseid = $course->id;
  248 + $datax->userid = $USER->id;
  249 + $datax->avscode = strval($response[5]);
  250 + $datax->transid = strval($response[6]);
  251 +
  252 + if (!insert_record("enrol_authorize", $datax)) { // Insert a transaction record
  253 + $this->email_cc_error_to_admin("Error while trying to insert valid transaction", $datax);
  254 + }
260 255
261   - } // end if (!enrol_student)
262   -
263   - if ($SESSION->wantsurl) {
264   - $destination = $SESSION->wantsurl;
265   - unset($SESSION->wantsurl);
266   - } else {
  256 + } // end if (!enrol_student)
  257 +
  258 + if ($SESSION->wantsurl) {
  259 + $destination = $SESSION->wantsurl;
  260 + unset($SESSION->wantsurl);
  261 + } else {
267 262 $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
268   - }
269   - //
270   - redirect($destination);
271   - } else {
272   - $this->errormsg = $response[3];
273   - }
  263 + }
  264 + redirect($destination);
  265 + }
274 266 }
275 267
276 268 function zero_cost($course) {
277 269
278 270 $cost = $this->get_cource_cost($course);
279   -
280   - if (abs($cost) < 0.01) { // no cost
281   - return true;
282   - }
283   -
284   - return false;
  271 + if (abs($cost) < 0.01) { // no cost
  272 + return true;
  273 + }
  274 + return false;
285 275 }
286 276
287 277 function get_cource_cost($course) {
288   - global $CFG;
289   - $cost = (float)0;
290   -
291   - if (isset($course->cost))
292   - {
293   - if (((float)$course->cost) < 0)
294   - {
295   - $cost = (float)$CFG->enrol_cost;
296   - }
297   - else
298   - {
299   - $cost = (float)$course->cost;
300   - }
301   - }
302   -
303   - $cost = format_float($cost, 2);
304   - return $cost;
  278 + global $CFG;
  279 + $cost = (float)0;
  280 +
  281 + if (isset($course->cost)) {
  282 + if (((float)$course->cost) < 0) {
  283 + $cost = (float)$CFG->enrol_cost;
  284 + } else {
  285 + $cost = (float)$course->cost;
  286 + }
  287 + }
  288 + $cost = format_float($cost, 2);
  289 + return $cost;
305 290 }
306 291
307   -
308 292 /// Override the get_access_icons() function
309 293 function get_access_icons($course) {
310   - global $CFG;
  294 + global $CFG;
311 295
312   - $str = '';
313   - $cost = $this->get_cource_cost($course);
  296 + $str = '';
  297 + $cost = $this->get_cource_cost($course);
314 298
315   - if (abs($cost) < 0.01) {
316   - $str = parent::get_access_icons($course);
317   - } else {
318   -
319   - $strrequirespayment = get_string("requirespayment");
320   - $strcost = get_string("cost");
  299 + if (abs($cost) < 0.01) {
  300 + $str = parent::get_access_icons($course);
  301 + } else {
  302 + $strrequirespayment = get_string("requirespayment");
  303 + $strcost = get_string("cost");
321 304
322   - if (empty($CFG->enrol_currency)) {
323   - set_config('enrol_currency', 'USD');
324   - }
  305 + if (empty($CFG->enrol_currency)) {
  306 + set_config('enrol_currency', 'USD');
  307 + }
325 308
326   - switch ($CFG->enrol_currency) {
327   - case 'EUR': $currency = '&euro;'; break;
328   - case 'CAD': $currency = '$'; break;
329   - case 'GBP': $currency = '&pound;'; break;
330   - case 'JPY': $currency = '&yen;'; break;
331   - default: $currency = '$'; break;
  309 + switch ($CFG->enrol_currency) {
  310 + case 'EUR': $currency = '&euro;'; break;
  311 + case 'CAD': $currency = '$'; break;
  312 + case 'GBP': $currency = '&pound;'; break;
  313 + case 'JPY': $currency = '&yen;'; break;
  314 + default: $currency = '$'; break;
332 315 }
333   -
334   - $str .= "<p class=\"coursecost\"><font size=-1>$strcost: ".
335   - "<a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\"></a>";
336   - $str .= "$currency".format_float($cost,2).'</a></p>';
337   -
338   - }
339   -
340   - return $str;
  316 +
  317 + $str .= "<p class=\"coursecost\"><font size=-1>$strcost: " .
  318 + "<a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\"></a>" .
  319 + "$currency" . format_float($cost, 2) . '</a></p>';
  320 + }
  321 + return $str;
341 322 }
342 323
343 324
344 325 function config_form($frm) {
345   - global $CFG;
346   -
347   - $ancurrencies = array( 'USD' => 'US Dollars',
348   - 'EUR' => 'Euros',
349   - 'JPY' => 'Japanese Yen',
350   - 'GBP' => 'British Pounds',
351   - 'CAD' => 'Canadian Dollars'
352   - );
353   -
354   - $vars = array('enrol_cost', 'enrol_currency', 'an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_test',
355   - 'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins', 'enrol_allowinternal');
356   - foreach ($vars as $var) {
357   - if (!isset($frm->$var)) {
358   - $frm->$var = '';
359   - }
360   - }
361   -
362   - $this->check_openssl_loaded(false);
363   - include("$CFG->dirroot/enrol/authorize/config.html");
  326 + global $CFG;
  327 + $ancurrencies = array(
  328 + 'USD' => 'US Dollars',
  329 + 'EUR' => 'Euros',
  330 + 'JPY' => 'Japanese Yen',
  331 + 'GBP' => 'British Pounds',
  332 + 'CAD' => 'Canadian Dollars'
  333 + );
  334 +
  335 + $vars = array('enrol_cost', 'enrol_currency', 'an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_test',
  336 + 'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins', 'enrol_allowinternal');
  337 + foreach ($vars as $var) {
  338 + if (!isset($frm->$var)) {
  339 + $frm->$var = '';
  340 + }
  341 + }
  342 +
  343 + $this->check_openssl_loaded(false);
  344 + include("$CFG->dirroot/enrol/authorize/config.html");
364 345 }
365 346
366 347 function check_openssl_loaded($die)
367 348 {
368 349 if (!extension_loaded('openssl')) {
369   - echo "<font color=red><center>PHP must be compiled --with-openssl</center></font>";
370   - if ($die)
371   - die;
372   - }
  350 + echo "<font color=red><center>PHP must be compiled --with-openssl</center></font>";
  351 + if ($die)
  352 + die;
  353 + }
373 354 }
374 355
375 356 function process_config($config) {
376 357
377 358 $this->check_openssl_loaded(true);
378   -
379   - if (!isset($config->an_login)) {
380   - $config->an_login = '';
381   - }
382   - set_config('an_login', $config->an_login);
383   -
384   - if (!isset($config->an_password)) {
385   - $config->an_password = '';
386   - }
387   - set_config('an_password', $config->an_password);
388   -
389   - if (!isset($config->an_tran_key)) {
390   - $config->an_tran_key = '';
391   - }
392   - set_config('an_tran_key', $config->an_tran_key);
393   -
394   - // Some required fields
395   - if (empty($config->an_login))
396   - {
397   - echo "an_login required";
398   - die;
399   - }
400   - if (empty($config->an_tran_key) && empty($config->an_password))
401   - {
402   - echo "an_tran_key or an_password required";
403   - die;
404   - }
405   -
406   - if (empty($config->an_referer)) {
407   - $config->an_referer = 'http://';
408   - }
409   - set_config('an_referer', $config->an_referer);
410   -
411   - if (!isset($config->an_test)) {
412   - $config->an_test = '';
413   - }
414   - set_config('an_test', $config->an_test);
415   -
416   - // ----
417   - if (!isset($config->enrol_cost)) {
418   - $config->enrol_cost = '0';
419   - }
420   - set_config('enrol_cost', $config->enrol_cost);
421   -
422   - if (!isset($config->enrol_currency)) {
423   - $config->enrol_currency = 'USD';
424   - }
425   - set_config('enrol_currency', $config->enrol_currency);
426   -
427   - if (!isset($config->enrol_mailstudents)) {
428   - $config->enrol_mailstudents = '';
429   - }
430   - set_config('enrol_mailstudents', $config->enrol_mailstudents);
431   -
432   - if (!isset($config->enrol_mailteachers)) {
433   - $config->enrol_mailteachers = '';
434   - }
435   - set_config('enrol_mailteachers', $config->enrol_mailteachers);
436   -
437   - if (!isset($config->enrol_mailadmins)) {
438   - $config->enrol_mailadmins = '';
439   - }
440   - set_config('enrol_mailadmins', $config->enrol_mailadmins);
441   -
442   - if (!isset($config->enrol_allowinternal)) {
443   - $config->enrol_allowinternal = '';
444   - }
445   - set_config('enrol_allowinternal', $config->enrol_allowinternal);
446   -
447   - return true;
448   -}
  359 + if (!isset($config->an_login)) {
  360 + $config->an_login = '';
  361 + }
  362 + set_config('an_login', $config->an_login);
449 363
450   -function email_cc_error_to_admin($subject, $data) {
451   - $admin = get_admin();
452   - $site = get_admin();
  364 + if (!isset($config->an_password)) {
  365 + $config->an_password = '';
  366 + }
  367 + set_config('an_password', $config->an_password);
453 368
454   - $message = "$site->fullname: Transaction failed.\n\n$subject\n\n";
  369 + if (!isset($config->an_tran_key)) {
  370 + $config->an_tran_key = '';
  371 + }
  372 + set_config('an_tran_key', $config->an_tran_key);
455 373
456   - foreach ($data as $key => $value) {
457   - $message .= "$key => $value\n";
458   - }
459   - email_to_user($admin, $admin, "CC ERROR: ".$subject, $message);
460   -}
  374 + // Some required fields
  375 + if (empty($config->an_login)) {
  376 + echo "an_login required";
  377 + die;
  378 + }
  379 + if (empty($config->an_tran_key) && empty($config->an_password)) {
  380 + echo "an_tran_key or an_password required";
  381 + die;
  382 + }
461 383
  384 + if (empty($config->an_referer)) {
  385 + $config->an_referer = 'http://';
  386 + }
  387 + set_config('an_referer', $config->an_referer);
462 388
463   -//To avoid wrong (for PayPal) characters in sent data
464   -function sanitise_for_cc($text) {
465   - global $CFG;
466   -
467   - if (!empty($CFG->sanitise_for_paypal)) {
468   - //Array of characters to replace (not allowed by PayPal)
469   - //Can be expanded as necessary to add other diacritics
470   - $replace = array('�' => 'a', //Spanish characters
471   - '�' => 'e',
472   - '�' => 'i',
473   - '�' => 'o',
474   - '�' => 'u',
475   - '�' => 'A',
476   - '�' => 'E',
477   - '�' => 'I',
478   - '�' => 'O',
479   - '�' => 'U',
480   - '�' => 'n',
481   - '�' => 'N',
482   - '�' => 'u',
483   - '�' => 'U');
484   - $text = strtr($text, $replace);
485   -
486   - //Make here other sanities if necessary
  389 + if (!isset($config->an_test)) {
  390 + $config->an_test = '';
  391 + }
  392 + set_config('an_test', $config->an_test);
  393 +
  394 + // --------------------------------------
  395 + if (!isset($config->enrol_cost)) {
  396 + $config->enrol_cost = '0';
  397 + }
  398 + set_config('enrol_cost', $config->enrol_cost);
487 399
488   - }
  400 + if (!isset($config->enrol_currency)) {
  401 + $config->enrol_currency = 'USD';
  402 + }
  403 + set_config('enrol_currency', $config->enrol_currency);
489 404
490   - return $text;
  405 + if (!isset($config->enrol_mailstudents)) {
  406 + $config->enrol_mailstudents = '';
  407 + }
  408 + set_config('enrol_mailstudents', $config->enrol_mailstudents);
  409 +
  410 + if (!isset($config->enrol_mailteachers)) {
  411 + $config->enrol_mailteachers = '';
  412 + }
  413 + set_config('enrol_mailteachers', $config->enrol_mailteachers);
491 414
  415 + if (!isset($config->enrol_mailadmins)) {
  416 + $config->enrol_mailadmins = '';
  417 + }
  418 + set_config('enrol_mailadmins', $config->enrol_mailadmins);
  419 +
  420 + if (!isset($config->enrol_allowinternal)) {
  421 + $config->enrol_allowinternal = '';
  422 + }
  423 + set_config('enrol_allowinternal', $config->enrol_allowinternal);
  424 +
  425 + return true;
492 426 }
493 427
  428 +function email_cc_error_to_admin($subject, $data) {
  429 + $admin = get_admin();
  430 + $site = get_admin();
494 431
495   -} // end of class definition
  432 + $message = "$site->fullname: Transaction failed.\n\n$subject\n\n";
  433 + foreach ($data as $key => $value) {
  434 + $message .= "$key => $value\n";
  435 + }
  436 + email_to_user($admin, $admin, "CC ERROR: ".$subject, $message);
  437 +}
496 438
497   -?>
  439 +} // end of class definition
  440 +?>

0 comments on commit 425b774

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