Folder reorganize 1
This commit is contained in:
144
data/personal/get_user_tags.php
Normal file
144
data/personal/get_user_tags.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../../session.php';
|
||||
require __DIR__ . '/../../dbinfo.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
|
||||
if (!isset($_SESSION['SESS_MEMBER_ID'])
|
||||
|| !is_numeric($_SESSION['SESS_MEMBER_ID'])
|
||||
) {
|
||||
http_response_code(403);
|
||||
echo json_encode(
|
||||
[
|
||||
'success' => false,
|
||||
'error' => 'Not authenticated',
|
||||
]
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userId = (int) $_SESSION['SESS_MEMBER_ID'];
|
||||
$dashboardKey = isset($_GET['dashboard']) && $_GET['dashboard'] !== ''
|
||||
? substr(trim($_GET['dashboard']), 0, 64)
|
||||
: 'default';
|
||||
|
||||
try {
|
||||
$connection = mysqli_connect($host, $username, $password, $database);
|
||||
if (!$connection) {
|
||||
throw new Exception('Database connection failed');
|
||||
}
|
||||
|
||||
mysqli_set_charset($connection, 'utf8mb4');
|
||||
|
||||
$sql = 'SELECT id,
|
||||
dashboard_key,
|
||||
widget_type,
|
||||
panel_size,
|
||||
position_index,
|
||||
tag_name,
|
||||
display_label,
|
||||
series_color,
|
||||
preferred_axis,
|
||||
update_interval_ms,
|
||||
time_window_minutes,
|
||||
rollup_function,
|
||||
scale_min,
|
||||
scale_max,
|
||||
threshold_low,
|
||||
threshold_high,
|
||||
is_active,
|
||||
config_json,
|
||||
last_viewed_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM user_tag_dashboards
|
||||
WHERE user_id = ?
|
||||
AND dashboard_key = ?
|
||||
AND is_active = 1
|
||||
ORDER BY position_index ASC, id ASC';
|
||||
|
||||
$statement = mysqli_prepare($connection, $sql);
|
||||
if (!$statement) {
|
||||
throw new Exception('Query preparation failed');
|
||||
}
|
||||
|
||||
mysqli_stmt_bind_param($statement, 'is', $userId, $dashboardKey);
|
||||
mysqli_stmt_execute($statement);
|
||||
$result = mysqli_stmt_get_result($statement);
|
||||
|
||||
if (!$result) {
|
||||
throw new Exception('Query execution failed');
|
||||
}
|
||||
|
||||
$widgets = [];
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
$config = null;
|
||||
if ($row['config_json']) {
|
||||
$decoded = json_decode($row['config_json'], true);
|
||||
$config = is_array($decoded) ? $decoded : null;
|
||||
}
|
||||
|
||||
$widgets[] = [
|
||||
'id' => (int) $row['id'],
|
||||
'dashboard_key' => $row['dashboard_key'],
|
||||
'widget_type' => $row['widget_type'],
|
||||
'panel_size' => $row['panel_size'],
|
||||
'position_index' => (int) $row['position_index'],
|
||||
'tag_name' => $row['tag_name'],
|
||||
'display_label' => $row['display_label'],
|
||||
'series_color' => $row['series_color'],
|
||||
'preferred_axis' => $row['preferred_axis'],
|
||||
'update_interval_ms' => (int) $row['update_interval_ms'],
|
||||
'time_window_minutes' => (int) $row['time_window_minutes'],
|
||||
'rollup_function' => $row['rollup_function'],
|
||||
'scale_min' => $row['scale_min'] !== null
|
||||
? (float) $row['scale_min']
|
||||
: null,
|
||||
'scale_max' => $row['scale_max'] !== null
|
||||
? (float) $row['scale_max']
|
||||
: null,
|
||||
'threshold_low' => $row['threshold_low'] !== null
|
||||
? (float) $row['threshold_low']
|
||||
: null,
|
||||
'threshold_high' => $row['threshold_high'] !== null
|
||||
? (float) $row['threshold_high']
|
||||
: null,
|
||||
'is_active' => (int) $row['is_active'],
|
||||
'config' => $config,
|
||||
'last_viewed_at' => $row['last_viewed_at'],
|
||||
'created_at' => $row['created_at'],
|
||||
'updated_at' => $row['updated_at'],
|
||||
];
|
||||
}
|
||||
|
||||
mysqli_stmt_close($statement);
|
||||
mysqli_close($connection);
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
'success' => true,
|
||||
'dashboard' => $dashboardKey,
|
||||
'count' => count($widgets),
|
||||
'widgets' => $widgets,
|
||||
]
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
if (isset($statement) && $statement) {
|
||||
mysqli_stmt_close($statement);
|
||||
}
|
||||
if (isset($connection) && $connection) {
|
||||
mysqli_close($connection);
|
||||
}
|
||||
|
||||
http_response_code(500);
|
||||
echo json_encode(
|
||||
[
|
||||
'success' => false,
|
||||
'error' => $exception->getMessage(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user