<?php
/**
 * Logout Handler
 * Dozar & Tripper Management System
 */

require_once __DIR__ . '/config/config.php';

// Log logout activity before destroying session
if (isLoggedIn() && file_exists(__DIR__ . '/includes/activity_log.php')) {
    require_once __DIR__ . '/includes/activity_log.php';
    $pdo = getPDO();
    logActivity($pdo, 'logout', 'auth', $_SESSION['user_id'], 'User logged out: ' . ($_SESSION['full_name'] ?? ''));
}

// Destroy session
session_destroy();

// Redirect to login page
header("Location: " . SITE_URL . "/login.php");
exit;
