T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/fix_missing_purchase_notification.php
<?php
/**
 * Script to fix missing purchase notifications
 * Finds purchases without notifications and creates them
 */

require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/utils/artist_notifications.php';

header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title>Fix Missing Purchase Notifications</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
        .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; }
        h1 { color: #333; }
        .section { margin: 20px 0; padding: 15px; background: #f9f9f9; border-radius: 5px; }
        table { width: 100%; border-collapse: collapse; margin: 10px 0; }
        th, td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }
        th { background: #667eea; color: white; }
        .success { color: #48bb78; }
        .error { color: #e53e3e; }
        .info { color: #4299e1; }
        .button { display: inline-block; padding: 10px 20px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; margin: 5px; }
        .button:hover { background: #5568d3; }
    </style>
</head>
<body>
<div class="container">
    <h1>🔔 Fix Missing Purchase Notifications</h1>

<?php
try {
    $pdo = getDBConnection();
    if (!$pdo) {
        throw new Exception("Database connection failed");
    }
    
    // Ensure table exists
    try {
        $pdo->exec("
            CREATE TABLE IF NOT EXISTS artist_purchase_notifications (
                id INT AUTO_INCREMENT PRIMARY KEY,
                artist_id INT NOT NULL,
                track_id INT NOT NULL,
                buyer_id INT NOT NULL,
                purchase_id INT NOT NULL,
                price_paid DECIMAL(10,2) NOT NULL,
                is_read TINYINT(1) DEFAULT 0,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                INDEX idx_artist_read (artist_id, is_read),
                INDEX idx_created_at (created_at),
                INDEX idx_artist_id (artist_id),
                INDEX idx_track_id (track_id),
                INDEX idx_buyer_id (buyer_id)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
        ");
    } catch (PDOException $e) {
        // Table might already exist
    }
    
    // Find purchases without notifications
    echo "<div class='section'>";
    echo "<h2>📋 Purchases Without Notifications</h2>";
    
    $stmt = $pdo->prepare("
        SELECT 
            tp.id as purchase_id,
            tp.user_id as buyer_id,
            tp.track_id,
            tp.price_paid,
            tp.purchase_date,
            mt.title as track_title,
            mt.user_id as artist_id,
            artist.name as artist_name,
            buyer.name as buyer_name,
            CASE WHEN apn.id IS NOT NULL THEN 1 ELSE 0 END as has_notification
        FROM track_purchases tp
        JOIN music_tracks mt ON tp.track_id = mt.id
        JOIN users artist ON mt.user_id = artist.id
        JOIN users buyer ON tp.user_id = buyer.id
        LEFT JOIN artist_purchase_notifications apn ON tp.id = apn.purchase_id
        WHERE apn.id IS NULL
        ORDER BY tp.purchase_date DESC
        LIMIT 50
    ");
    $stmt->execute();
    $missing_notifications = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<p class='info'>Found <strong>" . count($missing_notifications) . "</strong> purchases without notifications</p>";
    
    if (!empty($missing_notifications)) {
        echo "<table>";
        echo "<tr><th>Purchase ID</th><th>Track</th><th>Artist</th><th>Buyer</th><th>Price</th><th>Date</th><th>Action</th></tr>";
        
        foreach ($missing_notifications as $purchase) {
            echo "<tr>";
            echo "<td>{$purchase['purchase_id']}</td>";
            echo "<td>" . htmlspecialchars($purchase['track_title']) . " (ID: {$purchase['track_id']})</td>";
            echo "<td>{$purchase['artist_name']} (ID: {$purchase['artist_id']})</td>";
            echo "<td>{$purchase['buyer_name']} (ID: {$purchase['buyer_id']})</td>";
            echo "<td>\${$purchase['price_paid']}</td>";
            echo "<td>{$purchase['purchase_date']}</td>";
            echo "<td><a href='?create_notification={$purchase['purchase_id']}' class='button'>Create Notification</a></td>";
            echo "</tr>";
        }
        echo "</table>";
    }
    echo "</div>";
    
    // Handle notification creation
    if (isset($_GET['create_notification'])) {
        $purchase_id = (int)$_GET['create_notification'];
        
        echo "<div class='section'>";
        echo "<h2>🔧 Creating Notification for Purchase ID: $purchase_id</h2>";
        
        // Get purchase details
        $stmt = $pdo->prepare("
            SELECT 
                tp.id as purchase_id,
                tp.user_id as buyer_id,
                tp.track_id,
                tp.price_paid,
                mt.user_id as artist_id
            FROM track_purchases tp
            JOIN music_tracks mt ON tp.track_id = mt.id
            WHERE tp.id = ?
        ");
        $stmt->execute([$purchase_id]);
        $purchase = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if (!$purchase) {
            echo "<p class='error'>Purchase not found!</p>";
        } else {
            // Check if notification already exists
            $stmt = $pdo->prepare("SELECT id FROM artist_purchase_notifications WHERE purchase_id = ?");
            $stmt->execute([$purchase_id]);
            $existing = $stmt->fetch();
            
            if ($existing) {
                echo "<p class='error'>Notification already exists for this purchase!</p>";
            } else {
                // Create notification
                $result = notifyArtistOfTrackPurchase(
                    $purchase['artist_id'],
                    $purchase['track_id'],
                    $purchase['buyer_id'],
                    $purchase['price_paid'],
                    $purchase['purchase_id']
                );
                
                if ($result) {
                    echo "<p class='success'>✅ Notification created successfully!</p>";
                    echo "<p><a href='notifications.php' class='button'>View Notifications</a></p>";
                } else {
                    echo "<p class='error'>❌ Failed to create notification. Check error logs.</p>";
                }
            }
        }
        echo "</div>";
    }
    
    // Search for specific track "Ton Visage"
    echo "<div class='section'>";
    echo "<h2>🔍 Search for 'Ton Visage' Purchase</h2>";
    
    $stmt = $pdo->prepare("
        SELECT 
            tp.id as purchase_id,
            tp.user_id as buyer_id,
            tp.track_id,
            tp.price_paid,
            tp.purchase_date,
            mt.title as track_title,
            mt.user_id as artist_id,
            artist.name as artist_name,
            buyer.name as buyer_name,
            CASE WHEN apn.id IS NOT NULL THEN 1 ELSE 0 END as has_notification,
            apn.id as notification_id
        FROM track_purchases tp
        JOIN music_tracks mt ON tp.track_id = mt.id
        JOIN users artist ON mt.user_id = artist.id
        JOIN users buyer ON tp.user_id = buyer.id
        LEFT JOIN artist_purchase_notifications apn ON tp.id = apn.purchase_id
        WHERE mt.title LIKE '%Ton Visage%' OR mt.title LIKE '%ton visage%'
        ORDER BY tp.purchase_date DESC
    ");
    $stmt->execute();
    $ton_visage_purchases = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($ton_visage_purchases)) {
        echo "<p class='info'>No purchases found for 'Ton Visage'</p>";
    } else {
        echo "<p class='info'>Found <strong>" . count($ton_visage_purchases) . "</strong> purchase(s) for 'Ton Visage'</p>";
        echo "<table>";
        echo "<tr><th>Purchase ID</th><th>Track</th><th>Artist</th><th>Buyer</th><th>Price</th><th>Date</th><th>Has Notification</th><th>Action</th></tr>";
        
        foreach ($ton_visage_purchases as $purchase) {
            $has_notif = $purchase['has_notification'] ? '✅ Yes' : '❌ No';
            $action = $purchase['has_notification'] 
                ? "<span class='success'>Already exists</span>" 
                : "<a href='?create_notification={$purchase['purchase_id']}' class='button'>Create</a>";
            
            echo "<tr>";
            echo "<td>{$purchase['purchase_id']}</td>";
            echo "<td>" . htmlspecialchars($purchase['track_title']) . "</td>";
            echo "<td>{$purchase['artist_name']} (ID: {$purchase['artist_id']})</td>";
            echo "<td>{$purchase['buyer_name']} (ID: {$purchase['buyer_id']})</td>";
            echo "<td>\${$purchase['price_paid']}</td>";
            echo "<td>{$purchase['purchase_date']}</td>";
            echo "<td>{$has_notif}</td>";
            echo "<td>{$action}</td>";
            echo "</tr>";
        }
        echo "</table>";
    }
    echo "</div>";
    
} catch (Exception $e) {
    echo "<div class='section'>";
    echo "<p class='error'>Error: " . htmlspecialchars($e->getMessage()) . "</p>";
    echo "</div>";
}
?>

</div>
</body>
</html>


CasperSecurity Mini