<?php
/**
 * Simple test to verify fixes
 */

require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/config/database.php';
require_once dirname(__DIR__) . '/config/auth.php';

echo "<h1>Simple Test</h1>";

// Test 1: Log file writing
echo "<h2>Test 1: Log File Writing</h2>";
try {
    log_message("Test log message", "INFO");
    echo "✓ Log file write successful<br>";
} catch (Exception $e) {
    echo "❌ Log file write failed: " . $e->getMessage() . "<br>";
}

// Test 2: Database update
echo "<h2>Test 2: Database Update</h2>";
try {
    $user = db_fetch_one("SELECT * FROM users WHERE username = 'admin'");
    if ($user) {
        $result = db_update('users', 
            ['last_login' => date('Y-m-d H:i:s')], 
            'user_id = ?', 
            [$user['user_id']]
        );
        echo "✓ Database update successful<br>";
    }
} catch (Exception $e) {
    echo "❌ Database update failed: " . $e->getMessage() . "<br>";
}

// Test 3: Login function
echo "<h2>Test 3: Login Function</h2>";
try {
    $result = authenticate_user('admin', 'Admin@123', false);
    if (is_array($result) && !isset($result['error'])) {
        echo "✓ Login successful!<br>";
        echo "Welcome, " . $result['first_name'] . " " . $result['last_name'] . "<br>";
    } else {
        echo "❌ Login failed: " . ($result['error'] ?? 'Unknown error') . "<br>";
    }
} catch (Exception $e) {
    echo "❌ Login error: " . $e->getMessage() . "<br>";
}