From 04ad0d91e899580c987d88a9f018b15388133ca8 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 5 Jan 2005 00:28:26 +0000 Subject: [PATCH] Now text sent to PayPal can be 'sanitised' to avoid 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 | 14 +++++++------- enrol/paypal/enrol.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/enrol/paypal/enrol.html b/enrol/paypal/enrol.html index 71dcd93998..3cf2bf747c 100644 --- a/enrol/paypal/enrol.html +++ b/enrol/paypal/enrol.html @@ -8,11 +8,11 @@ - - + + "> - + id-$course->id" ?>"> @@ -26,10 +26,10 @@ "> - - - - + + + + diff --git a/enrol/paypal/enrol.php b/enrol/paypal/enrol.php index d1bf6194ee..acada2531c 100644 --- a/enrol/paypal/enrol.php +++ b/enrol/paypal/enrol.php @@ -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 -- 2.39.5