/**
  * @return string
  */
 public static function getDatetimeExpressionTemplate()
 {
     if (self::$datetimeTemplate === null) {
         $helper = Application::getConnection()->getSqlHelper();
         $format = Context::getCurrent()->getCulture()->getDateTimeFormat();
         $datetimeFieldName = '#FIELD#';
         $datetimeField = $datetimeFieldName;
         if (\CTimeZone::Enabled()) {
             $diff = \CTimeZone::GetOffset();
             if ($diff != 0) {
                 $datetimeField = $helper->addSecondsToDateTime($diff, $datetimeField);
             }
             unset($diff);
         }
         self::$datetimeTemplate = str_replace(array('%', $datetimeFieldName), array('%%', '%1$s'), $helper->formatDate($format, $datetimeField));
         unset($datetimeField, $datetimeFieldName, $format, $helper);
     }
     return self::$datetimeTemplate;
 }
 /**
  * Update base currency.
  *
  * @param string $currency			Currency id.
  * @return bool
  */
 public static function updateBaseCurrency($currency)
 {
     /** @global \CUser $USER */
     global $USER;
     $currency = CurrencyManager::checkCurrencyID($currency);
     if ($currency === false) {
         return false;
     }
     $event = new Main\Event('currency', self::EVENT_ON_UPDATE_BASE_CURRENCY, array('NEW_BASE_CURRENCY' => $currency));
     $event->send();
     unset($event);
     $conn = Main\Application::getConnection();
     $helper = $conn->getSqlHelper();
     $userID = isset($USER) && $USER instanceof \CUser ? (int) $USER->getID() : 0;
     $tableName = $helper->quote(CurrencyTable::getTableName());
     $baseField = $helper->quote('BASE');
     $dateUpdateField = $helper->quote('DATE_UPDATE');
     $modifiedByField = $helper->quote('MODIFIED_BY');
     $amountField = $helper->quote('AMOUNT');
     $amountCntField = $helper->quote('AMOUNT_CNT');
     $currencyField = $helper->quote('CURRENCY');
     $query = 'update ' . $tableName . ' set ' . $baseField . ' = \'N\', ' . $dateUpdateField . ' = ' . $helper->getCurrentDateTimeFunction() . ', ' . $modifiedByField . ' = ' . ($userID == 0 ? 'NULL' : $userID) . ' where ' . $currencyField . ' <> \'' . $helper->forSql($currency) . '\' and ' . $baseField . ' = \'Y\'';
     $conn->queryExecute($query);
     $query = 'update ' . $tableName . ' set ' . $baseField . ' = \'Y\', ' . $dateUpdateField . ' = ' . $helper->getCurrentDateTimeFunction() . ', ' . $modifiedByField . ' = ' . ($userID == 0 ? 'NULL' : $userID) . ', ' . $amountField . ' = 1, ' . $amountCntField . ' = 1 where ' . $currencyField . ' = \'' . $helper->forSql($currency) . '\'';
     $conn->queryExecute($query);
     static::updateBaseRates();
     $event = new Main\Event('currency', self::EVENT_ON_AFTER_UPDATE_BASE_CURRENCY, array('NEW_BASE_CURRENCY' => $currency));
     $event->send();
     unset($event);
     self::$baseCurrency = '';
     return true;
 }