From 655987979f412a5be3a6d8393463cfd235e699fe Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 9 Dec 2023 15:47:09 +0200 Subject: [PATCH] Refactor code to improve maintainability and readability This commit introduces changes aimed at enhancing code maintainability and readability. The most significant was moving code responsible for various future checks into a separate file to reduce clutter. Additionally, the code has been cleaned up, removing excessive spacing and redundancies. --- js/modpanel.js | 78 +++++ modules_data/_mod.php | 775 ++++++++++++++++++------------------------ 2 files changed, 414 insertions(+), 439 deletions(-) create mode 100644 js/modpanel.js diff --git a/js/modpanel.js b/js/modpanel.js new file mode 100644 index 00000000..402e775c --- /dev/null +++ b/js/modpanel.js @@ -0,0 +1,78 @@ +function nqst() { + const x = document.getElementById('addNewquest'); + x.style.display = x.style.display === 'none' ? '' : 'none'; +} + +const adds = [0, 0, 0, 0]; + +function addqact() { + const dd = document.getElementById('qact'); + adds[0]++; + dd.innerHTML = 'Атрибут: , значение:
' + dd.innerHTML; +} + +function addqtr() { + const dd = document.getElementById('qtr'); + adds[1]++; + dd.innerHTML = 'Атрибут: , значение:
' + dd.innerHTML; +} + +function addqng() { + const dd = document.getElementById('qng'); + adds[2]++; + dd.innerHTML = 'Атрибут: , значение:
' + dd.innerHTML; +} + +function addqnk() { + const dd = document.getElementById('qnk'); + adds[3]++; + dd.innerHTML = 'Атрибут: , значение:
' + dd.innerHTML; +} diff --git a/modules_data/_mod.php b/modules_data/_mod.php index 5ac79f06..be00058b 100644 --- a/modules_data/_mod.php +++ b/modules_data/_mod.php @@ -17,6 +17,7 @@ if (!$m->isModerator) { $merror = ''; $uer = ''; +$go = isset($_GET['go']) ? round($_GET['go']) : 0; if (!empty($_POST['logingo'])) { $moderation = new ModFactory( @@ -78,11 +79,6 @@ if (!empty($_POST['marrypartner1']) && !empty($_POST['marrypartner2'])) { echo ''; -$go = 0; -if (isset($_GET['go'])) { - $go = round($_GET['go']); -} - if ($go == 3 && $m->isAdmin) { ?> @@ -114,7 +110,8 @@ if ($go == 3 && $m->isAdmin) { $pl['room'] = $_POST['pl_room']; $pl['module'] = $_POST['pl_module']; - Db::sql('update an_quest set + Db::sql( + 'update an_quest set name = ?, sex = ?, ico_bot = ?, @@ -140,7 +137,8 @@ if ($go == 3 && $m->isAdmin) { $pl['room'], $pl['module'], $pl['id'], - ]); + ] + ); $pl = Db::getRow('select * from an_quest where id = ?', [(int)$_GET['eq']]); } @@ -204,8 +202,8 @@ if ($go == 3 && $m->isAdmin) { echo <<$qid - $qname($qsex) - Изменить + $qname($qsex) + ИзменитьУдалить
@@ -237,469 +235,368 @@ if ($go == 3 && $m->isAdmin) { $qd['align'] = 3; } elseif ($_POST['align3'] == 1) { $qd['align'] = 7; - - $i = 1; - while ($i != -1) { - if (isset($_POST['q_act_atr_' . $i])) { - if ($_POST['q_act_val_' . $i] != '') { - $qd['act_date'] .= $_POST['q_act_atr_' . $i] . ':=:' . $_POST['q_act_val_' . $i] . ':|:'; - } - } else { - $i = -2; - $qd['act_date'] = trim($qd['act_date'], ':|'); - } - $i++; - } - $i = 1; - while ($i != -1) { - if (isset($_POST['q_tr_atr_' . $i])) { - if ($_POST['q_tr_val_' . $i] != '') { - $qd['tr_date'] .= $_POST['q_tr_atr_' . $i] . ':=:' . $_POST['q_tr_val_' . $i] . ':|:'; - } - } else { - $i = -2; - $qd['tr_date'] = trim($qd['tr_date'], ':|'); - } - $i++; - } - $i = 1; - while ($i != -1) { - if (isset($_POST['q_ng_atr_' . $i])) { - if ($_POST['q_ng_val_' . $i] != '') { - $qd['win_date'] .= $_POST['q_ng_atr_' . $i] . ':=:' . $_POST['q_ng_val_' . $i] . ':|:'; - } - } else { - $i = -2; - $qd['win_date'] = trim($qd['win_date'], ':|'); - } - $i++; - } - $i = 1; - while ($i != -1) { - if (isset($_POST['q_nk_atr_' . $i])) { - if ($_POST['q_nk_val_' . $i] != '') { - $qd['lose_date'] .= $_POST['q_nk_atr_' . $i] . ':=:' . $_POST['q_nk_val_' . $i] . ':|:'; - } - } else { - $i = -2; - $qd['lose_date'] = trim($qd['lose_date'], ':|'); - } - $i++; - } - Db::sql( - 'insert into quests (name, min_lvl, max_lvl, tr_date, act_date, win_date, lose_date, info, line, align, fast) values (?,?,?,?,?,?,?,?,?,?,?)', - [ - $qd['name'], - $qd['lvl'][0], - $qd['lvl'][1], - $qd['tr_date'], - $qd['act_date'], - $qd['win_date'], - $qd['lose_date'], - $qd['info'], - $qd['line'], - $qd['align'], - $qd['fast'], - ] - ); } - ?> - + $i++; + } + Db::sql( + 'insert into quests (name, min_lvl, max_lvl, tr_date, act_date, win_date, lose_date, info, line, align, fast) values (?,?,?,?,?,?,?,?,?,?,?)', + [ + $qd['name'], + $qd['lvl'][0], + $qd['lvl'][1], + $qd['tr_date'], + $qd['act_date'], + $qd['win_date'], + $qd['lose_date'], + $qd['info'], + $qd['line'], + $qd['align'], + $qd['fast'], + ] + ); + } + ?> + - Текстовое поле - -
- - - - - - + +

Редактор заданий

- -
- - + table.newquest { + width: 100%; + border: 0; + background-color: #e1e1e1; + } + +
+ + + + + +

Редактор заданий

+ +
+ + + + + + + + + +
+ +
+
+ + + + - - - - + - -
- + +
+ + +
+
+ + -