Ethem made some mistakes here
- made some new tables and other changes for this module in STABLE - used a database to store language strings - made changes that required CORE changes in STABLE to work I'm resetting this module to how it was in Moodle 1.5 ... Ethem if you could reapply any FIXES only to this module then we can look at how to add currencies properly in 1.6.
This commit is contained in:
+11
-16
@@ -13,28 +13,13 @@
|
||||
<tr valign="top">
|
||||
<td align="right">enrol_currency:</td>
|
||||
<td>
|
||||
<?php
|
||||
$currenciesarray = get_records_menu("currencies", "", "", "name", "code,name");
|
||||
choose_from_menu ($currenciesarray, "enrol_currency", $frm->enrol_currency, "","", "") ?>
|
||||
<?php choose_from_menu ($ancurrencies, "enrol_currency", $frm->enrol_currency, "","", "") ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("currency") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right">loginhttps:</td>
|
||||
<td>
|
||||
<?php echo (empty($CFG->loginhttps) ? "<font color=\"red\">off</font>" : "<font color=\"green\">on</font>") ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$a->url = "$CFG->wwwroot/$CFG->admin/config.php#configsectionsecurity";
|
||||
print_string("logindesc", "enrol_authorize", $a)
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top"><td colspan="3"><hr noshade="noshade" size="1"></td></tr>
|
||||
|
||||
<tr valign="top">
|
||||
@@ -126,4 +111,14 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right">enrol_allowinternal:</td>
|
||||
<td>
|
||||
<input type="checkbox" value="1" name="enrol_allowinternal" <?php if (!empty($frm->enrol_allowinternal)) echo "checked=\"true\"" ?> />
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string('allowinternal') ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
@@ -10,205 +10,10 @@ 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');
|
||||
}
|
||||
|
||||
if ($oldversion < 2005071600) {
|
||||
// Be sure, only last 4 digit is inserted.
|
||||
table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null');
|
||||
table_column('enrol_authorize', 'courseid', 'courseid', 'integer', '10', 'unsigned', '0', 'not null');
|
||||
table_column('enrol_authorize', 'userid ', 'userid ', 'integer', '10', 'unsigned', '0', 'not null');
|
||||
// Add some indexes for speed.
|
||||
execute_sql(" ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX courseid(courseid) ");
|
||||
execute_sql(" ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX userid(userid) ");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -9,4 +9,4 @@ CREATE TABLE `prefix_enrol_authorize` (
|
||||
`avscode` char(1) default 'P',
|
||||
`transid` varchar(255) default '',
|
||||
PRIMARY KEY (`id`)
|
||||
) TYPE=MyISAM COMMENT='Holds all known information about authorize.net transactions';
|
||||
) TYPE=MyISAM COMMENT='Holds all known information about creditcard transactions';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<p align="center"><?php if (!empty($this->ccerrormsg) ) {formerr($this->ccerrormsg);} ?></p>
|
||||
<p align="center"><?php if (! empty($this->errormsg)) {formerr($this->errormsg);} ?></p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
<p><?php print_string("paymentrequired") ?></p>
|
||||
<p><b><?php echo get_string("cost").": $curcost[currency] $curcost[cost]"; ?></b></p>
|
||||
<p><b><?php echo get_string("cost").": $CFG->enrol_currency $cost"; ?></b></p>
|
||||
<p><?php print_string("paymentinstant") ?></p>
|
||||
|
||||
<form name="form" method="post" action="enrol.php" autocomplete="off">
|
||||
@@ -11,8 +11,8 @@
|
||||
<table align="center" width="100%" border=0>
|
||||
<tr>
|
||||
<td align="right"><?php print_string("nameoncard", "enrol_authorize") ?>: </td>
|
||||
<td align="left"><input type="text" name="ccfirstname" size="15" value="<?php p($userfirstname) ?>" />
|
||||
<input type="text" name="cclastname" size="15" value="<?php p($userlastname) ?>" /></td>
|
||||
<td align="left"><input type="text" name="ccfirstname" size="16" value="<?php p($userfirstname) ?>" />
|
||||
<input type="text" name="cclastname" size="16" value="<?php p($userlastname) ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><?php print_string("ccno", "enrol_authorize") ?>: </td>
|
||||
@@ -24,14 +24,8 @@
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
|
||||
}
|
||||
choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm);
|
||||
$nowdate = getdate();
|
||||
$nowyear = $nowdate["year"]-1;
|
||||
for ($i=$nowyear; $i<=$nowyear+11; $i++) {
|
||||
$years[$i] = $i;
|
||||
}
|
||||
choose_from_menu($years, 'ccexpireyyyy', $form->ccexpireyyyy);
|
||||
?></td>
|
||||
choose_from_menu($months, 'ccexpiremm', $form->ccexpiremm, '');
|
||||
?> <input type="text" name="ccexpireyyyy" size="4" maxlength="4" value="<?php p($form->ccexpireyyyy) ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
|
||||
|
||||
+166
-165
@@ -14,93 +14,78 @@ require_once("$CFG->dirroot/enrol/enrol.class.php");
|
||||
|
||||
class enrolment_plugin extends enrolment_base {
|
||||
|
||||
var $ccerrormsg;
|
||||
var $coursecost;
|
||||
|
||||
/// Override: print_entry()
|
||||
function print_entry($course) {
|
||||
global $CFG, $USER, $form;
|
||||
|
||||
$free_cost = $this->zero_cost($course);
|
||||
if ($this->zero_cost($course)) {
|
||||
if (!empty($CFG->enrol_allowinternal)) {
|
||||
parent::print_entry($course);
|
||||
} else {
|
||||
print_header();
|
||||
notice(get_string("enrolmentnointernal"), $CFG->wwwroot);
|
||||
}
|
||||
} else {
|
||||
// check payment
|
||||
$this->check_paid();
|
||||
|
||||
if ($free_cost || isguest()) { // No money for guests ;), So parent::print_entry
|
||||
parent::print_entry($course);
|
||||
return;
|
||||
}
|
||||
if ((!empty($CFG->loginhttps)) && (!isset($_SERVER['HTTPS']))) {
|
||||
$wwwsroot = str_replace('http://','https://', $CFG->wwwroot);
|
||||
$sdestination = "$wwwsroot/course/enrol.php?id=$course->id";
|
||||
redirect($sdestination);
|
||||
exit;
|
||||
}
|
||||
|
||||
// check payment
|
||||
$this->check_paid();
|
||||
$strloginto = get_string("loginto", "", $course->shortname);
|
||||
$strcourses = get_string("courses");
|
||||
$teacher = get_teacher($course->id);
|
||||
|
||||
// HTTPS support: I want to paid on secure layer.
|
||||
if ((!empty($CFG->loginhttps)) && (!isset($_SERVER['HTTPS']))) {
|
||||
$wwwsroot = str_replace('http://','https://', $CFG->wwwroot);
|
||||
$sdestination = "$wwwsroot/course/enrol.php?id=$course->id";
|
||||
redirect($sdestination);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_SERVER['HTTPS'])) {
|
||||
error(get_string("httpsrequired", "enrol_authorize"));
|
||||
}
|
||||
|
||||
$CCTYPES = array(
|
||||
'mcd' => 'Master Card',
|
||||
'vis' => 'Visa',
|
||||
'amx' => 'American Express',
|
||||
'dsc' => 'Discover',
|
||||
'dnc' => 'Diners Club',
|
||||
'jcb' => 'JCB',
|
||||
'swi' => 'Switch',
|
||||
'dlt' => 'Delta',
|
||||
'enr' => 'EnRoute'
|
||||
);
|
||||
|
||||
$formvars = array('password','ccfirstname','cclastname','cc','ccexpiremm','ccexpireyyyy','cctype','cvv','cczip');
|
||||
foreach ($formvars as $var) {
|
||||
if (!isset($form->$var)) {
|
||||
$form->$var = '';
|
||||
}
|
||||
}
|
||||
|
||||
$teacher = get_teacher($course->id);
|
||||
$strloginto = get_string("loginto", "", $course->shortname);
|
||||
$strcourses = get_string("courses");
|
||||
$userfirstname = empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname;
|
||||
$userlastname = empty($form->cclastname) ? $USER->lastname : $form->cclastname;
|
||||
$curcost = $this->get_course_cost($course);
|
||||
|
||||
$passwordoption = !empty($course->password);
|
||||
|
||||
print_header($strloginto, $course->fullname, "<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
|
||||
print_course($course, "80%");
|
||||
|
||||
if ($passwordoption && !$free_cost) {
|
||||
print_simple_box(get_string('choosemethod', 'enrol_authorize'), 'center');
|
||||
}
|
||||
|
||||
if ($passwordoption || $free_cost) {
|
||||
$password = '';
|
||||
include($CFG->dirroot . '/enrol/internal/enrol.html');
|
||||
}
|
||||
|
||||
if (!$free_cost) {
|
||||
print_header($strloginto, $course->fullname, "<a href=\"$CFG->wwwroot/course/\">$strcourses</a> -> $strloginto");
|
||||
print_course($course, "80%");
|
||||
print_simple_box_start("center");
|
||||
include($CFG->dirroot . '/enrol/authorize/enrol.html');
|
||||
print_simple_box_end();
|
||||
|
||||
$coursefullname = $course->fullname;
|
||||
$courseshortname= $course->shortname;
|
||||
$userfirstname = $USER->firstname;
|
||||
$userlastname = $USER->lastname;
|
||||
$useraddress = $USER->address;
|
||||
$usercity = $USER->city;
|
||||
$cost = $this->get_course_cost($course);
|
||||
|
||||
$CCTYPES = array(
|
||||
'mcd' => 'Master Card',
|
||||
'vis' => 'Visa',
|
||||
'amx' => 'American Express',
|
||||
'dsc' => 'Discover',
|
||||
'dnc' => 'Diners Club',
|
||||
'jcb' => 'JCB',
|
||||
'swi' => 'Switch',
|
||||
'dlt' => 'Delta',
|
||||
'enr' => 'EnRoute'
|
||||
);
|
||||
|
||||
$formvars = array('ccfirstname','cclastname','cc','ccexpiremm','ccexpireyyyy','cctype','cvv','cczip');
|
||||
foreach ($formvars as $var) {
|
||||
if (!isset($form->$var)) {
|
||||
$form->$var = '';
|
||||
}
|
||||
}
|
||||
|
||||
include($CFG->dirroot . '/enrol/authorize/enrol.html');
|
||||
print_simple_box_end();
|
||||
print_footer();
|
||||
}
|
||||
|
||||
print_footer();
|
||||
|
||||
}
|
||||
|
||||
/// Override: check_entry()
|
||||
function check_entry($form, $course) {
|
||||
global $CFG;
|
||||
|
||||
if ($this->zero_cost($course) || (!empty($form->password)) || isguest()) {
|
||||
parent::check_entry($form, $course);
|
||||
if ($this->zero_cost($course)) {
|
||||
if (!empty($CFG->enrol_allowinternal)) {
|
||||
parent::check_entry($form, $course);
|
||||
}
|
||||
} else {
|
||||
$this->cc_submit($form, $course);
|
||||
$this->cc_submit($form, $course);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,61 +96,60 @@ function cc_submit($form, $course)
|
||||
|
||||
if (empty($form->ccfirstname) || empty($form->cclastname) ||
|
||||
empty($form->cc) || empty($form->cvv) || empty($form->cctype) ||
|
||||
empty($form->ccexpiremm) || empty($form->ccexpireyyyy) || empty($form->cczip)) {
|
||||
$this->ccerrormsg = get_string("allfieldsrequired");
|
||||
return;
|
||||
}
|
||||
empty($form->ccexpiremm) || empty($form->ccexpireyyyy)) {
|
||||
$this->errormsg = get_string("allfieldsrequired");
|
||||
return;
|
||||
}
|
||||
|
||||
$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');
|
||||
return;
|
||||
if (! CCVal($form->cc, $form->cctype, $exp_date)) {
|
||||
$this->errormsg = get_string("ccinvalid", "enrol_authorize");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$this->check_paid();
|
||||
$order_number = 0; // can be get from db
|
||||
$formdata = array (
|
||||
'x_version' => '3.1',
|
||||
'x_delim_data' => 'True',
|
||||
'x_delim_char' => AN_DELIM,
|
||||
'x_encap_char' => AN_ENCAP,
|
||||
'x_relay_response' => 'False',
|
||||
'x_login' => $CFG->an_login,
|
||||
'x_test_request' => (!empty($CFG->an_test)) ? 'True' : 'False',
|
||||
'x_type' => 'AUTH_CAPTURE',
|
||||
'x_method' => 'CC',
|
||||
'x_first_name' => (empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname),
|
||||
'x_last_name' => (empty($form->cclastname) ? $USER->lastname : $form->cclastname),
|
||||
'x_address' => $USER->address,
|
||||
'x_city' => $USER->city,
|
||||
'x_zip' => $form->cczip,
|
||||
'x_country' => $USER->country,
|
||||
'x_state' => '',
|
||||
'x_card_num' => $form->cc,
|
||||
'x_card_code' => $form->cvv,
|
||||
'x_currency_code' => $curcost['currency'],
|
||||
'x_amount' => $curcost['cost'],
|
||||
'x_exp_date' => $exp_date,
|
||||
'x_email' => $USER->email,
|
||||
'x_email_customer' => 'False',
|
||||
'x_cust_id' => $USER->id,
|
||||
'x_customer_ip' => $_SERVER["REMOTE_ADDR"],
|
||||
'x_phone' => '',
|
||||
'x_fax' => '',
|
||||
'x_invoice_num' => $order_number,
|
||||
'x_description' => $course->shortname
|
||||
'x_version' => '3.1',
|
||||
'x_delim_data' => 'True',
|
||||
'x_delim_char' => AN_DELIM,
|
||||
'x_encap_char' => AN_ENCAP,
|
||||
'x_relay_response' => 'False',
|
||||
'x_login' => $CFG->an_login,
|
||||
'x_test_request' => (!empty($CFG->an_test)) ? 'True' : 'False',
|
||||
'x_type' => 'AUTH_CAPTURE',
|
||||
'x_method' => 'CC',
|
||||
// user
|
||||
'x_first_name' => (empty($form->ccfirstname) ? $USER->firstname : $form->ccfirstname),
|
||||
'x_last_name' => (empty($form->cclastname) ? $USER->lastname : $form->cclastname),
|
||||
'x_address' => $USER->address,
|
||||
'x_city' => $USER->city,
|
||||
'x_state' => '',
|
||||
'x_zip' => $form->cczip,
|
||||
'x_country' => $USER->country,
|
||||
'x_card_num' => $form->cc,
|
||||
'x_card_code' => $form->cvv,
|
||||
'x_currency_code' => $CFG->enrol_currency,
|
||||
'x_amount' => $this->get_course_cost($course),
|
||||
'x_exp_date' => $exp_date,
|
||||
'x_email' => $USER->email,
|
||||
'x_email_customer' => 'False',
|
||||
'x_cust_id' => $USER->id,
|
||||
'x_customer_ip' => $_SERVER["REMOTE_ADDR"],
|
||||
'x_phone' => '',
|
||||
'x_fax' => '',
|
||||
'x_invoice_num' => $order_number,
|
||||
'x_description' => $course->shortname
|
||||
);
|
||||
|
||||
//build the post string
|
||||
$poststring = '';
|
||||
if (!empty($CFG->an_tran_key)) {
|
||||
$poststring .= urlencode("x_tran_key") . "=" . urlencode($CFG->an_tran_key);
|
||||
}
|
||||
else { // MUST be x_tran_key or x_password
|
||||
$poststring .= urlencode("x_password") . "=" . urlencode($CFG->an_password);
|
||||
} else {
|
||||
$an_pswd = (isset($CFG->an_password)) ? $CFG->an_password : '';
|
||||
$poststring .= urlencode("x_password") . "=" . urlencode($an_pswd);
|
||||
}
|
||||
foreach($formdata as $key => $val) {
|
||||
$poststring .= "&" . urlencode($key) . "=" . urlencode($val);
|
||||
@@ -173,34 +157,37 @@ function cc_submit($form, $course)
|
||||
//built
|
||||
|
||||
$response = array();
|
||||
$anrefererheader = '';
|
||||
$anrefererheader = "";
|
||||
if (isset($CFG->an_referer) && (!empty($CFG->an_referer)) &&
|
||||
($CFG->an_referer != "http://") && ($CFG->an_referer != "https://")) {
|
||||
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
||||
($CFG->an_referer != "http://") && ($CFG->an_referer != "https://")) {
|
||||
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
||||
}
|
||||
|
||||
$fp = fsockopen("ssl://" . AN_HOST, AN_PORT, $errno, $errstr, 60);
|
||||
if(!$fp) {
|
||||
$this->ccerrormsg = "$errstr ($errno)";
|
||||
$this->errormsg = "$errstr ($errno)";
|
||||
return;
|
||||
} else {
|
||||
//send the server request
|
||||
fputs($fp,
|
||||
"POST " . AN_PATH . " HTTP/1.0\r\n" .
|
||||
"Host: " . AN_HOST . "\r\n" .
|
||||
$anrefererheader .
|
||||
"Content-type: application/x-www-form-urlencoded\r\n" .
|
||||
"Content-length: " . strlen($poststring) . "\r\n" .
|
||||
"Connection: close\r\n\r\n" .
|
||||
$poststring . "\r\n\r\n");
|
||||
"POST " . AN_PATH . " HTTP/1.1\r\n" .
|
||||
"Host: " . AN_HOST . "\r\n" .
|
||||
$anrefererheader .
|
||||
"Content-type: application/x-www-form-urlencoded\r\n" .
|
||||
"Content-length: " . strlen($poststring) . "\r\n" .
|
||||
"Connection: close\r\n\r\n" .
|
||||
$poststring . "\r\n\r\n");
|
||||
|
||||
//Get the response header from the server
|
||||
$str = '';
|
||||
while(!feof($fp) && !stristr($str, 'content-length')) {
|
||||
$str = fgets($fp, 4096);
|
||||
}
|
||||
$str = fgets($fp, 4096);
|
||||
}
|
||||
// If didnt get content-lenght, something is wrong.
|
||||
if (!stristr($str, 'content-length')) {
|
||||
$this->ccerrormsg = "content-length error";
|
||||
$this->errormsg = "content-length error";
|
||||
return;
|
||||
}
|
||||
|
||||
// Get length of data to be received.
|
||||
$length = trim(substr($str,strpos($str,'content-length') + 15));
|
||||
// Get buffer (blank data before real data)
|
||||
@@ -211,7 +198,7 @@ function cc_submit($form, $course)
|
||||
$response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
|
||||
if ($response === false)
|
||||
{
|
||||
$this->ccerrormsg = "response error";
|
||||
$this->errormsg = "response error";
|
||||
return;
|
||||
}
|
||||
$rcount = count($response) - 1;
|
||||
@@ -224,7 +211,7 @@ function cc_submit($form, $course)
|
||||
}
|
||||
|
||||
if ($response[0] != AN_APPROVED) {
|
||||
$this->ccerrormsg = isset($response[3]) ? $response[3] : 'unknown error';
|
||||
$this->errormsg = isset($response[3]) ? $response[3] : 'unknown error';
|
||||
} else {
|
||||
$SESSION->ccpaid = 1; // security check: don't duplicate payment
|
||||
if ($course->enrolperiod) {
|
||||
@@ -263,7 +250,8 @@ function cc_submit($form, $course)
|
||||
// end: send email
|
||||
|
||||
// begin: authorize_table
|
||||
$datax->cclastfour = substr($form->cc, -4);
|
||||
$cclast4 = substr($form->cc, -4);
|
||||
$datax->cclastfour = ($cclast4 === false) ? '0000' : $cclast4;
|
||||
$datax->ccexp = $exp_date;
|
||||
$datax->cvv = $form->cvv;
|
||||
$datax->ccname = $formdata['x_first_name'] . " " . $formdata['x_last_name'];
|
||||
@@ -288,32 +276,27 @@ function cc_submit($form, $course)
|
||||
}
|
||||
|
||||
function zero_cost($course) {
|
||||
$curcost = $this->get_course_cost($course);
|
||||
return (abs($curcost['cost']) < 0.01);
|
||||
|
||||
$cost = $this->get_course_cost($course);
|
||||
if (abs($cost) < 0.01) { // no cost
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_course_cost($course) {
|
||||
global $CFG;
|
||||
$cost = (float)0;
|
||||
|
||||
if (isset($coursecost))
|
||||
return $coursecost;
|
||||
|
||||
$currency = (empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
|
||||
|
||||
if (!empty($course->cost)) {
|
||||
$cost = (float)(((float)$course->cost) < 0) ? $CFG->enrol_cost : $course->cost;
|
||||
if (isset($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);
|
||||
$coursecost = array('cost'=>$cost, 'currency'=>$currency);
|
||||
|
||||
return $coursecost;
|
||||
return $cost;
|
||||
}
|
||||
|
||||
/// Override the get_access_icons() function
|
||||
@@ -321,17 +304,29 @@ function get_access_icons($course) {
|
||||
global $CFG;
|
||||
|
||||
$str = '';
|
||||
$curcost = $this->get_course_cost($course);
|
||||
$cost = $this->get_course_cost($course);
|
||||
|
||||
if (abs($curcost['cost']) < 0.01) {
|
||||
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;
|
||||
default: $currency = '$'; break;
|
||||
}
|
||||
|
||||
$str .= "<p class=\"coursecost\"><font size=-1>$strcost: " .
|
||||
"<a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\"></a>" .
|
||||
$curcost['currency'] . " " . $curcost['cost'] . '</a></p>';
|
||||
"$currency" . format_float($cost, 2) . '</a></p>';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
@@ -339,14 +334,21 @@ 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');
|
||||
$vars = array('enrol_cost', 'enrol_currency', 'an_login', 'an_tran_key', 'an_password', 'an_referer', 'an_test',
|
||||
'enrol_mailstudents', 'enrol_mailteachers', 'enrol_mailadmins', 'enrol_allowinternal');
|
||||
|
||||
foreach ($vars as $var) {
|
||||
if (!isset($frm->$var)) {
|
||||
$frm->$var = '';
|
||||
}
|
||||
if (!isset($frm->$var)) {
|
||||
$frm->$var = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->check_openssl_loaded()) {
|
||||
@@ -360,9 +362,6 @@ function config_form($frm) {
|
||||
if (empty($frm->an_tran_key) && empty($frm->an_password)) {
|
||||
notify("an_tran_key or an_password required");
|
||||
}
|
||||
if (empty($CFG->loginhttps)) {
|
||||
notify("\$CFG->loginhttps MUST BE ON");
|
||||
}
|
||||
}
|
||||
include($CFG->dirroot.'/enrol/authorize/config.html');
|
||||
}
|
||||
@@ -372,7 +371,6 @@ function check_openssl_loaded() {
|
||||
}
|
||||
|
||||
function process_config($config) {
|
||||
global $CFG;
|
||||
|
||||
$return = $this->check_openssl_loaded();
|
||||
|
||||
@@ -398,8 +396,6 @@ function process_config($config) {
|
||||
if (empty($config->an_tran_key) && empty($config->an_password)) {
|
||||
$return = false;
|
||||
}
|
||||
// $CFG->loginhttps must be on.
|
||||
$return = (!empty($CFG->loginhttps));
|
||||
|
||||
if (empty($config->an_referer)) {
|
||||
$config->an_referer = 'http://';
|
||||
@@ -437,12 +433,17 @@ function process_config($config) {
|
||||
}
|
||||
set_config('enrol_mailadmins', $config->enrol_mailadmins);
|
||||
|
||||
if (!isset($config->enrol_allowinternal)) {
|
||||
$config->enrol_allowinternal = '';
|
||||
}
|
||||
set_config('enrol_allowinternal', $config->enrol_allowinternal);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function email_cc_error_to_admin($subject, $data) {
|
||||
$admin = get_admin();
|
||||
$site = get_site();
|
||||
$site = get_admin();
|
||||
|
||||
$message = "$site->fullname: Transaction failed.\n\n$subject\n\n";
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
$module->version = 2005071600;
|
||||
$module->version = 2004081800;
|
||||
$module->requires = 2004081800;
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user