]> git.mjollnir.org Git - moodle.git/commitdiff
Admin can setup which credit card types will be accepted.
authorethem <ethem>
Fri, 5 May 2006 18:16:45 +0000 (18:16 +0000)
committerethem <ethem>
Fri, 5 May 2006 18:16:45 +0000 (18:16 +0000)
Merged from MOODLE_16_STABLE.

enrol/authorize/config.html
enrol/authorize/enrol.html
enrol/authorize/enrol.php

index 0e2f2c0777ca64e1f21c56efedca5f3a0dfa5d3d..ab7cb8fc4f9e0e2bdeb0ffd17b557bbdf9a51de8 100755 (executable)
@@ -21,8 +21,13 @@ if (isset($CFG->an_cutoff)) {
     $frm->an_cutoff_hour = intval($CFG->an_cutoff) / 60;
     $frm->an_cutoff_min = intval($CFG->an_cutoff) % 60;
 }
+
 if (!isset($frm->an_cutoff_hour)) $frm->an_cutoff_hour = '0';
 if (!isset($frm->an_cutoff_min)) $frm->an_cutoff_min = '5';
+if (!isset($frm->acceptccs)) {
+    $frm->acceptccs = array_keys(get_list_of_creditcards());
+    $CFG->an_acceptccs = implode(',', $frm->acceptccs);
+}
 
 ?>
 
@@ -95,6 +100,20 @@ if (!isset($frm->an_cutoff_min)) $frm->an_cutoff_min = '5';
     <td><?php print_string("antestmode", "enrol_authorize") ?></td>
 </tr>
 
+<tr valign="top">
+    <td align="right">an_acceptccs:</td>
+    <td><?php
+    foreach (get_list_of_creditcards(true) as $key => $val) {
+        echo '<input type="checkbox" name="acceptccs[]" value="'.$key.'"';
+        if (stristr($CFG->an_acceptccs, $key) !== false) {
+            echo ' checked="checked"';
+        }
+        echo " /> $val<br />\n";
+    }
+    ?></td>
+    <td><?php print_string("adminacceptccs", "enrol_authorize") ?></td>
+</tr>
+
 <tr valign="top"><td colspan="3"><h4><?php print_string("adminauthorizeccapture", "enrol_authorize") ?></h4></td></tr>
 
 <tr valign="top">
index 134e5a8cc5d76cc59498a90ee49b293afa005d5c..5dabac7544356d56c09c29a18b18e5895fd42730 100755 (executable)
@@ -59,12 +59,7 @@ $usercountry = empty($form->cccountry) ? $USER->country : $form->cccountry;
 <tr>
   <td align="right"><?php print_string("cctype", "enrol_authorize") ?>: </td>
   <td align="left"><?php
-  $CCTYPES = array(
-    'mcd' => 'Master Card', 'vis' => 'Visa',        'amx' => 'American Express',
-    'dsc' => 'Discover',    'dnc' => 'Diners Club', 'jcb' => 'JCB',
-    'swi' => 'Switch',      'dlt' => 'Delta',       'enr' => 'EnRoute'
-  );
-  choose_from_menu($CCTYPES, 'cctype', $form->cctype);
+  choose_from_menu(get_list_of_creditcards(), 'cctype', $form->cctype);
   if (!empty($this->ccerrors['cctype'])) { formerr($this->ccerrors['cctype']); }
   ?>
 </td>
index d0e034a159ae154c04b61fdb20230d936ee38826..9458b0a250066c38978664921166e4a6238b2920 100755 (executable)
@@ -3,6 +3,46 @@
 require_once $CFG->dirroot.'/enrol/enrol.class.php';
 require_once $CFG->dirroot.'/enrol/authorize/const.php';
 
+/**
+ * get_list_of_creditcards
+ *
+ * @param bool $getall
+ * @return array
+ */
+function get_list_of_creditcards($getall = false)
+{
+    global $CFG;
+    static $alltypes = array();
+
+    if (empty($alltypes)) {
+        $alltypes = array(
+        'mcd' => 'Master Card',
+        'vis' => 'Visa',
+        'amx' => 'American Express',
+        'dsc' => 'Discover',
+        'dnc' => 'Diners Club',
+        'jcb' => 'JCB',
+        'swi' => 'Switch',
+        'dlt' => 'Delta',
+        'enr' => 'EnRoute'
+        );
+    }
+
+    if ($getall || empty($CFG->an_acceptccs)) {
+        return $alltypes;
+    }
+
+    $ret = array();
+    $ccs = explode(',', $CFG->an_acceptccs);
+    $intersects = array_intersect(array_keys($alltypes), $ccs);
+
+    foreach ($intersects as $key) {
+        $ret[$key] = $alltypes[$key];
+    }
+
+    return $ret;
+}
+
 /**
  * enrolment_plugin_authorize
  *
@@ -464,6 +504,9 @@ class enrolment_plugin_authorize
         set_config('enrol_mailteachers', optional_param('enrol_mailteachers', ''));
         set_config('enrol_mailadmins', optional_param('enrol_mailadmins', ''));
 
+        $acceptccs = optional_param('acceptccs', array_keys(get_list_of_creditcards()));
+        set_config('an_acceptccs', implode(',', $acceptccs));
+
         // optional authorize.net settings
         set_config('an_avs', optional_param('an_avs', ''));
         set_config('an_test', optional_param('an_test', ''));