first commit
This commit is contained in:
160
admin/settings.php
Normal file
160
admin/settings.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
// ##############################################################
|
||||
use KupShop\AdminBundle\Util\ActivityLog;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
$main_class = 'ShopSettings';
|
||||
|
||||
class ShopSettings extends Window
|
||||
{
|
||||
protected $template = 'window/settings.tpl';
|
||||
|
||||
public function get_vars()
|
||||
{
|
||||
$vars = parent::get_vars();
|
||||
|
||||
$settings = Settings::createFromDB(null, true);
|
||||
|
||||
if (isset($settings['cat_show_cells'])) {
|
||||
$settings['cat_show_products'] = $settings['cat_show_cells'] * $settings['cat_show_rows'];
|
||||
}
|
||||
|
||||
$pageVars['data']['customSettings'] = $settings->getCustomSettings();
|
||||
foreach ($pageVars['data']['customSettings'] as $name => $setting) {
|
||||
$pageVars['customSettingsGroups'][getVal('group', $setting, 'Ostatní')][$name] = $setting;
|
||||
}
|
||||
|
||||
$pageVars['data']['ymlCustomSettings'] = $settings->getYmlCustomSettings();
|
||||
foreach ($pageVars['data']['ymlCustomSettings'] as $name => $setting) {
|
||||
$pageVars['ymlCustomSettingsGroups'][getVal('group', $setting, 'Ostatní')][$name] = $setting;
|
||||
}
|
||||
|
||||
$settings->id = 0;
|
||||
$pageVars['data'] = $settings;
|
||||
|
||||
$vars['body'] = $pageVars;
|
||||
$vars['type'] = 'settings';
|
||||
|
||||
$vars['state'] = $this->generateRandomString(8);
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function generateRandomString($length = 10)
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
global $dbcfg, $cfg;
|
||||
$data = getVal('data');
|
||||
$Submit = getVal('Submit');
|
||||
$disabled = getVal('disable_autoload');
|
||||
if (!empty($data) && !empty($Submit)) {
|
||||
$settings = Settings::createFromDB(null, true);
|
||||
|
||||
$customSettings = $settings->getCustomSettings();
|
||||
|
||||
foreach ($customSettings as $group => $setting) {
|
||||
if (!isset($data[$group]) && $setting['type'] == 'bool') {
|
||||
$data[$group] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$customYmlSettings = $settings->getYmlCustomSettings();
|
||||
|
||||
foreach ($customYmlSettings as $group => $setting) {
|
||||
if (!isset($data['custom'][$group]) && $setting['type'] == 'bool') {
|
||||
$data['custom'][$group] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$productTemplates = [];
|
||||
foreach ($data['product_templates'] as $template) {
|
||||
if (!empty($template['name']) && empty($template['delete'])) {
|
||||
$productTemplates[] = $template;
|
||||
}
|
||||
}
|
||||
|
||||
$data['product_templates'] = $productTemplates;
|
||||
|
||||
$data['shop_orders_finished'] = $this->prepareDate($data['shop_orders_finished']);
|
||||
|
||||
if (!empty($data['currencies'])) {
|
||||
foreach ($data['currencies'] as &$currency) {
|
||||
$this->preparePrice($currency['value']);
|
||||
}
|
||||
}
|
||||
|
||||
// trim all values in array
|
||||
array_walk_recursive($data, function (&$value) {
|
||||
$value = trim($value);
|
||||
});
|
||||
|
||||
$activityLog = ServiceContainer::getService(ActivityLog::class);
|
||||
$activityLog->addDifferencialActivityLog(ActivityLog::SEVERITY_NOTICE, ActivityLog::TYPE_CHANGE, 'Upraveno nastavení e-shopu.', (array) $settings, $data);
|
||||
|
||||
$settings->loadFromArray($data);
|
||||
|
||||
if (isset($settings['cat_show_cells'])) {
|
||||
unset($settings->cat_show_cells);
|
||||
unset($settings->cat_show_rows);
|
||||
}
|
||||
|
||||
if ($settings->saveToDB(null, $disabled)) {
|
||||
$ErrStr = $GLOBALS['txt_str']['status']['saved'];
|
||||
} else {
|
||||
$ErrStr = $GLOBALS['txt_str']['status']['scripterror'];
|
||||
}
|
||||
|
||||
$this->handleTabs(true);
|
||||
|
||||
MenuSectionTree::invalidateCache();
|
||||
\Settings::clearCache();
|
||||
|
||||
redirect('launch.php?s=settings.php&acn=edit&flap='.getVal('flap').'&ErrStr='.$ErrStr);
|
||||
} else {
|
||||
$this->handleTabs();
|
||||
Base::handle();
|
||||
}
|
||||
}
|
||||
|
||||
public function handleSyncCNB()
|
||||
{
|
||||
try {
|
||||
CNB::updateCurrencies();
|
||||
|
||||
$this->returnOK('Sesynchronizováno');
|
||||
} catch (Exception $e) {
|
||||
$this->returnError("Chyba při synchronizaci: {$e->getMessage()}");
|
||||
}
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
/** @var \KupShop\KupShopBundle\Util\Mail\Email $emailService */
|
||||
$email = ServiceContainer::getService("KupShop\KupShopBundle\Util\Mail\Email");
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
public function hasRights($name = null)
|
||||
{
|
||||
switch ($name) {
|
||||
case Window::RIGHT_DUPLICATE:
|
||||
case Window::RIGHT_DELETE:
|
||||
return false;
|
||||
default:
|
||||
return parent::hasRights($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user