<div class="page-header parallax" style="background-image:url('<?php echo SITE_URL; ?>images/listing_header.png');">
    <div class="container">
        <h1 class="page-title">Search results</h1>
    </div>
</div>
<div class="utility-bar">
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-sm-6 col-xs-8">
                <ol class="breadcrumb">
                    <li><a href="<?php echo SITE_URL; ?>">Home</a></li>
                    <li class="active">Search results</li>
                </ol>
            </div>
            <div class="col-md-4 col-sm-6 col-xs-4">
            </div>
        </div>
    </div>
</div>
<!-- Actions bar -->
q<div class="actions-bar tsticky">
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-sm-12">
                <div class="pull-right results-sorter">
                    <!-- <button type="button" class="btn btn-default listing-sort-btn">Sort by</button>
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                            aria-expanded="false">
                        <span class="caret"></span>
                        <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                        <li><a href="#">Year (High to Low)</a></li>
                        <li><a href="#">Year (Low to High)</a></li>
                        <li><a href="#">Mileage (Low to High)</a></li>
                        <li><a href="#">Mileage (High to Low)</a></li>
                    </ul> -->
                    <?php  $query_url = $_GET;
                    $query_result = http_build_query($query_url);  ?>
                    <form action="<?php echo SITE_URL; ?>listing.php">
                        <div class="form-group">
                            <select name="sortby" class="form-control"  id="sortby" onchange="sortfunction()">
                                <option value="0">Sort by</option>
                                <option value="DESC" <?php   if(isset($_get->sortby)){ $val = $_get->sortby; if(trim($val)=="desc" || trim($val)=="DESC"){ echo "selected";} }  ?> >Year (High to Low)</option>
                                <option value="ASC" <?php  if(isset($_get->sortby)){ $val = $_get->sortby; if(trim($val)=="asc" || trim($val)=="ASC"){ echo "selected";} }    ?> >Year (Low to High)</option>
                                <option value="price_asc"  <?php  if(isset($_get->sortby)){ $val = $_get->sortby; if(trim($val)=="price_asc" || trim($val)=="PRICE_ASC"){ echo "selected";} } ?> >Price (Low to High)</option>
                                <option value="price_desc" <?php  if(isset($_get->sortby)){ $val = $_get->sortby; if(trim($val)=="price_desc" || trim($val)=="PRICE_DESC"){ echo "selected";} } ?>  >Price (High to low)</option>
                            </select>
                        </div>
                    </form>
                </div>



                <div class="toggle-view view-count-choice pull-right">
                    <label>Show</label>
                    <div class="btn-group">

                        <?php
                        $query_url = $_GET;

                        $limit_url = null;

                        if(isset($_GET['pagelimit'])){
                            $limit_url = $_GET['pagelimit'];
                        }

                        $query_url['pagelimit'] = 10;

                        //                       echo $_GET['pagelimit'];
                        $query_result = http_build_query($query_url);
                        ?>
                        <a href="<?php echo SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result;?>" class="btn btn-default <?php echo ($limit_url==10) ? 'active' : ''; ?> ">10</a>

                        <?php
                        $query_url = $_GET;
                        $query_url['pagelimit'] = 20;
                        $query_result = http_build_query($query_url);
                        ?>


                        <a href="<?php echo SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result;?>" class="btn btn-default <?php  echo ($limit_url==20) ? 'active' : ''; ?> ">20</a>
                        <?php
                        $query_url = $_GET;
                        $query_url['pagelimit'] = 50;
                        $query_result = http_build_query($query_url);
                        ?>
                        <a href="<?php echo SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result;?>" class="btn btn-default  <?php echo ($limit_url==50) ? 'active' : ''; ?>" >50</a>
                    </div>
                </div>

                <div class="toggle-view view-format-choice pull-right">
                    <label>View</label>
                    <div class="btn-group">
                        <a href="#" class="btn btn-default  <?php if(isset($_GET['view']) && $_GET['view']=="results-list-view"){ echo "active"; }else if(!isset($_GET['view'])){ echo "active"; } ?> cls-view" id="results-list-view"><i class="fa fa-th-list"></i></a>
                    <!-- <a href="#" class="btn btn-default <?php if(isset($_GET['view']) && $_GET['view']=="results-grid-view"){ echo "active"; } ?> cls-view" id="results-grid-view"><i class="fa fa-th"></i></a> -->
                    </div>
                </div>
                <button class="btn btn-default visible-xs" id="Show-Filters">Search Filters</button>
            </div>
        </div>
    </div>
