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

$sqlfee=executework("select SUM(lms_instructor_courses.course_price) AS total_amount from lms_cart_list,lms_instructor_courses,lms_cart_course where lms_instructor_courses.id=lms_cart_list.purchage_course_id and lms_cart_list.parent_id='".$_SESSION['login_id']."' and lms_cart_course.cart_id=lms_cart_list.cart_id and lms_cart_course.order_status NOT IN('completed','cancelled')");
$cntt=@mysqli_num_rows($sqlfee);
$rowd=@mysqli_fetch_assoc($sqlfee); 

if(!empty($_GET['sid']))
$upd=add_to_cart($_GET['sid'],$_GET['child_id'],$_GET['action']);

?>

<div class="container py-5">
    <h3 class="mb-4">My Cart</h3>
    <?php 
		//$sql=executework("select *,(lms_cart_list.id) AS main_id from lms_cart_list,lms_instructor_courses where lms_instructor_courses.id=lms_cart_list.purchage_course_id and lms_cart_list.parent_id='".$_SESSION['login_id']."'");
		 
		 $sql=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_course.order_status NOT IN('completed','cancelled')");
		 	if(mysqli_num_rows($sql)>0)
			{
				$sno=1;
				while($row=mysqli_fetch_assoc($sql))
				{
	?>
        <div class="cart-course">
            <div class="course-info">
            	<div class="course-type"><?php  $course=get_course_type($row['course_id']); echo strtoupper(str_replace(['_', '-'], ' ', $course)); ?></div>
                <div class="course-title"> <?php echo get_course_name($row['course_id']); ?></div>
           		<div class="course-desc"> 
				<?php //echo urldecode($row['details']); 
					 $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-meta">
                    <span>⏱ 3 Months</span>
                    <span>📚 24 Classes</span>
                </div>
            </div>
            
            <div >
            	<div class="price">$<?php echo $row['course_price']; ?></div>
           		<button class="btn remove-btn" onClick="purchage_status('<?php echo $row['id']; ?>','<?php echo $row['child_id']; ?>','cart.php','remove');" >Remove</button>
            </div>
        
        </div>
    <?php } } ?>
    
    <?php if($rowd['total_amount']>=1){ ?>
    <!-- total -->
    <div class="row mt-4">
    
    <div class="col-md-6">
        <a href="childs_details.php" class="btn btn-outline-primary"> Continue Learning </a>
    </div>
    
    <div class="col-md-6 text-end">
    
    <div class="total-box">
        <h5>Total : $<?php echo $rowd['total_amount']; ?></h5>
        <a href="checkout.php"><button class="btn btn-success mt-2"> Checkout</button></a>
    </div>
    
    </div>
    </div>
<?php } else{ ?>
<div><center> <strong class="text-danger"> No Data Found </strong> </center></div>
<?php } ?>
</div>


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