[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
repository_afbs
/
admin
/
[
Home
]
File: statistics.php
<?php session_start(); require_once '../includes/config.php'; require_once '../includes/database.php'; require_once '../includes/functions.php'; require_once '../includes/auth.php'; if (!isAdmin()) { header('Location: ../login.php'); exit(); } $db = new Database(); $conn = $db->getConnection(); // Periode statistik $period = isset($_GET['period']) ? $_GET['period'] : 'monthly'; $year = isset($_GET['year']) ? $_GET['year'] : date('Y'); // Statistik umum $stats = [ 'total_theses' => getTotalTheses($conn), 'total_authors' => getTotalAuthors($conn), 'total_downloads' => getTotalDownloads($conn), 'total_views' => getTotalViews($conn) ]; // Statistik per tahun $yearly_stats = getYearlyStats($conn); // Statistik per bulan $monthly_stats = getMonthlyStats($conn, $year); // Top authors $top_authors = getTopAuthors($conn, 10); // Top downloads $top_downloads = getTopDownloads($conn, 10); // Statistik berdasarkan program studi $program_stats = getProgramStats($conn); // Statistik berdasarkan status $status_stats = getStatusStats($conn); $page_title = 'Statistik Repository'; include '../templates/header.php'; include '../templates/admin-navbar.php'; ?> <div class="container-fluid"> <div class="row"> <?php include '../templates/admin-sidebar.php'; ?> <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Statistik Repository</h1> <div class="btn-toolbar mb-2 mb-md-0"> <a href="export-statistics.php?period=<?php echo $period; ?>&year=<?php echo $year; ?>" class="btn btn-sm btn-outline-secondary"> <i class="fas fa-download"></i> Export </a> </div> </div> <!-- Statistik Cards --> <div class="row mb-4"> <div class="col-md-3"> <div class="card bg-primary text-white"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">Total Tugas Akhir</h6> <h2 class="mb-0"><?php echo $stats['total_theses']; ?></h2> </div> <i class="fas fa-file-pdf fa-3x opacity-50"></i> </div> </div> </div> </div> <div class="col-md-3"> <div class="card bg-success text-white"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">Total Penulis</h6> <h2 class="mb-0"><?php echo $stats['total_authors']; ?></h2> </div> <i class="fas fa-users fa-3x opacity-50"></i> </div> </div> </div> </div> <div class="col-md-3"> <div class="card bg-info text-white"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">Total Downloads</h6> <h2 class="mb-0"><?php echo number_format($stats['total_downloads']); ?></h2> </div> <i class="fas fa-download fa-3x opacity-50"></i> </div> </div> </div> </div> <div class="col-md-3"> <div class="card bg-warning text-white"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">Total Views</h6> <h2 class="mb-0"><?php echo number_format($stats['total_views']); ?></h2> </div> <i class="fas fa-eye fa-3x opacity-50"></i> </div> </div> </div> </div> </div> <!-- Filter --> <div class="card mb-4"> <div class="card-body"> <form method="GET" class="row align-items-center"> <div class="col-md-3"> <label class="form-label">Periode</label> <select name="period" class="form-select"> <option value="monthly" <?php echo $period == 'monthly' ? 'selected' : ''; ?>>Bulanan</option> <option value="yearly" <?php echo $period == 'yearly' ? 'selected' : ''; ?>>Tahunan</option> </select> </div> <div class="col-md-3"> <label class="form-label">Tahun</label> <select name="year" class="form-select"> <?php for($y = date('Y'); $y >= 2018; $y--): ?> <option value="<?php echo $y; ?>" <?php echo $year == $y ? 'selected' : ''; ?>> <?php echo $y; ?> </option> <?php endfor; ?> </select> </div> <div class="col-md-2"> <label class="form-label"> </label> <button type="submit" class="btn btn-primary w-100">Tampilkan</button> </div> </form> </div> </div> <!-- Charts --> <div class="row mb-4"> <div class="col-md-8"> <div class="card"> <div class="card-header"> <h5>Upload Tugas Akhir <?php echo $period == 'monthly' ? "Tahun $year" : 'per Tahun'; ?></h5> </div> <div class="card-body"> <canvas id="thesesChart" height="300"></canvas> </div> </div> </div> <div class="col-md-4"> <div class="card"> <div class="card-header"> <h5>Status Tugas Akhir</h5> </div> <div class="card-body"> <canvas id="statusChart" height="200"></canvas> </div> </div> </div> </div> <div class="row mb-4"> <div class="col-md-6"> <div class="card"> <div class="card-header"> <h5>Program Studi</h5> </div> <div class="card-body"> <canvas id="programChart" height="250"></canvas> </div> </div> </div> <div class="col-md-6"> <div class="card"> <div class="card-header"> <h5>Top 10 Penulis Teraktif</h5> </div> <div class="card-body"> <canvas id="authorsChart" height="250"></canvas> </div> </div> </div> </div> <!-- Tabel Top Downloads --> <div class="card mb-4"> <div class="card-header"> <h5>Top 10 Tugas Akhir Paling Banyak Diunduh</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>No</th> <th>Judul</th> <th>Penulis</th> <th>Tahun</th> <th>Downloads</th> <th>Views</th> </tr> </thead> <tbody> <?php $no = 1; foreach($top_downloads as $thesis): ?> <tr> <td><?php echo $no++; ?></td> <td> <a href="../detail.php?id=<?php echo $thesis['id']; ?>" target="_blank"> <?php echo htmlspecialchars(substr($thesis['title'], 0, 60)) . '...'; ?> </a> </td> <td><?php echo htmlspecialchars($thesis['authors']); ?></td> <td><?php echo $thesis['year']; ?></td> <td> <span class="badge bg-success"><?php echo number_format($thesis['downloads']); ?></span> </td> <td><?php echo number_format($thesis['views']); ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <!-- Statistik Tahunan --> <div class="card"> <div class="card-header"> <h5>Statistik Tahunan</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>Tahun</th> <th>Jumlah TA</th> <th>Total Views</th> <th>Total Downloads</th> <th>Rata-rata Views/TA</th> <th>Rata-rata Downloads/TA</th> </tr> </thead> <tbody> <?php foreach($yearly_stats as $stat): ?> <tr> <td><strong><?php echo $stat['year']; ?></strong></td> <td><?php echo $stat['total']; ?></td> <td><?php echo number_format($stat['total_views']); ?></td> <td><?php echo number_format($stat['total_downloads']); ?></td> <td><?php echo $stat['total'] > 0 ? round($stat['total_views'] / $stat['total'], 1) : 0; ?></td> <td><?php echo $stat['total'] > 0 ? round($stat['total_downloads'] / $stat['total'], 1) : 0; ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </main> </div> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script> // Chart Upload per Bulan <?php if($period == 'monthly'): ?> var ctx1 = document.getElementById('thesesChart').getContext('2d'); new Chart(ctx1, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'], datasets: [{ label: 'Jumlah Upload <?php echo $year; ?>', data: [<?php echo implode(',', array_column($monthly_stats, 'total')); ?>], borderColor: 'rgb(75, 192, 192)', backgroundColor: 'rgba(75, 192, 192, 0.2)', tension: 0.1 }] } }); <?php else: ?> var ctx1 = document.getElementById('thesesChart').getContext('2d'); new Chart(ctx1, { type: 'bar', data: { labels: [<?php echo "'" . implode("','", array_column($yearly_stats, 'year')) . "'"; ?>], datasets: [{ label: 'Jumlah Upload per Tahun', data: [<?php echo implode(',', array_column($yearly_stats, 'total')); ?>], backgroundColor: 'rgba(54, 162, 235, 0.5)', borderColor: 'rgb(54, 162, 235)', borderWidth: 1 }] } }); <?php endif; ?> // Chart Status var ctx2 = document.getElementById('statusChart').getContext('2d'); new Chart(ctx2, { type: 'doughnut', data: { labels: ['Approved', 'Pending', 'Rejected', 'Revision'], datasets: [{ data: [ <?php echo $status_stats['approved'] ?? 0; ?>, <?php echo $status_stats['pending'] ?? 0; ?>, <?php echo $status_stats['rejected'] ?? 0; ?>, <?php echo $status_stats['revision'] ?? 0; ?> ], backgroundColor: ['#28a745', '#ffc107', '#dc3545', '#17a2b8'] }] } }); // Chart Program Studi var ctx3 = document.getElementById('programChart').getContext('2d'); new Chart(ctx3, { type: 'pie', data: { labels: [<?php echo "'" . implode("','", array_column($program_stats, 'program_study')) . "'"; ?>], datasets: [{ data: [<?php echo implode(',', array_column($program_stats, 'total')); ?>], backgroundColor: [ '#007bff', '#28a745', '#17a2b8', '#ffc107', '#dc3545', '#6610f2' ] }] } }); // Chart Top Authors var ctx4 = document.getElementById('authorsChart').getContext('2d'); new Chart(ctx4, { type: 'bar', data: { labels: [<?php echo "'" . implode("','", array_column($top_authors, 'full_name')) . "'"; ?>], datasets: [{ label: 'Jumlah Tugas Akhir', data: [<?php echo implode(',', array_column($top_authors, 'total_theses')); ?>], backgroundColor: 'rgba(255, 193, 7, 0.5)', borderColor: 'rgb(255, 193, 7)', borderWidth: 1 }] }, options: { indexAxis: 'y', scales: { x: { beginAtZero: true, stepSize: 1 } } } }); </script> <?php include '../templates/footer.php'; ?> <?php // Fungsi-fungsi statistik function getTotalTheses($conn) { $query = "SELECT COUNT(*) as total FROM theses WHERE status = 'approved'"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC)['total']; } function getTotalAuthors($conn) { $query = "SELECT COUNT(DISTINCT author_id) as total FROM theses WHERE status = 'approved'"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC)['total']; } function getTotalDownloads($conn) { $query = "SELECT SUM(downloads) as total FROM theses"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC)['total'] ?? 0; } function getTotalViews($conn) { $query = "SELECT SUM(views) as total FROM theses"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC)['total'] ?? 0; } function getYearlyStats($conn) { $query = "SELECT YEAR(submitted_at) as year, COUNT(*) as total, SUM(views) as total_views, SUM(downloads) as total_downloads FROM theses WHERE status = 'approved' GROUP BY YEAR(submitted_at) ORDER BY year DESC"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function getMonthlyStats($conn, $year) { $query = "SELECT MONTH(submitted_at) as month, COUNT(*) as total FROM theses WHERE status = 'approved' AND YEAR(submitted_at) = :year GROUP BY MONTH(submitted_at) ORDER BY month"; $stmt = $conn->prepare($query); $stmt->bindParam(':year', $year); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $monthly = array_fill(1, 12, ['total' => 0]); foreach($results as $result) { $monthly[$result['month']] = $result; } return $monthly; } function getTopAuthors($conn, $limit) { $query = "SELECT u.id, u.full_name, u.nim, COUNT(t.id) as total_theses, SUM(t.downloads) as total_downloads, SUM(t.views) as total_views FROM users u JOIN theses t ON u.id = t.author_id WHERE t.status = 'approved' GROUP BY u.id ORDER BY total_theses DESC LIMIT :limit"; $stmt = $conn->prepare($query); $stmt->bindParam(':limit', $limit, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function getTopDownloads($conn, $limit) { $query = "SELECT id, title, authors, year, downloads, views FROM theses WHERE status = 'approved' ORDER BY downloads DESC LIMIT :limit"; $stmt = $conn->prepare($query); $stmt->bindParam(':limit', $limit, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function getProgramStats($conn) { $query = "SELECT program_study, COUNT(*) as total FROM theses WHERE status = 'approved' GROUP BY program_study ORDER BY total DESC"; $stmt = $conn->prepare($query); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function getStatusStats($conn) { $query = "SELECT status, COUNT(*) as total FROM theses GROUP BY status"; $stmt = $conn->prepare($query); $stmt->execute(); $stats = []; foreach($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $stats[$row['status']] = $row['total']; } return $stats; } ?>