Your IP : 216.73.216.93


Current Path : /home/users/unlimited/www/nigeria.codeskitter.site/
Upload File :
Current File : /home/users/unlimited/www/nigeria.codeskitter.site/course-details.php

<?php
include 'includes/config.php';
include 'includes/header.php';

if(!isset($_GET['id'])) {
    header("Location: courses.php");
    exit();
}

$course_id = $_GET['id'];

// Check if user is enrolled
$is_enrolled = false;
if(isset($_SESSION['user_id'])) {
    $enrollment_sql = "SELECT * FROM enrollments WHERE user_id = ? AND course_id = ?";
    $enrollment_stmt = $conn->prepare($enrollment_sql);
    $enrollment_stmt->bind_param("ii", $_SESSION['user_id'], $course_id);
    $enrollment_stmt->execute();
    $is_enrolled = $enrollment_stmt->get_result()->num_rows > 0;
}

// Redirect to course content if enrolled, otherwise show details
if($is_enrolled) {
    header("Location: course-content.php?id=" . $course_id);
    exit();
}

// Get course details for non-enrolled users
$course_sql = "SELECT c.*, cat.name as category_name, i.name as instructor_name 
               FROM courses c 
               LEFT JOIN categories cat ON c.category_id = cat.id 
               LEFT JOIN instructors i ON c.instructor_id = i.id 
               WHERE c.id = ?";
$course_stmt = $conn->prepare($course_sql);
$course_stmt->bind_param("i", $course_id);
$course_stmt->execute();
$course_result = $course_stmt->get_result();

if($course_result->num_rows == 0) {
    header("Location: courses.php");
    exit();
}

$course = $course_result->fetch_assoc();
// $image_path = getCourseImagePath($course['image']);
?>

<div class="container py-5">
    <div class="row">
        <div class="col-lg-8">
            <!-- Course details similar to course-content.php but without content -->
            <!-- This page will only show basic info and enrollment options -->
            <div class="card mb-4">
                <div class="card-body">
                    <h1 class="h2 mb-3"><?php echo htmlspecialchars($course['title']); ?></h1>
                    <p class="lead"><?php echo htmlspecialchars($course['description']); ?></p>
                    
                    <div class="alert alert-info">
                        <h5><i class="bi bi-info-circle me-2"></i>Enroll to Access Content</h5>
                        <p class="mb-0">Enroll in this course to view the full content and start learning!</p>
                    </div>
                    
                    <a href="course-content.php?id=<?php echo $course['id']; ?>" class="btn btn-primary">
                        View Course Preview
                    </a>
                </div>
            </div>
        </div>
        
        <div class="col-lg-4">
            <!-- Enrollment sidebar similar to course-content.php -->
            <div class="card">
                <div class="card-body">
                    <div class="price-section text-center mb-4">
                        <?php if($course['old_price'] > 0): ?>
                        <div class="old-price text-muted text-decoration-line-through mb-1">
                            $<?php echo number_format($course['old_price'], 2); ?>
                        </div>
                        <?php endif; ?>
                        <div class="current-price h3 text-primary mb-3">
                            <?php echo ($course['current_price'] == 0) ? 'Free' : '$' . number_format($course['current_price'], 2); ?>
                        </div>
                    </div>
                    
                    <div class="d-grid gap-2">
                        <?php if($course['current_price'] == 0): ?>
                            <a href="enroll.php?course_id=<?php echo $course['id']; ?>" class="btn btn-success btn-lg">
                                <i class="bi bi-play-circle me-2"></i>Enroll for Free
                            </a>
                        <?php else: ?>
                            <a href="checkout.php?course_id=<?php echo $course['id']; ?>" class="btn btn-primary btn-lg">
                                <i class="bi bi-cart me-2"></i>Enroll Now
                            </a>
                            <form method="POST" action="add_to_cart.php" class="d-inline">
                                <input type="hidden" name="course_id" value="<?php echo $course['id']; ?>">
                                <button type="submit" name="add_to_cart" class="btn btn-outline-primary w-100">
                                    <i class="bi bi-cart-plus me-2"></i>Add to Cart
                                </button>
                            </form>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'includes/footer.php'; ?>