Your IP : 216.73.217.49


Current Path : /var/www/amortar/data/www/amg174.ru-copy/bitrix/modules/intec.regionality/
Upload File :
Current File : /var/www/amortar/data/www/amg174.ru-copy/bitrix/modules/intec.regionality/options.php

<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die() ?>
<?php

use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Config\Option;
use intec\Core;
use intec\core\helpers\ArrayHelper;
use intec\core\helpers\Html;
use intec\core\helpers\Type;

/**
 * @global CMain $APPLICATION
 */

Loc::loadMessages(__FILE__);

$sModule = 'intec.regionality';
$arSettings = include(__DIR__.'/settings.php');

if (!Loader::includeModule('intec.core'))
    return;

if (!Loader::includeModule($sModule))
    return;

IntecRegionality::Initialize();

$oRequest = Core::$app->request;
$sRights = $APPLICATION->GetGroupRight($sModule);

if ($sRights >= 'R') {
    $bApply = !empty($_REQUEST['Apply']);
    $bReset = !empty($_REQUEST['Reset']);

    $arTabs = [[
        'DIV' => 'common',
        'TAB' => Loc::getMessage('intec.regionality.options.tabs.common'),
        'ICON' => 'settings',
        'TITLE' => Loc::getMessage('intec.regionality.options.tabs.common')
    ]];

    if ($oRequest->getIsPost() && check_bitrix_sessid() && ($bApply || $bReset)) {
        $arOptions = $_REQUEST['Options'];

        foreach ($arSettings as $sCode => $arSetting) {
            $sType = ArrayHelper::getValue($arSetting, 'type');
            $sValue = ArrayHelper::getValue($arOptions, [$sCode]);

            if ($bReset)
                $sValue = ArrayHelper::getValue($arSetting, 'default');

            if ($sType == 'boolean') {
                $sValue = Type::toBoolean($sValue) ? 1 : 0;
            } if ($sType == 'integer') {
                $sValue = Type::toInteger($sValue);
            } else if ($sType == 'float') {
                $sValue = Type::toFloat($sValue);
            } else if ($sType == 'list') {
                $arValues = ArrayHelper::getValue($arSetting, 'values');
                $arValues = ArrayHelper::getKeys($arValues);

                if (!Type::isArray($arValues))
                    $arValues = [];

                $sValue = ArrayHelper::fromRange($arValues, $sValue);
            }

            Option::set($sModule, $sCode, $sValue, false);
        }
    }

    $oTabControl = new CAdminTabControl('Settings', $arTabs);
?>
    <form method="POST">
        <?= bitrix_sessid_post() ?>
        <?php $oTabControl->Begin() ?>
        <?php $oTabControl->BeginNextTab() ?>
            <tr>
                <td>
                    <table class="adm-detail-content-table edit-table">
                        <?php foreach ($arSettings as $sCode => $arSetting) { ?>
                        <?php
                            $sKey = 'Options['.Html::encode($sCode).']';
                            $sName = ArrayHelper::getValue($arSetting, 'name');
                            $sType = ArrayHelper::getValue($arSetting, 'type');
                            $sDefault = ArrayHelper::getValue($arSetting, 'default');
                            $sValue = Option::get($sModule, $sCode, $sDefault, false);
                            $arValues = [];

                            if ($sType == 'list') {
                                $arValues = ArrayHelper::getValue($arSetting, 'values');

                                if (!Type::isArray($arValues))
                                    $arValues = [];
                            }
                        ?>
                            <tr>
                                <td class="adm-detail-content-cell-l" style="width: 50%;">
                                    <?= Html::encode($sName) ?>:
                                </td>
                                <td class="adm-detail-content-cell-r" style="width: 50%;">
                                    <?php if ($sType == 'boolean') { ?>
                                        <?= Html::hiddenInput($sKey, 0) ?>
                                        <?= Html::checkbox($sKey, $sValue, [
                                            'value' => 1
                                        ]) ?>
                                    <?php } else if ($sType == 'string' || $sType == 'integer' || $sType == 'float') { ?>
                                        <input type="text" name="<?= $sKey ?>" value="<?= $sValue ?>" />
                                    <?php } else if ($sType == 'list') { ?>
                                        <select name="<?= $sKey ?>">
                                            <?php foreach ($arValues as $sValueKey => $sValueName) { ?>
                                                <option value="<?= Html::encode($sValueKey) ?>"<?= $sValue == $sValueKey ? ' selected="selected"' : ''?>>
                                                    <?= Html::encode($sValueName) ?>
                                                </option>
                                            <?php } ?>
                                        </select>
                                    <?php } ?>
                                </td>
                            </tr>
                        <?php } ?>
                    </table>
                </td>
            </tr>
        <?php $oTabControl->Buttons() ?>
            <input type="submit" class="adm-btn-save" name="Apply" value="<?= Loc::getMessage('intec.regionality.options.buttons.apply') ?>" />
            <input type="submit" name="Reset" value="<?= Loc::getMessage('intec.regionality.options.buttons.reset') ?>" />
        <?php $oTabControl->End() ?>
    </form>
<?php } ?>