Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / enrol / paypal / enrol.php
blobe571851a1ddc418d337d9672a3c58addc0d839a2
1 <?php // $Id$
2 // Implements all the main code for the PayPal plugin
4 require_once("$CFG->dirroot/enrol/enrol.class.php");
7 class enrolment_plugin_paypal {
10 /// Override the base print_entry() function
11 function print_entry($course) {
12 global $CFG, $USER;
15 $strloginto = get_string("loginto", "", $course->shortname);
16 $strcourses = get_string("courses");
18 $teacher = get_teacher($course->id);
20 if ( (float) $course->cost < 0 ) {
21 $cost = (float) $CFG->enrol_cost;
22 } else {
23 $cost = (float) $course->cost;
25 $cost = format_float($cost, 2);
28 if (abs($cost) < 0.01) { // no cost, default to base class entry to course
30 $manual = enrolment_factory::factory('manual');
31 $manual->print_entry($course);
33 } else {
35 print_header($strloginto, $course->fullname,
36 "<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
37 print_course($course, "80%");
39 if ($course->password) { // Presenting two options
40 print_heading(get_string('costorkey', 'enrol_paypal'), 'center');
43 print_simple_box_start("center");
45 if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role
46 if (empty($CFG->loginhttps)) {
47 $wwwroot = $CFG->wwwroot;
48 } else {
49 // This actually is not so secure ;-), 'cause we're
50 // in unencrypted connection...
51 $wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
53 echo '<div align="center"><p>'.get_string('paymentrequired').'</p>';
54 echo '<p><b>'.get_string('cost').": $CFG->enrol_currency $cost".'</b></p>';
55 echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>';
56 echo '</div>';
57 } else {
58 //Sanitise some fields before building the PayPal form
59 $coursefullname = $course->fullname;
60 $courseshortname = $course->shortname;
61 $userfullname = fullname($USER);
62 $userfirstname = $USER->firstname;
63 $userlastname = $USER->lastname;
64 $useraddress = $USER->address;
65 $usercity = $USER->city;
67 include($CFG->dirroot.'/enrol/paypal/enrol.html');
70 print_simple_box_end();
72 if ($course->password) { // Second option
73 $password = '';
74 include($CFG->dirroot.'/enrol/manual/enrol.html');
77 print_footer();
80 } // end of function print_entry()
85 /// Override the get_access_icons() function
86 function get_access_icons($course) {
87 global $CFG;
89 $str = '';
91 if ( (float) $course->cost < 0) {
92 $cost = (float) $CFG->enrol_cost;
93 } else {
94 $cost = (float) $course->cost;
97 if (abs($cost) < 0.01) {
98 $manual = enrolment_factory::factory('manual');
99 $str = $manual->get_access_icons($course);
101 } else {
103 $strrequirespayment = get_string("requirespayment");
104 $strcost = get_string("cost");
106 if (empty($CFG->enrol_currency)) {
107 set_config('enrol_currency', 'USD');
110 switch ($CFG->enrol_currency) {
111 case 'EUR': $currency = '&euro;'; break;
112 case 'CAD': $currency = '$'; break;
113 case 'GBP': $currency = '&pound;'; break;
114 case 'JPY': $currency = '&yen;'; break;
115 case 'AUD': $currency = '$'; break;
116 default: $currency = '$'; break;
119 $str .= '<div class="cost" title="'.$strrequirespayment.'">'.$strcost.': ';
120 $str .= $currency.format_float($cost,2).'</div>';
124 return $str;
128 /// Override the base class config_form() function
129 function config_form($frm) {
130 global $CFG;
132 $paypalcurrencies = array( 'USD' => 'US Dollars',
133 'EUR' => 'Euros',
134 'JPY' => 'Japanese Yen',
135 'GBP' => 'British Pounds',
136 'CAD' => 'Canadian Dollars',
137 'AUD' => 'Australian Dollars'
140 $vars = array('enrol_cost', 'enrol_currency', 'enrol_paypalbusiness',
141 'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins');
142 foreach ($vars as $var) {
143 if (!isset($frm->$var)) {
144 $frm->$var = '';
148 include("$CFG->dirroot/enrol/paypal/config.html");
151 function process_config($config) {
153 if (!isset($config->enrol_cost)) {
154 $config->enrol_cost = 0;
156 set_config('enrol_cost', $config->enrol_cost);
158 if (!isset($config->enrol_currency)) {
159 $config->enrol_currency = 'USD';
161 set_config('enrol_currency', $config->enrol_currency);
163 if (!isset($config->enrol_paypalbusiness)) {
164 $config->enrol_paypalbusiness = '';
166 $config->enrol_paypalbusiness = trim($config->enrol_paypalbusiness); // remove trailing spaces etc.
167 set_config('enrol_paypalbusiness', $config->enrol_paypalbusiness);
169 if (!isset($config->enrol_mailstudents)) {
170 $config->enrol_mailstudents = '';
172 set_config('enrol_mailstudents', $config->enrol_mailstudents);
174 if (!isset($config->enrol_mailteachers)) {
175 $config->enrol_mailteachers = '';
177 set_config('enrol_mailteachers', $config->enrol_mailteachers);
179 if (!isset($config->enrol_mailadmins)) {
180 $config->enrol_mailadmins = '';
182 set_config('enrol_mailadmins', $config->enrol_mailadmins);
184 return true;
189 * This function enables internal enrolment when PayPal is primary and course key is set at the same time.
191 * @param form the form data submitted, as an object
192 * @param course the current course, as an object
194 function check_entry($form, $course) {
195 $manual = enrolment_factory::factory('manual');
196 $manual->check_entry($form, $course);
197 if (isset($manual->errormsg)) {
198 $this->errormsg = $manual->errormsg;
202 } // end of class definition