<?php 
include_once('header.php'); 
$latest_news=get_child('','','');

if(!empty($_GET['sid']))
$upd=checkout_status($_GET['sid']);

$seltotal=executework("select * from lms_cart_course where user_id='".$_SESSION['login_id']."' and order_status NOT IN('completed','cancelled')");
$cnttotal=@mysqli_num_rows($seltotal);
$rowtotal=@mysqli_fetch_array($seltotal);
?>

<style>
.class-header{
    background: linear-gradient(45deg, #0d6efd, #0dcaf0);
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
}
.card:hover{
    transform: translateY(-5px);
    transition: 0.3s;
}
</style>

<div class="container my-5">

    <!-- ================= CLASS 6 ================= -->
    <div class="mb-5">
	<?php
		//$selcart=executework("select DISTINCT lms_child_details.* from lms_cart_list,lms_child_details where lms_cart_list.child_id=lms_child_details.id and lms_cart_list.parent_id='".$_SESSION['login_id']."'");
		//echo "select DISTINCT lms_child_details.* from lms_cart_list,lms_child_details,lms_cart_course where lms_cart_list.child_id=lms_child_details.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')";
		
		//$selcart=executework("select DISTINCT lms_child_details.* from lms_cart_list,lms_child_details,lms_cart_course where lms_cart_list.child_id=lms_child_details.id  and lms_cart_course.cart_id=lms_cart_list.cart_id and lms_cart_course.user_id=lms_cart_list.parent_id and lms_cart_list.parent_id='".$_SESSION['login_id']."' and lms_cart_course.order_status NOT IN('completed','cancelled')");
		
		//$selcart=executework("select DISTINCT lms_child_details.* from lms_cart_list,lms_child_details where lms_cart_list.child_id=lms_child_details.id and lms_cart_list.parent_id='".$_SESSION['login_id']."'");
		
		$selcart=executework("select DISTINCT lms_child_details.* from lms_cart_list,lms_child_details,lms_cart_course where lms_cart_list.child_id=lms_child_details.id and lms_cart_course.cart_id=lms_cart_list.cart_id and lms_cart_course.order_status NOT IN('completed','cancelled') and lms_cart_list.parent_id='".$_SESSION['login_id']."';
");		
		while($rowcart=@mysqli_fetch_array($selcart))
		{			
			$selamount=executework("select *,SUM(lms_cart_list.amount) AS child_total from lms_cart_list,lms_cart_course where lms_cart_list.cart_id=lms_cart_course.cart_id and lms_cart_course.order_status NOT IN('completed','cancelled') and lms_cart_list.parent_id='".$_SESSION['login_id']."' and lms_cart_list.child_id='".$rowcart['id']."'");
			$cntamount=@mysqli_num_rows($selamount);
			$rowamount=@mysqli_fetch_array($selamount);
	?>
        <div class="class-header mb-3 mt-4">
        	<div>
            	<?php echo $rowcart['child_name']; ?>
            </div>
            <div align="right">
            	<strong> $ <?php echo $rowamount['child_total']; ?> </strong>
            </div>
        </div>

        <div class="row g-4">

           <?php 
				$sql=executework("select *,(lms_cart_list.id) AS main_id , (lms_cart_list.amount) as cost_product 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='".$rowcart['id']."' and lms_cart_course.order_status NOT IN('completed','cancelled')");
					if(mysqli_num_rows($sql)>0)
					{
						while($row=mysqli_fetch_assoc($sql))
						{
			?>
            <div class="col-md-12">
                <div class="card shadow border-0">
                    <div class="card-body">

                        <h5 class="fw-bold"><?php echo get_course_name($row['course_id']); ?></h5>
                        <p class="text-muted">
                        	<?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;
							 ?>
                        </p>

                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">📚 Classes: <?php echo $row['no_of_class']; ?></li>
                            <li class="list-group-item">⏱ Duration: <?php echo $row['duration']; ?></li>
                            <li class="list-group-item">💰 Price: $ <?php echo $row['cost_product']; ?></li>
                        </ul>

                    </div>
                </div>
            </div>
			<?php } } ?>
            

        </div>
<?php } ?>
    </div>
	
    

    <!-- ================= TOTAL ================= -->
    <div class="card shadow border-0">
        <div class="card-body d-flex justify-content-between align-items-center">

            <h4 class="mb-0">Total Price</h4>
            <h4 class="text-success mb-0">$ <?php echo $rowtotal['amount']; ?></h4>

        </div>
    </div>

    <!-- BUTTON -->
    <div class="text-center mt-4">
        <button class="btn btn-success px-5 py-2" onClick="validate_status('<?php echo $rowtotal['id']; ?>','','checkout.php');">Proceed to Payment</button>
    </div>

</div>

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