connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$pendingCount = 0; // Default value
try {
$table = 'fund_trans';
// Check user type and prepare appropriate query
if ($_SESSION['type'] === 'admin') {
// Admin can only see BM requests
$countStmt = $conn->prepare("SELECT COUNT(*) AS pending_count FROM `$table` WHERE status = 0 AND request_usr_type = 'bm'");
} elseif ($_SESSION['type'] === 'bm') {
// BM can only see Admin requests
$countStmt = $conn->prepare("SELECT COUNT(*) AS pending_count FROM `$table` WHERE status = 0 AND request_usr_type = 'admin'");
} else {
// Other user types see nothing
$countStmt = false;
$pendingCount = 0;
}
if ($countStmt) {
$countStmt->execute();
$countResult = $countStmt->get_result();
if ($countResult) {
$row = $countResult->fetch_assoc();
$pendingCount = $row['pending_count'] ?? 0;
}
$countStmt->close();
}
} catch (Exception $e) {
// Log error instead of showing to user
error_log("Error getting pending count: " . $e->getMessage());
}
$conn->close();
?>