<?php    
    // attempt to connect to the DB
    $dbconn = mysqli_connect("localhost", "root", "", "gamerental");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit(); // if it doesnt connect error page
    }
 
    // checking for an id if not then redirects back to rental
    $RentalID = 0;
    if (isset($_GET['RentalID']))
        $RentalID = $_GET['RentalID'];
    
    if ($RentalID == 0)
    {
        $redirect = "location: http://localhost/gamerental/rental";
        header($redirect);
    }

    // get the details of the rental 
    $sql = $dbconn->prepare("SELECT RentalID as rentalid,
									MemberID as memberid,
                                    GameID as gameid, 
									Expected as expected,
                                    Returned as returned, 
                                    Hired as hired, 
									Overdue as overdue							
								    from rental					
                                    where RentalID = ?");
    $sql->bind_param('i', $RentalID);	
    // execute the query 
    $sql->execute(); 
    
    // binding the fields
    $sql->bind_result($rentalid, $memberid,$gameid, $expected, $returned, $hired, $overdue);
    $sql->store_result();
    $sql->fetch();

  
    //close connection
    mysqli_close($dbconn);
?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="Assignment">
        <meta name="generator" content="Jekyll v3.8.5">
        <title>View Rental Details</title>  

        <!-- include any relevant css/js files -->
        <?php include "../template/pageheader.php"; ?>

    </head>
    <body>
        <!-- include the top menu -->
        <?php include "../template/topmenu.php"; ?> 
        <!-- end top menu -->

        <div class="container-fluid">
            <div class="row">
                <!-- insert the side menu -->
                <?php include "../template/sidemenu.php"; ?>	
                <!-- end side menu -->

                <!-- webpage content goes here -->
                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h1">Rental Details</h1> 
                    </div>
					 <div class="row">
                        <div class="col-md-1">
                            <label for="title">MemberID</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="title" name="title" 
                                   value="<?php echo $memberid?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="forename">GameID</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="forename" name="forename" 
                                   value="<?php echo $gameid?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="surname">Expected</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="surname" name="surname" 
                                   value="<?php echo $expected?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="address1">Returned</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="address1" name="address1" 
                                   value="<?php echo $returned?>" 
                                   readonly>
                        </div>
                    </div>                                                          
                    <div class="row">
                        <div class="col-md-1">
                            <label for="postcode">Hired</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="postcode" name="postcode" 
                                   value="<?php echo $hired?>" 
                                   readonly>
                        </div>
                    </div>
                   <div class="row">
                        <div class="col-md-1">
                            <label for="telephone">Overdue</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="telephone" name="telephone" 
                                   value="<?php echo $overdue?>" 
                                   readonly>
                        </div>
                    </div>     
                    <div class="col-md-2 mb-2">
                            <form action="delete.php" method="post">
                                <input type="hidden" id="RentalID" name="RentalID" value="<?php echo $RentalID?>">
                                <input type="Submit" value="Delete Rental" />
								
                            </form>
							<form action="index.php" method="post">
                                <input type="Submit" value="Back to List" />
                            </form>
                        </div>
               
                    
                
                    </div>
                </main>
            </div>
       

        <!-- include any relevant js files -->
        <?php include "../template/pagefooter.php"; ?>

    </body>
</html>