<?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- Transactions</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">
  <style type="text/css">
    .color-red{
      color: red;
    }
    #createnew{
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div class="body row">
    <?php
    global $navactive;
    $navactive="transactions";
    include('../includes/nav.php');
    ?>

    <div class="main">
      <div class="container">
        <header>
          <h3 class="center" id="introo_heading21">Your transactions record</h3>
          <br>
        </header>
        <a id="createnew" href="addtransactions.php">+create a new record</a>
        <div class="requestssdiv">
         <?php
         $all_transactions=get_all_transactions($user_id);
         ?>
         <table>
          <thead>
            <tr>
              <th data-field="book_name">Book Name</th>
              <th data-field="buyer_name">buyer name</th>
              <th data-field="status">status</th>
              <th data-field="status">cost</th>
              <th data-field="status">due return date</th>
              <th data-field="status">actual return date</th>
            </tr>
          </thead>

          <tbody>
            <?php
            while($row=mysqli_fetch_assoc($all_transactions)){
              echo "<tr>";
              echo "<td>".$row['bname']."</td>";
              echo "<td>".$row['uname']."</td>";
              if($row['status']==1)
              {
                echo "<td>"."Sold Permanently"."</td>";
                echo "<td>".$row['cost']."</td>";
                echo "<td>"."none"."</td>";
                echo "<td>"."none"."</td>";
              }
              if($row['status']==2)
              {
                echo "<td>"."Borrowed temporarily"."</td>";
                echo "<td>".$row['cost']."</td>";
                echo "<td>".$row['due_return_date']."</td>";
                echo "<td>".$row['act_return_date']."</td>";
              }
              echo "</tr>";
            }
            ?>
          </tbody>
        </table>
      </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();
  });
</script>
</body>
</html>