0) { $stmt = $pdo->prepare('SELECT "key", "value" FROM formula_coefficients WHERE id=?'); $stmt->execute([$id]); $old = $stmt->fetch(); $oldVal = $old ? $old['value'] : null; $stmt = $pdo->prepare('UPDATE formula_coefficients SET "key"=?, "value"=?, "description"=?, "formula_ref"=?, "updated_by"=? WHERE id=?'); $stmt->execute([$key, $value, $description, $formulaRef, $session['user_id'], $id]); } else { $stmt = $pdo->prepare('INSERT INTO formula_coefficients ("key", "value", "description", "formula_ref", "updated_by") VALUES (?,?,?,?,?)'); $stmt->execute([$key, $value, $description, $formulaRef, $session['user_id']]); } $message = 'Коэффициент "' . htmlspecialchars($key) . '" сохранён.'; $msgType = 'success'; $detail = "Key: $key, new: $value" . ($oldVal !== null ? ", old: $oldVal" : ''); auth_log($session['user_id'], 'coefficient_update', $detail); } catch (\PDOException $e) { $message = 'Ошибка: ' . ($e->getCode() === '23000' ? 'Ключ уже существует.' : $e->getMessage()); $msgType = 'error'; } } } elseif ($_POST['action'] === 'toggle') { $id = (int)($_POST['id'] ?? 0); $stmt = $pdo->prepare('SELECT "key", is_active FROM formula_coefficients WHERE id=?'); $stmt->execute([$id]); $c = $stmt->fetch(); if ($c) { $newState = $c['is_active'] ? 0 : 1; $stmt = $pdo->prepare("UPDATE formula_coefficients SET is_active=?, updated_by=? WHERE id=?"); $stmt->execute([$newState, $session['user_id'], $id]); auth_log($session['user_id'], 'coefficient_toggle', "Key: {$c['key']}, active: $newState"); $message = 'Статус коэффициента изменён.'; $msgType = 'info'; } } elseif ($_POST['action'] === 'reset_defaults') { $confirmed = $_POST['confirmed'] ?? ''; if ($confirmed === '1') { auth_log($session['user_id'], 'coefficient_reset', 'Сброс всех коэффициентов к значениям из migration.sql'); $message = 'Сброс не реализован — удалите таблицу и перезапустите migration.sql вручную.'; $msgType = 'warning'; } else { $message = 'Подтвердите сброс.'; $msgType = 'warning'; } } } // Get edit data $editCoeff = null; if (isset($_GET['edit'])) { $stmt = $pdo->prepare("SELECT * FROM formula_coefficients WHERE id=?"); $stmt->execute([(int)$_GET['edit']]); $editCoeff = $stmt->fetch(); } // Get all coefficients ordered by key $coeffs = $pdo->query('SELECT * FROM formula_coefficients ORDER BY "key"')->fetchAll(); // Group by prefix $groups = []; foreach ($coeffs as $c) { $prefix = explode('.', $c['key'])[0]; $groups[$prefix][] = $c; } $csrf = auth_csrf_token(); require __DIR__ . '/../../inc/header.php'; ?>

Коэффициенты формул

$items): ?>

параметров
Ключ Значение Описание Функция Статус Действия
✏️