<!-- Add this in the <head> section -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8sh+Wy2T8uLJl7DJaDz6Ip6kXUew0I88PUGGI" crossorigin="anonymous">
<style>
    form {
    display: flex;
    flex-direction: column;
    border: 1px solid #fff;
}

label {
    margin-top: 10px;
    color: #fff;
}

input {
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button {
    padding: 10px;
    background-color: #007bff;
    color: #fff;
    border: none;
    cursor: pointer;
    border-radius: 4px;
}
</style>



<?php $__env->startSection('content'); ?>

<?php

if (isset($_POST['submit'])) {
    // Assuming you have a MySQL database
    
    $servername = "localhost:3306";
                        $username = "ncaa_controlportal";
                        $password = "?)*Sx8_GBX1C";
                        $dbname = "ncaa_portal";
    
    
   

    // Create a connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check the connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Get form data
    $aircraftName = $_POST["AircraftName"];
    $aircraftType = $_POST["AircraftType"];
    $aircraftOperator = $_POST["AircraftOperator"];
    $callSign = $_POST["CallSign"];
    $lengthMeters = $_POST["LengthMeters"];
    $status = $_POST["Status"];
    $mileage = $_POST["Mileage"];
    $mtow = $_POST["MTOW"];
    $yearOfManufacture = $_POST["YearOfManufacture"];
    $insurer = $_POST["Insurer"];
    $liabilityLimit = $_POST["LiabilityLimit"];
    $insurancePolicy = $_POST["InsurancePolicy"];
    $premium = $_POST["Premium"];
    $expiryDate = $_POST["ExpiryDate"];
    $uemail = $_POST["Uemail"];
    
    try {
        // Create a PDO connection
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        // Set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        // Prepare and execute the SQL statement
        $stmt = $conn->prepare("INSERT INTO AircraftInsurance (AircraftName, AircraftType, AircraftOperator, CallSign, LengthMeters, Status, Mileage, MTOW, YearOfManufacture, Insurer, LiabilityLimit, InsurancePolicy, Premium, ExpiryDate, Uemail) 
                                VALUES (:AircraftName, :AircraftType, :AircraftOperator, :CallSign, :LengthMeters, :Status, :Mileage, :MTOW, :YearOfManufacture, :Insurer, :LiabilityLimit, :InsurancePolicy, :Premium, :ExpiryDate, :Uemail)");

        $stmt->bindParam(':AircraftName', $aircraftName);
        $stmt->bindParam(':AircraftType', $aircraftType);
        $stmt->bindParam(':AircraftOperator', $aircraftOperator);
        $stmt->bindParam(':CallSign', $callSign);
        $stmt->bindParam(':LengthMeters', $lengthMeters);
        $stmt->bindParam(':Status', $status);
        $stmt->bindParam(':Mileage', $mileage);
        $stmt->bindParam(':MTOW', $mtow);
        $stmt->bindParam(':YearOfManufacture', $yearOfManufacture);
        $stmt->bindParam(':Insurer', $insurer);
        $stmt->bindParam(':LiabilityLimit', $liabilityLimit);
        $stmt->bindParam(':InsurancePolicy', $insurancePolicy);
        $stmt->bindParam(':Premium', $premium);
        $stmt->bindParam(':ExpiryDate', $expiryDate);
        $stmt->bindParam(':Uemail', $uemail);

        $stmt->execute();

        // Redirect back to the form page with a success message
        header("Location: https://ncaa.frmlimited.net/reports/users/insurances/index?success=1");
        exit();
    } catch (PDOException $e) {
        // Display an error message on failure
        echo "Error: " . $e->getMessage();
    } finally {
        // Close the connection
        $conn = null;
    }





} 

?>
    <div class="container">
    <h2 class="content-heading">Report <small>view Aircraft report</small></h2>
    
     <!-- Button to trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAircraftModal">
        Add Insurance Record
    </button>
    
    <!-- Modal -->
    <div class="modal fade" id="addAircraftModal" tabindex="-1" role="dialog" aria-labelledby="addAircraftModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="addAircraftModalLabel">Add Aircraft</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button> 
                </div> 
                <div class="modal-body">
                    <!-- Your HTML form for adding an Aircraft goes here -->
                    <!-- Example form -->
                    <form action="<?php echo e(route('reports.users.insurances.index')); ?>" method="post">
                        <?php echo csrf_field(); ?>
                        <label for="aircraftName">Aircraft Name:</label>
            <input type="text" id="aircraftName" name="AircraftName" required>

            <label for="aircraftType">Aircraft Type:</label>
            <input type="text" id="aircraftType" name="AircraftType" required>

            <label for="aircraftOperator">Aircraft Operator:</label>
            <input type="text" id="aircraftOperator" name="AircraftOperator" required>

            <label for="callSign">Call Sign:</label>
            <input type="text" id="callSign" name="CallSign" required>

            <label for="lengthMeters">Length (Meters):</label>
            <input type="number" id="lengthMeters" name="LengthMeters" required>

            <label for="status">Status:</label>
            <input type="text" id="status" name="Status" required>

            <label for="mileage">Mileage:</label>
            <input type="number" id="mileage" name="Mileage" required>

            <label for="mtow">MTOW:</label>
            <input type="number" id="mtow" name="MTOW" required>

            <label for="yearOfManufacture">Year of Manufacture:</label>
            <input type="number" id="yearOfManufacture" name="YearOfManufacture" required>

            <!-- Insurance Information -->
            <label for="insurer">Insurer:</label>
            <input type="text" id="insurer" name="Insurer" required>

            <label for="liabilityLimit">Liability Limit:</label>
            <input type="number" id="liabilityLimit" name="LiabilityLimit" required>

            <label for="insurancePolicy">Insurance Policy:</label>
            <input type="text" id="insurancePolicy" name="InsurancePolicy" required>

            <label for="premium">Premium:</label>
            <input type="number" id="premium" name="Premium" required>

            <label for="expiryDate">Expiry Date:</label>
            <input type="date" id="expiryDate" name="ExpiryDate" required>

            <!-- User Information -->
          
            <input type="email" id="Uemail" value=" <?php echo Auth::user()->email; ?>" readonly hidden  name="Uemail" required>
            
           

            <button name="submit" type="submit">Insert Insurance Record</button>
            

           
            
            
           
        </form>
                </div>
            </div>
        </div>
    </div>
    
    <!-- <h2 class="table-header">Tower Report</h2> -->
      <table id="Report" class="styled-table">
                        <thead>
                            
                             <tr>
                               <th>S/N</th>
                                <th>AircraftName</th>
                                <th>Aircraft Type</th>
                                <th>Aircraft Operator</th>
                                <th>CallSign</th>
                                <th>Length Meters</th>
                                <th>Status</th>
                                <th>Mileage</th>
                                <th>MTOW</th>
                                
                                <th>Year Of Manufacture</th>
                                <th>Insurer</th>
                                <th>Liability Limit</th>
                                <th>Insurance Policy</th>
                                <th>Premium</th>
                                <th>Expiry Date</th>

                            </tr>
                        </thead>

                        <tfoot>
                             <tr>
                               <th>S/N</th>
                                <th>AircraftName</th>
                                <th>Aircraft Type</th>
                                <th>Aircraft Operator</th>
                                <th>CallSign</th>
                                <th>Length Meters</th>
                                <th>Status</th>
                                <th>Mileage</th>
                                <th>MTOW</th>
                                
                                <th>Year Of Manufacture</th>
                                <th>Insurer</th>
                                <th>Liability Limit</th>
                                <th>Insurance Policy</th>
                                <th>Premium</th>
                                <th>Expiry Date</th>

                            </tr>
                        </tfoot>
                        <tbody>
                       
                       
                       
                       
                       <?php
                       $servername = "localhost:3306";
                        $username = "ncaa_controlportal";
                        $password = "?)*Sx8_GBX1C";
                        $dbname = "ncaa_portal";
                        
                        // Create connection
                        $conn = new mysqli($servername, $username, $password, $dbname);
                        
                        // Check connection
                        if ($conn->connect_error) {
                            die("Connection failed: " . $conn->connect_error);
                        }
                        $email = Auth::user()->email; // Assuming this is your actual email value

                        // SQL query to select data from the database
                       $sql = "SELECT * FROM AircraftInsurance WHERE Uemail = '$email'";
                        $result = $conn->query($sql);

if ($result->num_rows > 0) {
$sn = 1;

    while ($row = $result->fetch_assoc()) {
        echo '<tr>';
        echo '<td>' . $sn . '</td>';
        echo '<td>' . $row['AircraftName'] . '</td>';
        echo '<td>' . $row['AircraftOperator'] . '</td>';
        echo '<td>' . $row['CallSign'] . '</td>';
        echo '<td>' . $row['AircraftType'] . '</td>';
        echo '<td>' . $row['LengthMeters'] . '</td>';
        echo '<td>' . $row['Status'] . '</td>';
        echo '<td>' . $row['Mileage'] . '</td>';
        echo '<td>' . $row['MTOW'] . '</td>';
        echo '<td>' . $row['YearOfManufacture'] . '</td>';
        echo '<td>' . $row['Insurer'] . '</td>';
        echo '<td>' . $row['LiabilityLimit'] . '</td>';
        echo '<td>' . $row['InsurancePolicy'] . '</td>';
        echo '<td>' . $row['Premium'] . '</td>';
        echo '<td>' . $row['ExpiryDate'] . '</td>';
        echo '</tr>';
        $sn++;
    }

    echo '</tbody></table>';
} else {
    echo "No records found.";
}

// Close the database connection
$conn->close();
                       
                       ?>
                       
                       
                        </tbody>
      </table>
    </div>
</div>
    <?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.report', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ncaa/public_html/resources/views/reports/users/insurances/index.blade.php ENDPATH**/ ?>