</div>
<!-- Start Body Content -->
<div class="main" role="main">
    <div id="content" class="content full">
        <div class="container">
            <div class="row">
                <!-- Search Filters -->
                <div class="col-md-3 search-filters" id="Search-Filters">
                    <form method="get" action="<?php echo SITE_URL; ?>listing.php">
                        <input type="hidden" name="stype" value="listing-search">
                        <input type="hidden" name="view" value="<?php if(isset($_GET['view']) && $_GET['view']=="results-list-view"){ echo "results-list-view"; }else if(isset($_GET['view']) && $_GET['view']=="results-grid-view"){ echo "results-grid-view"; } else if(!isset($_GET['view'])){ echo "results-list-view"; } ?>" >
                        <div class="tbsticky filters-sidebar">
                            <h3>Refine Search</h3>
                            <div class="accordion" id="toggleArea">
                                <!-- Filter by Year -->
                                <!-- <input type="hidden" name="pagelimit" value="10" > -->
                                <div class="accordion-group panel">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseOne">Year<i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseOne" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inline">
                                                <div class="form-group">
                                                    <label>Min Year</label>
                                                    <select name="minyear" class="form-control ">
                                                        <option value="">Any</option>
                                                        <?php for ($y=1970; $y<=date('Y'); $y++) { ?>
                                                        <option value="<?php echo $y; ?>" <?php echo ($_get->minyear==$y) ? 'selected' : ''; ?>><?php echo $y; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="form-group last-child">
                                                    <label>Max Year</label>
                                                    <select name="maxyear" class="form-control ">
                                                        <option value="">Any</option>
                                                        <?php for ($y=1970; $y<=date('Y'); $y++) { ?>
                                                        <option value="<?php echo $y; ?>" <?php echo ($_get->maxyear==$y) ? 'selected' : ''; ?>><?php echo $y; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <!--<button type="submit" class="btn btn-default btn-sm pull-right">Filter</button>-->
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Make -->
                                <div class="accordion-group panel">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseTwo">Make<i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseTwo" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control " name="make" onchange="populate('model',this.value)">
                                                        <option value="">Any</option>
                                                        <?php $query = $connection->prepare("SELECT * FROM `make` WHERE `status`=1 ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $make) { ?>
                                                        <?php if (empty($_get->make)) { ?>
                                                        <option value="<?php echo $make->idmake; ?>" <?php echo ($make->idmake == get_make_id_by_model($model)) ? 'selected' : ''; ?>><?php echo $make->name; ?></option>
                                                        <?php } else { ?>
                                                        <option value="<?php echo $make->idmake; ?>" <?php echo ($make->idmake == $_get->make) ? 'selected' : ''; ?>><?php echo $make->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Model -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseThird">Model <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseThird" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control " name="model" id="model">
                                                        <option value="">Any</option>
                                                        <?php if ($model != '') { ?>
                                                        <?php $query = $connection->prepare("SELECT `model`.* FROM `model` LEFT JOIN `make` ON `model`.`idmake` = `make`.`idmake` WHERE `make`.`idmake`=".get_make_id_by_model($model)." ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $m) { ?>
                                                        <option value="<?php echo $m->idmodel; ?>" <?php echo ($m->idmodel == $model) ? 'selected' : ''; ?>><?php echo $m->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                        <?php } elseif (!empty($_get->model)) { ?>
                                                        <?php $query = $connection->prepare("SELECT `model`.* FROM `model` LEFT JOIN `make` ON `model`.`idmake` = `make`.`idmake` WHERE `make`.`idmake`={$_get->model} ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $m) { ?>
                                                        <option value="<?php echo $m->idmodel; ?>" <?php echo ($m->idmodel == $_get->model) ? 'selected' : ''; ?>><?php echo $m->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                        <?php } elseif (!empty($_get->make)) { ?>
                                                        <?php $query = $connection->prepare("SELECT `model`.* FROM `model` LEFT JOIN `make` ON `model`.`idmake` = `make`.`idmake` WHERE `make`.`idmake`={$_get->make} ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $m) { ?>
                                                        <option value="<?php echo $m->idmodel; ?>" <?php echo ($m->idmodel == $_get->model) ? 'selected' : ''; ?>><?php echo $m->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <script>
                                    function populate (element, id) {
                                        $.ajax({
                                            type: 'POST',
                                            url: 'ajax/get-'+element+'.php',
                                            data: {id: id},
                                            success: function(response) {
                                                if(response != '') {
                                                    $("#"+element).empty();
                                                    $("#"+element).append(response);
                                                } else {
                                                    alert('There is some problem with XHR!');
                                                }
                                            },
                                            fail: function(e) {
                                                alert('XHR is not responding!'+e);
                                            }
                                        });
                                    }
                                </script>
                                <!-- Filter by Body Type -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseFour">Body type <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseFour" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control " name="bodytype">
                                                        <option value="">Any</option>
                                                        <?php $query = $connection->prepare("SELECT * FROM `bodytype` ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $bodytype) { ?>
                                                        <option value="<?php echo $bodytype->idbodytype; ?>" <?php echo ($bodytype->idbodytype == $_get->bodytype) ? 'selected' : ''; ?>><?php echo $bodytype->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Mileage -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseFive">Mileage <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseFive" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inline">
                                                <div class="form-group">
                                                    <label>Min Mileage</label>
                                                    <input type="number" class="form-control" name="minmile" style="width:104px;" >
                                                <!-- <select name="minmile" class="form-control ">
                                                                <option value="">Any</option>
                                                                <?php // for ($m=0; $m<=15; $m++) { ?>
                                                                    <option value="<?php //echo (100000*$m); ?>"><?php //echo (100000*$m); ?></option>
                                                                <?php //} ?>
                                                            </select> -->
                                                </div>
                                                <div class="form-group last-child">
                                                    <label>Max Mileage</label>
                                                    <input type="number" class="form-control" name="maxmile" style="width:104px;" >
                                                <!-- <select name="maxmile" class="form-control ">
                                                                <option value="">Any</option>
                                                                <?php // for ($m=0; $m<=15; $m++) { ?>
                                                                    <option value="<?php// echo (100000*$m); ?>"><?php // echo (100000*$m); ?></option>
                                                                <?php //} ?>
                                                            </select> -->
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Transmission -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseSix">Transmission <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseSix" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select name="transmission" class="form-control ">
                                                        <option value="" selected>None</option>
                                                        <option value="automatic" <?php echo ($_get->transmission == 'automatic') ? 'selected' : ''; ?>>Automatic</option>
                                                        <option value="manual" <?php echo ($_get->transmission == 'manual') ? 'selected' : ''; ?>>Manual</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Fuel Economy -->
                                <!--
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseSeven">Fuel economy <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseSeven" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control ">
                                                        <option selected>Selecy</option>
                                                        <option>5L/100Km or less</option>
                                                        <option>7L/100Km or less</option>
                                                        <option>9L/100Km or less</option>
                                                        <option>11L/100Km or less</option>
                                                        <option>11L/100Km or less</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                -->
                                <!-- Filter by Price -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseEight">Price <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseEight" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inline">
                                                <div class="form-group">
                                                    <label>Price Min</label>
                                                    <input type="number" class="form-control" name="minprice" style="width:104px;" >
                                                <!-- <select name="minprice" class="form-control ">
                                                                <option value="">Any</option>
                                                                <?php // for ($m=0; $m<=20; $m++) { ?>
                                                                    <option value="<?php //echo (100000*$m); ?>"><?php //echo (100000*$m); ?></option>
                                                                <?php //} ?>
                                                            </select> -->
                                                </div>
                                                <div class="form-group last-child">
                                                    <label>Price Max</label>
                                                    <input type="number" class="form-control" name="maxprice" style="width:104px;" >
                                                <!-- <select name="maxprice" class="form-control ">
                                                                <option value="">Any</option>
                                                                <?php //for ($m=0; $m<=20; $m++) { ?>
                                                                    <option value="<?php //echo (100000*$m); ?>"><?php // echo (100000*$m); ?></option>
                                                                <?php // } ?>
                                                            </select> -->
                                                </div>
                                                <!--<button type="submit" class="btn btn-default btn-sm pull-right">Filter</button>-->
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Location -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseNine">Location <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseNine" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control " name="locality">
                                                        <option value="">Any</option>
                                                        <?php $query = $connection->prepare("SELECT * FROM `locality` WHERE `idregion`={$_SESSION['geolocation']->idregion} ORDER BY `name` ASC"); ?>
                                                        <?php if ($query->execute() AND $query->rowCount()) { ?>
                                                        <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $locality) { ?>
                                                        <option value="<?php echo $locality->idlocality; ?>" <?php echo ($_get->locality == $locality->idlocality) ? 'selected' : ''; ?>><?php echo $locality->name; ?></option>
                                                        <?php } ?>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Filter by Color -->
                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseTen">Color <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseTen" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">
                                                    <select class="form-control " name="color">
                                                        <option value="">Any</option>
                                                        <?php $colors = ["White","Black","Red","Yellow","Brown","Grey","Silver","Gold","Blue","Green","Orange"]; ?>
                                                        <?php foreach ($colors as $color) { ?>
                                                        <option value="<?php echo $color ?>" <?php echo ($_get->color == $color) ? 'selected' : ''; ?>><?php echo $color; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseEleven">Package <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseEleven" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">

                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="packageby[]" value="all">All</label>
                                                    </div>

                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="packageby[]" value="1">Private</label>
                                                    </div>
                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="packageby[]" value="2">Company</label>
                                                    </div>
                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="packageby[]" value="3">Dealership</label>
                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="accordion-group">
                                    <div class="accordion-heading togglize"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#" href="#collapseTwelve">Ad Type <i class="fa fa-angle-down"></i> </a> </div>
                                    <div id="collapseTwelve" class="accordion-body collapse">
                                        <div class="accordion-inner">
                                            <div class="form-inliner">
                                                <div class="form-group">

                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="ad[]" value="all">All</label>
                                                    </div>

                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="ad[]" value="Toptilli">Toptilli</label>
                                                    </div>
                                                    <!-- <div class="checkbox">
                                                        <label><input type="checkbox" name="ad[]" value="Premium">Premium</label>
                                                    </div> -->
                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="ad[]" value="Basic">Basic</label>
                                                    </div>

                                                    <div class="checkbox">
                                                        <label><input type="checkbox" name="export" value="1">Export</label>
                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- End Toggle -->
                            <div class="col-md-12">
                                <button type="reset" class="col-md-6 btn-default btn-sm btn"><i class="fa fa-refresh"></i> Reset</button>
                                <button type="submit" class="col-md-6 btn-primary btn-sm btn"><i class="fa fa-search"></i> Search</button>
                            </div>
                        </div>
                    </form>
                </div>

                <!-- Listing Results -->
                <div class="col-md-9 results-container">
                    <div class="results-container-in">
                        <div class="waiting" style="display:none;">
                            <div class="spinner">
                                <div class="rect1"></div>
                                <div class="rect2"></div>
                                <div class="rect3"></div>
                                <div class="rect4"></div>
                                <div class="rect5"></div>
                            </div>
                        </div>
                        <style>
                            .result-item-title span{
                                margin-left: 10px;
                            }
                        </style>

                        <?php #include_once('includes/listing.tmp.php'); ?>

                        <div id="results-holder" class="results-list-view data-container" id="demo">

                            <!-- CREATED BY ZOHAIB -->
                            <?php if (count($posts)>0) { ?>
                            <?php foreach ($posts as $vehicle) { ?>
                            <?php if($vehicle->toptilli>0 && $vehicle->idusertype==3) { ?>
                            <?php $query = $connection->prepare("SELECT `value` AS `slideshow` FROM `packagefeature` WHERE `idpackage`={$vehicle->idpackage} AND `idpackagefeaturemeta` IN (SELECT `idpackagefeaturemeta` FROM `packagefeaturemeta` WHERE `meta`='slideshow')"); ?>
                            <?php if ($query->execute() AND $query->rowCount()) { $package = $query->fetch(PDO::FETCH_OBJ); } //print_r($package); die(); ?>
                            <!-- RESULT ITEM BY ZOHAIB -->
                            <div class="result_item bg_toptilli">
                                <div class="result_image_wrapper">
                                    <div class="featured-image format-image featureImageOne">
                                        <?php  if(!empty($vehicle->featureimage)){ ?>
                                        <?php $query =  $connection->prepare("SELECT * FROM `media` WHERE `idvehicle`={$vehicle->idvehicle} AND `type`='image' ORDER BY `idmedia` LIMIT 1"); ?>
                                        <?php if ($query->execute() AND $query->rowCount()) { $media = $query->fetch(PDO::FETCH_OBJ); ?>
                                        <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" alt="<?php echo $vehicle->title; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $vehicle->featureimage; ?>"></a>
                                        <?php } ?>

                                        <?php } ?>
                                        <span class="label label-top vehicle-age" style="font-family: ArialRoundMTBold;"><span style="color:#ff6633; text-transform: uppercase;">TOP</span><span style="color: #6699cc;  text-transform: lowercase;">tilli</span></span>
                                    </div>
                                    <div class="additional-images">
                                        <ul class="owl-carousel" data-columns="3" data-pagination="no" data-arrows="yes" data-single-item="no" data-items-desktop="3" data-items-desktop-small="3" data-items-tablet="3" data-items-mobile="3">
                                            <?php $query = $connection->prepare("SELECT * FROM `media` WHERE `idvehicle`={$vehicle->idvehicle} ORDER BY `idmedia`"); ?>
                                            <?php if ($query->execute() AND $query->rowCount()) { ?>
                                            <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $media) { ?>
                                            <li class="item format-<?php echo $media->type; ?>"> <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $media->source; ?>" alt=""></a></li>

                                            <?php } ?>
                                            <?php } ?>
                                        </ul>
                                    </div>
                                </div>
                                <div class="result_content">
                                    <h4 class="result-item-title bg_toptilli_title"><a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><?php echo $vehicle->title; ?> <span class="label label-default"><?php echo $vehicle->year; ?></span></a></h4>
                                    <div class="result_content_wrapper">
                                        <div class="result_cont_left">
                                            <p><?php echo substr(htmlspecialchars_decode($vehicle->overview),0,100); ?></p>
                                            <?php $query = $connection->prepare("SELECT * FROM `user` WHERE `iduser`={$vehicle->iduser} LIMIT 1"); ?>
                                            <?php $query ->execute();  ?>
                                            <?php
                                            $user = $query->fetch(PDO::FETCH_OBJ);
                                            ?>
                                            <div class="company_dtl_block">
                                                <div class="company_dtl_list">

                                                    <div class="company_logo">
                                                        <?php if(empty($user->imglogo)){ ?>
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <img src="http://via.placeholder.com/50x50?text=No Priview" alt=""></a>
                                                        <?php }else{ ?>
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <img src="<?php echo SITE_URL ?>/upload/user/logo/<?php echo $user->imglogo; ?>"></a>
                                                        <?php } ?>
                                                    </div>
                                                    <div class="company_dtl">
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <h3 class="comapny_name"><?php echo $user->cname; ?></h3></a>
                                                        <?php if(!empty($user->phone)){ ?>
                                                        <p class="comapny_tel"><i class="fa fa-phone" aria-hidden="true"></i><?php echo $user->phone; ?></p>
                                                        <?php } ?>
                                                        <?php if(!empty($user->address)){ ?>
                                                        <p class="comapny_tel"><i class="fa fa-map-marker" aria-hidden="true"></i><?php echo $user->address; ?></p>
                                                        <?php } ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="result_cont_right">
                                            <div class="result_item_price">
                                                <?php if($vehicle->pricecheck=="AFP"){ ?>
                                                <h3 class="item_price"><?php echo "Ask for Price"; ?></h3>
                                                <?php }else{ ?>
                                                <?php  if($vehicle->rprice>0):?>
                                                <h3 class="item_price reduce_price"><strike><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></strike></h3>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->rprice; ?></h3>
                                                <?php else:?>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></h3>
                                                <?php  endif;?>
                                                <?php } ?>
                                            </div>
                                            <div class="result_item_btns">
                                            <?php
                                            $query = $connection->prepare("SELECT * FROM `savecar` WHERE `idvehicle`={$vehicle->idvehicle}");
                                            if ($query->execute() AND $query->rowCount()) { ?>
                                            <!-- <a href="#" class="btn btn-default btn-sm"><i class="fa fa-star-o"></i> Save</a> -->
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#" disabled class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?> "><i class="fa fa-star-o"></i> Save</a>
                                                <?php }else{ ?>
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#"  class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?>"><i class="fa fa-star-o"></i>Save</a>
                                                <?php } ?>
                                                <script>
                                                    $(".save_car").click(function(e){
                                                        var id = $(this).attr('id');
                                                        e.preventDefault();
                                                        $.ajax({
                                                            type: "POST",
                                                            url: "ajax/savecar.php",
                                                            data: {
                                                                id:id
                                                            },
                                                            success: function (response) {
                                                                alert(response);
                                                                $('.fa-star').css('color','#f63');
                                                                $('#'+id).attr('disabled','disabled');
                                                            }
                                                        });
                                                    });
                                                    $(".nosave").click(function(e){
                                                        e.preventDefault();
                                                        window.location.href="<?php echo SITE_URL.'login.php'; ?>";
                                                    });
                                                </script>
                                                <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" class="btn btn-default btn-sm">View Details</a><br>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <?php  $query = $connection->query("SELECT * FROM `vehicle` WHERE `iduser`={$vehicle->iduser}"); ?>
                                <?php  $query->execute(); ?>
                                <?php  if($query->rowCount()): ?>
                                <?php  $relate_vehicles  = $query->fetchAll(PDO::FETCH_OBJ); ?>
                                <div class="other_cars_wrapper">
                                    <h3 class="title_other_cars">Other Cars by this dealer</h3>
                                    <div class="additional-images">
                                        <ul class="owl-carousel" data-columns="4" data-pagination="no" data-arrows="yes" data-single-item="no" data-items-desktop="4" data-items-desktop-small="4" data-items-tablet="2" data-items-mobile="2">
                                            <?php foreach ($relate_vehicles as $relate_vehicle) :  ?>

                                            <?php if ($relate_vehicle->idvehicle == $vehicle->idvehicle) {
                                            continue;
                                            } ?>
                                            <?php  $query = $connection->prepare("SELECT * FROM `media` WHERE `idvehicle` = {$relate_vehicle->idvehicle} AND `type` = 'image'"); ?>
                                            <?php  $query ->execute(); ?>
                                            <?php  $images = $query->fetch(PDO::FETCH_OBJ); ?>
                                            <?php if(empty($images->source)): ?>
                                            <img src="http://via.placeholder.com/890x600?text=No Priview" alt="">
                                            <?php else: ?>
                                            <li class="item format-image"> <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$relate_vehicle->title), FILTER_SANITIZE_URL)).'/'.$relate_vehicle->idvehicle.'.html'; ?>"><img src="<?php echo SITE_URL."upload/vehicle/{$images->source}";?>" alt=""></a></li>

                                            <?php endif; ?>

                                            <?php  endforeach; ?>
                                        </ul>
                                    </div>
                                </div>
                                <?php endif; ?>
                            </div>
                            <?php  ?>
                            <?php
                            # DEALERSHIP WITH TOPTILLI
                            } elseif ($vehicle->toptilli==0 && $vehicle->idusertype==3){ ?>
                            <?php $query = $connection->prepare("SELECT `value` AS `slideshow` FROM `packagefeature` WHERE `idpackage`={$vehicle->idpackage} AND `idpackagefeaturemeta` IN (SELECT `idpackagefeaturemeta` FROM `packagefeaturemeta` WHERE `meta`='slideshow')"); ?>
                            <?php if ($query->execute() AND $query->rowCount()) { $package = $query->fetch(PDO::FETCH_OBJ); } //print_r($package); die(); ?>
                            <!-- RESULT ITEM BY ZOHAIB -->
                            <div class="result_item bg_toptilli">
                                <div class="result_image_wrapper">
                                    <div class="featured-image format-image featureImageTwo">
                                        <a href="<?php echo SITE_URL; ?>/vehicle/<?php echo $vehicle->title; ?>/<?php echo $vehicle->idvehicle; ?>.html" alt="<?php echo $vehicle->title; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $vehicle->featureimage; ?>"></a>
                                    </div>
                                    <div class="additional-images">
                                        <ul class="owl-carousel" data-columns="3" data-pagination="no" data-arrows="yes" data-single-item="no" data-items-desktop="3" data-items-desktop-small="3" data-items-tablet="3" data-items-mobile="3">
                                            <?php $query = $connection->prepare("SELECT * FROM `media` WHERE `idvehicle`={$vehicle->idvehicle} ORDER BY `idmedia`"); ?>
                                            <?php if ($query->execute() AND $query->rowCount()) { ?>
                                            <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $media) { ?>
                                            <li class="item format-<?php echo $media->type; ?>"> <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $media->source; ?>" alt=""></a></li>
                                            <?php } ?>
                                            <?php } ?>
                                        </ul>
                                    </div>
                                </div>
                                <div class="result_content">
                                    <h4 class="result-item-title"><a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><?php echo $vehicle->title; ?> <span class="label label-default"><?php echo $vehicle->year; ?></span></a></h4>
                                    <div class="result_content_wrapper">
                                        <div class="result_cont_left">
                                            <p><?php echo substr(htmlspecialchars_decode($vehicle->overview),0,100); ?></p>
                                            <?php $query = $connection->prepare("SELECT * FROM `user` WHERE `iduser`={$vehicle->iduser} LIMIT 1"); ?>
                                            <?php $query ->execute();  ?>
                                            <?php
                                            $user = $query->fetch(PDO::FETCH_OBJ);
                                            ?>
                                            <div class="company_dtl_block">
                                                <div class="company_dtl_list">

                                                    <div class="company_logo">
                                                        <?php if(empty($user->imglogo)){ ?>
                                                        <?php if($user->idusertype==3){ ?>
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <img src="http://via.placeholder.com/50x50?text=No Priview" alt=""></a>
                                                        <?php }else{ ?>
                                                        <img src="http://via.placeholder.com/50x50?text=No Priview" alt="">
                                                        <?php } ?>
                                                        <?php }else{ ?>
                                                        <?php if($user->idusertype==3){ ?>
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <img src="<?php echo SITE_URL ?>/upload/user/logo/<?php echo $user->imglogo; ?>">
                                                        </a>
                                                        <?php }else{ ?>
                                                        <img src="<?php echo SITE_URL ?>/upload/user/logo/<?php echo $user->imglogo; ?>">
                                                        <?php } ?>
                                                        <?php } ?>
                                                    </div>
                                                    <div class="company_dtl">
                                                        <?php if($user->idusertype==3){ ?>
                                                        <a href="<?php echo SITE_URL."dealerinfo.php?id=$user->iduser"; ?>">
                                                            <h3 class="comapny_name"><?php echo $user->cname; ?></h3></a>
                                                        <?php }else{ ?>
                                                        <h3 class="comapny_name"><?php echo $user->cname; ?></h3>
                                                        <?php } ?>
                                                        <p class="comapny_tel"><i class="fa fa-phone" aria-hidden="true"></i><?php echo $user->phone; ?></p>
                                                        <p class="comapny_tel"><i class="fa fa-map-marker" aria-hidden="true"></i><?php echo $user->address; ?></p>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="result_cont_right">
                                            <div class="result_item_price">
                                                <?php if($vehicle->pricecheck=="AFP"){ ?>
                                                <h3 class="item_price"><?php echo "Ask for Price"; ?></h3>
                                                <?php }else{ ?>
                                                <?php  if($vehicle->rprice>0):?>
                                                <h3 class="item_price reduce_price"><strike><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></strike></h3>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->rprice; ?></h3>
                                                <?php else:?>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></h3>
                                                <?php  endif;?>
                                                <?php } ?>
                                            </div>
                                            <div class="result_item_btns">
                                            <?php
                                            $query = $connection->prepare("SELECT * FROM `savecar` WHERE `idvehicle`={$vehicle->idvehicle}");
                                            if ($query->execute() AND $query->rowCount()) { ?>
                                            <!-- <a href="#" class="btn btn-default btn-sm"><i class="fa fa-star-o"></i> Save</a> -->
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#" disabled class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?> "><i class="fa fa-star-o"></i> Save</a>
                                                <?php }else{ ?>
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#"  class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?>"><i class="fa fa-star-o"></i>Save</a>
                                                <?php } ?>
                                                <script>
                                                    $(".save_car").click(function(e){
                                                        var id = $(this).attr('id');
                                                        e.preventDefault();
                                                        $.ajax({
                                                            type: "POST",
                                                            url: "ajax/savecar.php",
                                                            data: {
                                                                id:id
                                                            },
                                                            success: function (response) {
                                                                alert(response);
                                                                $('.fa-star').css('color','#f63');
                                                                $('#'+id).attr('disabled','disabled');
                                                            }
                                                        });
                                                    });
                                                    $(".nosave").click(function(e){
                                                        e.preventDefault();
                                                        window.location.href="<?php echo SITE_URL.'login.php'; ?>";
                                                    });
                                                </script>
                                                <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" class="btn btn-default btn-sm">View Details</a><br>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            <?php  $query = $connection->query("SELECT * FROM `vehicle` WHERE `iduser`={$vehicle->iduser}"); ?>
                            <?php  $query->execute(); ?>
                            <!-- <?php  if($query->rowCount()): ?>
                            <?php  $relate_vehicles  = $query->fetchAll(PDO::FETCH_OBJ); ?>
                                    <div class="other_cars_wrapper">
                                        <h3 class="title_other_cars">Other Cars by this dealer</h3>
                                        <div class="additional-images">
                                            <ul class="owl-carousel" data-columns="4" data-pagination="no" data-arrows="yes" data-single-item="no" data-items-desktop="4" data-items-desktop-small="4" data-items-tablet="2" data-items-mobile="2">
<?php foreach ($relate_vehicles as $relate_vehicle) :  ?>

                            <?php if ($relate_vehicle->idvehicle == $vehicle->idvehicle) {
                            continue;
                            } ?>
                            <?php  $query = $connection->prepare("SELECT * FROM `media` WHERE `idvehicle` = {$relate_vehicle->idvehicle} AND `type` = 'image'"); ?>
                            <?php  $query ->execute(); ?>
                            <?php  $images = $query->fetch(PDO::FETCH_OBJ); ?>
                            <?php if(empty($images->source)): ?>
                                    <img src="http://via.placeholder.com/890x600?text=No Priview" alt="">
<?php else: ?>
                                    <li class="item format-image"> <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$relate_vehicle->title), FILTER_SANITIZE_URL)).'/'.$relate_vehicle->idvehicle.'.html'; ?>"><img src="<?php echo SITE_URL."upload/vehicle/{$images->source}";?>" alt=""></a></li>

                                                                        <?php endif; ?>

                            <?php  endforeach; ?>
                                    </ul>
                                </div>
                            </div>
<?php endif; ?> -->
                            </div>

                            <?php
                            #DEALERSHIP WITHOUT TOPTILLI
                            } elseif ($vehicle->idusertype!=3) {  ?>
                            <div class="result_item  <?php echo ($vehicle->toptilli) ? 'bg_toptilli':'bg_basic' ?>">
                                <div class="result_image_wrapper">
                                    <div class="featured-image format-image featureImageThree">
                                        <?php  if(!empty($vehicle->featureimage)){ ?>
                                        <?php $query =  $connection->prepare("SELECT * FROM `media` WHERE `idvehicle`={$vehicle->idvehicle} AND `type`='image' ORDER BY `idmedia` LIMIT 1"); ?>
                                        <?php if ($query->execute() AND $query->rowCount()) { $media = $query->fetch(PDO::FETCH_OBJ); ?>
                                        <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" alt="<?php echo $vehicle->title; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $vehicle->featureimage; ?>"></a>
                                        <?php } ?>

                                        <?php }else{ ?>
                                        <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" alt="<?php echo $vehicle->title; ?>"><img  src="http://via.placeholder.com/245x138?text=No+feature+image+No+Preview" alt="<?php echo $vehicle->title; ?> outer"></a>

                                        <?php } ?>
                                        <?php if($vehicle->toptilli>0){ ?>
                                        <span class="label label-top vehicle-age" style="font-family: ArialRoundMTBold;"><span style="color:#ff6633; text-transform: uppercase;">TOP</span><span style="color: #6699cc;  text-transform: lowercase;">tilli</span></span>
                                        <?php } ?>
                                    </div>
                                    <div class="additional-images">
                                        <ul class="owl-carousel" data-columns="3" data-pagination="no" data-arrows="yes" data-single-item="no" data-items-desktop="3" data-items-desktop-small="3" data-items-tablet="3" data-items-mobile="3">
                                            <?php $query = $connection->prepare("SELECT * FROM `media` WHERE `idvehicle`={$vehicle->idvehicle} ORDER BY `idmedia`"); ?>
                                            <?php if ($query->execute() AND $query->rowCount()) { ?>
                                            <?php foreach ($query->fetchAll(PDO::FETCH_OBJ) as $media) { ?>
                                            <li class="item format-<?php echo $media->type; ?>"> <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><img src="<?php echo SITE_URL; ?>upload/vehicle/<?php echo $media->source; ?>" alt=""></a></li>
                                            <?php } ?>
                                            <?php } ?>
                                        </ul>
                                    </div>
                                </div>
                                <div class="result_content">
                                    <?php if($vehicle->toptilli>0){ ?>
                                    <h4 class="result-item-title bg_toptilli_title"><a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><?php echo $vehicle->title; ?><span class="label label-default"><?php echo $vehicle->year; ?></span></a></h4>
                                    <?php }else{ ?>
                                    <h4 class="result-item-title"><a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>"><?php echo $vehicle->title; ?><span class="label label-default"><?php echo $vehicle->year; ?></span></a></h4>
                                    <?php } ?>
                                    <div class="result_content_wrapper">
                                        <div class="result_cont_left">
                                            <p><?php echo substr(htmlspecialchars_decode($vehicle->overview),0,100); ?></p>
                                            <?php $query = $connection->prepare("SELECT * FROM `user` WHERE `iduser`={$vehicle->iduser} LIMIT 1"); ?>
                                            <?php $query ->execute();  ?>
                                            <?php
                                            $user = $query->fetch(PDO::FETCH_OBJ);
                                            ?>
                                            <div class="company_dtl_block">
                                                <div class="company_dtl_list">
                                                    <?php if($user->idusertype==3){ ?>
                                                    <div class="company_logo">
                                                        <?php if(empty($user->imglogo)){ ?>
                                                        <img src="http://via.placeholder.com/50x50?text=No Priview" alt="">
                                                        <?php }else{ ?>
                                                        <img src="<?php echo SITE_URL ?>/upload/user/logo/<?php echo $user->imglogo; ?>">
                                                        <?php } ?>
                                                    </div>
                                                    <?php } ?>
                                                    <?php if($user->idusertype==3){ ?>
                                                    <div class="company_dtl">
                                                        <h3 class="comapny_name"><?php echo $user->cname; ?></h3>
                                                        <p class="comapny_tel"><i class="fa fa-phone" aria-hidden="true"></i><?php echo $user->phone; ?></p>
                                                        <p class="comapny_tel"><i class="fa fa-map-marker" aria-hidden="true"></i><?php echo $user->address; ?></p>
                                                    </div>
                                                    <?php } ?>
                                                    <?php if($user->idusertype==2){ ?>
                                                    <div class="company_dtl">
                                                        <div class="company_logo">
                                                            <?php if(empty($user->imglogo)){ ?>
                                                            <img src="http://via.placeholder.com/50x50?text=No Priview" alt="">
                                                            <?php }else{ ?>
                                                            <img src="<?php echo SITE_URL ?>/upload/user/logo/<?php echo $user->imglogo; ?>">
                                                            <?php } ?>
                                                        </div>
                                                        <h3 class="comapny_name"><?php echo $user->fname; ?></h3>
                                                        <p class="comapny_tel"><i class="fa fa-phone" aria-hidden="true"></i><?php echo $user->phone; ?></p>
                                                        <h3 class="fleet">Fleet Vehicle</h3>
                                                    </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="result_cont_right">
                                            <div class="result_item_price">
                                                <?php if($vehicle->pricecheck=="AFP"){ ?>
                                                <h3 class="item_price"><?php echo "Ask for Price"; ?></h3>
                                                <?php }else{ ?>
                                                <?php  if($vehicle->rprice>0):?>
                                                <h3 class="item_price reduce_price"><strike><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></strike></h3>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->rprice; ?></h3>
                                                <?php else:?>
                                                <h3 class="item_price"><?php echo $vehicle->currency; ?> <?php echo $vehicle->price; ?></h3>
                                                <?php  endif;?>
                                                <?php } ?>
                                            </div>
                                            <div class="result_item_btns">
                                            <?php
                                            $query = $connection->prepare("SELECT * FROM `savecar` WHERE `idvehicle`={$vehicle->idvehicle}");
                                            if ($query->execute() AND $query->rowCount()) { ?>
                                            <!-- <a href="#" class="btn btn-default btn-sm"><i class="fa fa-star-o"></i> Save</a> -->
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#" disabled class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?> "><i class="fa fa-star-o"></i> Save</a>
                                                <?php }else{ ?>
                                                <a  id="<?php echo $vehicle->idvehicle; ?>" href="#"  class="btn btn-default btn-sm <?php echo (empty($_SESSION[SITE_NAME.'-user-logged-in']))?'nosave':'save_car'; ?>"><i class="fa fa-star-o"></i>Save</a>
                                                <?php } ?>
                                                <script>
                                                    $(".save_car").click(function(e){
                                                        var id = $(this).attr('id');
                                                        e.preventDefault();
                                                        $.ajax({
                                                            type: "POST",
                                                            url: "ajax/savecar.php",
                                                            data: {
                                                                id:id
                                                            },
                                                            success: function (response) {
                                                                alert(response);
                                                                $('.fa-star').css('color','#f63');
                                                                $('#'+id).attr('disabled','disabled');
                                                            }
                                                        });
                                                    });
                                                    $(".nosave").click(function(e){
                                                        e.preventDefault();
                                                        window.location.href="<?php echo SITE_URL.'login.php'; ?>";
                                                    });
                                                </script>
                                                <a href="<?php echo SITE_URL.'vehicle/'.strtolower(filter_var(str_replace(' ','-',$vehicle->title), FILTER_SANITIZE_URL)).'/'.$vehicle->idvehicle.'.html'; ?>" class="btn btn-default btn-sm">View Details</a><br>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php } ?>
                            <?php } ?>
                            <?php } else { ?>
                            <p>No matching records found.</p>
                            <?php } ?>
                        </div>
                    </div>


                    <script src="https://pagination.js.org/dist/2.1.4/pagination.js"> </script>


                    <script>

                        $('#demo').pagination({
                            dataSource: 'https://www.oktilli.com/reterive-listing.php?pageNum=1&limit=10',
                            locator: 'items',
                            totalNumberLocator: function(response) {
                                // you can return totalNumber by analyzing response content
                                return Math.floor(Math.random() * (1000 - 100)) + 100;
                            },
                            pageSize: 10,
                            // ajax: {
                            //     beforeSend: function() {
                            //         dataContainer.html('Loading data from oktilli.com ...');
                            //     }
                            // },
                            // callback: function(data, pagination) {
                            //     // template method of yourself
                            //     var html = template(data);
                            //     dataContainer.html(html);
                            // }
                        })

                    </script>


                    <div class="paginationjs-pages">
                        <ul>

                        </ul></div>



                    <!-- <div class="text-align-center">
                        <ul class="pagination">
                            <li class="page-item disabled">
                                <span class="page-link">Previous</span>
                            </li>
                            <li class="active"><a href="#">1</a></li>
                            <li ><a href="#">2</a></li>
                            <li><a href="#">3</a></li>
                            <li><a href="#">4</a></li>
                            <li><a href="#">5</a></li>
                            <li class="page-item">
                                <a class="page-link" href="#">Next</a>
                            </li>
                        </ul>
                    </div> -->


                    <?php if((int)$num_pages>1):?>
                    <div class="text-align-center">
                        <ul class="pagination">
                            <?php //if($_get->offset>0){ ?>
                            <li>
                                <?php
                                $query_url = $_GET;
                                $query_url['offset'] = 0;
                                $query_result = http_build_query($query_url); ?>
                                <a class="page-link" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset=0' :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>">First</a>
                            </li>
                            <?php //} ?>

                            <?php if(!isset($_GET['offset'])) {?>
                            <?php if($num_pages>4){ ?>

                            <?php if(isset($_GET['offset'])  && $_GET['offset']>0 ){
                            $query_url = $_GET;
                            $query_url['offset'] = $_GET['offset']-1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Previous"; ?></a></li>
                            <?php } ?>

                            <?php for ($i=0; $i<=4; $i++) : ?>
                            <li class="<?php echo ($_get->offset == $i) ? 'active' : ''; ?> " >
                                <?php
                                $query_url = $_GET;
                                $query_url['offset'] = $i;
                                $query_result = http_build_query($query_url); ?>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo $i+1; ?></a></li>
                            <?php endfor; ?>
                            <?php }else{?>


                            <?php if(isset($_GET['offset'])  && $_GET['offset']>0 ){
                            $query_url = $_GET;
                            $query_url['offset'] = $_GET['offset']-1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Previous"; ?></a></li>
                            <?php } ?>


                            <?php for ($i=0; $i<=$num_pages-1; $i++) : ?>
                            <li class="<?php echo ($_get->offset == $i) ? 'active' : ''; ?> " >
                                <?php
                                $query_url = $_GET;
                                $query_url['offset'] = $i;
                                $query_result = http_build_query($query_url); ?>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo $i+1; ?></a></li>
                            <?php endfor; ?>

                            <?php } ?>

                            <?php }else if(isset($_GET['offset'])) { ?>

                            <?php   $total = $num_pages-1;

                            $current_page = $_GET['offset']+4;

                            //   echo "total_page".$total;
                            $difference =  $total-4;

                            //  echo "<br>total_page differece".$difference;
                            if($current_page<=$total){
                            ?>

                            <?php if(isset($_GET['offset'])  && $_GET['offset']>0 ){
                            $query_url = $_GET;
                            $query_url['offset'] = $_GET['offset']-1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Previous" ?></a></li>
                            <?php } ?>



                            <?php for ($i=$_GET['offset']; $i<=$_GET['offset']+4; $i++) : ?>
                            <li class="<?php echo ($_get->offset == $i) ? 'active' : ''; ?> " >
                                <?php
                                $query_url = $_GET;
                                $query_url['offset'] = $i;
                                $query_result = http_build_query($query_url); ?>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo $i+1; ?></a></li>
                            <?php endfor; ?>





                            <?php }else{  ?>

                            <?php if(isset($_GET['offset'])  && $_GET['offset']>0 ){
                            $query_url = $_GET;
                            $query_url['offset'] = $_GET['offset']-1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Previous"; ?></a></li>
                            <?php } ?>



                            <?php for ($i=$_GET['offset']; $i<=$num_pages-1; $i++) : ?>
                            <li class="<?php echo ($_get->offset == $i) ? 'active' : ''; ?> " >
                                <?php
                                $query_url = $_GET;
                                $query_url['offset'] = $i;
                                $query_result = http_build_query($query_url); ?>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$i :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo $i+1; ?></a></li>
                            <?php endfor; ?>

                            <?php } ?>

                            <?php }?>



                            <?php  if(!isset($_GET['offset'])){
                            $query_url = $_GET;
                            $query_url['offset'] = 1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset=1' :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Next"; ?></a></li>
                            <?php }else{ ?>

                            <?php if($_GET['offset']<$num_pages-1){ ?>
                            <?php  $next = $_GET['offset']+1;
                            $query_url = $_GET;
                            $query_url['offset'] = $_GET['offset']+1;
                            $query_result = http_build_query($query_url); ?>
                            <li>
                                <a class="page-link <?php echo ($_get->offset == $i) ? 'selected' : ''; ?>" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$next :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>"><?php echo "Next"; ?></a></li>
                            <?php } ?>

                            <?php }?>




                            <li>
                                <?php
                                if(isset($_GET['offset'])){ ?>

                                <?php   $query_url = $_GET;
                                $query_url['offset'] = $num_pages-1;
                                $query_result = http_build_query($query_url); ?>

                                <a class="page-link" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$num_pages-1 :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>">Last</a>

                                <?php }else{  $last_page = $num_pages-1; ?>
                                <a class="page-link" href="<?php echo empty($_GET) ?  SITE_URL.$_SERVER['REQUEST_URI'].'?offset='.$last_page :  SITE_URL.$_SERVER['PHP_SELF'].'?'.$query_result; ?>">Last</a>
                                <?php }?>
                            </li>

                        </ul>
                    </div>
                <?php endif; ?>








                <?php
                $pn = $_GET['offset'];
                ?>

                <!-- <ul class="pagination">  -->
                <?php
                // $sql = "SELECT COUNT(*) FROM table1";
                // $rs_result = mysql_query($sql);
                // $row = mysql_fetch_row($rs_result);
                // $total_records = $row[0];
                // $total_pages = ceil($total_records / $limit);
                //   if(isset($_GET['offset']))  {
                //     $k = (($pn+4>$num_pages)?$num_pages-4:(($pn-4<1)?5:$pn));
                //     $pagLink = "";
                //     if($pn>=2){
                //         echo "<li><a href='listing-new.php?offset=1'> << </a></li>";
                //         echo "<li><a href='listing-new.php?offset=".($pn-1)."'> < </a></li>";
                //     }
                //     for ($i=-4; $i<=4; $i++) {
                //       if($k+$i==$pn)
                //         $pagLink .= "<li class='active'><a href='listing-new.php?offset=".($k+$i)."'>".($k+$i)."</a></li>";
                //       else
                //         $pagLink .= "<li><a href='listing-new.php?offset=".($k+$i)."'>".($k+$i)."</a></li>";
                //     };
                //     echo $pagLink;
                //     if($pn<$total_pages){
                //         echo "<li><a href='listing-new.php?offset=".($pn+1)."'> > </a></li>";
                //         echo "<li><a href='listing-new.php?offset=".$total_pages."'> >> </a></li>";
                //     }
                // }
                ?>
                <!-- </ul> -->






                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>

<script>
    function sortfunction(){
        var selectvalue = $("#sortby").val();
        <?php
            $query_url = $_GET;
            if(isset($query_url['sortby'])){
            unset($_GET['sortby']);
            $query_url = $_GET;
            }
            $query_result = http_build_query($query_url);
            ?>

        if(selectvalue != 0){
            //alert(selectvalue);
            window.location.href=("<?php echo SITE_URL;?>listing.php?<?php echo $query_result; ?>&sortby="+selectvalue);
        }else{

        }

    }

    $(".cls-view").click(function(){

        var veiw_value = $(this).attr("id");

        <?php
            $query_url = $_GET;
            if(isset($query_url['view'])){
            unset($_GET['view']);
            $query_url = $_GET;
            }
            $query_result = http_build_query($query_url);
            ?>

            window.location.href=("<?php echo SITE_URL;?>listing.php?<?php echo $query_result; ?>&view="+veiw_value);

    });
</script>

