function is_admin($user_id) { global $conn; $sql = "SELECT is_admin FROM users WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); return $user['is_admin'] == 1; } function get_total_properties() { global $conn; $sql = "SELECT COUNT(*) as total FROM properties"; $result = $conn->query($sql); $row = $result->fetch_assoc(); return $row['total']; } function get_total_users() { global $conn; $sql = "SELECT COUNT(*) as total FROM users"; $result = $conn->query($sql); $row = $result->fetch_assoc(); return $row['total']; } function get_total_inquiries() { global $conn; $sql = "SELECT COUNT(*) as total FROM inquiries"; $result = $conn->query($sql); $row = $result->fetch_assoc(); return $row['total']; } function get_total_blog_posts() { global $conn; $sql = "SELECT COUNT(*) as total FROM blog_posts"; $result = $conn->query($sql); $row = $result->fetch_assoc(); return $row['total']; } function get_recent_activities() { global $conn; $sql = "SELECT * FROM ( SELECT 'New User' as type, name as description, created_at FROM users UNION ALL SELECT 'New Property' as type, title as description, created_at FROM properties UNION ALL SELECT 'New Inquiry' as type, CONCAT('Inquiry for ', p.title) as description, i.created_at FROM inquiries i JOIN properties p ON i.property_id = p.id UNION ALL SELECT 'New Blog Post' as type, title as description, created_at FROM blog_posts ) as activities ORDER BY created_at DESC LIMIT 10"; $result = $conn->query($sql); return $result->fetch_all(MYSQLI_ASSOC); }