From 10da752643f0e2aef1f9368302da0586c7857729 Mon Sep 17 00:00:00 2001 From: ethem Date: Thu, 14 Jul 2005 16:17:28 +0000 Subject: [PATCH] International payment. All currencies are added... --- enrol/authorize/config.html | 4 +- enrol/authorize/db/mysql.php | 189 ++++++++++++++++++++++++++++++++++- enrol/authorize/enrol.html | 2 +- enrol/authorize/enrol.php | 63 +++++------- enrol/authorize/version.php | 2 +- 5 files changed, 217 insertions(+), 43 deletions(-) diff --git a/enrol/authorize/config.html b/enrol/authorize/config.html index f8a9885b665..ee9434af892 100755 --- a/enrol/authorize/config.html +++ b/enrol/authorize/config.html @@ -13,7 +13,9 @@ enrol_currency: - enrol_currency, "","", "") ?> + enrol_currency, "","", "") ?> diff --git a/enrol/authorize/db/mysql.php b/enrol/authorize/db/mysql.php index fff0330aa3f..21e123a0114 100755 --- a/enrol/authorize/db/mysql.php +++ b/enrol/authorize/db/mysql.php @@ -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); + } +} ?> diff --git a/enrol/authorize/enrol.html b/enrol/authorize/enrol.html index 1a483e17236..f576df30bad 100755 --- a/enrol/authorize/enrol.html +++ b/enrol/authorize/enrol.html @@ -3,7 +3,7 @@

-

enrol_currency $cost"; ?>

+

diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index 1c604daff27..575de9f6729 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -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,27 +283,32 @@ 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 @@ -310,29 +316,17 @@ 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 = '€'; break; - case 'CAD': $currency = '$'; break; - case 'GBP': $currency = '£'; break; - case 'JPY': $currency = '¥'; break; - default: $currency = '$'; break; - } - $str .= "

$strcost: " . "wwwroot/course/view.php?id=$course->id\">" . - "$currency" . format_float($cost, 2) . '

'; + $curcost['currency'] . " " . $curcost['cost'] . '

'; } return $str; } @@ -340,13 +334,6 @@ function get_access_icons($course) { 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'); diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php index ea8f21d941b..257391e361f 100755 --- a/enrol/authorize/version.php +++ b/enrol/authorize/version.php @@ -1,6 +1,6 @@ version = 2004081800; +$module->version = 2005071400; $module->requires = 2004081800; ?>