304 lines
10 KiB
PHP
304 lines
10 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
|
|
// Проверка авторизации
|
|
if (!isset($_SESSION['id']) || !$_SESSION['id']) {
|
|
header("location: index.php");
|
|
die("Доступ запрещён!");
|
|
}
|
|
|
|
// Разрешить тестирование только определённым пользователям (опционально)
|
|
$allowed_users = [117, 12093, 6635]; // ID пользователей, кому разрешён тест
|
|
if (!in_array((int)$_SESSION['id'], $allowed_users)) {
|
|
die("⚠️ Доступ ограничен для тестирования. Обратитесь к администратору.");
|
|
}
|
|
|
|
$user_id = (int)$_SESSION['id'];
|
|
$company_id = (int)$_SESSION['agency_id'];
|
|
|
|
// Получаем доступные дашборды для тестирования
|
|
$sql_dashboards = "
|
|
SELECT dashboard_uuid, dashboard_name, role_required
|
|
FROM bi_analytics_dashboard_access
|
|
WHERE company_id = $company_id
|
|
AND is_active = 1
|
|
ORDER BY dashboard_name
|
|
";
|
|
|
|
$q_dashboards = mysql_query($sql_dashboards);
|
|
$available_dashboards = [];
|
|
|
|
while ($row = mysql_fetch_assoc($q_dashboards)) {
|
|
$user_role = isset($_SESSION['role']) ? $_SESSION['role'] : 'agent';
|
|
$role_order = ['agent' => 1, 'manager' => 2, 'company_head' => 3, 'admin' => 4];
|
|
$required_order = isset($role_order[$row['role_required']]) ? $role_order[$row['role_required']] : 1;
|
|
$user_order = isset($role_order[$user_role]) ? $role_order[$user_role] : 1;
|
|
|
|
if ($user_order >= $required_order) {
|
|
$available_dashboards[] = $row;
|
|
}
|
|
}
|
|
|
|
if (empty($available_dashboards)) {
|
|
echo '<div style="padding: 40px; text-align: center; font-family: sans-serif;">
|
|
<h3>📊 Нет доступных дашбордов</h3>
|
|
<p>Для вашей компании ещё не настроены дашборды BI-аналитики.</p>
|
|
</div>';
|
|
exit;
|
|
}
|
|
|
|
$default_dashboard = $available_dashboards[0];
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>BI Аналитика — Тестирование</title>
|
|
<script src="https://unpkg.com/@superset-ui/embedded-sdk"></script>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
|
background: #f0f2f5;
|
|
padding: 20px;
|
|
}
|
|
.bi-container {
|
|
max-width: 1600px;
|
|
margin: 0 auto;
|
|
background: #fff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
|
overflow: hidden;
|
|
}
|
|
.bi-header {
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
|
color: white;
|
|
padding: 20px 24px;
|
|
border-bottom: 1px solid rgba(255,255,255,0.1);
|
|
}
|
|
.bi-header h1 {
|
|
font-size: 24px;
|
|
font-weight: 600;
|
|
margin-bottom: 8px;
|
|
}
|
|
.bi-header p {
|
|
font-size: 14px;
|
|
opacity: 0.8;
|
|
}
|
|
.bi-header .badge {
|
|
display: inline-block;
|
|
background: #4CAF50;
|
|
padding: 4px 12px;
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
margin-top: 12px;
|
|
}
|
|
.bi-tabs {
|
|
background: #f8f9fa;
|
|
padding: 0 24px;
|
|
border-bottom: 1px solid #e9ecef;
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
.bi-tab-btn {
|
|
padding: 12px 24px;
|
|
border: none;
|
|
background: transparent;
|
|
color: #666;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
border-bottom: 2px solid transparent;
|
|
margin-bottom: -1px;
|
|
}
|
|
.bi-tab-btn:hover {
|
|
color: #4CAF50;
|
|
}
|
|
.bi-tab-btn.active {
|
|
color: #4CAF50;
|
|
border-bottom-color: #4CAF50;
|
|
background: white;
|
|
}
|
|
.bi-content {
|
|
padding: 20px 24px;
|
|
min-height: 600px;
|
|
}
|
|
#superset-dashboard-container {
|
|
width: 100%;
|
|
height: calc(100vh - 220px);
|
|
min-height: 550px;
|
|
position: relative;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
}
|
|
#superset-dashboard-container iframe {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
border: none !important;
|
|
}
|
|
.loading-overlay {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 12px;
|
|
height: 100%;
|
|
color: #666;
|
|
}
|
|
.error-message {
|
|
padding: 40px;
|
|
text-align: center;
|
|
color: #f44336;
|
|
}
|
|
.footer {
|
|
text-align: center;
|
|
padding: 16px;
|
|
font-size: 12px;
|
|
color: #999;
|
|
border-top: 1px solid #eee;
|
|
background: #fafafa;
|
|
}
|
|
.company-info {
|
|
display: inline-block;
|
|
background: rgba(255,255,255,0.15);
|
|
padding: 4px 12px;
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
margin-left: 16px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="bi-container">
|
|
<div class="bi-header">
|
|
<h1>
|
|
📊 BI Аналитика
|
|
<span class="company-info">Компания ID: <?= $company_id ?></span>
|
|
<span class="badge">🧪 Тестовый режим</span>
|
|
</h1>
|
|
<p>Тестирование дашбордов Superset</p>
|
|
</div>
|
|
|
|
<?php if (count($available_dashboards) > 1): ?>
|
|
<div class="bi-tabs">
|
|
<?php foreach ($available_dashboards as $dash): ?>
|
|
<button class="bi-tab-btn <?= $dash['dashboard_uuid'] === $default_dashboard['dashboard_uuid'] ? 'active' : '' ?>"
|
|
data-uuid="<?= htmlspecialchars($dash['dashboard_uuid']) ?>"
|
|
onclick="switchDashboard(this)">
|
|
<?= htmlspecialchars($dash['dashboard_name']) ?>
|
|
</button>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="bi-content">
|
|
<div id="superset-dashboard-container">
|
|
<div class="loading-overlay">
|
|
<img src="/images/rocket-spinner.svg" width="32" style="margin-right: 8px;">
|
|
Загрузка дашборда...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
🔍 Тестовый режим | Пользователь: <?= htmlspecialchars($_SESSION['id']) ?> | Дата: <?= date('d.m.Y H:i') ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentDashboardUuid = '<?= $default_dashboard['dashboard_uuid'] ?>';
|
|
|
|
function switchDashboard(btn) {
|
|
const newUuid = btn.getAttribute('data-uuid');
|
|
|
|
// Обновляем активный класс
|
|
document.querySelectorAll('.bi-tab-btn').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
|
|
if (newUuid !== currentDashboardUuid) {
|
|
currentDashboardUuid = newUuid;
|
|
reloadDashboard();
|
|
}
|
|
}
|
|
|
|
function reloadDashboard() {
|
|
const container = document.getElementById('superset-dashboard-container');
|
|
if (!container) return;
|
|
|
|
// Показываем загрузку
|
|
container.innerHTML = '<div class="loading-overlay"><img src="/images/rocket-spinner.svg" width="32" style="margin-right:8px;"> Загрузка дашборда...</div>';
|
|
|
|
setTimeout(() => {
|
|
initSupersetEmbed();
|
|
}, 100);
|
|
}
|
|
|
|
function initSupersetEmbed() {
|
|
const container = document.getElementById('superset-dashboard-container');
|
|
|
|
if (!container) return;
|
|
|
|
try {
|
|
console.log("🚀 Загрузка дашборда:", currentDashboardUuid);
|
|
|
|
supersetEmbeddedSdk.embedDashboard({
|
|
id: currentDashboardUuid,
|
|
supersetDomain: 'https://bi.joywork.ru',
|
|
mountPoint: container,
|
|
|
|
fetchGuestToken: async () => {
|
|
const response = await fetch('/ajax/getSupersetGuestToken.php?dashboard_id=' + encodeURIComponent(currentDashboardUuid));
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
const data = await response.json();
|
|
if (!data.token) {
|
|
throw new Error('Токен не получен');
|
|
}
|
|
return data.token;
|
|
},
|
|
|
|
dashboardUiConfig: {
|
|
hideTitle: false,
|
|
hideTab: false,
|
|
//hideChartControls: true,
|
|
showSQL: true,
|
|
filters: {
|
|
expanded: true,
|
|
},
|
|
urlParams: {
|
|
lang: 'ru',
|
|
filter_company_id: '<?= $company_id ?>'
|
|
}
|
|
},
|
|
}).catch(error => {
|
|
console.error("Ошибка встраивания:", error);
|
|
container.innerHTML = `<div class="error-message">
|
|
❌ Ошибка загрузки дашборда<br>
|
|
<small>${error.message}</small>
|
|
</div>`;
|
|
});
|
|
} catch (error) {
|
|
console.error("Ошибка инициализации:", error);
|
|
container.innerHTML = `<div class="error-message">
|
|
❌ Ошибка инициализации<br>
|
|
<small>${error.message}</small>
|
|
</div>`;
|
|
}
|
|
}
|
|
|
|
// Запускаем при загрузке
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
initSupersetEmbed();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|