芝麻web文件管理V1.00
编辑当前文件:/home/strato/chroot/opt/RZphp5/includes/Payment/DTABase.php
* @author Martin Schütte
* @copyright 2003-2005 Hermann Stainer, Web-Gear * @copyright 2008 Martin Schütte * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: DTABase.php,v 1.7 2009/05/13 17:02:21 mschuett Exp $ * @link http://pear.php.net/package/Payment_DTA */ /** * DTABase class provides common functions to classes DTA and DTAZV. * * @category Payment * @package Payment_DTA * @author Hermann Stainer
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version Release: @package_version@ * @link http://pear.php.net/package/Payment_DTA */ class DTABase { /** * Account data for the file sender. * * @var integer $account_file_sender * @access private */ var $account_file_sender; /** * Current timestamp. * * @var integer $timestamp * @access private */ var $timestamp; /** * Array of exchanges that the DTA file should contain. * * @var integer $exchanges * @access private */ var $exchanges; /** * Sum of amounts in exchanges (in Cents); for control total fields. * * @var integer $sum_amounts * @access private */ var $sum_amounts; /** * Return number of exchanges * * @access public * @return integer */ function count() { return count($this->exchanges); } /** * Constructor. * * @access protected */ function DTABase() { $this->invalidString_regexp = '/[^A-Z0-9 \.,&\-\/\+\*\$%]/'; $this->account_file_sender = array(); $this->exchanges = array(); $this->timestamp = time(); $this->sum_amounts = 0; } /** * Checks if the given string contains only chars valid for fields * in DTA files. * * @param string $string String that is checked. * * @access public * @return boolean */ function validString($string) { return !preg_match($this->invalidString_regexp, $string); } /** * Makes the given string valid for DTA files. * Some diacritics, especially German umlauts become uppercase, * all other chars not allowed are replaced with space. * * @param string $string String that should made valid. * * @access public * @return string */ function makeValidString($string) { $special_chars = array( 'á' => 'a', 'à' => 'a', 'ä' => 'ae', 'â' => 'a', 'ã' => 'a', 'å' => 'a', 'æ' => 'ae', 'ā' => 'a', 'ă' => 'a', 'ą' => 'a', 'ȁ' => 'a', 'ȃ' => 'a', 'Á' => 'A', 'À' => 'A', 'Ä' => 'Ae', 'Â' => 'A', 'Ã' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ā' => 'A', 'Ă' => 'A', 'Ą' => 'A', 'Ȁ' => 'A', 'Ȃ' => 'A', 'ç' => 'c', 'ć' => 'c', 'ĉ' => 'c', 'ċ' => 'c', 'č' => 'c', 'Ç' => 'C', 'Ć' => 'C', 'Ĉ' => 'C', 'Ċ' => 'C', 'Č' => 'C', 'ď' => 'd', 'đ' => 'd', 'Ď' => 'D', 'Đ' => 'D', 'é' => 'e', 'è' => 'e', 'ê' => 'e', 'ë' => 'e', 'ē' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ę' => 'e', 'ě' => 'e', 'ȅ' => 'e', 'ȇ' => 'e', 'É' => 'E', 'È' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ē' => 'E', 'Ĕ' => 'E', 'Ė' => 'E', 'Ę' => 'E', 'Ě' => 'E', 'Ȅ' => 'E', 'Ȇ' => 'E', 'ĝ' => 'g', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g', 'Ĝ' => 'G', 'Ğ' => 'G', 'Ġ' => 'G', 'Ģ' => 'G', 'ĥ' => 'h', 'ħ' => 'h', 'Ĥ' => 'H', 'Ħ' => 'H', 'ì' => 'i', 'ì' => 'i', 'î' => 'i', 'ï' => 'i', 'ĩ' => 'i', 'ī' => 'i', 'ĭ' => 'i', 'į' => 'i', 'ı' => 'i', 'ij' => 'ij', 'ȉ' => 'i', 'ȋ' => 'i', 'Í' => 'I', 'Ì' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ĩ' => 'I', 'Ī' => 'I', 'Ĭ' => 'I', 'Į' => 'I', 'İ' => 'I', 'IJ' => 'IJ', 'Ȉ' => 'I', 'Ȋ' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'ļ' => 'l', 'ľ' => 'l', 'ŀ' => 'l', 'ł' => 'l', 'Ĺ' => 'L', 'Ļ' => 'L', 'Ľ' => 'L', 'Ŀ' => 'L', 'Ł' => 'L', 'ñ' => 'n', 'ń' => 'n', 'ņ' => 'n', 'ň' => 'n', 'ʼn' => 'n', 'Ñ' => 'N', 'Ń' => 'N', 'Ņ' => 'N', 'Ň' => 'N', 'ó' => 'o', 'ò' => 'o', 'ö' => 'oe', 'ô' => 'o', 'õ' => 'o', 'ø' => 'o', 'ō' => 'o', 'ŏ' => 'o', 'ő' => 'o', 'œ' => 'oe', 'ȍ' => 'o', 'ȏ' => 'o', 'Ó' => 'O', 'Ò' => 'O', 'Ö' => 'Oe', 'Ô' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Ō' => 'O', 'Ŏ' => 'O', 'Ő' => 'O', 'Œ' => 'OE', 'Ȍ' => 'O', 'Ȏ' => 'O', 'ŕ' => 'r', 'ř' => 'r', 'ȑ' => 'r', 'ȓ' => 'r', 'Ŕ' => 'R', 'Ř' => 'R', 'Ȑ' => 'R', 'Ȓ' => 'R', 'ß' => 'ss', 'ś' => 's', 'ŝ' => 's', 'ş' => 's', 'š' => 's', 'ș' => 's', 'Ś' => 'S', 'Ŝ' => 'S', 'Ş' => 'S', 'Š' => 'S', 'Ș' => 'S', 'ţ' => 't', 'ť' => 't', 'ŧ' => 't', 'ț' => 't', 'Ţ' => 'T', 'Ť' => 'T', 'Ŧ' => 'T', 'Ț' => 'T', 'ú' => 'u', 'ù' => 'u', 'ü' => 'ue', 'û' => 'u', 'ũ' => 'u', 'ū' => 'u', 'ŭ' => 'u', 'ů' => 'u', 'ű' => 'u', 'ų' => 'u', 'ȕ' => 'u', 'ȗ' => 'u', 'Ú' => 'U', 'Ù' => 'U', 'Ü' => 'Ue', 'Û' => 'U', 'Ũ' => 'U', 'Ū' => 'U', 'Ŭ' => 'U', 'Ů' => 'U', 'Ű' => 'U', 'Ų' => 'U', 'Ȕ' => 'U', 'Ȗ' => 'U', 'ŵ' => 'w', 'Ŵ' => 'W', 'ý' => 'y', 'ÿ' => 'y', 'ŷ' => 'y', 'Ý' => 'Y', 'Ÿ' => 'Y', 'Ŷ' => 'Y', 'ź' => 'z', 'ż' => 'z', 'ž' => 'z', 'Ź' => 'Z', 'Ż' => 'Z', 'Ž' => 'Z', ); if (strlen($string) == 0) { return ""; } // ensure UTF-8, for single-byte-encodings use either // the internal encoding or assume ISO-8859-1 $utf8string = mb_convert_encoding($string, "UTF-8", array("UTF-8", mb_internal_encoding(), "ISO-8859-1")); // replace known special chars $result = strtr($utf8string, $special_chars); // upper case $result = strtoupper($result); // make sure every special char is replaced by one space, not two or three $result = mb_convert_encoding($result, "ASCII", "UTF-8"); $result = preg_replace($this->invalidString_regexp, ' ', $result); return $result; } /** * Writes the DTA file. * * @param string $filename Filename. * * @access public * @return boolean */ function saveFile($filename) { $content = $this->getFileContent(); $Dta_fp = @fopen($filename, "w"); if (!$Dta_fp) { $result = false; } else { $result = @fwrite($Dta_fp, $content); @fclose($Dta_fp); } return $result; } /** * Returns an array with information about the transactions. * Can be used to print an accompanying document (Begleitzettel) for disks. * * @access public * @return array Returns an array with keys: "sender_name", * "sender_bank_code", "sender_account", "sum_amounts", * "count", "date" */ function getMetaData() { return array( "sender_name" => strval($this->account_file_sender['name']), "sender_bank_code" => intval($this->account_file_sender['bank_code']), "sender_account" => floatval($this->account_file_sender['account_number']), "sum_amounts" => floatval($this->sum_amounts / 100.0), "count" => intval($this->count()), "date" => $this->timestamp, ); } }