v1.7.0: refactor max_bot to flat structure, add VCF+UserModel+NLP history context, portal pages and proxy fixes

- Refactored max_bot from nested packages to flat module structure
- Q2: Extended BotUser model (patronymic, email, org, address, vcf_raw, contact_hash, phone_verified, email_verified, last_interaction, total_conversations, total_tickets)
- Q2: VCF parser (FN, N, TEL, EMAIL, ORG, ADR), upsert on re-contact, NLP history context (_get_user_history_context -> YandexGPT)
- Q1: Broadcast preview modal with 10s confirmation timer
- Q3: CSS var(--white)->var(--bg-card), var(--text)->var(--text-primary)
- Q4: bot_settings showNotification(), editable max_bot_id
- Q5: Webhook secret passthrough via X-Max-Bot-Api-Secret
- Masking sensitive keys, dialog_cleared handler, migrate via _add_column_if_not_exists()
- Rate limit (asyncio.sleep 0.5 per 10), dead code removed, conv.intent context in contact.py
- Portal pages: bot_consent, bot_kb (edit), bot_settings, bot_test, bot_tickets, portal_settings
- Tests: 21/21 passing, added test_yandex_gpt.py, test_email_sender.py
- Deploy: deploy_full.sh, schema.sql, seed_knowledge_base.sql
This commit is contained in:
2026-05-29 02:30:30 +03:00
parent 493e0b37a1
commit 72b6879f4b
234 changed files with 26768 additions and 6240 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ if ($role === 'technician') {
$params[] = $userId;
}
$sql .= " ORDER BY FIELD(t.priority,'P1','P2','P3','P4'), t.deadline ASC";
$sql .= " ORDER BY CASE t.priority WHEN 'P1' THEN 1 WHEN 'P2' THEN 2 WHEN 'P3' THEN 3 WHEN 'P4' THEN 4 END, t.deadline ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
+242
View File
@@ -894,3 +894,245 @@ table .actions button {
@keyframes spin {
to { transform: rotate(360deg); }
}
/* ---------- NAVBAR ---------- */
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
height: 56px;
background: var(--bg-sidebar);
border-bottom: 1px solid var(--border);
position: sticky;
top: 0;
z-index: 50;
}
.navbar__brand a {
font-family: 'Montserrat', sans-serif;
font-weight: 700;
font-size: 16px;
color: var(--text-primary);
}
.navbar__menu {
display: flex;
align-items: center;
gap: 20px;
list-style: none;
margin: 0;
padding: 0;
}
.navbar__menu a {
color: var(--text-secondary);
font-size: 13px;
font-weight: 500;
transition: color 0.2s;
}
.navbar__menu a:hover {
color: var(--text-primary);
}
.navbar__logout {
color: var(--text-muted) !important;
}
/* ---------- DOCUMENTS ---------- */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 24px;
}
.docs-list {
display: grid;
gap: 8px;
margin-bottom: 24px;
}
.doc-item {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 14px 20px;
transition: all 0.2s;
}
.doc-item:hover {
border-color: var(--accent);
background: var(--bg-card-hover);
}
.doc-item a {
font-size: 15px;
font-weight: 500;
color: var(--text-primary);
}
.doc-item a:hover {
color: var(--accent);
}
.docs-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.doc-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 24px;
flex-wrap: wrap;
gap: 16px;
}
.doc-header h1 {
font-size: 24px;
font-weight: 700;
}
.doc-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.doc-content {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 28px;
line-height: 1.7;
}
.doc-content h1, .doc-content h2, .doc-content h3 {
margin-top: 24px;
margin-bottom: 12px;
color: var(--text-primary);
}
.doc-content h1 { font-size: 22px; }
.doc-content h2 { font-size: 18px; }
.doc-content h3 { font-size: 16px; }
.doc-content p {
margin-bottom: 12px;
color: var(--text-secondary);
}
.doc-content code {
background: var(--bg-input);
padding: 2px 6px;
border-radius: 4px;
font-size: 13px;
color: var(--accent);
}
.doc-content pre {
background: var(--bg-input);
padding: 16px;
border-radius: 6px;
overflow-x: auto;
margin-bottom: 16px;
}
.doc-content pre code {
background: none;
padding: 0;
}
.doc-content table {
margin-bottom: 16px;
}
.doc-content ul, .doc-content ol {
margin-bottom: 12px;
padding-left: 24px;
color: var(--text-secondary);
}
.doc-content li {
margin-bottom: 4px;
}
.doc-content blockquote {
border-left: 3px solid var(--accent);
padding-left: 16px;
margin: 16px 0;
color: var(--text-muted);
}
.doc-content a {
color: var(--accent);
}
.doc-content a:hover {
color: var(--accent-hover);
}
.form-actions {
display: flex;
gap: 10px;
margin-top: 16px;
}
/* ---------- PERMISSIONS TABLE ---------- */
.permissions-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.permissions-table th {
text-align: left;
padding: 12px 16px;
font-size: 12px;
font-weight: 700;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
border-bottom: 1px solid var(--border);
background: var(--bg-sidebar);
}
.permissions-table td {
padding: 12px 16px;
border-bottom: 1px solid var(--border);
vertical-align: middle;
}
.permissions-table tr:hover td {
background: rgba(0, 173, 239, 0.05);
}
.permissions-table input[type="checkbox"] {
width: 18px;
height: 18px;
accent-color: var(--accent);
cursor: pointer;
}
@media (max-width: 768px) {
.navbar {
flex-direction: column;
height: auto;
padding: 12px 16px;
gap: 12px;
}
.navbar__menu {
flex-wrap: wrap;
justify-content: center;
}
.doc-header {
flex-direction: column;
}
.container {
padding: 16px;
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ define('BRUTE_FORCE_MAX_ATTEMPTS', 3);
function auth_brute_force_check(string $login): bool {
$pdo = getDB();
$stmt = $pdo->prepare("SELECT COUNT(*) FROM login_attempts WHERE (login = ? OR ip_address = ?) AND attempt_time > DATE_SUB(NOW(), INTERVAL ? SECOND)");
$stmt = $pdo->prepare("SELECT COUNT(*) FROM login_attempts WHERE (login = ? OR ip_address = ?) AND attempt_time > NOW() - CAST(? || ' seconds' AS INTERVAL)");
$stmt->execute([$login, $_SERVER['REMOTE_ADDR'] ?? '', BRUTE_FORCE_WINDOW]);
return $stmt->fetchColumn() >= BRUTE_FORCE_MAX_ATTEMPTS;
}
+1 -1
View File
@@ -32,7 +32,7 @@ function get_coefficient(string $key, float $default = 0): float {
if ($cache === null) {
try {
$pdo = getDB();
$stmt = $pdo->query("SELECT `key`, `value` FROM formula_coefficients WHERE is_active=1");
$stmt = $pdo->query('SELECT "key", "value" FROM formula_coefficients WHERE is_active');
$cache = [];
while ($row = $stmt->fetch()) {
$cache[$row['key']] = (float)$row['value'];
+10 -2
View File
@@ -8,14 +8,22 @@
require_once __DIR__ . '/../data/db-config.php';
try {
if (DB_TYPE === 'pgsql') {
$dsn = 'pgsql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME;
} else {
$dsn = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET;
}
$pdo = new PDO(
'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET,
$dsn,
DB_USER,
DB_PASS,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$sql = file_get_contents(__DIR__ . '/../data/migration.sql');
$sqlPath = DB_TYPE === 'pgsql'
? __DIR__ . '/../py_service/sql/schema_postgresql.sql'
: __DIR__ . '/../data/migration.sql';
$sql = file_get_contents($sqlPath);
$statements = array_filter(array_map('trim', explode(';', $sql)));
$created = 0;
$inserted = 0;
+2 -2
View File
@@ -81,14 +81,14 @@ if ($severityFilter) {
$sql .= " AND i.severity = ?";
$params[] = $severityFilter;
}
$sql .= " ORDER BY FIELD(i.severity,'P1','P2','P3'), i.created_at DESC";
$sql .= " ORDER BY CASE i.severity WHEN 'P1' THEN 1 WHEN 'P2' THEN 2 WHEN 'P3' THEN 3 END, i.created_at DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$incidents = $stmt->fetchAll();
$objects = $pdo->query("SELECT id, name FROM objects WHERE status='active' ORDER BY name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE is_active=1 ORDER BY full_name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE is_active ORDER BY full_name")->fetchAll();
$csrf = auth_csrf_token();
require __DIR__ . '/../../inc/header.php';
+2 -2
View File
@@ -81,14 +81,14 @@ if ($search) {
$params[] = "%$search%";
$params[] = "%$search%";
}
$sql .= " ORDER BY FIELD(t.priority,'P1','P2','P3','P4'), t.deadline ASC, t.created_at DESC";
$sql .= " ORDER BY CASE t.priority WHEN 'P1' THEN 1 WHEN 'P2' THEN 2 WHEN 'P3' THEN 3 WHEN 'P4' THEN 4 END, t.deadline ASC, t.created_at DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$tasks = $stmt->fetchAll();
$activeObjects = $pdo->query("SELECT id, name FROM objects WHERE status='active' ORDER BY name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE role IN ('engineer','technician') AND is_active=1 ORDER BY full_name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE role IN ('engineer','technician') AND is_active ORDER BY full_name")->fetchAll();
$csrf = auth_csrf_token();
require __DIR__ . '/../../inc/header.php';
+1 -1
View File
@@ -39,7 +39,7 @@ if (isset($_GET['remove'])) {
}
$objects = $pdo->query("SELECT id, name FROM objects WHERE status='active' ORDER BY name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name, role FROM users WHERE role IN ('engineer','technician') AND is_active=1 ORDER BY full_name")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name, role FROM users WHERE role IN ('engineer','technician') AND is_active ORDER BY full_name")->fetchAll();
// Get active assignments
$assignments = $pdo->query("
+1 -1
View File
@@ -25,7 +25,7 @@ $stmt = $pdo->query("SELECT COUNT(*) FROM objects WHERE status='active'");
$totalObjects = $stmt->fetchColumn();
// Engineer count
$stmt = $pdo->query("SELECT COUNT(*) FROM users WHERE role IN ('engineer','technician') AND is_active=1");
$stmt = $pdo->query("SELECT COUNT(*) FROM users WHERE role IN ('engineer','technician') AND is_active");
$engineerCount = $stmt->fetchColumn();
// SLA compliance
+5 -5
View File
@@ -28,15 +28,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
try {
$oldVal = null;
if ($id > 0) {
$stmt = $pdo->prepare("SELECT `key`, `value` FROM formula_coefficients WHERE id=?");
$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 = $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 = $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) . '" сохранён.';
@@ -50,7 +50,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
}
} elseif ($_POST['action'] === 'toggle') {
$id = (int)($_POST['id'] ?? 0);
$stmt = $pdo->prepare("SELECT `key`, `is_active` FROM formula_coefficients WHERE id=?");
$stmt = $pdo->prepare('SELECT "key", is_active FROM formula_coefficients WHERE id=?');
$stmt->execute([$id]);
$c = $stmt->fetch();
if ($c) {
@@ -83,7 +83,7 @@ if (isset($_GET['edit'])) {
}
// Get all coefficients ordered by key
$coeffs = $pdo->query("SELECT * FROM formula_coefficients ORDER BY `key`")->fetchAll();
$coeffs = $pdo->query('SELECT * FROM formula_coefficients ORDER BY "key"')->fetchAll();
// Group by prefix
$groups = [];
+1 -1
View File
@@ -12,7 +12,7 @@ $pdo = getDB();
$userId = $session['user_id'];
// Calculate KPI for each engineer
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE role IN ('engineer','technician') AND is_active=1")->fetchAll();
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE role IN ('engineer','technician') AND is_active")->fetchAll();
$periodStart = date('Y-m-01');
$periodEnd = date('Y-m-t');
+1 -1
View File
@@ -173,7 +173,7 @@ if ($sessId) {
$qItems = [];
$qSections = [];
if ($sessId) {
$stmt = $pdo->prepare("SELECT * FROM questionnaire_items WHERE is_active=1 AND step=? ORDER BY sort_order, id");
$stmt = $pdo->prepare("SELECT * FROM questionnaire_items WHERE is_active AND step=? ORDER BY sort_order, id");
$stmt->execute([$step]);
$qItems = $stmt->fetchAll();
+1 -1
View File
@@ -13,7 +13,7 @@ $stmt = $pdo->prepare("
FROM tasks t
JOIN objects o ON o.id = t.object_id
WHERE t.assigned_to = ? AND t.status IN ('open','in_progress')
ORDER BY FIELD(t.priority,'P1','P2','P3','P4'), t.deadline ASC
ORDER BY CASE t.priority WHEN 'P1' THEN 1 WHEN 'P2' THEN 2 WHEN 'P3' THEN 3 WHEN 'P4' THEN 4 END, t.deadline ASC
");
$stmt->execute([$userId]);
$myTasks = $stmt->fetchAll();