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

$AllBookResult = SelectAllBookshelf();
$AllBookCount = mysql_num_rows($AllBookResult);

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

// find out total pages
$totalpages = ceil($AllBookCount / $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;

//FAVS
$BookResult = SelectBookshelfPaged($offset, $rowsperpage);
$BookCount = mysql_num_rows($BookResult);

?>
<!doctype html>
<html lang="en" class="no-js">
<head>
	<title>OTM Bookshelf | 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="Download or listen to all the On The Menu episodes.  Also available on iTunes and Google Play.">
	<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 BOOKSHELF</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">
					<div class="episodes-listing">
						<!--BOOKSHELF -->
						<?php
						  if($BookCount > 0)
							{ 
							while($BookRow = mysql_fetch_object($BookResult))
								{
									$fbsID = $BookRow->ID;
									$fbsTitle = stripslashes($BookRow->Title);
									$fbsAuthor = stripslashes($BookRow->Author);
									$fbsURL = $BookRow->URL;
									$fbsExcerpt = stripslashes($BookRow->Excerpt);
									
									
									if($BookRow->ImageName != '')
										$fbsImageName = stripslashes($BookRow->ImageName);
									else
										$fbsImageName =	"bookNotAvailable.jpg";
									
									$file = "./bookshelf/$fbsImageName"; 
									if (!is_file($file))
										$fbsImageName = "bookNotAvailable.jpg";
										
									
									$fbsDisplayOrder = stripslashes($BookRow->DisplayOrder);
									
									
								?>
						<article class="entry entry-episode">
							<div class="row align-items-lg-center">
								<div class="col-12 col-md-4 col-xl-2">
									<div class="entry-media entry-image multiply-effect">
										<a href="<?=$fbsURL;?>" target="_blank"><img class="first" src="bookshelf/<?=$fbsImageName;?>"  alt=""></a>
									</div>
								</div>
								<div class="col-12 col-md-8 col-xl-9">
									<header class="entry-header">
										
										<h4 class="entry-title" style="margin-bottom:0"><a href="<?=$fbsURL;?>" target="_blank"><?=$fbsTitle;?></a></h4>
										<p style="color:#b82619; margin-bottom:10px"><?=$fbsAuthor;?></p>
									</header>
									<div class="entry-content">
										<p><?=$fbsExcerpt;?><br><a href="<?=$fbsURL;?>" target="_blank">(Buy Now on Amazon)</a></p>
									</div>
									
								</div>
							</div>
						</article>
						<!--END A BOOKSHELF-->
						<?
						  	}//end while
						  }//end if

						  ?>
						<div class="pagination">More Bookshelf<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>
				<div id="sidebar" class="col-12 col-md-4 col-lg-3">
					<? 
					include("search-inc.php");
					?>
					<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 current-cat"><a href="bookshelf.php">Bookshelf</a></li>
							<li class="cat-item"><a href="favorites.php">Favorites</a></li>
							<li class="cat-item"><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>