<?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-md-4 col-sm-6 mix sale wow fadeInDown" data-wow-duration="2s" data-wow-delay="0.<?php echo $i; ?>s" data-wow-offset="<?php echo $i; ?>">
							<div class="product-grid">
								<div class="product-image">
									
                                    <?php
									 if(!empty($latest_news[$i]['course_img'])){ ?>
                                        <img class="pic-1" src="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>" alt="">
                                        <img class="pic-2" src="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>" alt="">
                                    <?php } else{ ?>
                                         <img class="pic-1" src="assets/images/banner/course-bg-p2.png" alt="">
                                         <img class="pic-2" src="assets/images/banner/course-bg-p2.png" alt="">
                                    <?php } ?>
                                   
									<ul class="social">
										<li> 
                                            <a href="javascript:void(0);" class="popup-img" data-image="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>"><i class="ti-zoom-in"></i></a>
                                        </li>
										<li><a href="" data-tip="Add to Wishlist"><i class="ti-bag"></i></a></li>
										<li><a href="view_course.php?course_id=<?php echo $latest_news[$i]['id']; ?>" data-tip="Add to Cart"><i class="ti-shopping-cart"></i></a></li>
									</ul>
									<span class="product-new-label"><?php $result = str_replace("_", " ", $latest_news[$i]['course_type']); echo mb_strtoupper($result); ?></span>
								</div>
								<ul class="rating">
									<li class="fa fa-star"></li>
									<li class="fa fa-star"></li>
									<li class="fa fa-star"></li>
									<li class="fa fa-star"></li>
									<li class="fa fa-star"></li>
								</ul>
								<div class="product-content">
									<h3 class="title"><a href="view_course.php?course_id=<?php echo $latest_news[$i]['id']; ?>">
									<?php 
                                        $text = $latest_news[$i]['course_title'];
										$text = trim($text);
										
										if (mb_strlen($text) > 26) {
											echo mb_substr($text, 0, 26) . '...';
										} else {
											echo $text;
										}
                                    ?></a></h3>
									<div class="price">$<?php echo $latest_news[$i]['course_price']/100*$latest_news[$i]['course_discount']; ?>
										<span>$<?php echo $latest_news[$i]['course_price']; ?></span>
									</div>
									<a class="add-to-cart" href="">+ Add To Cart</a>
								</div>
							</div>
						</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'); ?>