getActive()->getSymbol();
$currencyObject = $currencyContext->getActive();
}
$PRICE['currency_object'] = $currencyObject ?? null;
$PRICE['currency'] = $currency;
// mena
$PRICE['vat'] = $vat;
// obsahuje hodnotu dane, ktera je pro tuto polozku
// -------------------------------------------------
// pricteni dane z ceny
if ($vat != 0) {
// normalni cena s DPH
$PRICE['value_with_vat'] = calcPrice($PRICE['value_without_vat'], $vat)->value(2); // ( $PRICE['value_without_vat'] * ( 1 + ( $vat / 100 ) ) );
// cena DPH
$PRICE['value_vat'] = $PRICE['value_with_vat']->sub(toDecimal($PRICE['value_without_vat']));
} else {
$PRICE['value_vat'] = toDecimal(0);
}
// cena pred bez zaokrouhleni
$PRICE['value_with_vat_no_rounding'] = $PRICE['value_with_vat'];
$PRICE['value_without_vat_no_rounding'] = $PRICE['value_without_vat'];
return $PRICE;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @param int $discount
* @param int $vat
* @param null $IDproduct
* @param null $IDcategory
* @param null $IDproducer
*
* @return Decimal[]
*/
function formatCustomerPrice($price, $discount = 0, $vat = 0, $IDproduct = null, $IDcategory = null, $IDproducer = null, ?PriceLevel $priceLevel = null, $currency = null)
{
$discount = toDecimal($discount);
// pole, ktere se bude vracet
$PRICE['price_with_vat'] = toDecimal($price);
// normalni cena s DPH
$PRICE['price_without_vat'] = toDecimal($price);
// cena bez DPH
$currencyContext = Contexts::get(CurrencyContext::class);
if (!$currency) {
$currency = $currencyContext->getDefault();
}
$PRICE['currency_object'] = $currency;
$PRICE['currency'] = $currencyContext->getActive()->getSymbol();
// mena
$PRICE['vat'] = $vat;
// -------------------------------------------------
// sleva pro dealery
$PRICE = calcCustomerPrice($PRICE, $discount, $vat, $IDproduct, $IDcategory, $IDproducer, $priceLevel);
// -------------------------------------------------
// normalni sleva
if (!$discount->isZero() && empty($PRICE['B2B_discount'])) {
$PRICE['price_without_vat'] = calcPrice($PRICE['price_without_vat'], null, $discount);
$PRICE['price_with_vat'] = $PRICE['price_without_vat'];
}
// -------------------------------------------------
// pricteni dane z ceny
if ($vat != 0) {
// normalni cena s DPH
$PRICE['price_with_vat'] = calcPrice($PRICE['price_with_vat'], $vat);
}
// -------------------------------------------------
// rozhodnout, ktera cena se bude zapocitavat
if (!empty($PRICE['B2B_discount'])) {
$PRICE['value_with_vat'] = roundPrice($PRICE['B2B_price_with_vat']);
$PRICE['value_without_vat'] = $PRICE['value_with_vat']->removeVat($vat);
} else {
$PRICE['value_with_vat'] = roundPrice($PRICE['price_with_vat']);
$PRICE['value_without_vat'] = $PRICE['value_with_vat']->removeVat($vat);
}
// cena pred bez zaokrouhleni
$PRICE['value_with_vat_no_rounding'] = $PRICE['value_with_vat'];
$PRICE['value_without_vat_no_rounding'] = $PRICE['value_without_vat'];
// -------------------------------------------------
return $PRICE;
}
function calcCustomerPrice($PRICE, $discount, $vat, $IDproduct = null, $IDcategory = null, $IDproducer = null, ?PriceLevel $priceLevel = null)
{
if (!$priceLevel && findModule(Modules::PRICE_LEVELS)) {
/** @var \KupShop\KupShopBundle\Context\PriceLevelContext $plService */
$plService = ServiceContainer::getService(\KupShop\KupShopBundle\Context\PriceLevelContext::class);
$priceLevel = $plService->getActive();
}
if ($priceLevel) {
$PRICE['B2B_price_with_vat'] = null;
// cena s B2B slevou s dani
$PRICE['B2B_price_without_vat'] = null;
// cena s B2B slevou bez dane
$PRICE['B2B_discount'] = null;
// obsahuje hodnotu dane slevy
$PRICE['B2B_discount_unit'] = null;
// obsahuje jednotku slevy
// $discount = 0;
$B2B_discount = null;
$B2B_unit = null;
// urceni slevy podle slevy k produktu
if ($IDproduct > 0 && isset($priceLevel->products[$IDproduct])) {
$B2B_discount = $priceLevel->products[$IDproduct]['discount'];
$B2B_unit = $priceLevel->products[$IDproduct]['unit'];
} // urceni slevy podle slevy k sekci
elseif (!is_array($IDcategory) && $IDcategory > 0 && isset($priceLevel->sections[$IDcategory])) {
$B2B_discount = $priceLevel->sections[$IDcategory]['discount'];
$B2B_unit = $priceLevel->sections[$IDcategory]['unit'];
} // urceni slevy podle slevy k vyrobci
elseif ($IDproducer > 0 && isset($priceLevel->producers[$IDproducer])) {
$B2B_discount = $priceLevel->producers[$IDproducer]['discount'];
$B2B_unit = $priceLevel->producers[$IDproducer]['unit'];
} // urceni slevy pokud neni urcena sekce - dohledat sekci k produktu
else {
if ($IDproduct > 0 && (is_null($IDcategory) || is_array($IDcategory)) && !empty($priceLevel->sections)) {
if (is_null($IDcategory)) {
$IDcategory = sqlQueryBuilder()->select('id_section')->from('products_in_sections')
->where(\Query\Operator::equals(['id_product' => $IDproduct]))
->execute()->fetchAll();
$IDcategory = array_column($IDcategory, 'id_section');
}
foreach ($IDcategory as $id_section) {
if (isset($priceLevel->sections[$id_section])) {
if (is_null($B2B_discount)
|| ($priceLevel->sections[$id_section]['discount'] > $B2B_discount
&& $priceLevel->sections[$id_section]['unit'] == $B2B_unit)
|| ($priceLevel->sections[$id_section]['unit'] == 'perc'
&& $B2B_unit == 'price')
) {
$B2B_discount = $priceLevel->sections[$id_section]['discount'];
$B2B_unit = $priceLevel->sections[$id_section]['unit'];
// ulozit nalezenou informaci o zbozi
$priceLevel->products[$IDproduct]['discount'] = $B2B_discount;
$priceLevel->products[$IDproduct]['unit'] = $B2B_unit;
}
}
}
}
// urceni slevy podle vyrobce - dohledat vyrobce k produktu
if (is_null($B2B_discount) && is_null($IDproducer) && $IDproduct > 0 && !empty($priceLevel->producers)) {
$SQL3 = sqlQuery('SELECT p.producer
FROM products AS p
WHERE p.id=:id_product', ['id_product' => $IDproduct]);
while ($row = sqlFetchArray($SQL3)) {
if (isset($priceLevel->producers[$row['producer']])) {
$B2B_discount = $priceLevel->producers[$row['producer']]['discount'];
$B2B_unit = $priceLevel->producers[$row['producer']]['unit'];
}
}
sqlFreeResult($SQL3);
}
if ($range = $priceLevel->getRangeByPrice($PRICE['price_without_vat'])) {
$B2B_discount = $range['discount'];
$B2B_unit = $range['unit'];
}
}
// globalni sleva
if (is_null($B2B_discount)) {
$B2B_discount = $priceLevel->discount;
$B2B_unit = $priceLevel->unit;
}
// Sleva ze slevy
if (!$discount->isZero() && !is_null($priceLevel->discount_discount)) {
$B2B_discount = $priceLevel->discount_discount;
}
$PRICE['B2B_price_original'] = $PRICE['price_without_vat'];
$PRICE['B2B_price_original_vat'] = calcPrice($PRICE['price_without_vat'], $vat);
$currency = Contexts::get(CurrencyContext::class)->getActive();
switch ($B2B_unit) {
case 'perc':
if (!$discount->isZero()) {
if ($priceLevel->add) {
$B2B_discount = toDecimal(100)->sub(
toDecimal(100)->sub(toDecimal($B2B_discount))->mul(toDecimal(100)->sub($discount))->div(toDecimal(100)));
} else {
$B2B_discount = toDecimal($B2B_discount)->lowerThan($discount) ? $discount : $B2B_discount;
}
}
$PRICE['B2B_price_without_vat'] = calcPrice($PRICE['price_with_vat'], 0, $B2B_discount);
$PRICE['B2B_discount'] = toDecimal($B2B_discount)->round(2);
$PRICE['B2B_discount_unit'] = '%';
$PRICE['B2B_discount_name'] = $priceLevel->name;
break;
case 'price':
$PRICE['B2B_price_without_vat'] = $PRICE['price_with_vat']->sub(toDecimal($B2B_discount));
$PRICE['B2B_discount'] = toDecimal($B2B_discount);
$PRICE['B2B_discount_unit'] = $currency->getSymbol();
if ($PRICE['B2B_price_without_vat']->isNegative()) {
$PRICE['B2B_price_without_vat'] = DecimalConstants::zero();
}
break;
case 'final_price':
$PRICE['B2B_price_without_vat'] = toDecimal($B2B_discount);
$PRICE['B2B_discount'] = $PRICE['B2B_price_without_vat']->sub(toDecimal($B2B_discount));
$PRICE['B2B_discount_unit'] = $currency->getSymbol();
break;
}
$PRICE['B2B_price_with_vat'] = $PRICE['B2B_price_without_vat'];
// pricteni dane z ceny
if ($vat != 0) {
$PRICE['B2B_price_with_vat'] = calcPrice($PRICE['B2B_price_without_vat'], $vat);
// ( $PRICE['B2B_price_without_vat'] * ( 1 + ( $vat / 100 ) ) );
// normalni B2B cena s DPH
}
}
if (findModule('currencies')) {
$fields = ['B2B_price_with_vat',
'B2B_price_without_vat',
'B2B_price_original',
'B2B_price_original_vat',
'price_with_vat',
'price_without_vat',
'value_with_vat',
'value_without_vat',
'value_with_vat_no_rounding',
'value_without_vat_no_rounding',
];
foreach ($fields as $field) {
if (isset($PRICE[$field])) {
$PRICE[$field] = applyCurrency($PRICE[$field], $PRICE['currency_object']);
}
}
}
return $PRICE;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// Prepocita castu podle meny, kterou ma nastaven aktualne prihlaseny uzivatel
/**
* @deprecated Use PriceConverter
*
* @return Decimal
*/
function applyCurrency($price, $currencyObject = null)
{
$price = toDecimal($price);
$currency = Contexts::get(CurrencyContext::class)->getActive();
if ($currencyObject && $currencyObject->getId() == $currency->getId()) {
return $price;
}
if (!$currency->getRate()->equals(DecimalConstants::one())) {
$price = $price->div($currency->getRate());
}
return $price;
}
/**
* @deprecated Use PriceConverter
*
* @return Decimal
*/
function unapplyCurrency($price)
{
$price = toDecimal($price);
$currency = Contexts::get(CurrencyContext::class)->getActive();
if (!$currency->getRate()->equals(DecimalConstants::one())) {
$price = $price->mul($currency->getRate());
}
return $price;
}
$activeCurrency = null;
/**
* @return array
*
* @deprecated Pouzij CurrencyContext
*/
function getCustomerCurrency()
{
$currency = Contexts::get(CurrencyContext::class)->getActive();
return [
'name' => $currency->getName(),
'code' => $currency->getId(),
'symbol' => $currency->getSymbol(),
'price_round' => $currency->getPriceRound(),
'price_round_order' => $currency->getPriceRoundOrder(),
'price_round_direction' => $currency->getPriceRoundDirection(),
'price_precision' => $currency->getPricePrecision(),
'price_decimal_mark' => $currency->getPriceDecimalMark(),
'rate' => $currency->getRate(),
];
}
/**
* @deprecated Use ContextManager
*/
function changeCurrency($currency = 'rollback')
{
static $currency_stack = [];
global $activeCurrency;
$currencyContext = Contexts::get(CurrencyContext::class);
$activeCurrency = null;
if ($currency == 'rollback') {
$currency = array_pop($currency_stack);
} elseif (!empty($currencyContext->getActive())) {
array_push($currency_stack, $currencyContext->getActive());
}
if (is_object($currency)) {
$currencyContext->activate($currency->getId());
} else {
if ($currency == null) {
$currency = 'CZK';
}
$currencyContext->activate($currency);
}
return $currency;
}
/**
* @deprecated Use PriceLevelContext
*/
function changePriceLevel($priceLevel = null)
{
static $static_price_level = null;
global $ctrl;
if ($priceLevel === null) {
$priceLevel = $static_price_level;
} elseif (!empty($ctrl['dealerPricelevel']) && is_null($static_price_level)) {
$static_price_level = $ctrl['dealerPricelevel'];
}
$ctrl['dealerPricelevel'] = $priceLevel;
return $priceLevel;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function printPrice($PRICE, $param = [])
{
global $cfg;
$PRICE = \KupShop\KupShopBundle\Wrapper\PriceWrapper::unwrap($PRICE);
$dbcfg = Settings::getDefault();
$currencyContext = Contexts::get(CurrencyContext::class);
$currency = $currencyContext->getActive();
$source = null;
// class Price to array
if ($PRICE instanceof KupShop\KupShopBundle\Util\Price\Price) {
$source = $PRICE->getSource();
// convert currency
$price = \KupShop\KupShopBundle\Util\Price\PriceCalculator::convert($PRICE, $currency);
$ceil = ($param['ceil'] ?? null);
$round = !($ceil === false);
$PRICE = [
'value_with_vat' => $price->getPriceWithVat($round),
'value_without_vat' => $price->getPriceWithoutVat($round),
'currency' => $currency->getSymbol(),
'currency_object' => $currency,
'vat' => $price->getVat(),
];
}
// class Price to array
if ($PRICE instanceof KupShop\KupShopBundle\Util\Price\TotalPrice) {
// convert currency
$priceConverter = ServiceContainer::getService(\KupShop\I18nBundle\Util\PriceConverter::class);
$PRICE = [
'value_with_vat' => $priceConverter->convert($PRICE->getCurrency(), $currency, $PRICE->getPriceWithVat()),
'value_without_vat' => $priceConverter->convert($PRICE->getCurrency(), $currency, $PRICE->getPriceWithoutVat()),
'currency' => $currency->getSymbol(),
'currency_object' => $currency,
'vat' => 0,
];
}
// kontrola promenne $PRICE
if (!is_array($PRICE)) {
$price = toDecimal($PRICE);
$PRICE = [];
// obsahuje konecnou cenu s dani, ktera ma byt zapocitana
$PRICE['value_with_vat'] = $price;
// obsahuje konecnou cenu bez dane, ktera ma byt zapocitana
$PRICE['value_without_vat'] = $price;
// mena
if (!empty($param['currency'])) {
if ($param['currency'] instanceof \KupShop\I18nBundle\Entity\Currency) {
$currency = $param['currency'];
} else {
$currencies = $currencyContext->getAll();
if (array_key_exists($param['currency'], $currencies)) {
$currency = $currencies[$param['currency']];
}
}
}
$PRICE['currency'] = $currency->getSymbol();
$PRICE['currency_object'] = $currency;
// obsahuje hodnotu dane, ktera je pro tuto polozku
$PRICE['vat'] = 0;
}
$cond = [
'withVat' => $dbcfg['prod_show_price_vat'] == 'Y',
'ceil' => 'default',
'format' => true,
'printcurrency' => true,
'printdealerdiscount' => false,
'dealerdiscount' => true,
'decimal' => null,
];
$cond = array_merge($cond, $param);
if ($cond['withVat'] === 'dynamic') {
if (isset($_COOKIE['prices_vat'])) {
$cond['withVat'] = $_COOKIE['prices_vat'] == 'withVat';
} else {
$cond['withVat'] = $dbcfg['prod_show_price_vat'] == 'Y';
}
}
// zda pouzit cenu s / bez DPH
$price = ($cond['withVat']) ? $PRICE['value_with_vat'] : $PRICE['value_without_vat'];
if (!$cond['dealerdiscount'] && isset($PRICE['B2B_price_original'])) {
$price = ($cond['withVat']) ? $PRICE['B2B_price_original_vat'] : $PRICE['B2B_price_original'];
}
// Formatted price decimal places
$decimal = $currency->getPricePrecision();
// kdyz je format=default, tak rozhodnout podle nastaveni v DB
if ($cond['ceil'] == 'default') {
$cond['ceil'] = $currency->getPriceRound();
} elseif (!$cond['ceil']) {
$decimal = 2;
}
// Round price if set
if ($cond['ceil']) {
$price = roundPrice($price, -1, 'DB', 2, $currency, source: $source);
} else {
if ($price->round(2)->isZero() && !$price->isZero()) {
$price = roundPrice($price, 1, 'up', 4, $currency, source: $source);
}
}
if ($cond['format'] === 'float') {
return $price->asString();
}
if ($cond['decimal']) {
$decimal = $cond['decimal'];
}
// Backward compatibility if price_precision not set
if (is_null($decimal)) {
$decimal = $cond['ceil'] == 100 ? 0 : 2;
}
// Detect precision
if ($decimal == 'dynamic') {
$decimal = $price->round(2)->isInteger() ? 0 : 2;
}
$price = $price->printValue($decimal, $currency->getPriceDecimalMark());
// formatovani ceny pro vystup
if ($cond['format'] == true) {
// dopsat jednotku ceny
if ($cond['printcurrency']) {
$price_format = translate('price_format', 'functions', true) ?: ['price_value', ' ', 'currency_symbol'];
$price_format = array_map(function ($value) use ($price, $PRICE) {
return match ($value) {
'price_value' => $price,
'currency_symbol' => $PRICE['currency'],
'currency_id' => $PRICE['currency_object']->getId(),
default => $value,
};
}, $price_format);
$price = join('', $price_format);
}
// dopsat slevu dealera
if ($cond['printdealerdiscount'] && isset($PRICE['B2B_discount'])) {
$name = getVal('B2B_discount_name', $PRICE, translate('setPrice', 'functions')['b2b']);
if ($PRICE['B2B_discount_unit'] == '%') {
$price .= " ({$name}: {$PRICE['B2B_discount']}%)";
} else {
$price .= "
({$name}: {$PRICE['B2B_discount']} {$PRICE['B2B_discount_unit']})";
}
}
}
return $price;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @param $price Decimal
* @param int $roundTo
* @param string $direction
* @param int $decimal
*
* @return Decimal
*/
function roundPrice($price, $roundTo = -1, $direction = 'DB', $decimal = null, ?KupShop\I18nBundle\Entity\Currency $currency = null, $bata = null, $source = null)
{
if (!$currency) {
$currency = Contexts::get(CurrencyContext::class)->getActive();
}
if ($source) {
$params = ['price' => &$price, 'roundTo' => &$roundTo, 'direction' => &$direction, 'decimal' => &$decimal, 'currency' => &$currency, 'bata' => &$bata];
Contexts::get(CurrencyContext::class)->getSourceRounding($source, $params);
}
if (!is_a($price, 'Decimal')) {
if (is_null($price)) {
$price = '0';
}
$price = toDecimal($price);
}
// kontrola zadanych parametru
if ($roundTo == -1 || $roundTo === null) {
$roundTo = $currency->getPriceRound();
}
if ($direction == 'DB' || $direction === null) {
$direction = $currency->getPriceRoundDirection();
}
if ($decimal === null) {
$decimal = $currency->getPricePrecision();
// Detect precision
if ($decimal == 'dynamic') {
$decimal = 2;
}
}
if ($bata === null) {
$bata = $currency->getBata();
}
// Pre-round input number to avoid invalid rounding of 5.00000213 numbers
$price = $price->value(4);
if (!$roundTo) {
return $price;
}
$original_price = $price;
$price = $price->value(2);
// Pri zaporne hodnote je potreba otocit up to down, aby vysla stejna cena v plusu i v minusu
if ($price->isNegative()) {
$price = $price->abs();
}
if ($bata) {
if ($price->isZero()) {
$bata = null;
} else {
$bata = toDecimal($bata);
$price = $price->add($bata);
$decimal = 2;
}
}
// kdyz zaokrouhlovat na cela cisla
if ($roundTo == 100) {
switch ($direction) {
case 'up':
$price = $price->ceil();
break;
case 'down':
$price = $price->floor();
break;
case 'math':
$price = $price->round();
break;
}
} elseif ($roundTo == -5 || $roundTo == -10) {
$money = $price->asFloat();
switch ($direction) {
case 'up':
$money = abs($roundTo) * ceil($money / abs($roundTo));
break;
case 'down':
$money = abs($roundTo) * floor($money / abs($roundTo));
break;
case 'math':
$money = abs($roundTo) * round($money / abs($roundTo));
break;
}
$price = toDecimal($money);
} elseif ($roundTo == 50 || $roundTo == 5 || $roundTo == 25) {
// kdyz zaokrouhlovat na 50satniky
// rozdelit cenu na koruny a halere
@list($money, $groat) = explode('.', $price->printFloatValue(2));
settype($money, 'integer');
settype($groat, 'integer');
$multiplier = $roundTo == 50 ? 2 : ($roundTo == 25 ? 4 : 20);
$groat = ($groat / pow(10, $decimal)) * $multiplier;
switch ($direction) {
case 'up':
$groat = ceil($groat);
break;
case 'down':
$groat = floor($groat);
break;
case 'math':
$groat = round($groat);
break;
}
$groat = $groat / $multiplier;
if ($price->isNegative()) {
$price = toDecimal($money)->sub(toDecimal($groat));
} else {
$price = toDecimal($money)->add(toDecimal($groat));
}
} elseif ($roundTo == 10) {
// zaokrouhleni bud na halere nebo na desetniky
$decimal = 1;
switch ($direction) {
case 'up':
$price = $price->ceil($decimal);
break;
case 'down':
$price = $price->floor($decimal);
break;
case 'math':
$price = $price->round($decimal);
break;
}
}
if ($bata) {
$price = $price->sub($bata);
}
if ($original_price->isNegative() && $price->isPositive()) {
$price = $price->additiveInverse();
}
if ($price->isZero() && !$original_price->isZero()) {
if ($roundTo > 0) {
$price = toDecimal($roundTo / 100);
} else {
$price = toDecimal(-$roundTo);
}
}
return $price->value($decimal);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
if (!function_exists('getVat')) {
function getVat(&$id = null)
{
$vatContext = Contexts::get(VatContext::class);
if (is_null($id)) {
$vat = $vatContext->getDefault();
$id = $vat['id'];
} else {
$vat = $vatContext->getVat($id);
}
return $vatContext->translate($vat['vat'] ?? 0);
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
if (!function_exists('getAdminVat')) {
/**
* @return array ['value' => 21, 'id' => 1]
*/
function getAdminVat(): array
{
static $defaultVat;
if (!isset($defaultVat)) {
$qb = sqlQueryBuilder()->select('id, vat')->from('vats')
->where("is_default='Y'");
if (findModule(Modules::OSS_VATS)) {
$qb->andWhere('automanaged=0')
->orderBy('id_country');
}
$vatRow = $qb->setMaxResults(1)->execute()->fetch();
$defaultVat = [
'value' => $vatRow ? $vatRow['vat'] : 21,
'id' => $vatRow ? $vatRow['id'] : null,
];
}
return $defaultVat;
}
}
/**
* @return \KupShop\KupShopBundle\Util\Logging\SentryLogger
*
* @deprecated Use \Sentry\captureException() directly
*/
function getRaven()
{
static $client = null;
if (!$client) {
$client = ServiceContainer::getService(\KupShop\KupShopBundle\Util\Logging\SentryLogger::class);
}
return $client;
}
/**
* For debug logging only!
*/
function getLogger(): Psr\Log\LoggerInterface
{
static $logger = null;
if (!$logger) {
$logger = ServiceContainer::getService('logger');
}
return $logger;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function error_handler($errno, $errstr, $errfile, $errline, $errctx = null)
{
if (!($errno & error_reporting())) {
return;
}
if (isDevelopment()) {
return false;
}
if (isDebug()) {
// debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
exit("{$errfile}:{$errline} - Error: {$errstr}");
}
// disable logging into kibana - sentry shoul be used
// logError($errfile, $errline, "Error: {$errstr}", false);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function exception_handler($exception, $event_id = null)
{
http_response_code(500);
if (isSuperuser()) {
echo $exception->getTraceAsString();
exit("\n".$exception->getFile().':'.$exception->getLine().' - '.$exception->getMessage());
}
global $cfg;
if (getVal('SMARTY_DEBUG') || isDebug() || !empty($cfg['development'])) {
exit('Uncaught exception: '.$exception->getMessage());
}
if (!$event_id) {
$raven = getRaven();
$event_id = (string) $raven->captureException($exception);
}
logError('Exception', 0, "Uncaught exception: Event id: {$event_id}: {$exception->getMessage()}", false);
$smarty = createSmarty();
$smarty->assign([
'exception' => $exception,
'event_id' => $event_id,
'ctrl' => &$GLOBALS['ctrl'],
]);
$smarty->display('error500.tpl');
}
if (!isLocalDevelopment() && php_sapi_name() != 'cli') {
// Production
if (!findModule('components')) {
set_exception_handler('exception_handler');
}
} else {
// Local dev
ini_set('display_errors', 1);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// funkce zjistuje aktualni cas provadeni skriptu
function getScriptTime()
{
return microtime(true);
}
/**
* @deprecated Unused, delete
*/
function measureTime($name)
{
static $time = null;
if (!$time) {
$time = [$name, microtime(true)];
return;
}
wpj_debug("Time measurement '{$time[0]}: ".((microtime(true) - $time[1]) * 1000).'ms');
$time = [$name, microtime(true)];
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// funkce definuje
/**
* @deprecated Useless, delete
*/
function setStartTime()
{
if (!defined('SCRIPT_START_TIME')) {
define('SCRIPT_START_TIME', getScriptTime());
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// funkce kontroluje cas provadeni skriptu a kdyz tak prodlouzi time limit
/**
* @deprecated Useless, delete
*/
function controlTimeLimit()
{
if (!defined('SCRIPT_START_TIME')) {
return;
}
if ((getScriptTime() - SCRIPT_START_TIME) >= (ini_get('max_execution_time') - 1)) {
@set_time_limit(ini_get('max_execution_time') + 5);
// echo ini_get('max_execution_time')."
";
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Do not use, type table name directly
*/
function getTableName($name, $quote = true)
{
$old_mapping = [
'photos-products' => 'photos_products_relation',
'products-related' => 'products_related',
'products-favorites' => 'products_favorites',
'products-sections' => 'products_in_sections',
'photos_articles' => 'photos_articles_relation',
];
if (array_key_exists($name, $old_mapping)) {
return $old_mapping[$name];
}
if (strstr($name, '.') !== false) {
return $name;
}
return ($quote == true) ? '`'.$name.'`' : $name;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// funkce na monitorovani chyb v systemu
// $file = soubor, $line = radka, $text = pridavny text chyby,
// $repeatMsg = zda opakovat chybove hlaseni, nebo staci jen jednou
/**
* @deprecated Use logger directly
*/
function logError($file, $line, $text, $repeatMsg = true)
{
static $logger = null;
$logger = $logger ?? ServiceContainer::getService('logger');
$logger->error($text, ['file' => $file, 'line' => $line]);
return;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @param null $submodule
* @param null $default
*/
function findModule($module, $submodule = null, $default = null)
{
$array = &$GLOBALS['cfg']['Modules'];
if (!empty($array[$module])) {
if (is_null($submodule)) {
return true;
}
return getVal($submodule, $array[$module], $default);
} elseif (array_search($module, $array, true) === false) {
if ($default === null) {
return false;
}
return $default;
} else {
if (!is_null($default)) {
return $default;
}
return is_null($submodule);
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Use built-in Smarty template loading mechanism
*/
function findTemplate($file, $dir = 'null')
{
return $file;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Use getImage with prefetched photo id, update_date and description
*/
function leadImage($IDa, $imgType = 1, $type = 'PRODUCT')
{
$ret = null;
switch ($type) {
case 'PRODUCT':
$qb = sqlQueryBuilder()
->select('ph.id, ph.descr, ph.source, ph.image_2, ph.date_update')
->from('photos_products_relation', 'ppr')
->leftJoin('ppr', 'photos', 'ph', 'ppr.id_photo = ph.id')
->where(Translation::coalesceTranslatedFields(PhotosTranslation::class))
->andWhere('ppr.id_product=:id_product AND ppr.show_in_lead="Y" AND ppr.active="Y"')
->setParameter('id_product', $IDa)
->setMaxResults(1);
break;
case 'ARTICLE':
$qb = sqlQueryBuilder()
->select('ph.id, ph.descr, ph.source, ph.image_2, ph.date_update')
->from('photos_articles_relation', 'pa')
->leftJoin('pa', 'photos', 'ph', 'pa.id_photo = ph.id')
->where(Translation::coalesceTranslatedFields(PhotosTranslation::class))
->andWhere('pa.id_art=:id_art AND pa.show_in_lead="Y" AND pa.active="Y"')
->setParameter('id_art', $IDa)
->setMaxResults(1);
break;
}
if ($photo = $qb->execute()->fetchAssociative()) {
$ret = getImage($photo['id'], $photo['image_2'], $photo['source'], $imgType, $photo['descr'], strtotime($photo['date_update']));
}
return $ret;
}
function quickLoadImage($ID, $size, $photoId)
{
if (empty($photoId) || ($image = getImage($photoId, null, null, $size)) === false) {
$image = leadImage($ID, $size);
}
return $image;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function productCampaign($field, &$codes = null)
{
global $cfg;
$campaign = [];
$explodedCampaign = explodeFlags($field);
foreach (getCampaigns() as $flag => $name) {
if (!empty($explodedCampaign[$flag])) {
$campaign[] = $name['singular'];
$codes[$flag] = $name;
}
}
return join(' + ', $campaign);
}
function getCampaigns()
{
$cfg = Config::get();
$languageContext = Contexts::get(LanguageContext::class);
if ($languageContext->translationActive()) {
$translator = ServiceContainer::getService(\KupShop\KupShopBundle\Util\Locale\PHPArrayTranslator::class);
$campaignTranslations = [];
$translator->loadTranslations($campaignTranslations, 'campaigns', false, $languageContext->getActiveId());
if (isset($campaignTranslations['campaigns'])) {
return array_replace_recursive($cfg['Products']['Flags'], $campaignTranslations['campaigns']);
}
}
return $cfg['Products']['Flags'];
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function getCategoryFullPath($IDCat)
{
$cat_parts = getReturnNavigation($IDCat);
$category = '';
if (count($cat_parts) > 0) {
$category = join(' / ', array_map(function ($x) {
return $x['text'];
}, array_slice($cat_parts[0], 1)));
}
return $category;
}
function getCategoryUrl($IDCat, $campaign = '', $producer = '')
{
$cat_parts = getReturnNavigation($IDCat, 'ESHOP_CATEGORY', [], $campaign, $producer);
if (count($cat_parts) > 0) {
$parents = [];
foreach ($cat_parts[0] as $part) {
if (!empty($part['ID'])) {
$parents[$part['ID']] = $part['text'];
}
}
return createScriptURL([
's' => 'category',
'IDcat' => $campaign.$IDCat,
'IDpd' => $producer,
'parents' => $parents,
'TITLE' => $cat_parts[0][count($cat_parts[0]) - 1]['text'],
]);
}
return null;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function getReturnNavigation($IDcat, $type = 'ESHOP_CATEGORY', $linkplus = [], $catCampaign = '', $catProducer = '')
{
$ret_array = [];
$IDcat = intval($IDcat);
if ($IDcat > 0) {
switch ($type) {
case 'ESHOP_CATEGORY':
$section = ServiceContainer::getService(SectionTree::class)->get()->getSectionById($IDcat);
if (isset($section)) {
$retRow_array = [];
// load producer name
$catProducerTitle = '';
if (findModule(\Modules::PRODUCERS) && !empty($catProducer)) {
$qb = sqlQueryBuilder()->from('producers', 'pr')
->andWhere(\Query\Operator::equals(['pr.id' => $catProducer]))
->setMaxResults(1);
if (findModule(\Modules::TRANSLATIONS)) {
$qb->andWhere(
\Query\Translation::coalesceTranslatedFields(
\KupShop\I18nBundle\Translations\ProducersTranslation::class,
['name']
)
);
} else {
$qb->select('name');
}
$catProducerTitle = $qb->execute()->fetchColumn();
}
// add ancestor sections
foreach ($section->getParents() as $parent) {
if ($parent->getId() === $section->getId()) {
// add active section
array_push($retRow_array, [
'text' => $section->getNameShort() ? $section->getNameShort() : $section->getName(),
'ID' => $parent->getId(),
]);
} else {
array_push($retRow_array, [
'text' => $parent->getNameShort(),
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'category',
'IDcat' => $parent->getId().$catCampaign,
'IDpd' => $catProducer,
'producerTitle' => $catProducerTitle,
'TITLE' => $parent->getNameShort(),
'parents' => $parent->getParentIDs(),
]),
'ID' => $parent->getId(),
]);
}
}
// add producer
if (!empty($catProducerTitle)) {
$home = sprintf(translate('getSections', 'functions')['catalogProducer'], $catProducerTitle);
array_unshift($retRow_array, [
'text' => $home,
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'category',
'IDpd' => $catProducer,
'producerTitle' => $catProducerTitle,
'TITLE' => $home,
]),
'ID' => '0',
]);
}
array_unshift($retRow_array, [
'text' => translate('getSections', 'functions')['home'],
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]),
]);
array_push($ret_array, $retRow_array);
}
break;
case 'PRODUCT':
$retRow_array = [];
$section = ServiceContainer::getService(SectionTree::class)->get()->getSectionById($IDcat);
if (isset($section)) {
foreach ($section->getParents() as $parent) {
array_push($retRow_array, [
'text' => $parent->getNameShort(),
'section_name' => $parent->getName(),
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'category',
'IDcat' => $parent->getId().$catCampaign,
'IDpd' => $catProducer,
'TITLE' => $parent->getNameShort(),
'parents' => $parent->getParentIDs(),
]),
'ID' => $parent->getId(),
]);
}
}
array_unshift($retRow_array, [
'text' => translate('getSections', 'functions')['home'],
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]),
]);
array_push($ret_array, $retRow_array);
break;
case 'ARTICLE':
$ret_array[0] = [];
if (findModule(\Modules::ARTICLES_SECTIONS)) {
$branchID = $IDcat;
while (!empty($branchID)) {
$qb = sqlQueryBuilder()->select('ab.id, ab.top_branch')
->from('articles_branches', 'ab')
->andWhere(\Query\Operator::equals(['ab.id' => $branchID]))
->andWhere(\Query\Translation::coalesceTranslatedFields(ArticlesSectionsTranslation::class, ['name']))
->setMaxResults(1);
$qb->andWhere(Translation::joinTranslatedFields(ArticlesSectionsTranslation::class,
function (QueryBuilder $qb, $columnName, $translatedField) {
$qb->andWhere(Operator::coalesce($translatedField, 'ab.figure').' = "Y" ');
return false;
}, ['figure']));
$Row = $qb->execute()->fetch();
if ($Row) {
$branchID = $Row['top_branch'];
$Name = $Row['name'];
$IDCatCurr = $Row['id'];
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'articles',
'IDb' => $IDCatCurr,
'TITLE' => $Name,
]);
array_unshift($ret_array[0], [
'text' => $Name,
'link' => $url,
'IDb' => $IDCatCurr,
]);
} else {
break;
}
}
} else {
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'articles',
]);
array_unshift($ret_array[0], [
'text' => translate('getSections', 'functions')['articles'],
'link' => $url,
]);
}
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]);
array_unshift($ret_array[0],
[
'text' => translate('getSections', 'functions')['home'],
'link' => $url,
]/*,
[
"text"=>translate('getSections', 'functions')['articles'],
"link"=>$url . "clanky/"
]*/
);
break;
case 'ARTICLES_BRANCHES':
$ret_array[0] = [];
$i = 0;
while (!empty($IDcat)) {
$qb = sqlQueryBuilder()->select('ab.id, ab.top_branch')
->from('articles_branches', 'ab')
->andWhere(\Query\Operator::equals(['ab.id' => $IDcat]))
->andWhere(\Query\Translation::coalesceTranslatedFields(ArticlesSectionsTranslation::class, ['name']))
->setMaxResults(1);
$qb->andWhere(Translation::joinTranslatedFields(ArticlesSectionsTranslation::class,
function (QueryBuilder $qb, $columnName, $translatedField) {
$qb->andWhere(Operator::coalesce($translatedField, 'ab.figure').' = "Y" ');
return false;
}, ['figure']));
$Row = $qb->execute()->fetch();
if ($Row) {
if ($i > 0) {
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'articles',
'IDb' => $IDcat,
'TITLE' => $Row['name'],
]);
array_unshift($ret_array[0], [
'text' => $Row['name'],
'link' => $url,
]);
} else {
array_unshift($ret_array[0], [
'text' => $Row['name'],
]);
}
$IDcat = $Row['top_branch'];
} else {
break;
}
$i++;
}
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]);
array_unshift(
$ret_array[0],
['text' => translate('getSections', 'functions')['home'], 'link' => $url]/*,
[ "text"=>translate('getSections', 'functions')['articles']]*/
);
break;
case 'PAGE':
$id_link = sqlQueryBuilder()->select('parent')
->from('menu_links')
->where(Operator::equals(['id' => $IDcat]))
->orderBy('parent', 'ASC')
->execute()->fetchColumn();
$ret_array[0] = [];
while ($id_link > 0) {
$qb = sqlQueryBuilder()->select('ml.id, ml.parent, ml.name, ml.url')
->from('menu_links', 'ml')
->andWhere(\Query\Operator::equals(['ml.id' => $id_link]))
->andWhere(Operator::equals(['ml.type' => MenuUtil::TYPE_PAGE]))
->andWhere(\Query\Translation::coalesceTranslatedFields(\KupShop\I18nBundle\Translations\MenuLinksTranslation::class, ['name', 'url']))
->setMaxResults(1);
$row = $qb->execute()->fetch();
if ($row) {
if ($id_link == $row['parent']) {
break;
}
$id_link = $row['parent'];
array_unshift($ret_array[0], [
'text' => $row['name'],
'link' => '/'.ltrim($row['url']),
]);
} else {
break;
}
}
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]);
array_unshift($ret_array[0], [
'text' => translate('getSections', 'functions')['home'],
'link' => $url,
]);
break;
}
} else {
// IDcat = 0
switch ($type) {
case 'ESHOP_CATEGORY':
$ret_array[0] = [];
$catProducerTitle = '';
if (!empty($catProducer)) {
$catProducerTitle = returnSQLResult('SELECT name
FROM '.getTableName('producers').'
WHERE id='.intval($catProducer).' LIMIT 1');
}
if (!empty($catProducer)) {
$home = sprintf(translate('getSections', 'functions')['catalogProducer'], $catProducerTitle);
} elseif ($catCampaign) {
$titles = translate('title', 'category');
switch ($catCampaign) {
case 'F':
$home = $titles['favorites'];
break;
case 'W':
$home = $titles['watchdog'];
break;
case 'N':
$home = $titles['news'];
break;
case 'A':
$home = $titles['sale'];
break;
case 'D':
$home = $titles['campaign'];
break;
case 'M':
$home = $titles['newsletter'];
break;
}
} else {
$home = translate('getSections', 'functions')['catalog'];
}
if (!empty($home)) {
array_unshift($ret_array[0], [
'text' => $home,
]);
}
array_unshift($ret_array[0], [
'text' => translate('getSections', 'functions')['home'],
'link' => createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]),
]);
break;
case 'ARTICLES_BRANCHES':
$ret_array[0] = [];
array_unshift($ret_array[0],
['text' => translate('getSections', 'functions')['home'], 'link' => '/'],
['text' => translate('getSections', 'functions')['articles']]
);
break;
case 'USER':
$ret_array[0] = [];
$url = path('account');
array_unshift($ret_array[0], [
'text' => translate('title', 'account'),
'link' => $url,
]);
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]);
array_unshift($ret_array[0], [
'text' => translate('getSections', 'functions')['home'],
'link' => $url,
]);
break;
case 'RECLAMATION':
array_unshift($linkplus, [
'text' => translate('reclamations', 'reclamations'),
'link' => path('kupshop_reclamations_reclamations_reclamations'),
]);
if (\User::getCurrentUserId()) {
return getReturnNavigation(-1, 'USER', $linkplus);
} else {
return getReturnNavigation(-1, 'NO_TYPE', $linkplus);
}
// no break
case 'RETURN':
array_unshift($linkplus, [
'text' => translate('returns_title', 'returns'),
'link' => path('kupshop_returns_returns_returns'),
]);
if (\User::getCurrentUserId()) {
return getReturnNavigation(-1, 'USER', $linkplus);
} else {
return getReturnNavigation(-1, 'NO_TYPE', $linkplus);
}
// no break
case 'NO_TYPE':
$ret_array[0] = [];
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'index',
]);
array_unshift($ret_array[0], [
'text' => translate('getSections', 'functions')['home'],
'link' => $url,
]);
break;
}
}
if ($type != 'ESHOP_CATEGORY' && $linkplus) {
foreach ($linkplus as $link) {
if (!is_array($link)) {
$link = ['text' => $link];
}
$ret_array[0][] = $link;
}
}
return $ret_array;
}
/**
* @deprecated Use Symfony Request, getClientIp method
*/
function getIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // if from shared
return $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // if from a proxy
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'] ?? '';
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function stripTags($String, $Convert = false, $NL = '\r\n')
{
if ($Convert) {
$String = preg_replace("@((
)|<\/p>)@i", $NL, $String);
}
$String = preg_replace('/(<[^>]*>)/i', ' ', $String);
if ($Convert) {
$String = str_replace(' ', ' ', $String);
$String = str_replace('"', '"', $String);
$String = str_replace('>', '>', $String);
$String = str_replace('<', '<', $String);
$String = str_replace('&', '&', $String);
}
$String = preg_replace('/( )+/i', ' ', $String);
$String = trim($String);
return $String;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated in favour of \KupShop\KupShopBundle\Util\StringUtil::normalizeWhitespace()
*
* @return string|string[]|null
*/
function CutString($String)
{
$String = trim($String);
$String = preg_replace("/[\t\r\n]/i", '', $String);
$String = preg_replace('/( )+/i', ' ', $String);
return $String;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// vybere polozku ze selectoveho menu
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function CheckSelect($Value1, $Value2)
{
if ($Value1 == $Value2) {
return ' selected="selected"';
} else {
return '';
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// zaskrtne checkbox
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function CheckRadio($Value1, $Value2)
{
if ($Value1 == $Value2) {
return ' checked="checked"';
} else {
return '';
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function setCookies($Name, $Value, $Expiry = 2592000, $options = [])
{
if (isFunctionalTests()) {
return true;
}
$time = null;
if ($Expiry < 0) { // Remove
$Value = '';
unset($_COOKIE[$Name]);
} else {
$_COOKIE[$Name] = $Value;
}
if (!is_null($Expiry)) {
$time = time() + $Expiry;
}
setcookie($Name, $Value, array_merge([
'expires' => $time,
'path' => '/',
'secure' => true,
'samesite' => 'Lax',
], $options));
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Unused, delete
*/
function ShortText($Text, $Reduce)
{
$Word = preg_split('/[[:blank:]]+/', $Text);
$NoWords = count($Word);
$Length = 0;
$RtrnText = '';
for ($i = 0; $i < $NoWords; $i++) {
$RtrnText .= $Word[$i].' ';
$Length = strlen($RtrnText);
if ($Length + 3 + strlen($Word[$i]) >= $Reduce) {
break;
}
}
if (strlen($RtrnText) >= $Reduce) {
$RtrnText = substr($RtrnText, 0, $Reduce - 3);
}
if (strlen($Text) > strlen($RtrnText)) {
$RtrnText .= '...';
}
return wordwrap($RtrnText, 60, "\n", 1);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Unused, delete
*/
function getInputsFromString($String, $ex1, $ex2, $except = [])
{
$return = '';
$Input = explode($ex1, $String);
for ($i = 0; $i < count($Input); $i++) {
if ($Input[$i] != '') {
$data = explode($ex2, $Input[$i]);
if (array_search($data[0], $except) === false) {
$return .= '';
}
}
}
return $return;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// FUNKCE: pridava vytvari URL odkazu bud klasickou nebo SEO friendly
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
if (!function_exists('createScriptURL')) {
function createScriptURL($params)
{
/** @var $legacyUrlGenerator \KupShop\KupShopBundle\Util\LegacyUrlGenerator */
$legacyUrlGenerator = ServiceContainer::getService(\KupShop\KupShopBundle\Util\LegacyUrlGenerator::class);
return $legacyUrlGenerator->generate($params);
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// FUNKCE: pridava do vytvarene URL dalsi parametry
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function createScriptURL_Next_Params($SEO_URL, $params)
{
if (count($params) == 0) {
return $SEO_URL;
}
// zda se ma URL Encodovat
$ENCODE_URL = !empty($params['ESCAPE']) && ($params['ESCAPE'] != 'NO');
unset($params['ESCAPE']);
$QS = '';
foreach ($params as $param => $value) {
if ($param != 'URL' && $param != 'TITLE') {
if ($ENCODE_URL) {
$value = urlencode($value);
}
$QS .= '&'.$param.'='.$value;
}
}
if ($QS != '') {
if (strpos($SEO_URL, '?') === false) {
$SEO_URL .= '?';
$QS = substr($QS, 1);
}
if ($ENCODE_URL) {
$QS = htmlspecialchars($QS);
}
$SEO_URL .= $QS;
}
return $SEO_URL;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// FUNKCE: vytvari ze stringu SEO friendly URL
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Use StringUtil::slugify
*/
function createScriptURL_Text($string)
{
return \KupShop\KupShopBundle\Util\StringUtil::slugify($string);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Do nothing
*/
function sqlConnect()
{
return true;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @param array $params
* @param array $types
*
* @return \Doctrine\DBAL\Statement
*/
function sqlQuery($Query, $params = '', $types = [])
{
if (is_array($params)) {
return sqlQueryParams($Query, $params, $types);
}
wpj_debug($Query);
$stmt = sqlGetConnection()->query($Query);
return $stmt;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function sqlQueryParams($Query, $params = [], $types = [])
{
wpj_debug([$Query, $params]);
$stmt = sqlGetConnection()->executeQuery($Query, $params, $types);
return $stmt;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Unused, delete
*/
function sqlError($stmt, $logError = true, $printError = true, $exit = true, $msg = '')
{
// jinak chybu aspon zalogovat
if ($logError) {
$error = 'MySQL Error: '.print_r($stmt->errorInfo(), true);
if ($msg != '') {
$error .= "\r\nSQL: ".$msg;
}
// $error .= print_r(debug_backtrace(), true);
logError(__FILE__, __LINE__, $error);
}
// vypsat hlasku a ukoncit
if ($printError) {
echo "Database Error:
{$error}";
}
// ukoncit skript
if ($exit) {
exit;
}
return true;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function sqlPrepare($Query)
{
wpj_debug([$Query]);
$stmt = sqlGetConnection()->prepare($Query);
return $stmt;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
function sqlExecute($stmt, $params)
{
wpj_debug([$stmt, $params]);
$stmt->execute($params);
return $stmt;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @param $stmt \Doctrine\DBAL\Statement
*
* @return int
*/
function sqlNumRows($stmt)
{
if (!$stmt) {
return 0;
}
return $stmt->rowCount();
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/**
* @deprecated Unused, delete
*/
function sqlNumFields($stmt)
{
if (($user = getAdminUser()) && $user['id'] === 0) {
exit('