]> git.mjollnir.org Git - moodle.git/commitdiff
Now text sent to PayPal can be 'sanitised' to avoid
authorstronk7 <stronk7>
Wed, 5 Jan 2005 00:28:26 +0000 (00:28 +0000)
committerstronk7 <stronk7>
Wed, 5 Jan 2005 00:28:26 +0000 (00:28 +0000)
some diacritics (spanish for now) break the enrol process.
Only German and French diacritics are supported for now by PayPal.
Functionality can be easily expanded to other characters.
It make the sanitity when $CFG->sanitise_for_paypal is enabled.

Merged from MOODLE_14_STABLE

enrol/paypal/enrol.html
enrol/paypal/enrol.php

index 71dcd939981d352386ee443be882e25907103840..3cf2bf747c3ccb0f1ab4ba0520f6979d4377c663 100644 (file)
@@ -8,11 +8,11 @@
 
 <input type="hidden" name="cmd" value="_xclick">
 <input type="hidden" name="business" value="<?php p($CFG->enrol_paypalbusiness)?>">
-<input type="hidden" name="item_name" value="<?php p($course->fullname) ?>">
-<input type="hidden" name="item_number" value="<?php p($course->shortname) ?>">
+<input type="hidden" name="item_name" value="<?php p($coursefullname) ?>">
+<input type="hidden" name="item_number" value="<?php p($courseshortname) ?>">
 <input type="hidden" name="quantity" value="1">
 <input type="hidden" name="on0" value="<?php print_string("user") ?>">
-<input type="hidden" name="os0" value="<?php echo fullname($USER) ?>">
+<input type="hidden" name="os0" value="<?php p($userfullname) ?>">
 <input type="hidden" name="custom" value="<?php echo "$USER->id-$course->id" ?>">
 
 <input type="hidden" name="currency_code" value="<?php p($CFG->enrol_currency) ?>">
 <input type="hidden" name="rm" value="2">
 <input type="hidden" name="cbt" value="<?php print_string("continuetocourse") ?>">
 
-<input type="hidden" name="first_name" value="<?php p($USER->firstname) ?>">
-<input type="hidden" name="last_name" value="<?php p($USER->lastname) ?>">
-<input type="hidden" name="address" value="<?php p($USER->address) ?>">
-<input type="hidden" name="city" value="<?php p($USER->city) ?>">
+<input type="hidden" name="first_name" value="<?php p($userfirstname) ?>">
+<input type="hidden" name="last_name" value="<?php p($userlastname) ?>">
+<input type="hidden" name="address" value="<?php p($useraddress) ?>">
+<input type="hidden" name="city" value="<?php p($usercity) ?>">
 <input type="hidden" name="email" value="<?php p($USER->email) ?>">
 <input type="hidden" name="country" value="<?php p($USER->country) ?>">
 
index d1bf6194ee82feeba62e412d9f68d1c5b169fb2c..acada2531cef5a3113a1b3ee0e0bf7e2e33c44a5 100644 (file)
@@ -39,6 +39,14 @@ function print_entry($course) {
         print_course($course, "80%");
         print_simple_box_start("center");
 
+        //Sanitise some fields before building the PayPal form
+        $coursefullname  = $this->sanitise_for_paypal($course->fullname);
+        $courseshortname = $this->sanitise_for_paypal($course->shortname);
+        $userfullname    = $this->sanitise_for_paypal(fullname($USER));
+        $userfirstname   = $this->sanitise_for_paypal($USER->firstname);
+        $userlastname    = $this->sanitise_for_paypal($USER->lastname);
+        $useraddress     = $this->sanitise_for_paypal($USER->address);
+        $usercity        = $this->sanitise_for_paypal($USER->city);
 
         include("$CFG->dirroot/enrol/paypal/enrol.html");
 
@@ -142,6 +150,37 @@ function process_config($config) {
 
 }
 
+//To avoid wrong (for PayPal) characters in sent data
+function sanitise_for_paypal($text) {
+    global $CFG;
+
+    if (!empty($CFG->sanitise_for_paypal)) {
+        //Array of characters to replace (not allowed by PayPal)
+        //Can be expanded as necessary to add other diacritics
+        $replace = array('á' => 'a',        //Spanish characters
+                         'é' => 'e',
+                         'í' => 'i',
+                         'ó' => 'o',
+                         'ú' => 'u',
+                         'Á' => 'A',
+                         'É' => 'E',
+                         'Í' => 'I',
+                         'Ó' => 'O',
+                         'Ú' => 'U',
+                         'ñ' => 'n',
+                         'Ñ' => 'N',
+                         'ü' => 'u',
+                         'Ü' => 'U');
+        $text = strtr($text, $replace);
+    
+        //Make here other sanities if necessary
+
+    }
+
+    return $text;
+
+}
+
 
 } // end of class definition