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/.cursor-server/data/User/History/33ee19dd/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/.cursor-server/data/User/History/33ee19dd/sWwv.php
<?php
/**
 * Subscription Helper Functions
 * Functions to check subscription status and monthly track limits
 */

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

/**
 * Check if user has active subscription
 */
function hasActiveSubscription($user_id) {
    $pdo = getDBConnection();
    
    $stmt = $pdo->prepare("
        SELECT id, plan_name, status, current_period_end
        FROM user_subscriptions
        WHERE user_id = ?
        AND status IN ('active', 'trialing')
        AND current_period_end > NOW()
        ORDER BY created_at DESC
        LIMIT 1
    ");
    $stmt->execute([$user_id]);
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

/**
 * Get or create monthly track usage record
 */
function getMonthlyTrackUsage($user_id, $plan_name = null) {
    $pdo = getDBConnection();
    $year_month = date('Y-m');
    
    // Get or create usage record
    $stmt = $pdo->prepare("
        SELECT * FROM monthly_track_usage
        WHERE user_id = ? AND year_month = ?
    ");
    $stmt->execute([$user_id, $year_month]);
    $usage = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$usage) {
        // Determine track limit based on plan
        $track_limit = 0;
        if ($plan_name === 'essential') {
            $track_limit = 5;
        }
        
        // Create new record
        $stmt = $pdo->prepare("
            INSERT INTO monthly_track_usage (user_id, year_month, tracks_created, track_limit, reset_at)
            VALUES (?, ?, 0, ?, NOW())
        ");
        $stmt->execute([$user_id, $year_month, $track_limit]);
        
        // Get the created record
        $stmt = $pdo->prepare("
            SELECT * FROM monthly_track_usage
            WHERE user_id = ? AND year_month = ?
        ");
        $stmt->execute([$user_id, $year_month]);
        $usage = $stmt->fetch(PDO::FETCH_ASSOC);
    }
    
    return $usage;
}

/**
 * Check if user can create a track (monthly limit check)
 * Returns array with 'allowed' => true/false and 'message' => string
 */
function canCreateTrack($user_id) {
    $pdo = getDBConnection();
    
    // Get user info
    $stmt = $pdo->prepare("SELECT plan FROM users WHERE id = ?");
    $stmt->execute([$user_id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$user) {
        return ['allowed' => false, 'message' => 'User not found'];
    }
    
    // If user has 'essential' plan, check monthly limit
    if (strtolower($user['plan']) === 'essential') {
        $subscription = hasActiveSubscription($user_id);
        
        if (!$subscription) {
            return [
                'allowed' => false,
                'message' => 'Your subscription is not active. Please renew your subscription to create tracks.'
            ];
        }
        
        $usage = getMonthlyTrackUsage($user_id, 'essential');
        
        if ($usage['tracks_created'] >= $usage['track_limit']) {
            $next_reset = date('F 1, Y', strtotime('first day of next month'));
            return [
                'allowed' => false,
                'message' => "You've reached your monthly limit of {$usage['track_limit']} tracks. Your limit will reset on {$next_reset}.",
                'tracks_used' => $usage['tracks_created'],
                'track_limit' => $usage['track_limit']
            ];
        }
        
        return [
            'allowed' => true,
            'tracks_used' => $usage['tracks_created'],
            'track_limit' => $usage['track_limit'],
            'tracks_remaining' => $usage['track_limit'] - $usage['tracks_created']
        ];
    }
    
    // For other plans (free, starter, pro, premium), use credit system
    return ['allowed' => true, 'system' => 'credits'];
}

/**
 * Increment monthly track usage
 */
function incrementMonthlyTrackUsage($user_id) {
    $pdo = getDBConnection();
    $year_month = date('Y-m');
    
    $stmt = $pdo->prepare("
        UPDATE monthly_track_usage
        SET tracks_created = tracks_created + 1,
            updated_at = NOW()
        WHERE user_id = ? AND year_month = ?
    ");
    $stmt->execute([$user_id, $year_month]);
    
    return $stmt->rowCount() > 0;
}

/**
 * Get subscription info for user
 */
function getSubscriptionInfo($user_id) {
    $pdo = getDBConnection();
    
    $stmt = $pdo->prepare("
        SELECT 
            us.*,
            u.name as user_name,
            u.email as user_email
        FROM user_subscriptions us
        JOIN users u ON us.user_id = u.id
        WHERE us.user_id = ?
        ORDER BY us.created_at DESC
        LIMIT 1
    ");
    $stmt->execute([$user_id]);
    return $stmt->fetch(PDO::FETCH_ASSOC);
}
?>


CasperSecurity Mini