| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: enrol.php,v 1.28.2.3 2008/01/07 20:56:20 poltawski Exp $ 2 // Implements all the main code for the PayPal plugin 3 4 require_once("$CFG->dirroot/enrol/enrol.class.php"); 5 6 7 class enrolment_plugin_paypal { 8 9 10 /// Override the base print_entry() function 11 function print_entry($course) { 12 global $CFG, $USER; 13 14 15 $strloginto = get_string("loginto", "", $course->shortname); 16 $strcourses = get_string("courses"); 17 18 $teacher = get_teacher($course->id); 19 20 if ( (float) $course->cost < 0 ) { 21 $cost = (float) $CFG->enrol_cost; 22 } else { 23 $cost = (float) $course->cost; 24 } 25 26 if (abs($cost) < 0.01) { // no cost, default to base class entry to course 27 28 $manual = enrolment_factory::factory('manual'); 29 $manual->print_entry($course); 30 31 } else { 32 $navlinks = array(); 33 $navlinks[] = array('name' => $strcourses, 'link' => "$CFG->wwwroot/course", 'type' => 'misc'); 34 $navlinks[] = array('name' => $strloginto, 'link' => null, 'type' => 'misc'); 35 $navigation = build_navigation($navlinks); 36 37 print_header($strloginto, $course->fullname, $navigation); 38 print_course($course, "80%"); 39 40 if ($course->password) { // Presenting two options 41 print_heading(get_string('costorkey', 'enrol_paypal'), 'center'); 42 } 43 44 print_simple_box_start("center"); 45 46 if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role 47 if (empty($CFG->loginhttps)) { 48 $wwwroot = $CFG->wwwroot; 49 } else { 50 // This actually is not so secure ;-), 'cause we're 51 // in unencrypted connection... 52 $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); 53 } 54 echo '<div align="center"><p>'.get_string('paymentrequired').'</p>'; 55 echo '<p><b>'.get_string('cost').": $CFG->enrol_currency $cost".'</b></p>'; 56 echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>'; 57 echo '</div>'; 58 } else { 59 //Sanitise some fields before building the PayPal form 60 $coursefullname = $course->fullname; 61 $courseshortname = $course->shortname; 62 $userfullname = fullname($USER); 63 $userfirstname = $USER->firstname; 64 $userlastname = $USER->lastname; 65 $useraddress = $USER->address; 66 $usercity = $USER->city; 67 68 include($CFG->dirroot.'/enrol/paypal/enrol.html'); 69 } 70 71 print_simple_box_end(); 72 73 if ($course->password) { // Second option 74 $password = ''; 75 include($CFG->dirroot.'/enrol/manual/enrol.html'); 76 } 77 78 print_footer(); 79 80 } 81 } // end of function print_entry() 82 83 84 85 86 /// Override the get_access_icons() function 87 function get_access_icons($course) { 88 global $CFG; 89 90 $str = ''; 91 92 if ( (float) $course->cost < 0) { 93 $cost = (float) $CFG->enrol_cost; 94 } else { 95 $cost = (float) $course->cost; 96 } 97 98 if (abs($cost) < 0.01) { 99 $manual = enrolment_factory::factory('manual'); 100 $str = $manual->get_access_icons($course); 101 102 } else { 103 104 $strrequirespayment = get_string("requirespayment"); 105 $strcost = get_string("cost"); 106 107 if (empty($CFG->enrol_currency)) { 108 set_config('enrol_currency', 'USD'); 109 } 110 111 switch ($CFG->enrol_currency) { 112 case 'EUR': $currency = '€'; break; 113 case 'CAD': $currency = '$'; break; 114 case 'GBP': $currency = '£'; break; 115 case 'JPY': $currency = '¥'; break; 116 case 'AUD': $currency = '$'; break; 117 default: $currency = '$'; break; 118 } 119 120 $str .= '<div class="cost" title="'.$strrequirespayment.'">'.$strcost.': '; 121 $str .= $currency.format_float($cost,2).'</div>'; 122 123 } 124 125 return $str; 126 } 127 128 /// Override the base class config_form() function 129 function config_form($frm) { 130 global $CFG; 131 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' 138 ); 139 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 = ''; 145 } 146 } 147 148 include("$CFG->dirroot/enrol/paypal/config.html"); 149 } 150 151 function process_config($config) { 152 153 if (!isset($config->enrol_cost)) { 154 $config->enrol_cost = 0; 155 } 156 set_config('enrol_cost', $config->enrol_cost); 157 158 if (!isset($config->enrol_currency)) { 159 $config->enrol_currency = 'USD'; 160 } 161 set_config('enrol_currency', $config->enrol_currency); 162 163 if (!isset($config->enrol_paypalbusiness)) { 164 $config->enrol_paypalbusiness = ''; 165 } 166 $config->enrol_paypalbusiness = trim($config->enrol_paypalbusiness); // remove trailing spaces etc. 167 set_config('enrol_paypalbusiness', $config->enrol_paypalbusiness); 168 169 if (!isset($config->enrol_mailstudents)) { 170 $config->enrol_mailstudents = ''; 171 } 172 set_config('enrol_mailstudents', $config->enrol_mailstudents); 173 174 if (!isset($config->enrol_mailteachers)) { 175 $config->enrol_mailteachers = ''; 176 } 177 set_config('enrol_mailteachers', $config->enrol_mailteachers); 178 179 if (!isset($config->enrol_mailadmins)) { 180 $config->enrol_mailadmins = ''; 181 } 182 set_config('enrol_mailadmins', $config->enrol_mailadmins); 183 184 return true; 185 186 } 187 188 /** 189 * This function enables internal enrolment when PayPal is primary and course key is set at the same time. 190 * 191 * @param form the form data submitted, as an object 192 * @param course the current course, as an object 193 */ 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; 199 } 200 } 201 202 /** 203 * Provides method to print the enrolment key form code. This method is called 204 * from /enrol/manual/enrol.html if it's included 205 * @param object a valid course object 206 */ 207 function print_enrolmentkeyfrom($course) { 208 $manual = enrolment_factory::factory('manual'); 209 $manual->print_enrolmentkeyfrom($course); 210 } 211 212 213 } // end of class definition 214 215 ?>
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 |