47771011f8895f5af1c5ea8edbb0ac0a2aac3e0e
[TYPO3CMS/Extensions/static_info_tables.git] / pi1 / class.tx_staticinfotables_pi1.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 *
29 * Class for handling static info tables: countries, and subdivisions, currencies, languages and taxes
30 *
31 * $Id$
32 *
33 * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
34 */
35
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 65: class tx_staticinfotables_pi1 extends tslib_pibase
42 * 94: function init($conf=array())
43 * 147: function getStaticInfoName($type='COUNTRIES', $code, $country='', $countrySubdivision='', $self=0)
44 * 211: function buildStaticInfoSelector($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1)
45 * 296: function initCountries($param='UN', $lang='', $local=FALSE, $addWhere='')
46 * 353: function initCountrySubdivisions($param, $addWhere='')
47 * 399: function initCurrencies($addWhere='')
48 * 439: function initLanguages($addWhere='')
49 * 479: function optionsConstructor($nameArray, $selectedArray=array())
50 * 500: function loadCurrencyInfo($currencyCode)
51 * 545: function formatAmount($amount, $displayCurrencyCode='')
52 * 573: function formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='')
53 * 615: function getCurrentLanguage()
54 *
55 * TOTAL FUNCTIONS: 12
56 * (This index is automatically created/updated by the extension "extdeveval")
57 *
58 */
59
60
61
62 require_once(PATH_tslib.'class.tslib_pibase.php');
63 require_once(t3lib_extMgm::extPath('static_info_tables').'class.tx_staticinfotables_div.php');
64
65 class tx_staticinfotables_pi1 extends tslib_pibase {
66
67 var $cObj; // The backReference to the mother cObj object set at call time
68 var $prefixId = 'tx_staticinfotables_pi1'; // Same as class name
69 var $scriptRelPath = 'pi1/class.tx_staticinfotables_pi1.php'; // Path to this script relative to the extension dir.
70 var $extKey = 'static_info_tables'; // The extension key.
71 var $conf = array();
72 var $currency; // default currency
73 var $currencyInfo = array();
74 var $defaultCountry;
75 var $defaultCountryZone;
76 var $defaultLanguage;
77 var $types = array('TERRITORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES');
78 var $tables = array(
79 'TERRITORIES' => 'static_territories',
80 'COUNTRIES' => 'static_countries',
81 'SUBDIVISIONS' => 'static_country_zones',
82 'CURRENCIES' => 'static_currencies',
83 'LANGUAGES' => 'static_languages',
84 'TAXES' => 'static_taxes',
85 'SUBTAXES' => 'static_taxes'
86 );
87
88 /**
89 * Initializing the class: sets the language based on the TS configuration language property
90 *
91 * @param array $conf ... overwriting setup of extension
92 * @return boolean Always returns true
93 */
94 function init($conf=array()) {
95 global $TSFE;
96
97 $this->conf = $TSFE->tmpl->setup['plugin.'][$this->prefixId.'.'];
98
99 //Get the default currency and make sure it does exist in table static_currencies
100 $this->currency = $conf['currencyCode'];
101 if (!$this->currency) {
102 $this->currency = (trim($this->conf['currencyCode'])) ? trim($this->conf['currencyCode']) : 'EUR';
103 }
104 //If not set, we use the Euro
105 if (!$this->getStaticInfoName('CURRENCIES', $this->currency)) {
106 $this->currency = 'EUR';
107 }
108 $this->currencyInfo = $this->loadCurrencyInfo($this->currency);
109
110 $this->defaultCountry = $conf['countryCode'];
111 if (!$this->defaultCountry) {
112 $this->defaultCountry = trim($this->conf['countryCode']);
113 }
114 if (!$this->getStaticInfoName('COUNTRIES', $this->defaultCountry)) {
115 $this->defaultCountry = 'DEU';
116 }
117
118 $this->defaultCountryZone = $conf['countryZoneCode'];
119 if (!$this->defaultCountryZone) {
120 $this->defaultCountryZone = trim($this->conf['countryZoneCode']);
121 }
122 if (!$this->getStaticInfoName('SUBDIVISIONS', $this->defaultCountryZone, $this->defaultCountry)) {
123 $this->defaultCountryZone = 'NRW';
124 }
125
126 $this->defaultLanguage = $conf['languageCode'];
127 if (!$this->defaultLanguage) {
128 $this->defaultLanguage = trim($this->conf['languageCode']);
129 }
130 if (!$this->getStaticInfoName('LANGUAGES', $this->defaultLanguage)) {
131 $this->defaultLanguage = 'EN';
132 }
133 return true;
134 }
135
136 /**
137 * Getting the name of a country, country subdivision, currency, language, tax
138 *
139 * @param string Defines the type of entry of the requested name: 'TERRIRORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES'
140 * @param string The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision
141 * @param string The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision, can be a comma ',' separated string, then all the single items are looked up and returned
142 * @param string The value of the country code (cn_iso_3) for which a name of type 'SUBDIVISIONS', 'TAXES' or 'SUBTAXES' is requested (meaningful only in these cases)
143 * @param string The value of the country subdivision code for which a name of type 'SUB_TAXES' is requested (meaningful only in this case)
144 * @param [type] $self: ...
145 * @return string The name of the object in the current language
146 */
147 function getStaticInfoName($type='COUNTRIES', $code, $country='', $countrySubdivision='', $self=0) {
148 global $TYPO3_DB, $TSFE;
149
150 if (in_array($type, $this->types) && trim($code)) {
151 $codeArray = t3lib_div::trimExplode(',',($code));
152
153 $table = $this->tables[$type];
154 $lang = $this->getCurrentLanguage();
155 $isoCode = array();
156 $isoCode[] = trim($code);
157
158 $nameArray = array();
159 foreach ($codeArray as $tmpisoCode) {
160 $isoCodeArray = array();
161 $isoCodeArray[] = $tmpisoCode;
162
163 switch($type) {
164 case 'TERRITORIES':
165 case 'COUNTRIES':
166 case 'CURRENCIES':
167 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
168 break;
169 case 'SUBDIVISIONS':
170 case 'TAXES':
171 $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
172 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
173 break;
174 case 'SUBTAXES':
175 $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
176 $isoCodeArray[] = trim($countrySubdivision) ? trim($countrySubdivision) : $this->defaultCountryZone;
177 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
178 break;
179 case 'LANGUAGES':
180 $isoCodeArray = t3lib_div::trimExplode( '_', $code, 1);
181 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $self);
182 break;
183 }
184 $nameArray[] = $TSFE->csConv($name, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
185 }
186 $rc = implode(',',$nameArray);
187 } else {
188 $rc = FALSE;
189 }
190 return $rc;
191 }
192
193 /**
194 * Buils a HTML drop-down selector of countries, country subdivisions, currencies or languages
195 *
196 * @param string Defines the type of entries to be presented in the drop-down selector: 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES' or 'LANGUAGES'
197 * @param string A value for the name attribute of the <select> tag
198 * @param string A value for the class attribute of the <select> tag
199 * @param array The values of the code of the entries to be pre-selected in the drop-down selector: value of cn_iso_3, zn_code, cu_iso_3 or lg_iso_2
200 * @param string The value of the country code (cn_iso_3) for which a drop-down selector of type 'SUBDIVISIONS' is requested (meaningful only in this case)
201 * @param boolean/string If set to 1, an onchange attribute will be added to the <select> tag for immediate submit of the changed value; if set to other than 1, overrides the onchange script
202 * @param string A value for the id attribute of the <select> tag
203 * @param string A value for the title attribute of the <select> tag
204 * @param string A where clause for the records
205 * @param string language to be used
206 * @param boolean $local: If set, we are looking for the "local" title field
207 * @param array additional array to be merged as key => value pair
208 * @param int max elements that can be selected. Default: 1
209 * @return string A set of HTML <select> and <option> tags
210 */
211 function buildStaticInfoSelector($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1) {
212 global $TSFE;
213
214 if ($size > 1) {
215 $multiple = ' multiple="multiple"';
216 $name .= '[]';
217 } else {
218 $multiple="";
219 }
220 if (isset($selectedArray) && !is_array($selectedArray)) {
221 $selectedArray = t3lib_div::trimExplode (',',$selectedArray);
222 }
223
224 $charset = $TSFE->renderCharset;
225 $country = trim($country);
226 $nameAttribute = (trim($name)) ? 'name="'.htmlspecialchars(trim($name),ENT_COMPAT,$charset).'" ' : '';
227 $classAttribute = (trim($class)) ? 'class="'.htmlspecialchars(trim($class),ENT_COMPAT,$charset).'" ' : '';
228 $idAttribute = (trim($id)) ? 'id="'.htmlspecialchars(trim($id),ENT_COMPAT,$charset).'" ' : '';
229 $titleAttribute = (trim($title)) ? 'title="'.htmlspecialchars(trim($title),ENT_COMPAT,$charset).'" ' : '';
230 $onchangeAttribute = '';
231 if ($submit) {
232 if ($submit == 1) {
233 $onchangeAttribute = $this->conf['onChangeAttribute'];
234 } else {
235 $onchangeAttribute = $submit;
236 }
237 $onchangeAttribute = str_replace('"', '\'', $onchangeAttribute);
238 $onchangeAttribute = tx_staticinfotables_div::quoteJSvalue($onchangeAttribute);
239 $onchangeAttribute = 'onchange='.$onchangeAttribute;
240 }
241 $selector = '<select size="'.$size.'" '.$idAttribute.$nameAttribute.$titleAttribute.$classAttribute.$onchangeAttribute.$multiple.'>'.chr(10);
242
243 switch($type) {
244 case 'COUNTRIES':
245 $nameArray = $this->initCountries('ALL',$lang,$local,$addWhere);
246 $defaultSelectedArray = array($this->defaultCountry);
247 break;
248 case 'SUBDIVISIONS':
249 $param = (trim($country) ? trim($country) : $this->defaultCountry);
250 $nameArray = $this->initCountrySubdivisions($param,$addWhere);
251 if($param == $this->defaultCountry) {
252 $defaultSelectedArray = array($this->defaultCountryZone);
253 }
254 break;
255 case 'CURRENCIES':
256 $nameArray = $this->initCurrencies($addWhere);
257 $defaultSelectedArray = array($this->currency);
258 break;
259 case 'LANGUAGES':
260 $nameArray = $this->initLanguages($addWhere);
261 $defaultSelectedArray = array($this->defaultLanguage);
262 break;
263 }
264
265 if (!$defaultSelectedArray) {
266 reset($nameArray);
267 $defaultSelectedArray = array(key($nameArray));
268 }
269 $bEmptySelected = (empty($selectedArray) || ((count($selectedArray) == 1) && empty($selectedArray[0])));
270 $selectedArray = ((!$bEmptySelected || count($mergeArray)) ? $selectedArray : $defaultSelectedArray);
271
272 if (count($mergeArray)) {
273 $nameArray = array_merge($nameArray, $mergeArray);
274 uasort($nameArray, 'strcoll');
275 }
276 if(count($nameArray) > 0) {
277 $selector .= $this->optionsConstructor($nameArray, $selectedArray);
278 $selector .= '</select>'.chr(10);
279 } else {
280 $selector = '';
281 }
282 return $selector;
283 }
284
285 /**
286 * Getting all countries into an array
287 * where the key is the ISO alpha-3 code of the country
288 * and where the value is the name of the country in the current language
289 *
290 * @param string It defines a selection: 'ALL', 'UN', 'EU'
291 * @param string language to be used
292 * @param boolean If set, we are looking for the "local" title field
293 * @param string additional WHERE clause
294 * @return array An array of names of countries
295 */
296 function initCountries($param='UN', $lang='', $local=FALSE, $addWhere='') {
297 global $TYPO3_DB, $TSFE;
298
299 $table = $this->tables['COUNTRIES'];
300 if (!$lang) {
301 $lang = $this->getCurrentLanguage();
302 }
303 $nameArray = array();
304 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang, $local);
305 $prefixedTitleFields = array();
306 $prefixedTitleFields[] = $table.'.cn_iso_3';
307 foreach ($titleFields as $titleField) {
308 $prefixedTitleFields[] = $table.'.'.$titleField;
309 }
310
311 array_unique($prefixedTitleFields);
312 $labelFields = implode(',', $prefixedTitleFields);
313 if ($param == 'UN') {
314 $where = 'cn_uno_member=1';
315 } elseif ($param == 'EU') {
316 $where = 'cn_eu_member=1';
317 } elseif ($param == 'ALL') {
318 $where = '1=1';
319 } else {
320 $where = '1=1';
321 }
322 $where .= ($addWhere ? ' AND '.$addWhere : '');
323
324 $res = $TYPO3_DB->exec_SELECTquery(
325 $labelFields,
326 $table,
327 $where.$TSFE->sys_page->enableFields($table)
328 );
329
330 while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
331 foreach ($titleFields as $titleField) {
332 if ($row[$titleField]) {
333 $nameArray[$row['cn_iso_3']] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
334 break;
335 }
336 }
337 }
338 $TYPO3_DB->sql_free_result($res);
339 uasort($nameArray, 'strcoll');
340 return $nameArray;
341 }
342
343 /**
344 * Getting all country subdivisions of a given country into an array
345 * where the key is the code of the subdivision
346 * and where the value is the name of the country subdivision in the current language
347 * You can leave the ISO code empty and use the additional WHERE clause instead of it.
348 *
349 * @param string The ISO alpha-3 code of a country
350 * @param string additional WHERE clause
351 * @return array An array of names of country subdivisions
352 */
353 function initCountrySubdivisions($param, $addWhere='') {
354 global $TYPO3_DB, $TSFE;
355
356 $table = $this->tables['SUBDIVISIONS'];
357 if (strlen($param) == 3) {
358 $country = $param;
359 $where = 'zn_country_iso_3='.$TYPO3_DB->fullQuoteStr($country,$table);
360 } else {
361 $where = '1=1';
362 }
363 $where .= ($addWhere ? ' AND '.$addWhere : '');
364 $lang = $this->getCurrentLanguage();
365 $nameArray = array();
366 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
367 $prefixedTitleFields = array();
368 foreach ($titleFields as $titleField) {
369 $prefixedTitleFields[] = $table.'.'.$titleField;
370 }
371 $labelFields = implode(',', $prefixedTitleFields);
372 $res = $TYPO3_DB->exec_SELECTquery(
373 $table.'.zn_code,'.$labelFields,
374 $table,
375 $where.
376 $TSFE->sys_page->enableFields($table)
377 );
378 while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
379 foreach ($titleFields as $titleField) {
380 if ($row[$titleField]) {
381 $nameArray[$row['zn_code']] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
382 break;
383 }
384 }
385 }
386 $TYPO3_DB->sql_free_result($res);
387 uasort($nameArray, 'strcoll');
388 return $nameArray;
389 }
390
391 /**
392 * Getting all currencies into an array
393 * where the key is the ISO alpha-3 code of the currency
394 * and where the value are the name of the currency in the current language
395 *
396 * @param string additional WHERE clause
397 * @return array An array of names of currencies
398 */
399 function initCurrencies($addWhere='') {
400 global $TYPO3_DB, $TSFE;
401
402 $where = '1=1'.($addWhere ? ' AND '.$addWhere : '');
403 $table = $this->tables['CURRENCIES'];
404 $lang = $this->getCurrentLanguage();
405 $nameArray = array();
406 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
407 $prefixedTitleFields = array();
408 foreach ($titleFields as $titleField) {
409 $prefixedTitleFields[] = $table.'.'.$titleField;
410 }
411 $labelFields = implode(',', $prefixedTitleFields);
412 $res = $TYPO3_DB->exec_SELECTquery(
413 $table.'.cu_iso_3,'.$labelFields,
414 $table,
415 $where.$TSFE->sys_page->enableFields($table)
416 );
417 while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
418 foreach ($titleFields as $titleField) {
419 if ($row[$titleField]) {
420 $nameArray[$row['cu_iso_3']] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
421 break;
422 }
423 }
424 }
425 $TYPO3_DB->sql_free_result($res);
426 uasort($nameArray, 'strcoll');
427 return $nameArray;
428 }
429
430 /**
431 * Getting all languages into an array
432 * where the key is the ISO alpha-2 code of the language
433 * and where the value are the name of the language in the current language
434 * Note: we exclude sacred and constructed languages
435 *
436 * @param string additional WHERE clause
437 * @return array An array of names of languages
438 */
439 function initLanguages($addWhere='') {
440 global $TYPO3_DB, $TSFE;
441
442 $where = '1=1'.($addWhere ? ' AND '.$addWhere : '');
443 $table = $this->tables['LANGUAGES'];
444 $lang = $this->getCurrentLanguage();
445 $nameArray = array();
446 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
447 $prefixedTitleFields = array();
448 foreach ($titleFields as $titleField) {
449 $prefixedTitleFields[] = $table.'.'.$titleField;
450 }
451 $labelFields = implode(',', $prefixedTitleFields);
452 $res = $TYPO3_DB->exec_SELECTquery(
453 $table.'.lg_iso_2,'.$table.'.lg_country_iso_2,'.$labelFields,
454 $table,
455 $where.' AND lg_sacred = 0 AND lg_constructed = 0 '.
456 $TSFE->sys_page->enableFields($table)
457 );
458 while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
459 $code = $row['lg_iso_2'].($row['lg_country_iso_2']?'_'.$row['lg_country_iso_2']:'');
460 foreach ($titleFields as $titleField) {
461 if ($row[$titleField]) {
462 $nameArray[$code] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
463 break;
464 }
465 }
466 }
467 $TYPO3_DB->sql_free_result($res);
468 uasort($nameArray, 'strcoll');
469 return $nameArray;
470 }
471
472 /**
473 * Builds a list of <option> tags
474 *
475 * @param array An array where the values will be the texts of an <option> tags and keys will be the values of the tags
476 * @param string A pre-selected value: if the value appears as a key, the <option> tag will bear a 'selected' attribute
477 * @return string A string of HTML <option> tags
478 */
479 function optionsConstructor($nameArray, $selectedArray=array()) {
480 global $TSFE;
481
482 $options = '';
483 foreach($nameArray as $value => $name) {
484 $options .= '<option value="'.$value.'"';
485 if (in_array($value, $selectedArray)) {
486 $options .= ' selected="selected"';
487 }
488 $options .= '>'.$name.'</option>'.chr(10);
489 }
490
491 return $options;
492 }
493
494 /**
495 * Loading currency display parameters from Static Info Tables
496 *
497 * @param string An ISO alpha-3 currency code
498 * @return array An array of information regarding the currrency
499 */
500 function loadCurrencyInfo($currencyCode) {
501 global $TYPO3_DB;
502
503 // Fetching the currency record
504 $this->currencyInfo['cu_iso_3'] = trim($currencyCode);
505 $this->currencyInfo['cu_iso_3'] = ($this->currencyInfo['cu_iso_3']) ? $this->currencyInfo['cu_iso_3'] : $this->currency;
506 $res = $TYPO3_DB->exec_SELECTquery(
507 '*',
508 'static_currencies',
509 'cu_iso_3='.$TYPO3_DB->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
510 );
511 // If not found we fetch the default currency!
512 if (!$TYPO3_DB->sql_num_rows($res)) {
513 $TYPO3_DB->sql_free_result($res);
514 $this->currencyInfo['cu_iso_3'] = $this->currency;
515 $res = $TYPO3_DB->exec_SELECTquery(
516 '*',
517 'static_currencies',
518 'cu_iso_3='.$TYPO3_DB->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
519 );
520 }
521 $row = $TYPO3_DB->sql_fetch_assoc($res);
522 $TYPO3_DB->sql_free_result($res);
523
524 $this->currencyInfo['cu_name'] = $this->getStaticInfoName('CURRENCIES', $this->currencyInfo['cu_iso_3']);
525 $this->currencyInfo['cu_symbol_left'] = $row['cu_symbol_left'];
526 $this->currencyInfo['cu_symbol_right'] = $row['cu_symbol_right'];
527 $this->currencyInfo['cu_decimal_digits'] = $row['cu_decimal_digits'];
528 $this->currencyInfo['cu_decimal_point'] = $row['cu_decimal_point'];
529 $this->currencyInfo['cu_thousands_point'] = $row['cu_thousands_point'];
530
531 return $this->currencyInfo;
532 }
533
534 /**
535 * Formatting an amount in the currency loaded by loadCurrencyInfo($currencyCode)
536 *
537 * '' - the currency code is not displayed
538 * 'RIGHT' - the code is displayed at the right of the amount
539 * 'LEFT' - the code is displayed at the left of the amount
540 *
541 * @param float An amount to be displayed in the loaded currency
542 * @param string A flag specifying if the the currency code should be displayed:
543 * @return string The formated amounted
544 */
545 function formatAmount($amount, $displayCurrencyCode='') {
546
547 $formatedAmount = '';
548
549 if( $displayCurrencyCode == 'LEFT' ) {
550 $formatedAmount .= $this->currencyInfo['cu_iso_3'].chr(32);
551 }
552 $formatedAmount .= $this->currencyInfo['cu_symbol_left'];
553 $formatedAmount .= number_format($amount, intval($this->currencyInfo['cu_decimal_digits']), $this->currencyInfo['cu_decimal_point'], (($this->currencyInfo['cu_thousands_point'])?$this->currencyInfo['cu_thousands_point']:chr(32)));
554 $formatedAmount .= (($this->currencyInfo['cu_symbol_right'])?chr(32):'').$this->currencyInfo['cu_symbol_right'];
555 if( $displayCurrencyCode == 'RIGHT' ) {
556 $formatedAmount .= chr(32).$this->currencyInfo['cu_iso_3'];
557 }
558
559 return $formatedAmount;
560 }
561
562 /**
563 * Formatting an address in the format specified
564 *
565 * @param string A street address
566 * @param string A city
567 * @param string A country subdivision code (zn_code)
568 * @param string A ISO alpha-3 country code (cn_iso_3)
569 * @param string A zip code
570 * @param [type] $countryCode: ...
571 * @return string The formated address using the country address format (cn_address_format)
572 */
573 function formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='') {
574 global $TYPO3_DB;
575
576 $formatedAddress = '';
577
578 // Get country name
579 $countryName = $this->getStaticInfoName('COUNTRIES', (($countryCode)?$countryCode:$this->defaultCountry));
580 if (!$countryName) {
581 return $formatedAddress;
582 }
583
584 // Get address format
585 $res = $TYPO3_DB->exec_SELECTquery(
586 'cn_address_format',
587 'static_countries',
588 'cn_iso_3='.$TYPO3_DB->fullQuoteStr(trim((($countryCode)?$countryCode:$this->defaultCountry)),'static_countries')
589 );
590 $row = $TYPO3_DB->sql_fetch_assoc($res);
591 $TYPO3_DB->sql_free_result($res);
592 $addressFormat = $row['cn_address_format'];
593
594 // Get country subdivision name
595 $countrySubdivisionName = $this->getStaticInfoName('SUBDIVISIONS', (($subdivisionCode)?$subdivisionCode:$this->defaultCountryZone), (($countryCode)?$countryCode:$this->defaultCountry));
596
597 // Format the address
598 $formatedAddress = $this->conf['addressFormat.'][$addressFormat];
599 $formatedAddress = str_replace('%street', $streetAddress, $formatedAddress);
600 $formatedAddress = str_replace('%city', $city, $formatedAddress);
601 $formatedAddress = str_replace('%zip', $zip, $formatedAddress);
602 $formatedAddress = str_replace('%countrySubdivisionCode', $subdivisionCode, $formatedAddress);
603 $formatedAddress = str_replace('%countrySubdivisionName', $countrySubdivisionName, $formatedAddress);
604 $formatedAddress = str_replace('%countryName', strtoupper($countryName), $formatedAddress);
605 $formatedAddress = implode($delim, t3lib_div::trimExplode(';', $formatedAddress, 1));
606
607 return $formatedAddress;
608 }
609
610 /**
611 * Returns the current language as iso-2-alpha code
612 *
613 * @return string 'DE', 'EN', 'DK', ...
614 */
615 function getCurrentLanguage() {
616 global $TSFE, $TYPO3_DB;
617
618 $rc = tx_staticinfotables_div::getCurrentLanguage();
619 return $rc;
620 }
621 }
622
623 if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/pi1/class.tx_staticinfotables_pi1.php']) {
624 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/pi1/class.tx_staticinfotables_pi1.php']);
625 }
626
627 ?>