1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32:
33: 34: 35: 36: 37:
38: class Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_License extends Mage_Adminhtml_Block_System_Config_Form_Field {
39:
40: protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
41: 42: 43: 44: 45: 46:
47: $stores = Mage::app()->getStores();
48: $urls = array();
49: foreach ($stores as $store) {
50:
51: try {
52: $url = Zend_Uri_Http::fromString($store->getBaseUrl())->getHost();
53: if (!in_array($url, $urls)) {
54: $urls[] = $url;
55: }
56: } catch (Exception $ex) {
57:
58: Mage::log(sprintf('Invalid base url %s for store id %s', $store->getBaseUrl(), $store->getId()), Zend_Log::WARN);
59:
60: }
61: }
62: $date = new Zend_Date(time(), Zend_Date::TIMESTAMP);
63: $timezone = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
64: $date->setTimezone($timezone);
65:
66:
67: $license = array(
68: 'urls' => $urls,
69: 'countries' => array(
70: 'EE' => array('Y', 'Y', 'Y'),
71: 'LV' => array('T', 'T', 'T'),
72: 'LT' => array('T', 'N', 'N'),
73: ),
74: 'date' => $date->get(Zend_Date::ISO_8601),
75: 'sku' => '010125',
76: 'token' => '12346789',
77: );
78:
79: $l = $this->_getOfficeHelper()->getCarrierLicense('eabiomnivaterminal');
80:
81: $inputData = array(
82: "countryName" => Mage::getStoreConfig('general/country/default'),
83: "stateOrProvinceName" => 'N/A',
84: "localityName" => 'N/A',
85: "organizationName" => 'N/A',
86: "organizationalUnitName" => implode(',', $urls),
87: "commonName" => 'Aktsiamaailm LLC',
88: "emailAddress" => Mage::getStoreConfig('trans_email/ident_general/email'),
89: );
90: $keys = $this->_getKeypairHelper()->generateKeyPair($inputData);
91:
92: $text = 'Change license';
93: if (!$license) {
94: $text = 'Register license';
95: }
96:
97:
98: return $element->getElementHtml().'<br/>' . '<pre>'.htmlspecialchars(print_r(Mage::getStoreConfig('carriers/eabiomnivaterminal/test'), true), ENT_COMPAT | ENT_HTML401 | ENT_IGNORE).'</pre>'
99: . <<<HTML
100: <ul class="eabi_postoffice_license">
101: <li><strong>{$this->_getOfficeHelper()->__('Basic license')}</strong> {$this->_getBasicLicense($license)}</li>
102: <li><strong>{$this->_getOfficeHelper()->__('Automatic data sending')}</strong>{$this->_getDatasendLicense($license)}</li>
103: <li><strong>{$this->_getOfficeHelper()->__('Cash on delivery')}</strong>{$this->_getCodLicense($license)}</li>
104: <li><strong>{$this->_getOfficeHelper()->__('Allowed for URL-s')}</strong>{$this->_getUrlsLicense($license)}</li>
105: <li><strong> </strong><span class="change-license"><a href="">{$this->_getOfficeHelper()->__($text)}</a></span></li>
106: </ul>
107: HTML;
108: }
109:
110: protected function _getUrlsLicense($input) {
111: $urls = $input['urls'];
112: if (!count($urls)) {
113: return '<span class="no-license">'.$this->_getOfficeHelper()->__('not-licensed').'</span>';
114: }
115: return '<span class="countries">' .implode(', ', $urls).'</span>';
116: }
117: protected function _getBasicLicense($input) {
118: $result = $this->_getGenericLicense($input, 0);
119: return $result;
120: }
121:
122: protected function _getDatasendLicense($input) {
123: $result = $this->_getGenericLicense($input, 1);
124: return $result;
125: }
126:
127: protected function _getCodLicense($input) {
128: $result = $this->_getGenericLicense($input, 2);
129: return $result;
130: }
131:
132: private function _getGenericLicense($input, $index) {
133: $result = array();
134: $isTimedOut = false;
135: foreach ($input['countries'] as $countryCode => $data) {
136: $test = $data[$index];
137: if ($test == 'Y') {
138: $result[] = $this->_getCountryName($countryCode);
139: } else if ($test == 'T' && !$isTimedOut) {
140: $result[] = $this->_getCountryName($countryCode) . '-' . $this->_getOfficeHelper()->__('demo');
141: }
142: }
143: if (!count($result)) {
144: return '<span class="no-license">'.$this->_getOfficeHelper()->__('not-licensed').'</span>';
145: }
146: return '<span class="countries">' .implode(', ', $result).'</span>';
147: }
148:
149: private function _getCountryName($code) {
150: return Mage::app()->getLocale()->getCountryTranslation($code);
151: }
152:
153:
154: private function _toJson($input) {
155: return json_encode($input);
156: }
157:
158: 159: 160: 161:
162: protected function _getOfficeHelper() {
163: return Mage::helper('eabi_postoffice');
164: }
165:
166: 167: 168: 169:
170: protected function _getKeypairHelper() {
171: return Mage::helper('eabi/keypair');
172: }
173:
174:
175: 176: 177: 178:
179: protected function _getEabi() {
180: return Mage::helper('eabi');
181: }
182:
183: }
184:
185: