--- DTA.original.php 2008-03-12 00:41:28.000000000 +0100 +++ DTA.func.php 2008-11-09 20:39:40.000000000 +0100 @@ -166,25 +166,22 @@ $result = ""; if (strlen($string) > 0) { - $search = array( - "'Ä'", - "'Ö'", - "'Ü'", - "'ä'", - "'ö'", - "'ü'", - "'ß'" - ); - - $replace = array( - "Ae", - "Oe", - "Ue", - "ae", - "oe", - "ue", - "ss" - ); + $search = array("'ä'", "'á'", "'à'", "'ã'", "'å'", "'ç'", + "'é'", "'è'", "'ë'", "'í'", "'ì'", "'ï'", + "'ñ'", "'ö'", "'ó'", "'ò'", "'ø'", "'ß'", + "'ü'", "'ú'", "'ù'", + "'Ä'", "'Á'", "'À'", "'Ã'", "'Å'", "'Ç'", + "'É'", "'È'", "'Ë'", "'Í'", "'Ì'", "'Ï'", + "'Ñ'", "'Ö'", "'Ó'", "'Ò'", "'Ø'", + "'Ü'", "'Ú'", "'Ù'"); + $replace = array("ae", "a" , "a" , "a" , "a" , "c" , + "e" , "e" , "e" , "i" , "i" , "i" , + "n" , "oe" , "o" , "o" , "o" , "ss" , + "ue", "u" , "u", + "AE", "A" , "A" , "A" , "A" , "C" , + "E" , "E" , "E" , "I" , "I" , "I" , + "N" , "Oe" , "O" , "O" , "O" , + "UE", "U" , "U"); $result = strtoupper(preg_replace ($search, $replace, $string)); @@ -213,7 +210,12 @@ */ function setAccountFileSender($account) { - if (strlen($account['name']) > 0 && is_numeric($account['bank_code']) && is_numeric($account['account_number'])) { + if (strlen($account['name']) > 0 + && strlen($account['bank_code']) <= 8 + && ctype_digit($account['bank_code']) + && strlen($account['account_number']) <= 10 + && ctype_digit($account['account_number'])) { + if (empty($account['additional_name'])) { $account['additional_name'] = ""; } @@ -269,9 +271,21 @@ $account_sender['additional_name'] = $this->account_file_sender['additional_name']; } - if (strlen($account_sender['name']) > 0 && is_numeric($account_sender['bank_code']) && is_numeric($account_sender['account_number']) && strlen($account_receiver['name']) > 0 && is_numeric($account_receiver['bank_code']) && is_numeric($account_receiver['account_number']) && is_numeric($amount) && $amount > 0 && ((is_array($purposes) && count($purposes) >= 1) || (is_string($purposes) && strlen($purposes) > 0))) { + if (strlen($account_sender['name']) > 0 + && strlen($account_sender['bank_code']) <= 8 + && ctype_digit($account_sender['bank_code']) + && strlen($account_sender['account_number']) <= 10 + && ctype_digit($account_sender['account_number']) + && strlen($account_receiver['name']) > 0 + && strlen($account_receiver['bank_code']) <= 8 + && ctype_digit($account_receiver['bank_code']) + && strlen($account_receiver['account_number']) <= 10 + && ctype_digit($account_receiver['account_number']) + && is_numeric($amount) && $amount > 0 + && ((is_array($purposes) && count($purposes) >= 1) + || (is_string($purposes) && strlen($purposes) > 0))) { - $amount = round($amount * 100); + $amount = intval(round($amount * 100)); if (is_string($purposes)) { $purposes = array($purposes, ""); @@ -354,13 +368,15 @@ // currency (1 = Euro) $content .= "1"; + assert(strlen($content) == 128); + /** * data record(s) C */ foreach ($this->exchanges as $exchange) { $sum_account_numbers += $exchange['receiver_account_number']; - $sum_bank_codes += $exchange['receiver_bank_code']; + $sum_bank_codes += (int) $exchange['receiver_bank_code']; $sum_amounts += $exchange['amount']; $additional_purposes = $exchange['purposes']; @@ -469,6 +485,8 @@ } } + assert(strlen($content) % 128 == 0); + /** * data record E */ @@ -483,15 +501,21 @@ $content .= str_pad (count($this->exchanges), 7, "0", STR_PAD_LEFT); // free (reserve) $content .= str_repeat ("0", 13); + // use number_format() to ensure proper integer formatting // sum of account numbers - $content .= str_pad ($sum_account_numbers, 17, "0", STR_PAD_LEFT); + $content .= str_pad(number_format($sum_account_numbers, 0, "", ""), + 17, "0", STR_PAD_LEFT); // sum of bank codes - $content .= str_pad ($sum_bank_codes, 17, "0", STR_PAD_LEFT); + $content .= str_pad(number_format($sum_bank_codes, 0, "", ""), + 17, "0", STR_PAD_LEFT); // sum of amounts - $content .= str_pad ($sum_amounts, 13, "0", STR_PAD_LEFT); + $content .= str_pad(number_format($sum_amounts, 0, "", ""), + 13, "0", STR_PAD_LEFT); // delimitation $content .= str_repeat (" ", 51); + assert(strlen($content) % 128 == 0); + return $content; } @@ -516,6 +540,15 @@ return $result; } -} -?> \ No newline at end of file + /** + * Return number of exchanges + * + * @access public + * @return integer + */ + function count() + { + return count($this->exchanges); + } +}