<?php
if (isset($_GET['link'])) {
if ($linkname == "0empty") {
?>
          <div class="col-lg-12 col-md-12 portfolio-item filter-app">
            <div class="alert alert-danger">
              <p>Your link is empty</p>
            </div>
          </div>

        </div>
      </div>
    </section>
<?php
}else{
if (isset($_GET['page'])) {
$page = $_GET['page'];
if (empty($page)) {
$page = 1;
}
}else{
 $page = 1; 
}


$finish = $page*50;
$start = $page-1;
$start = $start*50;

$query = $conn->query("SELECT * FROM course WHERE name = '$linkname' order by 'id' DESC");
$fetch = $query->fetchAll(PDO::FETCH_OBJ);
$count = $query->rowCount();
$num = 1;
foreach ($fetch as $key) {
$cid = $key->id;
}
if ($mod == "journals") {
$whereis = "journal";
}elseif ($mod == "textbooks") {
$whereis = "text";

}

$query = $conn->query("SELECT * FROM books WHERE course = '$cid' AND type = '$whereis' order by 'id' DESC LIMIT  $start, 50");
$fetch = $query->fetchAll(PDO::FETCH_OBJ);
$count = $query->rowCount();
$num = 1;
if ($count > 0) {
  foreach ($fetch as $value) {
  $iden = $value->id;
  $ident = $value->iden;
  $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;
  $type = $value->type;
  $course = $value->course;
  $by = $value->by;
  $date = $value->date;
  $underc = $value->underc;

  if ($type == "journal") {
    $types = "Journal";
  }elseif ($type == "text") {
    $types = "Textbook";
  }
?>
<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>
                                  <p><b>Under Course:</b> <?php echo $underc ?></p>
                                  <p><b>Type:</b> <?php echo $types ?></p>
                                   <?php
                                  if ($type == 'journal') {
                                    $fetch2 = $conn->query("SELECT * FROM articles WHERE fors = '$ident'");
                                    $result2 = $fetch2->fetchAll(PDO::FETCH_OBJ);
                                    $count2 = $fetch2->rowCount();
                                    if ($count2 > 0) {
                                  ?>
                                  <p><b>Articles</b></p>
                                   <div class="row">
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                  <p><b>Title</b></p>
                                              </div>
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                <p><b>Page</b></p>
                                              </div>
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                <p><b>Autors</b></p>
                                              </div>
                                   </div>
                                  <?php
                                    foreach ($result2 as $key2) {
                                      $aid = $key2->id;
                                      $afor = $key2->fors;
                                      $aname = $key2->name;
                                      $anum = $key2->num;
                                      $aby = $key2->by;
                                  ?>
                                  <div class="row">
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                <div class="well" style="overflow: scroll;">
                                                  <?php echo "$aname";  ?>
                                                </div>
                                              </div>
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                <div class="well" style="overflow: scroll;">
                                                  <?php echo "$anum";  ?>
                                                </div>
                                              </div>
                                              <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
                                                <div class="well" style="overflow: scroll;">
                                                  <?php echo "$aby";  ?>
                                                </div>
                                              </div>
                                   </div>
                                  <?php
                                    }
                                  }else{
                                  ?>
                                  <p><b>No Article</b></p>
                                  <?php
                                  }
                                }
                                  ?>
                                 </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

  }
}else{
?>
<div class="clearfix"></div>
<div class="container">
<div class="row">
<div class="alert alert-warning col-xs-12 col-sm-12 col-md-12 text-center">
  There is nothing here... Please go back to home
</div>
</div>
</div>
<?php
}
?>


<?php
}
?>
</div>
Total = <?php echo "$count"; ?>
<div class="row">
<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
if (empty($page) || $page == 0) {
$page = 0;
$newp = $page+1;
?>
<a href="?mod=<?php echo $mod ?>&link=<?php echo $linkname ?>&page=<?php echo $newp ?>"><button class="btn btn-default btn-sm border-warning"><i class="fa fa-chevron-right"></i></button></a>
<?php

}
$query = $conn->query("SELECT * FROM books WHERE course = '$cid' order by 'id' DESC");
$fetch = $query->fetchAll(PDO::FETCH_OBJ);
$count = $query->rowCount();
$num = 1;

$finish = $page*50;
$start = $page-1;
$start = $start*50;

if ($finish == $count) {
  $newp = $page-1;
?>
<a href="?mod=<?php echo $mod ?>&link=<?php echo $linkname ?>&page=<?php echo $newp ?>"><button class="btn btn-default btn-sm border-warning"><i class="fa fa-chevron-left"></i></button></a>&nbsp;
<?php
}elseif ($finish < $count && $finish != 0 && $page != 1) {
  $newp1 = $page+1;
  $newp2 = $page-1;
  if ($newp2 == 0) {
   $newp2 = "";
  }
?>
<a href="?mod=<?php echo $mod ?>&link=<?php echo $linkname ?>&page=<?php echo $newp2 ?>"><button class="btn btn-default btn-sm border-warning"><i class="fa fa-chevron-left"></i></button></a>&nbsp;
<a href="?mod=<?php echo $mod ?>&link=<?php echo $linkname ?>&page=<?php echo $newp1 ?>"><button class="btn btn-default btn-sm border-warning"><i class="fa fa-chevron-right"></i></button></a>
<?php
}elseif ($page >= 1 && $finish < $count) {
  $newp1 = $page+1;
?>
<a href="?mod=<?php echo $mod ?>&link=<?php echo $linkname ?>&page=<?php echo $newp1 ?>"><button class="btn btn-default btn-sm border-warning"><i class="fa fa-chevron-right"></i></button></a>
<?php
}else{

}
}else{
 $page = 1;
}
?>

 
</div>

</div>
</section>

<?php

}
?>