<?php /*?><?php
include_once('functions.php');

$course_id = $_POST['course_id'] ?? '';
$limit = 4;

if(empty($course_id))
{
	$latest_news = get_courses_filter($course_id,'','',1,$limit);
}
else
{
	$latest_news = get_courses_filter('',$course_id,'',1,$limit);
}

//$latest_news = get_courses_filter($course_id,'','',1,$limit);
//$latest_news = get_course_master($course_id,$limit);
$cart_ids = get_cart_details();

for($i=0;$i<count($latest_news);$i++)
{
    if(in_array($latest_news[$i]['id'],$cart_ids))
        $add=1;
    else
        $add=0;
?>

<div class="col-lg-4 col-md-4 col-sm-6">
    <div class="product-grid">
        <div class="product-image">

            <?php if(!empty($latest_news[$i]['course_img'])){ ?>
                <img src="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>">
            <?php } else { ?>
                <img src="assets/images/banner/course-bg-p2.png">
            <?php } ?>

         	 <ul class="social">
				<li> 
                   <a href="view_course.php?course_id=<?php echo $latest_news[$i]['id']; ?>" ><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 class="cart_main_add<?php echo $latest_news[$i]['id']; ?>" onclick="add_to_cart('<?php echo $latest_news[$i]['id']; ?>','<?php echo $_SESSION['login_id']; ?>','add')" data-tip="Add to Cart"><i class="ti-shopping-cart"></i></a></li>
                                        
                <li><a style="background-color:#2eca7f" class="cart_main_remove<?php echo $latest_news[$i]['id']; ?>" onclick="add_to_cart('<?php echo $latest_news[$i]['id']; ?>','<?php echo $_SESSION['login_id']; ?>','remove')" data-tip="Remove From Cart"><i class="ti-close text-light"></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>

<script>
toggle_cart('<?php echo $latest_news[$i]['id']; ?>','<?php echo $add; ?>');
</script>

<?php } ?><?php */?>




<?php

if(isset($_POST['action']) && $_POST['action'] == 'load_courses')
{
    $filters = $_POST['filters'];

    $course_id = $filters['course_id'] ?? '';
    $price     = $filters['price'] ?? '';
    $search    = $filters['search'] ?? '';

    $limit = 6;

    $latest_news = get_courses_filter($course_id, $price, $search, 1, $limit);
    $cart_ids = get_cart_details();

    for($i=0;$i<count($latest_news);$i++)
    {
        $add = in_array($latest_news[$i]['id'],$cart_ids) ? 1 : 0;
?>

<div class="col-md-4">
    <div class="product">

        <img src="../instructor/courses_upload/<?php echo $latest_news[$i]['course_img']; ?>" width="100%">

        <h5>
            <?php 
            $text = $latest_news[$i]['course_title'];
            echo (strlen($text) > 30) ? substr($text,0,30).'...' : $text;
            ?>
        </h5>

        <p>
            $<?php echo $latest_news[$i]['course_price']/100*$latest_news[$i]['course_discount']; ?>
            <del>$<?php echo $latest_news[$i]['course_price']; ?></del>
        </p>

        <button onclick="add_to_cart('<?php echo $latest_news[$i]['id']; ?>','<?php echo $_SESSION['login_id']; ?>','add')" class="btn btn-success btn-sm">
            Add to Cart
        </button>

    </div>
</div>

<script>
toggle_cart('<?php echo $latest_news[$i]['id']; ?>','<?php echo $add; ?>');
</script>

<?php
    }
    exit;
}
?>