<?php
// includes/functions.php

function logActivity($pdo, $member_id, $action_type, $details) {
    try {
        $stmt = $pdo->prepare("INSERT INTO member_activity_logs 
                              (member_id, action_type, details, ip_address, user_agent, created_at) 
                              VALUES (?, ?, ?, ?, ?, NOW())");
        
        $ip_address = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
        $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'unknown';
        
        $stmt->execute([
            $member_id,
            $action_type,
            $details,
            $ip_address,
            $user_agent
        ]);
        
        return true;
    } catch (PDOException $e) {
        // Log to error log if database logging fails
        error_log("Failed to log activity: " . $e->getMessage());
        return false;
    }
}