connect_error) { die('Unable to access the database, please try again later'); } if (!checkUserSession($conn)) { setcookie('session', '', time(), "/", "", true, true); header('Location: /dashboard/login.php'); die(); } $checkedSession = true; $session = htmlspecialchars($_COOKIE['session']); $stmt = $conn->prepare("SELECT uid, username, email, api_key, role, discord_id FROM users WHERE session = ?"); $stmt->bind_param("s", $session); $stmt->execute(); $stmt->bind_result($uid, $username, $email, $api_key, $role, $discord_id); $stmt->fetch(); $stmt->close(); $username = htmlspecialchars($username, ENT_QUOTES, 'UTF-8'); checkDiscordLink($discord_id); $sql = "SELECT value FROM settings WHERE id = 1"; $result = $conn->query($sql); $row = $result->fetch_assoc(); $news = base64_decode($row['value']); $sql = "SELECT value FROM settings WHERE id = 2"; $result = $conn->query($sql); $row = $result->fetch_assoc(); $motd = base64_decode($row['value']); $totalSize = 0; $uploadCount = 0; $sql = "SELECT size FROM uploads WHERE uid = '$uid'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $totalSize += $row['size']; $uploadCount++; } } $uploadsByDay = $overallUploadsByDay = $overallLoginsByDay = array(); $currentDate = new DateTime('now', new DateTimeZone('America/Los_Angeles')); for ($i = 0; $i < 7; $i++) { $day = $currentDate->format('m-d-Y'); $uploadsByDay[$day] = 0; $overallUploadsByDay[$day] = 0; $overallLoginsByDay[$day] = 0; $currentDate->sub(new DateInterval('P1D')); } $sql = "SELECT uploaded FROM uploads WHERE uid = '$uid' AND uploaded >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $timestamp = $row['uploaded']; $dateTime = new DateTime("@$timestamp"); $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles")); $day = $dateTime->format('m-d-Y'); if (isset($uploadsByDay[$day])) { $uploadsByDay[$day]++; } } } $sql = "SELECT uploaded FROM uploads WHERE uploaded >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $timestamp = $row['uploaded']; $dateTime = new DateTime("@$timestamp"); $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles")); $day = $dateTime->format('m-d-Y'); if (isset($overallUploadsByDay[$day])) { $overallUploadsByDay[$day]++; } } } $sql = "SELECT login_time FROM logins WHERE login_time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $timestamp = $row['login_time']; $dateTime = new DateTime("@$timestamp"); $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles")); $day = $dateTime->format('m-d-Y'); if (isset($overallLoginsByDay[$day])) { $overallLoginsByDay[$day]++; } } } $size = formatUnitSize($totalSize); $uploadStatsData = json_encode(array_reverse(array_values($uploadsByDay))); $overallUploadStatsData = json_encode(array_reverse(array_values($overallUploadsByDay))); $loginStatsData = json_encode(array_reverse(array_values($overallLoginsByDay))); $uploadStatsLabels = json_encode(array_reverse(array_keys($uploadsByDay))); $role_format = $role == 1 ? "Owner" : ($role == 2 ? "Manager" : ($role == 0 ? "User" : "Unknown")); date_default_timezone_set('America/Los_Angeles'); $motd = str_ireplace('%discord%', 'Discord', $motd); $news = str_ireplace('%discord%', 'Discord', $news); $motd = str_ireplace('%username%', $username, $motd); $news = str_ireplace('%username%', $username, $news); $motd = str_ireplace('%uploads%', $uploadCount, $motd); $news = str_ireplace('%uploads%', $uploadCount, $news); $motd = str_ireplace('%role%', $role_format, $motd); $news = str_ireplace('%role%', $role_format, $news); $motd = str_ireplace('%uid%', $uid, $motd); $news = str_ireplace('%uid%', $uid, $news); $motd = str_ireplace('%year%', date('Y'), $motd); $news = str_ireplace('%year%', date('Y'), $news); $motd = str_ireplace('%month%', date('n'), $motd); $news = str_ireplace('%month%', date('n'), $news); $motd = str_ireplace('%monthformat%', date('F'), $motd); $news = str_ireplace('%monthformat%', date('F'), $news); $motd = str_ireplace('%day%', date('j'), $motd); $news = str_ireplace('%day%', date('j'), $news); $motd = str_ireplace('%dayformat%', date('l'), $motd); $news = str_ireplace('%dayformat%', date('l'), $news); $motd = str_ireplace('%date%', date('n/j/Y'), $motd); $news = str_ireplace('%date%', date('n/j/Y'), $news); $motd = str_ireplace('%dateformat%', date('F jS, Y'), $motd); $news = str_ireplace('%dateformat%', date('F jS, Y'), $news); $motd = str_ireplace('%storage%', $size, $motd); $news = str_ireplace('%storage%', $size, $news); ob_start(); ?>

Hello, 👋

Storage Used

/2.5 GB

Uploads

User ID

Recent News

MOTD

Daily Uploads

Daily Unique Logins