File "report5.php"
Full Path: /home/leadltht/fastlinkinternet.com/wp-comment-form/reports/report5.php
File size: 8.91 KB
MIME-type: text/html
Charset: utf-8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client Reporting</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Select2 CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Select2 JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- Font Awesome for icons -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
</head>
<body>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('/home/leadltht/fastlinkinternet.com/administrator/data-provider/config.php'); // Ensure the correct path to config.php
// Initialize variables
$fromDate = $toDate = $server = '';
$reportDetails = [];
$clientCount = 0;
$aggregatedData = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fromDate = $_POST['fromDate'];
$toDate = $_POST['toDate'];
$server = $_POST['server'];
// Build SQL query based on filters
$sql = "SELECT installation_date, CONCAT(firstname, ' ', COALESCE(middlename,''), ' ', lastname) as fullname, plan_name, plan_price, server
FROM member_list
WHERE 1=1";
if (!empty($fromDate) && !empty($toDate)) {
$sql .= " AND installation_date BETWEEN '$fromDate' AND '$toDate'";
}
if (!empty($server)) {
$sql .= " AND server = '$server'";
}
// Execute query
$result = $conn->query($sql);
if (!$result) {
die("Query failed: " . $conn->error);
}
$reportDetails = $result->fetch_all(MYSQLI_ASSOC);
$clientCount = count($reportDetails);
// Calculate aggregated data for chart
foreach ($reportDetails as $report) {
$key = date('Y-m-d', strtotime($report['installation_date']));
if (!isset($aggregatedData[$key])) {
$aggregatedData[$key] = 0;
}
$aggregatedData[$key]++;
}
// Sort the aggregated data by key
ksort($aggregatedData);
}
?>
<div class="container mt-1">
<h3 class="mb-4">Generate Client Report</h3>
<form method="POST" id="report-form" action="">
<div class="form-group row">
<div class="col-sm-3">
<label for="fromDate" class="col-form-label">From Date:</label>
<input type="date" name="fromDate" id="fromDate" class="form-control" value="<?= $fromDate ?>">
</div>
<div class="col-sm-3">
<label for="toDate" class="col-form-label">To Date:</label>
<input type="date" name="toDate" id="toDate" class="form-control" value="<?= $toDate ?>">
</div>
<div class="col-sm-3">
<label for="server" class="col-form-label">Server:</label>
<select name="server" id="server" class="form-control">
<option value="">Select a server</option>
<!-- Add server options dynamically from the database -->
<?php
$serverResult = $conn->query("SELECT DISTINCT server FROM member_list ORDER BY server ASC");
while ($serverRow = $serverResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($serverRow['server']) . '">' . htmlspecialchars($serverRow['server']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3 d-flex align-items-end">
<button type="submit" class="btn btn-primary">Show Report</button>
</div>
</div>
</form>
</div>
<!-- Display Report Boxes -->
<div class="container mt-4">
<div class="row">
<div class="col-sm-6">
<div class="card text-white bg-success mb-3">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center">
<div>
<h5 class="card-title">Number of Clients Added</h5>
<p class="card-text"><?= $clientCount ?></p>
</div>
<div>
<i class="fas fa-user-plus fa-3x"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Chart.js Graph -->
<div class="container mt-5">
<?php if (!empty($reportDetails)): ?>
<canvas id="reportChart"></canvas>
<script>
$(document).ready(function() {
$('#server').select2({
placeholder: "Select a server",
allowClear: true
});
var ctx = document.getElementById('reportChart').getContext('2d');
var aggregatedData = <?= json_encode($aggregatedData) ?>;
var labels = Object.keys(aggregatedData);
var data = Object.values(aggregatedData);
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Number of Clients Added',
data: data,
backgroundColor: 'rgba(54, 162, 235, 1)', // Blue color
borderColor: 'rgba(54, 162, 235, 1)', // Blue color
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
});
</script>
<?php else: ?>
<p>No data found.</p>
<?php endif; ?>
</div>
<!-- Display Report -->
<div class="container mt-5">
<?php if (!empty($reportDetails)): ?>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Installation Date</th>
<th>Client Name</th>
<th>Plan Name</th>
<th>Plan Price</th>
<th>Server</th>
</tr>
</thead>
<tbody>
<?php $counter = 1; ?>
<?php foreach ($reportDetails as $report): ?>
<tr>
<td><?= $counter++ ?></td>
<td><?= htmlspecialchars($report['installation_date']) ?></td>
<td><?= htmlspecialchars($report['fullname']) ?></td>
<td><?= htmlspecialchars($report['plan_name']) ?></td>
<td>₱<?= number_format($report['plan_price']) ?></td>
<td><?= htmlspecialchars($report['server']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No data found.</p>
<?php endif; ?>
</div>
<!-- Initialize Select2 for Server -->
<script>
$(document).ready(function() {
$('#server').select2({
placeholder: "Select a server",
allowClear: true
});
});
</script>
</body>
</html>