<!--<link rel="stylesheet" href="/includes/css/style.css" type="text/css">-->
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$INC_DIR = $_SERVER["DOCUMENT_ROOT"]. "/includes/";
include_once($INC_DIR. "header.php");
include_once($INC_DIR. "constants.php");
include_once($INC_DIR. "function.php");
require_once('includes/filterArrays.php');
if (!isset($current_page)) {
    $my_site_link = $_SERVER['PHP_SELF'];
    $link_array = explode('/', $my_site_link);
    $current_page = end($link_array);
}
$current_page = chop($current_page, ".php");
$count = 0;
$showPagination = true;
if($showPagination){
	$start=0;
	if (isset($_GET['page_no']) && $_GET['page_no']!="") {
	    $page_no = $_GET['page_no'];
	    } else {
  		$page_no = 1;
    }
    $total_records_per_page = 15;
    $offset = ($page_no-1) * $total_records_per_page;
	$previous_page = $page_no - 1;
	$next_page = $page_no + 1;
	$adjacents = "2";
	$sqlListingCount = STATIC_LISTING_COUNT_QUERY1;
	$getListingIdsCount = select_row($sqlListingCount);
    $total_records = $getListingIdsCount['total'];
	$total_no_of_pages = ceil($total_records / $total_records_per_page);
	$second_last = $total_no_of_pages - 1; 
	$getProperties = STATIC_LISTING_QUERY1." LIMIT $total_records_per_page OFFSET $offset";
	$results = select_array($getProperties);
	if(isset($results['status']) && $results['status'] == 404){
		$count = 0;	
	}else{
		$count = count($results);
	}
}else{
	$sql = STATIC_LISTING_QUERY1;
	$results = select_array($sql);
	$count = count($results);
	if(!isset($_GET['start'])){
		$start=0;
	}else{
		$start = $_GET['start'];
	}
}
?>
			<div class="page content-full-width pl-result plr-grid-load-more pl-result-grid">
				<div class="content-sidebar-wrap container">
					<main class="content">
						<div class="pl-result-wrap">
							<?php if($count > 0) { ?>
								<div class="pl-number-of-items">Tim's Sold Listings: <?php echo $showPagination? $total_records: $count;?></div>
								<?php
                                /* 
                                if(($showPagination) && $count > 0) {
                                    include('pagination/pagination.php');
                                    include_once($INC_DIR. "pagination/pagination.php");
                                }*/
                                ?>
                                <?php if(($showPagination)) {
                                    include($INC_DIR. "pagination/pagination.php");
                                }?>
								<div id="<?php echo $row['ListingId']; ?>" class="pl-result-content grid-section pl-result-grid-main">
									<div class="grid-results">
										<?php $startIndex = $start;
										foreach ($results as $key => $row){
										?>
											<div class="lazy-load pl-result-property-area pl-result-content-inner">
												<div class="row pl-result-content-top">
													<div class="pl-featured-image">
		                                                <?php
														$sql = "Select `MediaKey`,`OriginatingSystemName` from `bonstmedia2` WHERE `ResourceRecordID` = '".$row['ListingId']."' Order By `MediaObjectID` ASC LIMIT 1";
														$imageData = select_row($sql);
														$count = count(array($sql));
														//for counting photo count start
														
														if($count > 0) {
															$resourceId = str_ireplace('NST','',$row['ListingId']);
															$parts = str_split($resourceId, 1);
															$parts_mk = str_split($resourceId, 1);
															
															array_pop($parts);
															$final = implode("/", $parts);
															$final_mk = implode("/", $parts_mk);
															$mediaKey = $imageData['MediaKey'];
															$img_url = WASSERVERURL.$mediaKey.'.MedRes.jpeg';
														} {
															$img_url_404 = "this.onerror=null;this.src='https://".$_SERVER['HTTP_HOST']."/includes/images/photo_coming_soon_640x480.jpg'";	
														} ?>
		                                                <div class="slideshow-container">
		                                                    <a href="<?php echo $_SERVER['HTTP_ORIGIN']."/z/fl2/h/static-details3.php?page=".$startIndex."&ListingId=".$row['ListingId']."&returnURL=static-grid1"; ?>"><img class="d-block w-100 " onError="<?php echo $img_url_404; ?>"
		                                                    src="/includes/tiny_image/timthumb.php?w=640&q=90&src=<?php echo $img_url; ?>" alt="Slide"></a>
		                                                </div>
		                                            </div>
												</div>
												<div class="pl-result-content-bottom">
													<div class="row">
														<?php 
														$propertySubType = '';
														$unitNumber = '';
														$bedrooms = '';
														$bathrooms = '';
														$sqft = '';
														$ListingId = '';
														if(isset($row['PropertySubType']) && !empty($row['PropertySubType'])){
															$propertySubType = $row['PropertySubType'];
														}
														if(isset($row['UnitNumber']) && !empty($row['UnitNumber'])){
															$unitNumber = " #".$row['UnitNumber'];
														}
														if(isset($row['BedroomsTotal']) && !empty($row['BedroomsTotal'])){
															$bedrooms = 'Beds: '.$row['BedroomsTotal'];
														}
														if(isset($row['BathroomsTotalInteger']) && !empty($row['BathroomsTotalInteger'])){
															$bathrooms = '| Bathroom: '.$row['BathroomsTotalInteger'];
														}
														if(isset($row['LivingArea']) && !empty($row['LivingArea'])){
															$sqft = ' | Sqft: '.$row['LivingArea'];
														}						 
														if(isset($row['ListingId']) && !empty($row['ListingId'])){
															$ListingId = ' | MLS Number: '.$row['ListingId'];
														}						 
														?>
														<div class="row pl-result-content-header">
															<span class="price">$<?php if($row['AlphaStatus'] == 'E'){ echo number_format($row['ClosePrice']);} else { echo number_format($row['ListPrice']); } ?></span>
															<span class="status">Status: <?php echo $row['StandardStatus'];?></span>
														</div>
														<div class="row pl-result-content-main">
															<div class="row pl-result-details">
																<div class="property-type"><?php echo $row['PropertyType']; ?></div>
																<div class="property-location"><span class="address-line"><?php echo $row['StreetNumber']." ".$row['StreetDirPrefix']." ".$row['StreetName']." ".$row['StreetSuffix']." ".$row['StreetDirSuffix'].$unitNumber;?>
																</span><span class="address-line"><?php echo $row['City']." ".$row['StateOrProvince']." ".$row['PostalCode'];?></span></div>
																<ul class="property-description">
																	<li><span class="list_label">Beds</span><span class="list_value"><?php echo $row['BedroomsTotal'];?></span>|&nbsp;<span class="list_label">Baths</span><span class="list_value"><?php echo $row['BathroomsTotalInteger'];?></span></li>
																	<li><span class="list_label">Living Area:</span><span class="list_value"><?php echo $row['LivingArea'];?>&nbsp;SqFt</span></li>
																	<li><span class="list_label">MLS Number</span><span class="list_value"><?php echo str_ireplace('NST','',$row['ListingId']);?></span></li>
																</ul>
															</div>
															<div class="pl-quick-link-buttons">
																<div class="pl-details-vd">
																	<!-- <a class="button view-details" href="<?php //echo $_SERVER['HTTP_ORIGIN']."/fl2/static-blmtfdetails.php?page=".$startIndex."&ListingId=".$row['ListingId']."&query=".$query."&returnURL=static-grid1"; ?>">View Details</a> -->
																	<a class="button view-details" href="<?php echo $_SERVER['HTTP_ORIGIN']."/z/fl2/h/static-details3.php?page=".$startIndex."&ListingId=".$row['ListingId']."&returnURL=static-grid1"; ?>">View Details</a>
																</div>
																<!--
																<div class="pl-courtesy">
																	<?php
																	/*
																		$CoListAgentMlsId = $searchFields['CoListAgentMlsId'];
																		$ListAgentMlsId = $searchFields['ListAgentMlsId'];
																		$BuyerAgentMlsId = $searchFields['BuyerAgentMlsId'];
																		$CoBuyerAgentMlsId = $searchFields['CoBuyerAgentMlsId'];
																		if($CoListAgentMlsId == $AgentMlsId || $CoListAgentMlsId == $AgentMlsId2 || $ListAgentMlsId == $AgentMlsId || $ListAgentMlsId == $AgentMlsId2){
																			$courtesy =  'Listed By '.$AgentName.' '.$AgentName2; 
																		}elseif($BuyerAgentMlsId == $AgentMlsId || $BuyerAgentMlsId == $AgentMlsId2 || $CoBuyerAgentMlsId == $AgentMlsId || $CoBuyerAgentMlsId == $AgentMlsId2){
																			$courtesy =  'Buyer Representation: Listing By '.$row['ListOfficeName']; 
																		}*/
																	?>
																	<span class="eg"><?php // echo $courtesy;?></span>
																</div>-->
															</div>
														</div>
													</div>
												</div>
											</div>
										<?php 
										$startIndex++;
										} ?>
									</div>
								</div>
								<?php
                                /* 
                                if(($showPagination) && $count > 0) {
                                    include('pagination/pagination.php');
                                    include_once($INC_DIR. "pagination/pagination.php");
                                }*/
                                ?>
                                <?php if(($showPagination)) {
                                    include($INC_DIR. "pagination/pagination.php");
                                }?>
								<!--<div id="loader-icon" style="display:none;" class="center"><img src="/includes/images/loading.gif"></div>-->
							<?php } else { ?>
								<div class="no-data center">No Result Found</div>
							<?php } ?>
						</div>
					</main>
					<aside class="sidebar"></aside>
				</div>
			</div>
<?php 
// include_once('/includes/footer.php');
include_once($INC_DIR. "footer.php"); ?>