Permalink
Browse files

International payment. All currencies are added...

  • Loading branch information...
ethem
ethem committed Jul 14, 2005
1 parent 145ec44 commit 10da752643f0e2aef1f9368302da0586c7857729
Showing with 217 additions and 43 deletions.
  1. +3 −1 enrol/authorize/config.html
  2. +187 −2 enrol/authorize/db/mysql.php
  3. +1 −1 enrol/authorize/enrol.html
  4. +25 −38 enrol/authorize/enrol.php
  5. +1 −1 enrol/authorize/version.php
@@ -13,7 +13,9 @@
<tr valign="top">
<td align="right">enrol_currency:</td>
<td>
- <?php choose_from_menu ($ancurrencies, "enrol_currency", $frm->enrol_currency, "","", "") ?>
+ <?php
+ $currenciesarray = get_records_menu("currencies", "", "", "name", "code,name");
+ choose_from_menu ($currenciesarray, "enrol_currency", $frm->enrol_currency, "","", "") ?>
</td>
<td>
<?php print_string("currency") ?>
@@ -10,10 +10,195 @@ function authorize_upgrade($oldversion=0) {
if ($oldversion == 0) {
modify_database("$CFG->dirroot/enrol/authorize/db/mysql.sql");
+ }
+
+ if ($oldversion < 2005071400) {
+ execute_sql("CREATE TABLE `{$CFG->prefix}currencies` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `code` char(3) NOT NULL default '',
+ `name` varchar(64) NOT NULL default '',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `code` (`code`)
+ ) TYPE=MyISAM
+ COMMENT='Currencies codes and names';");
+ insert_currencies();
+
+ $curcode = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
+ $objcur = get_record("currencies", "code", $curcode);
+ table_column('course', '', 'currency', 'integer', '10', 'unsigned', $objcur->id, 'not null', 'cost');
}
return $result;
-}
-
+}
+
+function insert_currencies() {
+
+ global $CFG;
+
+ $currencies = array(
+ 'AFA' => 'Afghanistan Afghani',
+ 'ALL' => 'Albanian Lek',
+ 'DZD' => 'Algerian Dinar',
+ 'ADP' => 'Andorran Peseta',
+ 'AOK' => 'Angolan Kwanza',
+ 'ARA' => 'Argentinian Austral',
+ 'AWG' => 'Aruban Florin',
+ 'AUD' => 'Australian Dollar',
+ 'ATS' => 'Austrian Schilling',
+ 'BSD' => 'Bahamian Dollar',
+ 'BHD' => 'Bahraini Dinar',
+ 'BDT' => 'Bangladeshi Taka',
+ 'BBD' => 'Barbados Dollar',
+ 'BEF' => 'Belgian Franc',
+ 'BZD' => 'Belize Dollar',
+ 'BMD' => 'Bermudian Dollar',
+ 'BTN' => 'Bhutan Ngultrum',
+ 'BOB' => 'Bolivian Boliviano',
+ 'BWP' => 'Botswanian Pula',
+ 'BRC' => 'Brazilian Cruzeiro',
+ 'GBP' => 'British Pound',
+ 'BND' => 'Brunei Dollar',
+ 'BGL' => 'Bulgarian Lev',
+ 'BUK' => 'Burma Kyat',
+ 'BIF' => 'Burundi Franc',
+ 'CAD' => 'Canadian Dollar',
+ 'CVE' => 'Cape Verde Escudo',
+ 'KYD' => 'Cayman Islands Dollar',
+ 'CLP' => 'Chilean Peso',
+ 'CLF' => 'Chilean Unidades de Fomento',
+ 'COP' => 'Colombian Peso',
+ 'KMF' => 'Comoros Franc',
+ 'CRC' => 'Costa Rican Colon',
+ 'CUP' => 'Cuban Peso',
+ 'CYP' => 'Cyprus Pound',
+ 'CSK' => 'Czech Koruna',
+ 'DKK' => 'Danish Krone',
+ 'YDD' => 'Democratic Yemeni Dinar',
+ 'DEM' => 'Deutsche Mark',
+ 'DJF' => 'Djibouti Franc',
+ 'DOP' => 'Dominican Peso',
+ 'NLG' => 'Dutch Guilder',
+ 'DDM' => 'East German Mark (DDR)',
+ 'TPE' => 'East Timor Escudo',
+ 'ECS' => 'Ecuador Sucre',
+ 'EGP' => 'Egyptian Pound',
+ 'SVC' => 'El Salvador Colon',
+ 'ETB' => 'Ethiopian Birr',
+ 'EUR' => 'Euro',
+ 'FKP' => 'Falkland Islands Pound',
+ 'FJD' => 'Fiji Dollar',
+ 'FIM' => 'Finnish Markka',
+ 'FRF' => 'French Franc',
+ 'GMD' => 'Gambian Dalasi',
+ 'GHC' => 'Ghanaian Cedi',
+ 'GIP' => 'Gibraltar Pound',
+ 'GRD' => 'Greek Drachma',
+ 'GTQ' => 'Guatemalan Quetzal',
+ 'GNF' => 'Guinea Franc',
+ 'GWP' => 'Guinea-Bissau Peso',
+ 'GYD' => 'Guyanan Dollar',
+ 'HTG' => 'Haitian Gourde',
+ 'HNL' => 'Honduran Lempira',
+ 'HKD' => 'Hong Kong Dollar',
+ 'HUF' => 'Hungarian Forint',
+ 'ISK' => 'Iceland Krona',
+ 'INR' => 'Indian Rupee',
+ 'IDR' => 'Indonesian Rupiah',
+ 'IRR' => 'Iranian Rial',
+ 'IQD' => 'Iraqi Dinar',
+ 'IEP' => 'Irish Punt',
+ 'ILS' => 'Israeli Shekel',
+ 'ITL' => 'Italian Lira',
+ 'JMD' => 'Jamaican Dollar',
+ 'JPY' => 'Japanese Yen',
+ 'JOD' => 'Jordanian Dinar',
+ 'KHR' => 'Kampuchean (Cambodian) Riel',
+ 'KES' => 'Kenyan Schilling',
+ 'KWD' => 'Kuwaiti Dinar',
+ 'LAK' => 'Lao Kip',
+ 'LBP' => 'Lebanese Pound',
+ 'LSL' => 'Lesotho Loti',
+ 'LRD' => 'Liberian Dollar',
+ 'LYD' => 'Libyan Dinar',
+ 'LUF' => 'Luxembourg Franc',
+ 'MOP' => 'Macau Pataca',
+ 'MGF' => 'Malagasy Franc',
+ 'MWK' => 'Malawi Kwacha',
+ 'MYR' => 'Malaysian Ringgit',
+ 'MVR' => 'Maldive Rufiyaa',
+ 'MTL' => 'Maltese Lira',
+ 'MRO' => 'Mauritanian Ouguiya',
+ 'MUR' => 'Mauritius Rupee',
+ 'MXP' => 'Mexican Peso',
+ 'MNT' => 'Mongolian Tugrik',
+ 'MAD' => 'Moroccan Dirham',
+ 'MZM' => 'Mozambique Metical',
+ 'NPR' => 'Nepalese Rupee',
+ 'ANG' => 'Netherlands Antillian Guilder',
+ 'YUD' => 'New Yugoslavia Dinar',
+ 'NZD' => 'New Zealand Dollar',
+ 'NIC' => 'Nicaraguan Cordoba',
+ 'NGN' => 'Nigerian Naira',
+ 'KPW' => 'North Korean Won',
+ 'NOK' => 'Norwegian Kroner',
+ 'OMR' => 'Omani Rial',
+ 'PKR' => 'Pakistan Rupee',
+ 'PAB' => 'Panamanian Balboa',
+ 'PGK' => 'Papua New Guinea Kina',
+ 'PYG' => 'Paraguay Guarani',
+ 'PEI' => 'Peruvian Inti',
+ 'PHP' => 'Philippine Peso',
+ 'PLZ' => 'Polish Zloty',
+ 'PTE' => 'Portuguese Escudo',
+ 'QAR' => 'Qatari Rial',
+ 'ROL' => 'Romanian Leu',
+ 'RWF' => 'Rwanda Franc',
+ 'WST' => 'Samoan Tala',
+ 'STD' => 'Sao Tome and Principe Dobra',
+ 'SAR' => 'Saudi Arabian Riyal',
+ 'SCR' => 'Seychelles Rupee',
+ 'SLL' => 'Sierra Leone Leone',
+ 'SGD' => 'Singapore Dollar',
+ 'SBD' => 'Solomon Islands Dollar',
+ 'SOS' => 'Somali Schilling',
+ 'ZAR' => 'South African Rand',
+ 'KRW' => 'South Korean Won',
+ 'ESP' => 'Spanish Peseta',
+ 'LKR' => 'Sri Lanka Rupee',
+ 'SHP' => 'St. Helena Pound',
+ 'SDP' => 'Sudanese Pound',
+ 'SRG' => 'Suriname Guilder',
+ 'SZL' => 'Swaziland Lilangeni',
+ 'SEK' => 'Swedish Krona',
+ 'CHF' => 'Swiss Franc',
+ 'SYP' => 'Syrian Potmd',
+ 'TWD' => 'Taiwan Dollar',
+ 'TZS' => 'Tanzanian Schilling',
+ 'THB' => 'Thai Bhat',
+ 'TOP' => "Tongan Pa\'anga",
+ 'TTD' => 'Trinidad and Tobago Dollar',
+ 'TND' => 'Tunisian Dinar',
+ 'YTL' => 'Turkish YTL',
+ 'UGS' => 'Uganda Shilling',
+ 'AED' => 'United Arab Emirates Dirham',
+ 'UYP' => 'Uruguayan Peso',
+ 'USD' => 'US Dollar',
+ 'SUR' => 'USSR Rouble',
+ 'VUV' => 'Vanuatu Vatu',
+ 'VEB' => 'Venezualan Bolivar',
+ 'VND' => 'Vietnamese Dong',
+ 'YER' => 'Yemeni Rial',
+ 'CNY' => 'Yuan (Chinese) Renminbi',
+ 'ZRZ' => 'Zaire Zaire',
+ 'ZMK' => 'Zambian Kwacha',
+ 'ZWD' => 'Zimbabwe Dollar'
+ );
+ foreach ($currencies as $key => $val) {
+ $newcur = new object;
+ $newcur->code = $key;
+ $newcur->name = $val;
+ insert_record('currencies', $newcur, false);
+ }
+}
?>
@@ -3,7 +3,7 @@
<div align="center">
<p><?php print_string("paymentrequired") ?></p>
-<p><b><?php echo get_string("cost").": $CFG->enrol_currency $cost"; ?></b></p>
+<p><b><?php echo get_string("cost").": $curcost[currency] $curcost[cost]"; ?></b></p>
<p><?php print_string("paymentinstant") ?></p>
<form name="form" method="post" action="enrol.php" autocomplete="off">
View
@@ -62,7 +62,7 @@ function print_entry($course) {
$strcourses = get_string("courses");
$userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname;
$userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname;
- $cost = $this->get_course_cost($course);
+ $curcost = $this->get_course_cost($course);
$passwordoption = !empty($course->password);
@@ -113,6 +113,7 @@ function cc_submit($form, $course)
$exp_date = (($form->ccexpiremm<10) ? strval('0'.$form->ccexpiremm) : strval($form->ccexpiremm)) . ($form->ccexpireyyyy);
$valid_cc = CCVal($form->cc, $form->cctype, $exp_date);
+ $curcost = $this->get_course_cost($course);
if (!$valid_cc) {
$this->ccerrormsg = ($valid_cc===0) ? get_string('ccexpired', 'enrol_authorize') : get_string('ccinvalid', 'enrol_authorize');
@@ -140,8 +141,8 @@ function cc_submit($form, $course)
'x_state' => '',
'x_card_num' => $form->cc,
'x_card_code' => $form->cvv,
- 'x_currency_code' => $CFG->enrol_currency,
- 'x_amount' => $this->get_course_cost($course),
+ 'x_currency_code' => $curcost['currency'],
+ 'x_amount' => $curcost['cost'],
'x_exp_date' => $exp_date,
'x_email' => $USER->email,
'x_email_customer' => 'False',
@@ -282,71 +283,57 @@ function cc_submit($form, $course)
}
function zero_cost($course) {
-
- $cost = $this->get_course_cost($course);
- if (abs($cost) < 0.01) { // no cost
- return true;
- }
- return false;
+ $curcost = $this->get_course_cost($course);
+ return (abs($curcost['cost']) < 0.01);
}
function get_course_cost($course) {
global $CFG;
$cost = (float)0;
-
+ $currency = (empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
+
if (isset($course->cost)) {
- if (((float)$course->cost) < 0) {
- $cost = (float)$CFG->enrol_cost;
- } else {
- $cost = (float)$course->cost;
- }
+ if (((float)$course->cost) < 0) {
+ $cost = (float)$CFG->enrol_cost;
+ } else {
+ $cost = (float)$course->cost;
+ }
+ }
+
+ if ( (!empty($course->currency)) && (intval($course->currency)!=0) ) {
+ $objcur = get_record("currencies", "id", $course->currency);
+ $currency = strval($objcur->code);
}
+
$cost = format_float($cost, 2);
- return $cost;
+ $ret = array('cost'=>$cost, 'currency'=>$currency);
+
+ return $ret;
}
/// Override the get_access_icons() function
function get_access_icons($course) {
global $CFG;
$str = '';
- $cost = $this->get_course_cost($course);
+ $curcost = $this->get_course_cost($course);
- if (abs($cost) < 0.01) {
+ if (abs($curcost['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 = '&euro;'; break;
- case 'CAD': $currency = '$'; break;
- case 'GBP': $currency = '&pound;'; break;
- case 'JPY': $currency = '&yen;'; break;
- default: $currency = '$'; break;
- }
-
$str .= "<p class=\"coursecost\"><font size=-1>$strcost: " .
"<a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\"></a>" .
- "$currency" . format_float($cost, 2) . '</a></p>';
+ $curcost['currency'] . " " . $curcost['cost'] . '</a></p>';
}
return $str;
}
function config_form($frm) {
global $CFG;
- $ancurrencies = array(
- 'USD' => 'US Dollars',
- 'EUR' => 'Euros',
- 'JPY' => 'Japanese Yen',
- 'GBP' => 'British Pounds',
- 'CAD' => 'Canadian Dollars'
- );
$vars = array('an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_test',
'enrol_cost', 'enrol_currency', 'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins');
@@ -1,6 +1,6 @@
<?PHP // $Id$
-$module->version = 2004081800;
+$module->version = 2005071400;
$module->requires = 2004081800;
?>

0 comments on commit 10da752

Please sign in to comment.