<?php
// Simple script to check if tickets exist in the database
require_once 'includes/config.php';
require_once 'includes/db.php';

if (!$pdo) {
    die("Database connection failed");
}

try {
    // Check if tickets table exists and has data
    $stmt = $pdo->query("SELECT COUNT(*) as count FROM tickets");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo "Total tickets in database: " . $result['count'] . "\n";
    
    if ($result['count'] > 0) {
        // Get a few recent tickets
        $stmt = $pdo->query("SELECT id, subject, status, created_at FROM tickets ORDER BY created_at DESC LIMIT 5");
        $tickets = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        echo "Recent tickets:\n";
        foreach ($tickets as $ticket) {
            echo "- Ticket #" . $ticket['id'] . ": " . $ticket['subject'] . " (" . $ticket['status'] . ")\n";
        }
    } else {
        echo "No tickets found in database\n";
    }
    
    // Check ticket types
    $stmt = $pdo->query("SELECT COUNT(*) as count FROM ticket_types");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    echo "Ticket types in database: " . $result['count'] . "\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>