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

if(!empty($_GET['page_index']))
$page_index=$_GET['page_index'];
else if(!empty($_POST['page_index']))
$page_index=$_POST['page_index'];
else
$page_index=1;

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

$n=get_courses_count('',$course_id,'','0,1'); 
if(!empty($n[0]['cnt']))
$count=$n[0]['cnt'];
else
$count=0;
$page_cnt=50;
$sno=(($page_index-1)*$page_cnt)+1;
$pages=ceil($count/$page_cnt); 
$limit=(($page_index-1)*$page_cnt).",50";
$latest_news=get_courses('',$course_id,'',1,$limit);
?>
	<!-- START SECTION TOP -->
	<section class="section-top">
		<div class="container">
			<div class="col-lg-10 offset-lg-1 text-center">
				<div class="section-top-title wow fadeInRight" data-wow-duration="1s" data-wow-delay="0.3s" data-wow-offset="0">
					<h1>Available Courses</h1>
					<ul>
						<li><a href="index.php">Home</a></li>
						<li> / Course</li>
					</ul>
				</div><!-- //.HERO-TEXT -->
			</div><!--- END COL -->
		</div><!--- END CONTAINER -->
	</section>	
	<!-- END SECTION TOP -->

	<!--START COURSE -->
	<div class="best-cpurse section-padding">
		<div class="container">
			<div class="section-title">
			  <h2>Popular Courses</h2>
			  <p>Choose Our <span><u>Top Courses</u></span></p>
			</div>				
			<div class="row">					
				  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="form1" > 
                  	<input type="hidden" name="page_index" value="<?php echo $page_index; ?>" />
                  </form>
                  
               <?php
					  for($i=0;$i<count($latest_news);$i++)
					  {
					  
					  $sela=executework("SELECT * FROM  lms_cart_list,lms_cart_course where lms_cart_course.cart_id=lms_cart_list.cart_id and lms_cart_list.child_id ='".$_SESSION['login_id']."' and lms_cart_list.purchage_course_id='".$latest_news[$i]['id']."' and lms_cart_course.user_type='Student'");
			$cnta=@mysqli_num_rows($sela);
			$rowa=@mysqli_fetch_array($sela); 
    			  ?>
                  
                <div class="col-lg-4 col-sm-6 col-xs-12 wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.1s" data-wow-offset="0">
					<div class="course-slide">
						<div class="course-img">
                        	<?php if(!empty($latest_news[$i]['course_img'])){ ?>
								<img src="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>" alt="">
							<?php } else{ ?>
                           		 <img src="assets/images/banner/course-bg-p2.png" alt="">
                            <?php } ?>
                            <div class="course-date"> 
                            
                            <?php if($cnta==0 && empty($rowa['order_status'])){ ?>
								<span class="month">$<?php echo $latest_news[$i]['course_price']; ?></span>
                            <?php } if($cnta!=0 && $rowa['order_status']=='completed'){ ?>
                            	<span class="month">View</span>
                            <?php } ?>
							</div>
						</div> 
						<div class="course-content"><a class="c_btn" href="view_course.php?course_id=<?php echo $latest_news[$i]['id']; ?>"><?php echo $latest_news[$i]['course_type']; ?></a>
							 <h3>
                                <a href="view_course.php?course_id=<?php echo $latest_news[$i]['id']; ?>">
                                    <?php 
                                        $text = $latest_news[$i]['course_title'];
                                        $words = explode(" ", $text);
                            
                                        echo $words[0];
                                        if (isset($words[1])) {
                                            echo " " . $words[1];
                                        }
                                    ?>
                                </a>
                            </h3>
							<span><i class="fa fa-calendar"></i><?php echo $latest_news[$i]['no_of_class']; ?> Classes</span> <br />
							<span><i class="fa fa-clock-o"></i><?php echo $latest_news[$i]['duration']; ?> Days Course Duration</span> 
						</div>
					</div><!--END COURSE SLIDE -->	
				</div><!--END COL -->
               <?php } 
			    if(count($latest_news)==0)
				{
			   ?> 
              		 <div> <center> <strong style="color:red"> No Data Found </strong> </center> </div>
               <?php } ?>
               
                			
			</div><!--END ROW -->		
		</div><!--END CONTAINER -->
	</div>
	<!--END COURSE -->	
<?php include_once('footer.php'); ?>