| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: localfuncs.php,v 1.10.2.2 2008/03/21 12:08:28 ethem Exp $ 2 3 function get_course_cost($course) 4 { 5 global $CFG; 6 7 $cost = (float)0; 8 $currency = (!empty($course->currency)) 9 ? $course->currency :( empty($CFG->enrol_currency) 10 ? 'USD' : $CFG->enrol_currency ); 11 12 if (!empty($course->cost)) { 13 $cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost; 14 } 15 16 $cost = format_float($cost, 2); 17 $ret = array( 18 'cost' => $cost, 19 'currency' => $currency 20 ); 21 22 return $ret; 23 } 24 25 function zero_cost($course) { 26 $curcost = get_course_cost($course); 27 return (abs($curcost['cost']) < 0.01); 28 } 29 30 function prevent_double_paid($course) 31 { 32 global $CFG, $SESSION, $USER; 33 34 $sql = "SELECT id FROM {$CFG->prefix}enrol_authorize WHERE userid = '$USER->id' AND courseid = '$course->id' "; 35 36 if (empty($CFG->an_test)) { // Real mode 37 $sql .= 'AND status IN('.AN_STATUS_AUTH.','.AN_STATUS_UNDERREVIEW.','.AN_STATUS_APPROVEDREVIEW.')'; 38 } 39 else { // Test mode 40 $sql .= 'AND status='.AN_STATUS_NONE; 41 } 42 43 if (($recid = get_field_sql($sql))) { 44 $a = new stdClass; 45 $a->orderid = $recid; 46 $a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$a->orderid"; 47 redirect($a->url, get_string("paymentpending", "enrol_authorize", $a), '10'); 48 return; 49 } 50 if (isset($SESSION->ccpaid)) { 51 unset($SESSION->ccpaid); 52 redirect($CFG->wwwroot . '/login/logout.php?sesskey='.sesskey()); 53 return; 54 } 55 } 56 57 function get_list_of_creditcards($getall = false) 58 { 59 global $CFG; 60 61 $alltypes = array( 62 'mcd' => 'Master Card', 63 'vis' => 'Visa', 64 'amx' => 'American Express', 65 'dsc' => 'Discover', 66 'dnc' => 'Diners Club', 67 'jcb' => 'JCB', 68 'swi' => 'Switch', 69 'dlt' => 'Delta', 70 'enr' => 'EnRoute' 71 ); 72 73 if ($getall or empty($CFG->an_acceptccs)) { 74 return $alltypes; 75 } 76 77 $ret = array(); 78 $ccs = explode(',', $CFG->an_acceptccs); 79 foreach ($ccs as $key) { 80 $ret[$key] = $alltypes[$key]; 81 } 82 return $ret; 83 } 84 85 function get_list_of_payment_methods($getall = false) 86 { 87 global $CFG; 88 89 if ($getall || empty($CFG->an_acceptmethods)) { 90 return array(AN_METHOD_CC, AN_METHOD_ECHECK); 91 } 92 else { 93 return explode(',', $CFG->an_acceptmethods); 94 } 95 } 96 97 function get_list_of_bank_account_types($getall = false) 98 { 99 global $CFG; 100 101 if ($getall || empty($CFG->an_acceptechecktypes)) { 102 return array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS'); 103 } 104 else { 105 return explode(',', $CFG->an_acceptechecktypes); 106 } 107 } 108 109 function email_to_admin($subject, $data) 110 { 111 global $SITE; 112 113 $admin = get_admin(); 114 $data = (array)$data; 115 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); 119 } 120 121 function send_welcome_messages($orderdata) 122 { 123 global $CFG, $SITE; 124 125 if (empty($orderdata)) { 126 return; 127 } 128 129 if (is_numeric($orderdata)) { 130 $orderdata = array($orderdata); 131 } 132 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) . ") 137 ORDER BY e.userid"; 138 139 if (($rs = get_recordset_sql($sql)) && ($ei = rs_fetch_next_record($rs))) 140 { 141 if (1 < count($orderdata)) { 142 $sender = get_admin(); 143 } 144 else { 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); 148 } 149 150 do 151 { 152 $usercourses = array(); 153 $lastuserid = $ei->userid; 154 155 while ($ei && $ei->userid == $lastuserid) { 156 $usercourses[] = $ei->fullname; 157 $ei = rs_fetch_next_record($rs); 158 } 159 160 if (($user = get_record('user', 'id', $lastuserid))) { 161 $a = new stdClass; 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); 168 } 169 } 170 while ($ei); 171 172 rs_close($rs); 173 } 174 } 175 176 function check_openssl_loaded() 177 { 178 return extension_loaded('openssl'); 179 } 180 181 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |