<?php
include('../includes/functions.php');
session_start();
make_connection();
if(is_loggedin());
else
  redirect_to('index.php');
$user=get_user();
if(!$user)
 redirect_to('index.php');
$user_id=$user['regno'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <?php include('../includes/head.php');?>
  <title>Utopia- View Requests</title>
  <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" type="text/css" href="materialize/css/materialize.css">
  <link rel="stylesheet" type="text/css" href="css/home.css">
  <link rel="stylesheet" type="text/css" href="css/searchbook.css">
  <style type="text/css">
    .color-red{
      color: red;
    }
    .norequests{
      position: absolute;
      bottom: 10px;

    }
    .badge-bs {
      display: inline-block;
      min-width: 10px;
      padding: 3px 7px;
      font-size: 14px;
      font-weight: 700;
      line-height: 1;
      color: #fff;
      text-align: center;
      white-space: nowrap;
      vertical-align: middle;
      background-color: #4dad69;
      border-radius: 10px;
    }
    .bookid{
      position: absolute;
      top: 5px;
      left:50%;
      text-decoration:underline;
      color: rgb(238, 110, 115);
    }
  </style>
</head>
<body>
  <div class="body row">
    <?php
    global $navactive;
    $navactive="requests";
    include('../includes/nav.php');
    ?>

    <div class="main">
      <div class="container">
        <header>
          <h3 class="center" id="introo_heading21">Requests received for your books</h3>
          <h6 class="left-align" id="introo_heading22">Contact them to sell your books!</h6>
          <br>
        </header>
        <div class="requestssdiv">
          <?php
          $all_books=get_all_books_uid($user_id);
          $nobooks=0;
          if($all_books){
            while($row=mysqli_fetch_assoc($all_books))
            {
              $nobooks++;
              $book_id=$row['id'];
              $book_requests=get_all_book_request($book_id,$user_id);
              if(empty($book_requests))
                echo print_book_requests($row,false);
              else
                echo print_book_requests($row,$book_requests);
            }
          }

          if($nobooks==0)
            echo "<h4>You don't have any book. Try <a href='addbook.php'>adding books</a> to receive requests from people to buy your books.</h4>";
          ?>
        </div>
      </div>
    </div>
  </div>
  <script src="js/jquery.js"></script>
  <script src="materialize/js/materialize.js"></script>
  <script>
    $(".button-collapse").sideNav();
    $('.button-collapse').sideNav({
      menuWidth: 300, // Default is 240
      edge: 'left', // Choose the horizontal origin
      closeOnClick: false // Closes side-nav on <a> clicks, useful for Angular/Meteor
    }
    );
  </script>
  <script>
    $(document).ready(function(){
    // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
    $('.modal-trigger').leanModal();
  });
    <?php
    if($nobooks==0)
    {
      echo "
      $('#introo_heading21').text('');
      $('#introo_heading22').text('');
      ";
    }
    ?>
  </script>
</body>
</html>