<?php include_once('header.php'); 

if(!empty($_POST['child_id']))
$child_id=$_POST['mid'];
else if(!empty($_GET['child_id']))
$child_id=$_GET['child_id'];
else
$child_id='';

$sel=executework("select *,(lms_cart_list.id) AS main_id from lms_cart_list,lms_instructor_courses,lms_cart_course where lms_instructor_courses.id=lms_cart_list.purchage_course_id and lms_cart_course.cart_id=lms_cart_list.cart_id and lms_cart_list.parent_id='".$_SESSION['login_id']."' and lms_cart_list.child_id='".$child_id."' and lms_cart_course.order_status IN('completed')");
$cnt=@mysqli_num_rows($sel);
$row=@mysqli_fetch_array($sel);
?>

<style>

body {
    background: #f5f7fa;
}

/* Course Card */
.course-card {
    border: none;
    border-radius: 15px;
    overflow: hidden;
    transition: all 0.4s ease;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    background: #fff;
    position: relative;
}

/* Hover Effect */
.course-card:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

/* Image Container */
.course-img {
    overflow: hidden;
}

/* Image Zoom */
.course-img img {
    transition: transform 0.5s ease;
    width: 100%;
}

.course-card:hover .course-img img {
    transform: scale(1.1);
}

/* Badge */
.course-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: #0d6efd;
    color: #fff;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 20px;
}

/* Content */
.course-body {
    padding: 20px;
}

.course-title {
    font-size: 18px;
    font-weight: 600;
}

.course-desc {
    font-size: 14px;
    color: #666;
    margin: 10px 0;
    height: 45px;
    overflow: hidden;
}

/* Footer */
.course-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Button Animation */
.btn-custom {
    border-radius: 25px;
    padding: 6px 15px;
    transition: 0.3s;
}

.btn-custom:hover {
    background: #0d6efd;
    color: #fff;
    transform: scale(1.05);
}

</style>


<div class="container py-5">
    <div class="row g-4">
	<?php 		 
		
		// $sql=executework("SELECT *FROM lms_cart_course RIGHT JOIN lms_cart_list ON lms_cart_course.cart_id = lms_cart_list.cart_id where lms_cart_list.child_id='".$child_id."' and lms_cart_list.parent_id='".$_SESSION['login_id']."' and  lms_cart_course.order_status in('completed')");
		$sql=executework("SELECT *
FROM lms_cart_list cl
JOIN lms_cart_course cc 
    ON cc.cart_id = cl.cart_id
JOIN lms_instructor_courses ic 
    ON ic.id = cl.purchage_course_id
WHERE cl.child_id = '10'
AND cl.parent_id = '2'
AND cc.order_status = 'completed'");
		 	if(mysqli_num_rows($sql)>0)
			{
				$sno=1;
				while($row=mysqli_fetch_assoc($sql))
				{
	?>
        <!-- Course 1 -->
        <div class="col-md-4">
            <div class="course-card">
                <div class="course-badge"><?php  $course=get_course_type($row['course_id']); echo strtoupper(str_replace(['_', '-'], ' ', $course)); ?></div>
                <div class="course-img">
                    <img src="https://via.placeholder.com/400x250" alt="">
                </div>

                <div class="course-body">
                    <div class="course-title"><?php echo $row['course_title']; ?></div>
                    <div class="course-desc">
                        <?php 
					 $content = urldecode($row['details']); 
					$text = strip_tags($content);
					$lines = preg_split('/\r\n|\r|\n/', $text);
					// Take first 3 lines
					$first3 = array_slice($lines, 0, 3);
					
					$details = implode("<br>", $first3);
					
					if (count($lines) > 3) {
						$details .= "...";
					}
					
					echo $details;
				 ?>
                    </div>

                    <div class="course-footer">
                        <span class="text-primary fw-bold">&nbsp;</span>
                        <button class="btn btn-outline-primary btn-custom">View Course</button>
                    </div>
                </div>
            </div>
        </div>
	<?php } } ?>
      

    </div>
</div>

<?php include_once('footer.php'); ?>