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);
122 function send_welcome_messages($orderdata)
126 if (empty($orderdata)) {
130 if (is_numeric($orderdata)) {
131 $orderdata = array($orderdata);
134 $select = "SELECT e.id, e.courseid, e.userid, c.fullname
135 FROM {$CFG->prefix}enrol_authorize e
136 INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid
137 WHERE e.id IN(" . implode(',', $orderdata) . ")
140 $emailinfo = get_records_sql($select);
141 if (1 == count($emailinfo)) {
142 $ei = reset($emailinfo);
143 $context = get_context_instance(CONTEXT_COURSE
, $ei->courseid
);
144 $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
145 $sender = array_shift($paymentmanagers);
148 $sender = get_admin();
151 $ei = reset($emailinfo);
152 while ($ei !== false) {
153 $usercourses = array();
154 $lastuserid = $ei->userid
;
155 for ($current = $ei; $current !== false && $current->userid
== $lastuserid; $current = next($emailinfo)) {
156 $usercourses[] = $current->fullname
;
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);
170 function check_openssl_loaded()
172 return extension_loaded('openssl');