3 function get_course_cost($course)
8 $currency = (!empty($course->currency
))
9 ?
$course->currency
:( empty($CFG->enrol_currency
)
10 ?
'USD' : $CFG->enrol_currency
);
12 if (!empty($course->cost
)) {
13 $cost = (float)(((float)$course->cost
) < 0) ?
$CFG->enrol_cost
: $course->cost
;
16 $cost = format_float($cost, 2);
19 'currency' => $currency
25 function zero_cost($course) {
26 $curcost = get_course_cost($course);
27 return (abs($curcost['cost']) < 0.01);
30 function prevent_double_paid($course)
32 global $CFG, $SESSION, $USER;
34 $sql = "SELECT id FROM {$CFG->prefix}enrol_authorize WHERE userid = '$USER->id' AND courseid = '$course->id' ";
36 if (empty($CFG->an_test
)) { // Real mode
37 $sql .= 'AND status IN('.AN_STATUS_AUTH
.','.AN_STATUS_UNDERREVIEW
.','.AN_STATUS_APPROVEDREVIEW
.')';
40 $sql .= 'AND status='.AN_STATUS_NONE
;
43 if (($recid = get_field_sql($sql))) {
46 $a->url
= "$CFG->wwwroot/enrol/authorize/index.php?order=$a->orderid";
47 redirect($a->url
, get_string("paymentpending", "enrol_authorize", $a), '10');
50 if (isset($SESSION->ccpaid
)) {
51 unset($SESSION->ccpaid
);
52 redirect($CFG->wwwroot
. '/login/logout.php?sesskey='.sesskey());
57 function get_list_of_creditcards($getall = false)
62 'mcd' => 'Master Card',
64 'amx' => 'American Express',
66 'dnc' => 'Diners Club',
73 if ($getall or empty($CFG->an_acceptccs
)) {
78 $ccs = explode(',', $CFG->an_acceptccs
);
79 foreach ($ccs as $key) {
80 $ret[$key] = $alltypes[$key];
85 function get_list_of_payment_methods($getall = false)
89 if ($getall ||
empty($CFG->an_acceptmethods
)) {
90 return array(AN_METHOD_CC
, AN_METHOD_ECHECK
);
93 return explode(',', $CFG->an_acceptmethods
);
97 function get_list_of_bank_account_types($getall = false)
101 if ($getall ||
empty($CFG->an_acceptechecktypes
)) {
102 return array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS');
105 return explode(',', $CFG->an_acceptechecktypes
);
109 function email_to_admin($subject, $data)
113 $admin = get_admin();
114 $data = (array)$data;
116 $message = "$SITE->fullname: Transaction failed.\n\n$subject\n\n";
117 $message .= print_r($data, true);
118 email_to_user($admin, $admin, "$SITE->fullname: Authorize.net ERROR", $message);
121 function send_welcome_messages($orderdata)
125 if (empty($orderdata)) {
129 if (is_numeric($orderdata)) {
130 $orderdata = array($orderdata);
133 $sql = "SELECT e.id, e.courseid, e.userid, c.fullname
134 FROM {$CFG->prefix}enrol_authorize e
135 INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid
136 WHERE e.id IN(" . implode(',', $orderdata) . ")
139 if (($rs = get_recordset_sql($sql)) && ($ei = rs_fetch_next_record($rs)))
141 if (1 < count($orderdata)) {
142 $sender = get_admin();
145 $context = get_context_instance(CONTEXT_COURSE
, $ei->courseid
);
146 $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
147 $sender = array_shift($paymentmanagers);
152 $usercourses = array();
153 $lastuserid = $ei->userid
;
155 while ($ei && $ei->userid
== $lastuserid) {
156 $usercourses[] = $ei->fullname
;
157 $ei = rs_fetch_next_record($rs);
160 if (($user = get_record('user', 'id', $lastuserid))) {
162 $a->name
= $user->firstname
;
163 $a->courses
= implode("\n", $usercourses);
164 $a->profileurl
= "$CFG->wwwroot/user/view.php?id=$lastuserid";
165 $a->paymenturl
= "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
166 $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
167 @email_to_user
($user, $sender, get_string("enrolmentnew", '', $SITE->shortname
), $emailmessage);
176 function check_openssl_loaded()
178 return extension_loaded('openssl');