<?php
include("admin/db.php");
login();

$AllPixResult = SelectAllPictures();
$AllPixCount = mysql_num_rows($AllPixResult);

// number of rows to show per page
$rowsperpage = 10;

// find out total pages
$totalpages = ceil($AllPixCount / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage']))
   $currentpage = (int) $_GET['currentpage']; 
else 
   $currentpage = 1; // default page num

// if current page is greater than total pages...
if ($currentpage > $totalpages)
   $currentpage = $totalpages; // set current page to last page
   
// if current page is less than first page...
if ($currentpage < 1)
	$currentpage = 1; // set current page to first page

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

//UPDATES AKA NEWS
$PixResult = SelectPagedPictures($offset, $rowsperpage);
$PixCount = mysql_num_rows($PixResult);

?>
<!doctype html>
<html lang="en" class="no-js">
<head>
	<title>Photos | On The Menu Podcast</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta http-equiv="description" content="Photos of places and events from all around the world that OTM has visited">
	<meta name="keywords" content="fine dining,food,restaurants,food reviews,restaurant reviews,Ann Haigh,Peter Haigh,food podcast,on the menu" />
	<link href="https://fonts.googleapis.com/css?family=Oswald:300,400%7CKarla:400,700" rel="stylesheet">
	<link rel="shortcut icon" href="images/favicon.ico">
	<link rel="stylesheet" href="assets/css/bootstrap-reboot.css">
	<link rel="stylesheet" href="assets/css/bootstrap-grid.css">
	<link rel="stylesheet" href="assets/css/material-design-iconic-font.css">
	<link rel="stylesheet" href="assets/css/style.css">
</head>
<body class="home">
	<header id="top" class="navbar navbar-sticky">
		<div class="container">
			<div class="row align-items-center">
				<? 
				include("site-title.php");
				?>
				<? 
				include("nav.php");
				?>
				<nav id="social-links-menu" style="padding-top:10px" class="col-lg-4 col-md-auto order-4 order-md-1 order-lg-3 col-sm-12">
				  <div class="row">
				   <div class="col-lg-4 col-md-4" style="padding-bottom: 10px;">
				   
					<? 
					include("sm-top.php");
					?>
					</div>
					<div class="col-lg-8 col-md-8">
				<!--START TOP PLAYER-->
					<?php
						//LATEST LISTEN
					$latestresult = SelectLatestListen();
					$latestcount = mysql_num_rows($latestresult);
					 if($latestcount > 0)
					  { 
						while($latestrow = mysql_fetch_object($latestresult))
						{
							$latestURLVar = stripslashes($latestrow->URL);
						
						}//end while
					}
					?>
						<p style="font-size: 14px; margin: 0px; padding-bottom:2px; text-align: center">Listen To The Latest Episode</p>
						<audio class="wp-audio-shortcode" preload="none" style="width: 100%;" controls="controls">
						<source src="<?=$latestURLVar;?>" type="audio/mpeg" />
						</audio>
					<!--END TOP PLAYER-->
					</div>	
				</nav>
				
			
				<div class="site-menu-toggle col-auto order-2 order-sm-3">
					<a href="#site-menu">
						<span class="screen-reader-text">Toggle navigation</span>
					</a>
				</div>
			</div>
		</div>
	</header>

	<header id="featured" class="featured-content2 fade-background-50 padding-top-bottom">
		<div class="container">
			<div class="row align-items-center">
				<div class="col-12 col-md">
					<h1>OTM IN PICTURES</h1>
				</div>
			</div>
		</div>
	</header>

   <main id="content" class="has-sidebar padding-top-bottom">
		<div class="container">
			<div class="row">
				<div class="col-12 col-md-8 col-lg-9">
					<article class="entry entry-post">
						<div class="entry-content"><br>
							<?php
						  if($PixCount > 0)
						{ 
							while($PixRow = mysql_fetch_object($PixResult))
							{
									$pixID = $PixRow->ID;
									$pixImageName = stripslashes($PixRow->ImageName);
									
									if($PixRow->ImageName != '')
										$pixImageName = stripslashes($PixRow->ImageName);
									else
										$pixImageName =	"bookNotAvailable.jpg";
									
									$pixBody = stripslashes($PixRow->Body);
									//$pixDisplay = stripslashes($PixRow->DisplayOrder);

									$file = "./pictures/$pixImageName"; 
									if (is_file($file)) {
										echo "<!--START ENTRY-->\n";
										echo "<img src=\"pictures/$pixImageName\" alt=\"\" class=\"img-responsive\" /> <br />\n";
										echo "<p>$pixBody</p>\n";
										echo "<!--END ENTRY-->\n";
									}

							}
						}
						else
						{
							$pixTitle = "There are no photos to display!";
						
							echo "<!--START ENTRY-->\n";						
						    echo "<h4>$pixTitle</h4>\n";
							echo "<p>&nbsp;</p>\n";				
							echo "<!--END ENTRY-->\n";
						}							
									
							?>
					
							
							
					  </div>
					</article>
					<div class="pagination">More Photos:<br>
					<?php
						/******  build the pagination links ******/
				// range of num links to show
				$range = 3;

				// if not on page 1, don't show back links
				if ($currentpage > 1) {
				   // show << link to go back to page 1
				   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1' class=\"next page-numbers\"><<</a> ";
				   // get previous page num
				   $prevpage = $currentpage - 1;
				   // show < link to go back to 1 page
				   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage' class=\"next page-numbers\"><span class=\"zmdi zmdi-chevron-left\"></span></a> ";
				} // end if 

				// loop to show links to range of pages around current page
				for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
				   // if it's a valid page number...
				   if (($x > 0) && ($x <= $totalpages)) {
					  // if we're on current page...
					  if ($x == $currentpage) {
						 // 'highlight' it but don't make a link
						 echo " <span aria-current=\"page\" class=\"page-numbers current\"><b>$x</b></span> ";
					  // if not current page...
					  } else {
						 // make it a link
						   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x' class=\"next page-numbers\">$x</a> ";
					  } // end else
				   } // end if 
				} // end for

				// if not on last page, show forward and last page links        
				if ($currentpage != $totalpages) {
				   // get next page
				   $nextpage = $currentpage + 1;
					// echo forward link for next page 
				   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage' class=\"next page-numbers\"><span class=\"zmdi zmdi-chevron-right\"></span></a> ";
				   // echo forward link for lastpage
				   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages' class=\"next page-numbers\">>></a> ";
				} // end if
				/****** end build pagination links ******/
				?>
						</div>
				</div>
				<div id="sidebar" class="col-12 col-md-4 col-lg-3">
				
					<div class="widget widget_categories">
						<h5 class="add-separator"><span>Site Categories</span></h5>
						<ul>
							<li class="cat-item"><a href="about.php">About</a></li>
							<li class="cat-item"><a href="episodes.php">Episodes</a></li>
							<li class="cat-item"><a href="news.php">News</a>
							<li class="cat-item"><a href="articles.php">Articles</a></li>
							<li class="cat-item"><a href="bookshelf.php">Bookshelf</a></li>
							<li class="cat-item"><a href="favorites.php">Favorites</a></li>
							<li class="cat-item current-cat"><a href="photos.php">Photos</a></li>
							<li class="cat-item"><a href="index.php">Home</a></li>
						</ul>
					</div>
					<? 
						include("podcast-sub.php");
					?>
					
					
				</div>
			</div>
		</div>
	</main>

	<? 
		include("footer.php");
	?>

	<script src="assets/js/jquery-3.2.1.min.js"></script>
	<script src="assets/js/modernizr-custom.js"></script>
	<script src="assets/js/functions.js"></script>

	<!-- MediaElement.js files -->
	<link rel="stylesheet" id="mediaelement-css"  href="assets/mediaelement/mediaelementplayer-legacy.css">
	<link rel="stylesheet" id="wp-mediaelement-css"  href="assets/mediaelement/wp-mediaelement.css">
	<link rel="stylesheet" id="castilo-additional-mediaelement-css"  href="assets/css/mediaelement-castilo.css">
	<script src="assets/mediaelement/mediaelement-and-player.js"></script>
	<script src="assets/mediaelement/mediaelement-migrate.js"></script>
	<script src="assets/mediaelement/wp-mediaelement.js"></script>
	<script src="assets/js/mediaelement-castilo.js"></script>
	<script src="assets/js/index.js"></script>
</body>
</html>