mirror of
https://github.com/moodle/moodle.git
synced 2025-02-09 01:21:57 +01:00
190 lines
5.2 KiB
PHP
190 lines
5.2 KiB
PHP
<?php // $Id$
|
||
// Implements all the main code for the Paypal plugin
|
||
|
||
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
||
|
||
|
||
class enrolment_plugin extends enrolment_base {
|
||
|
||
|
||
/// Override the base print_entry() function
|
||
function print_entry($course) {
|
||
global $CFG, $USER;
|
||
|
||
|
||
$strloginto = get_string("loginto", "", $course->shortname);
|
||
$strcourses = get_string("courses");
|
||
|
||
|
||
$teacher = get_teacher($course->id);
|
||
|
||
|
||
if ( (float) $course->cost < 0 ) {
|
||
$cost = (float) $CFG->enrol_cost;
|
||
} else {
|
||
$cost = (float) $course->cost;
|
||
}
|
||
$cost = format_float($cost, 2);
|
||
|
||
|
||
if (abs($cost) < 0.01) { // no cost, default to base class entry to course
|
||
|
||
|
||
parent::print_entry($course);
|
||
|
||
} else {
|
||
|
||
print_header($strloginto, $course->fullname,
|
||
"<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
|
||
print_course($course, "80%");
|
||
print_simple_box_start("center");
|
||
|
||
//Sanitise some fields before building the PayPal form
|
||
$coursefullname = $this->sanitise_for_paypal($course->fullname);
|
||
$courseshortname = $this->sanitise_for_paypal($course->shortname);
|
||
$userfullname = $this->sanitise_for_paypal(fullname($USER));
|
||
$userfirstname = $this->sanitise_for_paypal($USER->firstname);
|
||
$userlastname = $this->sanitise_for_paypal($USER->lastname);
|
||
$useraddress = $this->sanitise_for_paypal($USER->address);
|
||
$usercity = $this->sanitise_for_paypal($USER->city);
|
||
|
||
include("$CFG->dirroot/enrol/paypal/enrol.html");
|
||
|
||
print_simple_box_end();
|
||
print_footer();
|
||
|
||
}
|
||
} // end of function print_entry()
|
||
|
||
|
||
|
||
|
||
/// Override the get_access_icons() function
|
||
function get_access_icons($course) {
|
||
global $CFG;
|
||
|
||
$str = '';
|
||
|
||
if ( (float) $course->cost < 0) {
|
||
$cost = (float) $CFG->enrol_cost;
|
||
} else {
|
||
$cost = (float) $course->cost;
|
||
}
|
||
|
||
if (abs($cost) < 0.01) {
|
||
$str = parent::get_access_icons($course);
|
||
|
||
} else {
|
||
|
||
$strrequirespayment = get_string("requirespayment");
|
||
$strcost = get_string("cost");
|
||
|
||
if (empty($CFG->enrol_currency)) {
|
||
set_config('enrol_currency', 'USD');
|
||
}
|
||
|
||
switch ($CFG->enrol_currency) {
|
||
case 'EUR': $currency = '€'; break;
|
||
case 'CAD': $currency = '$'; break;
|
||
case 'GBP': $currency = '£'; break;
|
||
case 'JPY': $currency = '¥'; break;
|
||
case 'AUD': $currency = '$'; break;
|
||
default: $currency = '$'; break;
|
||
}
|
||
|
||
$str .= '<span class="courseboxcost" title="'.$strrequirespayment.'">'.$strcost.': ';
|
||
$str .= $currency.format_float($cost,2).'</span>';
|
||
|
||
}
|
||
|
||
return $str;
|
||
}
|
||
|
||
|
||
/// Override the base class config_form() function
|
||
function config_form($frm) {
|
||
global $CFG;
|
||
|
||
$paypalcurrencies = array( 'USD' => 'US Dollars',
|
||
'EUR' => 'Euros',
|
||
'JPY' => 'Japanese Yen',
|
||
'GBP' => 'British Pounds',
|
||
'CAD' => 'Canadian Dollars',
|
||
'AUD' => 'Australian Dollars'
|
||
);
|
||
|
||
include("$CFG->dirroot/enrol/paypal/config.html");
|
||
}
|
||
|
||
function process_config($config) {
|
||
|
||
if (!isset($config->enrol_cost)) {
|
||
$config->enrol_cost = 0;
|
||
}
|
||
set_config('enrol_cost', $config->enrol_cost);
|
||
|
||
if (!isset($config->enrol_currency)) {
|
||
$config->enrol_currency = 'USD';
|
||
}
|
||
set_config('enrol_currency', $config->enrol_currency);
|
||
|
||
if (!isset($config->enrol_paypalbusiness)) {
|
||
$config->enrol_paypalbusiness = '';
|
||
}
|
||
set_config('enrol_paypalbusiness', $config->enrol_paypalbusiness);
|
||
|
||
if (!isset($config->enrol_mailstudents)) {
|
||
$config->enrol_mailstudents = '';
|
||
}
|
||
set_config('enrol_mailstudents', $config->enrol_mailstudents);
|
||
|
||
if (!isset($config->enrol_mailteachers)) {
|
||
$config->enrol_mailteachers = '';
|
||
}
|
||
set_config('enrol_mailteachers', $config->enrol_mailteachers);
|
||
|
||
if (!isset($config->enrol_mailadmins)) {
|
||
$config->enrol_mailadmins = '';
|
||
}
|
||
set_config('enrol_mailadmins', $config->enrol_mailadmins);
|
||
|
||
return true;
|
||
|
||
}
|
||
|
||
//To avoid wrong (for PayPal) characters in sent data
|
||
function sanitise_for_paypal($text) {
|
||
global $CFG;
|
||
|
||
if (!empty($CFG->sanitise_for_paypal)) {
|
||
//Array of characters to replace (not allowed by PayPal)
|
||
//Can be expanded as necessary to add other diacritics
|
||
$replace = array('<27>' => 'a', //Spanish characters
|
||
'<27>' => 'e',
|
||
'<27>' => 'i',
|
||
'<27>' => 'o',
|
||
'<27>' => 'u',
|
||
'<27>' => 'A',
|
||
'<27>' => 'E',
|
||
'<27>' => 'I',
|
||
'<27>' => 'O',
|
||
'<27>' => 'U',
|
||
'<27>' => 'n',
|
||
'<27>' => 'N',
|
||
'<27>' => 'u',
|
||
'<27>' => 'U');
|
||
$text = strtr($text, $replace);
|
||
|
||
//Make here other sanities if necessary
|
||
|
||
}
|
||
|
||
return $text;
|
||
|
||
}
|
||
|
||
|
||
} // end of class definition
|
||
|
||
?>
|