<?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='';

$courses=get_child_courses($child_id);
?>

<div class="container py-5">
	<input type="hidden" name="child_id" value="<?php echo $child_id; ?>">
   <?php
	  for($i=0;$i<count($courses);$i++)
		  {
			if($courses[$i]['status']==0)
			$clr="primary";
			else
			$clr="success";
	?>
    <div class="course-card parallax" data-speed="2">
        <div class="course-title"><?php echo $courses[$i]['course_title']; ?></div>
        <div class="course-desc">
        	<?php 
				$content = urldecode($courses[$i]['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>
        <a href="course_concepts.php?child_id=<?php echo $child_id; ?>&view_id=<?php echo $courses[$i]['purchage_course_id']; ?>"> <button class="btn btn-primary course-btn">View Course</button></a>
    </div>
	<?php } if(count($courses)==0){ ?>
    	<div> <center> <strong class="text-danger"> No Courses Available <a href="view_courses.php?child_id=<?php echo $child_id; ?>" style="text-decoration:none"> Enrol Now </a> </strong></center></div>
    <?php } ?>
</div>


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