Instantly share code, notes, and snippets.
Created
August 28, 2023 15:06
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save eagles038/61be99bc829839d0410d25d085cc3d54 to your computer and use it in GitHub Desktop.
Добавление пункта в меню админки и страница настроек
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // добавляем в init.php | |
| <?php | |
| AddEventHandler('main', 'OnBuildGlobalMenu', 'addMenuItem'); | |
| function addMenuItem(&$aGlobalMenu, &$aModuleMenu) | |
| { | |
| global $USER; | |
| if ($USER->IsAdmin()) { | |
| $aGlobalMenu['global_menu_custom'] = [ | |
| 'menu_id' => 'custom', | |
| 'text' => 'Настройки сайта', | |
| 'title' => 'Настройки сайта', | |
| 'url' => '/local/admin/settings.php?lang=".LANG,', | |
| 'sort' => 10, | |
| 'items_id' => 'global_menu_custom', | |
| 'help_section' => 'custom', | |
| 'items' => [ | |
| [ | |
| 'parent_menu' => 'global_menu_custom', | |
| 'sort' => 20, | |
| 'url' => '/local/admin/settings.php?lang=ru', | |
| 'text' => 'Страница настроек', | |
| 'title' => 'Страница настроек', | |
| 'icon' => 'fav_menu_icon_2', | |
| 'page_icon' => 'fav_menu_icon_2', | |
| 'items_id' => 'menu_custom', | |
| ], | |
| ], | |
| ]; | |
| } | |
| } | |
| // добавил файл | |
| /local/admin/settings.php | |
| <?php | |
| require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_before.php'); | |
| use \Bitrix\Main\Config\Option; | |
| $tabs[] = ['DIV' => 'customSettings', 'TAB' => 'Страница настроек', 'TITLE' => 'Страница настроек']; | |
| $tabControl = new \CAdminTabControl('customSettingsTabControl', $tabs, true, true); | |
| $request = \Bitrix\Main\Context::getCurrent()->getRequest(); | |
| if (check_bitrix_sessid() && $request->isPost() && strlen($request['save'])) { | |
| $options = $request['options']; | |
| if ($options) { | |
| foreach ($options as $key => $option) { | |
| if ($option) { | |
| Option::set('customSettings', $key, serialize($option)); | |
| } else { | |
| Option::set('customSettings', $key); | |
| } | |
| } | |
| unset($key, $option, $options); | |
| } else { | |
| Option::delete('customSettings'); | |
| } | |
| } | |
| $APPLICATION->SetTitle('Страница настроек'); | |
| require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_after.php'); | |
| $settings = [ | |
| [ | |
| 'CLASS' => '', | |
| 'ITEMS' => [ | |
| [ | |
| 'TYPE' => 'text', | |
| 'CODE' => 'phone', | |
| 'NAME' => 'Телефон', | |
| 'HINT' => '' | |
| ], | |
| [ | |
| 'TYPE' => 'text', | |
| 'CODE' => 'mail', | |
| 'NAME' => 'Почта', | |
| 'HINT' => '' | |
| ], | |
| ] | |
| ], | |
| ]; | |
| ?> | |
| <form name='settings_form' method='POST' action='<?= POST_FORM_ACTION_URI; ?>'> | |
| <?php | |
| $tabControl->Begin(); | |
| $tabControl->BeginNextTab(); | |
| foreach ($settings as $sGroup) { | |
| $opened = $_COOKIE[$sGroup['CLASS']]; | |
| ?> | |
| <tbody> | |
| <?php | |
| foreach ($sGroup['ITEMS'] as $option) { | |
| ?> | |
| <tr class="row"> | |
| <td class="adm-detail-content-cell-l" style="width:50%;"> | |
| <label for="field_<?=$option['CODE']; ?>"> | |
| <?=$option['NAME']; ?>: | |
| </label> | |
| </td> | |
| <?php | |
| $value = unserialize(Option::get('customSettings', $option['CODE'])); | |
| if ($option['TYPE'] === 'checkbox') { | |
| ?> | |
| <td class="adm-detail-content-cell-r"> | |
| <input type="hidden" name="options[<?=$option['CODE']; ?>]" value="0"> | |
| <input id="field_<?=$option['CODE']; ?>" type="<?=$option['TYPE']; ?>" name="options[<?=$option['CODE']; ?>]" <?= ((int)$value === 1) ? 'checked' : ''; ?> value="1"> | |
| </td> | |
| <?php | |
| } | |
| if ($option['TYPE'] === 'text') { | |
| ?> | |
| <td class="adm-detail-content-cell-r" style="width:50%;"> | |
| <input id="field_<?=$option['CODE']; ?>" size="90" type="<?=$option['TYPE']; ?>" name="options[<?=$option['CODE']; ?>]" size="30" value="<?= (mb_strlen($value) > 0) ? $value : ''; ?>"> | |
| </td> | |
| <?php | |
| } | |
| if ($option['TYPE'] === 'textarea') { | |
| ?> | |
| <td class="adm-detail-content-cell-r"> | |
| <textarea id="field_<?=$option['CODE']; ?>" name="options[<?=$option['CODE']; ?>]" cols="75" rows="10"><?=$value; ?></textarea> | |
| </td> | |
| <?php | |
| } | |
| ?> | |
| </tr> | |
| <?php | |
| } | |
| ?> | |
| <!-- <tr> | |
| <td class="adm-detail-content-cell-l">Нижний промо-текст</td> | |
| <td class="adm-detail-content-cell-r"><input type="text" size="90" id="popup-promo-bottom" value="<?=$SETTINGS['POPUP_PROMO_BOTTOM']?>" /></td> | |
| </tr> --> | |
| <!-- <tr> | |
| <td class="adm-detail-content-cell-l">Вкл/выкл возможности оплаты билетов</td> | |
| <td class="adm-detail-content-cell-r"> | |
| <input type="checkbox" id="tickets-payment" value="" class="adm-designed-checkbox" <? if ($SETTINGS['TICKETS_PAYMENT']=='true') {?> checked <?}?> /> | |
| <label class="adm-designed-checkbox-label" for="tickets-payment" title=""></label> | |
| </td> | |
| </tr> --> | |
| <!-- <tr> | |
| <td class="adm-detail-content-cell-l">Метрики</td> | |
| <td class="adm-detail-content-cell-r"><textarea type="text" rows="15" size="90" id="metrics" style="width: 100%;"><?=$SETTINGS['METRICS']?></textarea></td> | |
| </tr> --> | |
| <!-- <tr> | |
| <td width="40%" class="adm-detail-content-cell-l">Профиль:</td> | |
| <td width="300" class="adm-detail-content-cell-r"> | |
| <select id="" name="presets" onchange=""> | |
| <option value="0" selected="">Пользовательский</option> | |
| <option value="1">111</option> | |
| <option value="2">222</option> | |
| <option value="3">333</option> | |
| </select> | |
| </td> | |
| </tr> --> | |
| </tbody><? | |
| } | |
| unset($option); | |
| $tabControl->Buttons(['btnApply' => false]); | |
| echo bitrix_sessid_post(); | |
| $tabControl->End(); | |
| ?> | |
| </form> | |
| <?php | |
| require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php'); | |
| ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment