00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_System_Currency_Rate_Matrix extends Mage_Adminhtml_Block_Template
00035 {
00036 public function __construct()
00037 {
00038 $this->setTemplate('system/currency/rate/matrix.phtml');
00039 }
00040
00041 protected function _prepareLayout()
00042 {
00043 $newRates = Mage::getSingleton('adminhtml/session')->getRates();
00044 Mage::getSingleton('adminhtml/session')->unsetData('rates');
00045
00046 $currencyModel = Mage::getModel('directory/currency');
00047 $currencies = $currencyModel->getConfigAllowCurrencies();
00048 $defaultCurrencies = $currencyModel->getConfigBaseCurrencies();
00049 $oldCurrencies = $this->_prepareRates($currencyModel->getCurrencyRates($defaultCurrencies, $currencies));
00050
00051 foreach( $currencies as $currency ) {
00052 foreach( $oldCurrencies as $key => $value ) {
00053 if( !array_key_exists($currency, $oldCurrencies[$key]) ) {
00054 $oldCurrencies[$key][$currency] = '';
00055 }
00056 }
00057 }
00058
00059 foreach( $oldCurrencies as $key => $value ) {
00060 ksort($oldCurrencies[$key]);
00061 }
00062
00063 sort($currencies);
00064
00065 $this->setAllowedCurrencies($currencies)
00066 ->setDefaultCurrencies($defaultCurrencies)
00067 ->setOldRates($oldCurrencies)
00068 ->setNewRates($this->_prepareRates($newRates));
00069
00070 return parent::_prepareLayout();
00071 }
00072
00073 protected function getRatesFormAction()
00074 {
00075 return $this->getUrl('*/*/saveRates');
00076 }
00077
00078 protected function _prepareRates($array)
00079 {
00080 if( !is_array($array) ) {
00081 return $array;
00082 }
00083
00084 foreach ($array as $key => $rate) {
00085 foreach ($rate as $code => $value) {
00086 $parts = explode('.', $value);
00087 if( sizeof($parts) == 2 ) {
00088 $parts[1] = str_pad(rtrim($parts[1], 0), 4, '0', STR_PAD_RIGHT);
00089 $array[$key][$code] = join('.', $parts);
00090 } elseif( $value > 0 ) {
00091 $array[$key][$code] = number_format($value, 4);
00092 } else {
00093 $array[$key][$code] = null;
00094 }
00095 }
00096 }
00097 return $array;
00098 }
00099 }