113 $cacheTime = (int)(defined(
'CURRENCY_CACHE_TIME') ? CURRENCY_CACHE_TIME : CURRENCY_CACHE_DEFAULT_TIME);
114 $cacheId = self::CACHE_CURRENCY_SHORT_LIST_ID.LANGUAGE_ID;
116 if ($managedCache->read($cacheTime, $cacheId, $currencyTableName))
118 $currencyList = $managedCache->get($cacheId);
123 $currencyIterator = CurrencyTable::getList([
126 'FULL_NAME' =>
'CURRENT_LANG_FORMAT.FULL_NAME',
134 while ($currency = $currencyIterator->fetch())
136 $currency[
'FULL_NAME'] = (string)$currency[
'FULL_NAME'];
137 $currencyList[$currency[
'CURRENCY']] = $currency[
'CURRENCY']
138 . ($currency[
'FULL_NAME'] !==
'' ?
' (' . $currency[
'FULL_NAME'] .
')' :
'')
141 unset($currency, $currencyIterator);
142 $managedCache->set($cacheId, $currencyList);
145 return $currencyList;
158 $cacheTime = defined(
'CURRENCY_CACHE_TIME') ? (int)CURRENCY_CACHE_TIME : CURRENCY_CACHE_DEFAULT_TIME;
159 $cacheId = self::CACHE_CURRENCY_SYMBOL_LIST_ID.LANGUAGE_ID;
161 if ($managedCache->read($cacheTime, $cacheId, $currencyTableName))
163 $currencyList = $managedCache->get($cacheId);
167 $sanitizer = new \CBXSanitizer();
168 $sanitizer->setLevel(\CBXSanitizer::SECURE_LEVEL_LOW);
169 $sanitizer->ApplyDoubleEncode(
false);
172 $currencyIterator = CurrencyTable::getList([
175 'FORMAT_STRING' =>
'CURRENT_LANG_FORMAT.FORMAT_STRING',
183 while ($currency = $currencyIterator->fetch())
185 $showValue = $currency[
'CURRENCY'];
186 $currencyFormat = (string)$currency[
'FORMAT_STRING'];
187 if ($currencyFormat !==
'')
189 $symbol = \CCurrencyLang::applyTemplate(
'', $currencyFormat);
190 if (is_string($symbol))
192 $symbol = trim($symbol);
195 $showValue = $symbol;
199 $currencyList[$currency[
'CURRENCY']] = $sanitizer->SanitizeHtml($showValue);
202 $managedCache->set($cacheId, $currencyList);
205 return $currencyList;
218 $cacheTime = defined(
'CURRENCY_CACHE_TIME') ? (int)CURRENCY_CACHE_TIME : CURRENCY_CACHE_DEFAULT_TIME;
219 $cacheId = self::CACHE_CURRENCY_NAME_LIST_ID.LANGUAGE_ID;
221 if ($managedCache->read($cacheTime, $cacheId, $currencyTableName))
223 $currencyList = $managedCache->get($cacheId);
228 $currencyIterator = CurrencyTable::getList([
231 'FULL_NAME' =>
'CURRENT_LANG_FORMAT.FULL_NAME',
239 while ($currency = $currencyIterator->fetch())
241 $fullName = (string)$currency[
'FULL_NAME'];
242 if ($fullName ===
'')
244 $fullName = $currency[
'CURRENCY'];
247 $currencyList[$currency[
'CURRENCY']] = $fullName;
250 $managedCache->set($cacheId, $currencyList);
253 return $currencyList;
281 $installedCurrencies = Option::get(
'currency',
'installed_currencies');
282 if ($installedCurrencies ===
'')
284 $bitrix24 = Main\ModuleManager::isModuleInstalled(
'bitrix24');
287 $siteIterator = Main\SiteTable::getList([
297 $site = $siteIterator->fetch();
300 $languageID = (string)$site[
'LANGUAGE_ID'];
302 unset($site, $siteIterator);
304 if ($languageID ===
'')
309 if (!$bitrix24 && $languageID ===
'ru')
312 $languageIterator = LanguageTable::getList([
325 while ($language = $languageIterator->fetch())
327 $languageList[$language[
'ID']] = $language[
'ID'];
329 unset($language, $languageIterator);
330 if (isset($languageList[
'kz']))
334 elseif (isset($languageList[
'by']))
338 elseif (isset($languageList[
'ua']))
342 unset($languageList);
397 Option::set(
'currency',
'installed_currencies', implode(
',', $currencyList),
'');
399 return $currencyList;
403 return explode(
',', $installedCurrencies);
415 $language = static::checkLanguage($language);
419 $managedCache->clean(self::CACHE_CURRENCY_LIST_ID, $currencyTableName);
420 if (empty($language))
422 $languageIterator = LanguageTable::getList([
425 while ($oneLanguage = $languageIterator->fetch())
427 $managedCache->clean(self::CACHE_CURRENCY_LIST_ID.
'_'.$oneLanguage[
'ID'], $currencyTableName);
428 $managedCache->clean(self::CACHE_CURRENCY_SHORT_LIST_ID.$oneLanguage[
'ID'], $currencyTableName);
429 $managedCache->clean(self::CACHE_CURRENCY_SYMBOL_LIST_ID.$oneLanguage[
'ID'], $currencyTableName);
430 $managedCache->clean(self::CACHE_CURRENCY_NAME_LIST_ID.$oneLanguage[
'ID'], $currencyTableName);
432 unset($oneLanguage, $languageIterator);
436 $managedCache->clean(self::CACHE_CURRENCY_LIST_ID.
'_'.$language, $currencyTableName);
437 $managedCache->clean(self::CACHE_CURRENCY_SHORT_LIST_ID.$language, $currencyTableName);
438 $managedCache->clean(self::CACHE_CURRENCY_SYMBOL_LIST_ID.$language, $currencyTableName);
439 $managedCache->clean(self::CACHE_CURRENCY_NAME_LIST_ID.$language, $currencyTableName);
441 $managedCache->clean(self::CACHE_BASE_CURRENCY_ID, $currencyTableName);
444 global $stackCacheManager;
445 $stackCacheManager->clear(
'currency_rate');
446 $stackCacheManager->clear(
'currency_currency_lang');
487 $currency = static::getBaseCurrency();
488 if ($currency ===
'')
491 $currencyIterator = CurrencyTable::getList([
496 'filter' => ($updateCurrency ==
'' ? [] : [
'=CURRENCY' => $updateCurrency])
498 while ($existCurrency = $currencyIterator->fetch())
500 $baseRate = ($existCurrency[
'CURRENCY'] != $currency
501 ? \CCurrencyRates::getConvertFactorEx($existCurrency[
'CURRENCY'], $currency)
504 $updateResult = CurrencyTable::update($existCurrency[
'CURRENCY'], array(
'CURRENT_BASE_RATE' => $baseRate));
505 if ($updateResult->isSuccess())
509 self::EVENT_ON_AFTER_UPDATE_BASE_RATE,
511 'OLD_BASE_RATE' => (
float)$existCurrency[
'CURRENT_BASE_RATE'],
512 'CURRENT_BASE_RATE' => $baseRate,
513 'BASE_CURRENCY' => $currency,
514 'CURRENCY' => $existCurrency[
'CURRENCY'],
519 unset($updateResult);
522 unset($existCurrency, $currencyIterator);
536 if ($currency ===
false)
541 self::EVENT_ON_UPDATE_BASE_CURRENCY,
543 'NEW_BASE_CURRENCY' => $currency,
549 $conn = Main\Application::getConnection();
550 $helper = $conn->getSqlHelper();
552 $userID = (isset($USER) && $USER instanceof \CUser ? (int)$USER->getID() : 0);
555 $baseField = $helper->quote(
'BASE');
556 $dateUpdateField = $helper->quote(
'DATE_UPDATE');
557 $modifiedByField = $helper->quote(
'MODIFIED_BY');
558 $amountField = $helper->quote(
'AMOUNT');
559 $amountCntField = $helper->quote(
'AMOUNT_CNT');
560 $currencyField = $helper->quote(
'CURRENCY');
561 $query =
'update '.$tableName.
' set '.$baseField.
' = \'N\', '.
562 $dateUpdateField.
' = '.$helper->getCurrentDateTimeFunction().
', '.
563 $modifiedByField.
' = '.($userID == 0 ?
'NULL' : $userID).
564 ' where '.$currencyField.
' <> \''.$helper->forSql($currency).
'\' and
'.$baseField.' = \
'Y\'';
565 $conn->queryExecute($query);
566 $query =
'update '.$tableName.
' set '.$baseField.
' = \'Y\', '.
567 $dateUpdateField.
' = '.$helper->getCurrentDateTimeFunction().
', '.
568 $modifiedByField.
' = '.($userID == 0 ?
'NULL' : $userID).
', '.
569 $amountField.
' = 1, '.$amountCntField.
' = 1 where '.$currencyField.
' = \''.$helper->forSql($currency).
'\'';
570 $conn->queryExecute($query);
572 static::updateBaseRates();
576 self::EVENT_ON_AFTER_UPDATE_BASE_CURRENCY,
578 'NEW_BASE_CURRENCY' => $currency,
583 self::$baseCurrency =
null;