Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
some interface improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolya2la authored and tntrex committed Jan 29, 2019
1 parent 183012b commit 33f05db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Module {
private $MODULE_ID;
private $MODULE_VERSION;
private $MODULE_VERSION_DATE;
private $ADMIN_FORM_ID;

public $options;
public $logger;
Expand All @@ -25,6 +26,7 @@ public function __construct(array $options = []) {
$this->MODULE_ID = $options['MODULE_ID'];
$this->MODULE_VERSION = $options['MODULE_VERSION'];
$this->MODULE_VERSION_DATE = $options['MODULE_VERSION_DATE'];
$this->ADMIN_FORM_ID = $options['ADMIN_FORM_ID'];

$this->options = new Options\Manager($this->MODULE_ID);
$this->logger = new Logger($this->MODULE_ID);
Expand Down Expand Up @@ -71,7 +73,7 @@ public function setVersionDate($MODULE_VERSION_DATE) {
}

public function showOptionsForm() {
$form = new Options\Form($this->options);
$form = new Options\Form($this->options, $this->ADMIN_FORM_ID);
$form->handleRequest();
$form->write();
}
Expand Down
23 changes: 17 additions & 6 deletions src/Options/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class Form {

private $tabControl = null;
private $context = null;
private $formId = null;

public function __construct($options) {
public function __construct($options, $formId) {
global $USER, $APPLICATION;
if (!$USER->isAdmin()) {
$APPLICATION->authForm('Nope');
$APPLICATION->authForm('Access denied.');
}

$this->options = $options;
$this->context = Application::getInstance()->getContext();
$this->formId = $formId ?: 'module_settings_form';

defined('ADMIN_MODULE_NAME') or define('ADMIN_MODULE_NAME', $this->options->getModuleId());
}
Expand Down Expand Up @@ -99,20 +101,28 @@ public function write() {

$this->tabControl->begin();
?>
<form method="post" action="<?=sprintf('%s?mid=%s&lang=%s', $this->getRequest()->getRequestedPage(), urlencode($mid), LANGUAGE_ID)?>">
<form method="post" action="<?=sprintf('%s?mid=%s&lang=%s', $this->getRequest()->getRequestedPage(), urlencode($mid), LANGUAGE_ID)?>" name="<?=$this->formId?>" id="<?=$this->formId?>">
<?php
echo bitrix_sessid_post();
foreach ($this->tabControl->tabs as $tab) {
$this->tabControl->beginNextTab();
$filteredOpts = array_filter($fields, function ($opt) use ($tab) { return $opt['tab'] === $tab['DIV']; });
foreach ($filteredOpts as $opt_name=>$opt) { ?>
<tr>
<tr id="<?=$opt_name?>_row">
<?
switch ($opt['type']) {
case 'html':
?>
<td colspan="2">
if (strlen($opt['label'])) {
?>
<td width="30%" style="vertical-align: top; line-height: 25px;">
<label for="<?=$opt_name?>"><?=$opt['label'] . ($opt['required'] ? ' *' : '')?>:</label>
<td width="70%">
<?
} else {
?>
<td colspan="2">
<?
}
if ($opt['html']) {
echo $opt['html'];
} else if (file_exists($opt['path'])) {
Expand Down Expand Up @@ -182,6 +192,7 @@ public function write() {
?>
<input
type="<?=$opt['type']?>"
size="<?=$opt['size'] ?: '50'?>"
name="<?=$opt_name?>"
id="<?=$opt_name?>"
value="<?=htmlspecialchars(Option::get(ADMIN_MODULE_NAME, $opt_name));?>"
Expand Down

0 comments on commit 33f05db

Please sign in to comment.