<?php
if (isset($_GET['link']) || isset($_GET['search']) && isset($_GET['mod'])) {
  $mod = $_GET['mod'];

if ($mod == "journals") {
$worduse = "Journals";
}elseif ($mod == "textbooks") {
$worduse = "Textbooks";

}
?>

<?php
if (isset($_GET['link'])) {
  $linkname = $_GET['link'];
  if (empty($linkname)) {
  $linkname = "0empty";
  }
?>
<section id="portfolio">
      <div class="container wow fadeInUp">
        <div class="section-header">
          <h3 class="section-title"><?php echo $worduse; ?> in <?php echo $linkname; ?></h3>
        </div>
        <div class="row" id="portfolio-wrapper">
<?php
}elseif (isset($_GET['search'])) {
  $searchname = $_GET['search'];
  if (empty($searchname)) {
  $searchname = "0empty";
  }
?>


<section id="portfolio">
      <div class="container wow fadeInUp">
        <div class="section-header">
          <h3 class="section-title">Search result for <?php echo $searchname; ?></h3>
        </div> 
        <div class="row" id="portfolio-wrapper">
<?php
}
?>

<?php
include('inc/booklink.php');
include('inc/booksearch.php');
?>

          
            
        
<?php
}else{
?>
<section id="portfolio">
      <div class="container wow fadeInUp">
        <div class="section-header">
          <h3 class="section-title">Books</h3>
        </div>
        <div class="row" id="portfolio-wrapper">
<?php
$query = $conn->query("SELECT * FROM books WHERE type = 'text' ORDER BY RAND() LIMIT 50");
$fetch = $query->fetchAll(PDO::FETCH_OBJ);
$count = $query->rowCount();
$num = 1;
if ($count > 0) {
  foreach ($fetch as $value) {
  $iden = $value->id;
  $name = $value->name;
  $author = $value->author;
  $frontpage = $value->frontpage;
  $description = $value->description;
  $dop = $value->dop;
  $edition = $value->edition;
  $publisher = $value->publisher;
  $pop = $value->pop;
  $nop = $value->nop;
  $file = $value->file;
  $course = $value->course;
  $by = $value->by;
  $date = $value->date;
?>
<div class="col-lg-3 col-md-6 portfolio-item filter-app">
              <img src="books/image/<?php echo "$frontpage"; ?>" alt="">
              <div class="details">
                <h4><?php echo "$name"; ?> by <?php echo "$author"; ?><br>
                <i class="fa fa-eye fa-2x" title="View Details" data-toggle="modal" data-target="#viewthis<?php echo $iden; ?>"></i>&nbsp;&nbsp;
                  <i class="fa fa-book fa-2x" title="Read" data-toggle="modal" data-target="#readthis<?php echo $iden; ?>"></i>
                </h4>
              </div>
          </div>


          <div class="modal fade" id="viewthis<?php echo $iden; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog modal-sm">
                                <div class="modal-content">
                                 <div class="modal-header" style="background: white;">
                                 <h5 class="modal-title" id="myModalLabel" style="color: black; text-transform: capitalize; font-weight: bolder;"><?php echo $name; ?> </h5>
                                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="color: black;">&times;</button>
                                 </div>
                                 <div class="modal-body">
                                    <img src="books/image/<?php echo $frontpage ?>" width="100%" class="center">
                                    <hr>

                                  <p><b>Author:</b> <?php echo $author ?></p>
                                  <p><b>Description:</b> <?php echo $description ?></p>
                                  <p><b>Date of Publication:</b> <?php echo $dop ?></p>
                                  <p><b>Edition:</b> <?php echo $edition ?></p>
                                  <p><b>Publisher:</b> <?php echo $publisher ?></p>
                                  <p><b>Place of Publication:</b> <?php echo $pop ?></p>
                                  <p><b>Number of Pages:</b> <?php echo $nop ?></p>
                                 </div>
                                 </div><!-- /.modal-content -->
                                </div><!-- /.modal -->
                            </div>


                            <div class="modal fade" id="readthis<?php echo $iden; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                 <div class="modal-header" style="background: white;">
                                 <h5 class="modal-title" id="myModalLabel" style="color: black; text-transform: capitalize; font-weight: bolder;"><?php echo $name; ?> </h5>
                                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="color: black;">&times;</button>
                                 </div>
                                 <div class="modal-body">
                                    <iframe ?wmode="transparent" src="books/file/<?php echo $file; ?>#toolbar=0&navpanes=0&scrollbar=0" style=""  width="100%" height="500px" id="iframe"></iframe>
                                 </div>
                                 </div><!-- /.modal-content -->
                                </div><!-- /.modal -->
                            </div>


<?php

  }
}
?>
</div>
</div>
</section>
<?php
}
?>    