<!DOCTYPE html>
<html lang="en">

 <?php include 'head.php';?>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

h1, h2 {
    text-align: center;
}

.branch-list {
    list-style-type: none;
    padding: 0;
    text-align: center;
}

.branch-list li {
    margin: 10px 0;
}

.branch-list a {
    text-decoration: none;
    color: #333;
    font-weight: bold;
}

.branch-list a:hover {
    color: #4CAF50;
}

/* Add more styling as needed */

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  margin: 0 auto;
  border:2;
}

th, td {
  padding: 10px;
  text-align: left;
}

th {
  background-color: #04AA6D;
  color: white;
}
label, input {
  width: 200px;
}
</style>
<body>

  <!-- ======= Header ======= -->
  
 <?php include 'menubar.php';?>

 <?php include 'sidebar.php';?>


  <main id="main" class="main">

<!DOCTYPE html>
<html>
<head>
    <title>Student Search</title>
</head>
<body>

<h2>Search Student by ID</h2>
<form name="Form1" method="get" action="book_allotstudent.php" enctype="text/plain" id="Form1" onsubmit="return ValidateForm1(this)">
<table style="width: 100%">
	<tr>
		<td style="width: 274px; height: 35px">Enter Registration No:</td>
		<td style="height: 35px">
		<form method="post">
			<input name="q" id='q' style="width: 250px" type="text"></form>
		</td>
	</tr>
	<tr>
		<td style="width: 274px">&nbsp;</td>
		<td>
		
			<button name="Submit" type="submit" id="Button1" name="" value="Submit" style="width: 102px">Submit</button>
	
		</td>
	</tr>
</table>
</form>

<table border="1">
        <tr>
            <th>Serial</th>
			<th>Student ID</th>
            <th>Name</th>
            <th>Father</th>
            <th>Mother</th>
            <th>DOB</th>
            <th>Address</th>
            <th>Mobile</th>
            <th>Mobile 2</th>
            <th>Aadhar</th>
            <th>Reg Date</th>
            <th>Reg Month</th>
            <th>Reg Year</th>
            <th>Fees Amount</th>
            <th>Fees Deposit Date</th>
            <th>Fees Mode</th>
            
        </tr>
<h2>Registration Details</h2>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "tslibrary_user", "rb!tsl838", "tslibrary_data");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 $var = @$_GET['q'];
$serial=1;
// Attempt select query execution
$sql = "SELECT * FROM student_registration where student_id='$var'";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){


        while($row = mysqli_fetch_array($result)){
  
           echo "<tr>";
            echo "<td>$serial</td>";
			      echo "<td>{$row['student_id']}</td>";
            echo "<td>{$row['name']}</td>";
            echo "<td>{$row['father']}</td>";
            echo "<td>{$row['mother']}</td>";
            echo "<td>{$row['dob']}</td>";
            echo "<td>{$row['address']}</td>";
            echo "<td>{$row['mobile']}</td>";
            echo "<td>{$row['mobile2']}</td>";
            echo "<td>{$row['aadhar']}</td>";
            echo "<td>{$row['reg_date']}</td>";
            echo "<td>{$row['reg_month']}</td>";
            echo "<td>{$row['reg_year']}</td>";
            echo "<td>{$row['fees_amount']}</td>";
            echo "<td>{$row['fees_deposit_date']}</td>";
            echo "<td>{$row['fees_mode']}</td>";
      
            echo "</tr>";
			$serial=$serial+1;
        }
       echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else{
        echo "Not Available any student ID";
	exit;	
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
?>
 <h1>Already Book Allotment Details </h1>
    <?php
    // Connect to the database (replace with your database credentials)
    $db = new mysqli('localhost', "tslibrary_user", "rb!tsl838", "tslibrary_data");

    if ($db->connect_error) {
        die("Connection failed: " . $db->connect_error);
    }

    // Query to select records from the book_allot_receive table
    $sql = "SELECT * FROM book_allot_receive where student_id='$var'";
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        echo '<table border="1">';
        echo '<tr><th>ID</th><th>Title</th><th>Allotment Date</th><th>Student ID</th><th>ISBN</th>
		<th>Receive Book</th></tr>';

        while ($row = $result->fetch_assoc()) {
			$bookalootdate=$row['book_allotment_date'];
			$bookrecevivedate=$row['book_receive_date'];
			if($bookalootdate>2 AND $bookrecevivedate<1 )
			{
            echo '<tr>';
            echo '<td>' . $row['ID'] . '</td>';
            echo '<td>' . $row['book_title'] . '</td>';
            echo '<td>' . $row['book_allotment_date'] . '</td>';
            echo '<td>' . $row['student_id'] . '</td>';
            echo '<td>' . $row['book_isbn_no'] . '</td>';
			echo '<td>' . "<a href='book_recevie_form.php?ID=".$row['ID']. "'>Book Receive</a>". '</td>';
            echo '</tr>';
			}
        }

        echo '</table>';
    } else {
        
    }

    $db->close();
    ?>



    <h1>New Book Allotment </h1>

    <form action="process_book_allot.php" method="post">
        <label for="student_id">Student ID:</label>
        <input type="text" name="student_id" id='student_id' value='<?php echo $var ?>' required>
        <br>
		<label for="student_id">Today Issue Date:</label>
        <input type="text" name="issuedate" id='issuedate' value='<?php echo date('d/m/Y') ?>' required>
		<br>
        <label for="book_id">Select a Book:</label>
        <select name="book_id" id='book_id'>
            <?php
            // Connect to the database (replace with your credentials)
            $db = new mysqli('localhost', "tslibrary_user", "rb!tsl838", "tslibrary_data");

            if ($db->connect_error) {
                die("Connection failed: " . $db->connect_error);
            }

            // Query to select books from the book_allot_receive table
            $sql = "SELECT * FROM books";
            $result = $db->query($sql);

            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                    echo '<option value="' . $row['ISBN'] . '">' . $row['title'] . '</option>';
                }
            } else {
                echo '<option value="0">No available books</option>';
            }

            $db->close();
            ?>
        </select>
        <br>

        <label for="action">Action:</label>
        <select name="action">
            <option value="allot">Allot</option>
         
        </select>
        <br>

        <input type="submit" value="Submit">
    </form>
	
	
	
	
</body>
</html>

   



  </main><!-- End #main -->

   <?php include 'footer.php';?>

</body>

</html>