<!-- 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);
    }

    
        // Retrieve form data for Aircraft Information
        $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'];
        
        $name1 = $_POST['Name1'];
        $ncaaLicID1 = $_POST['NCAALicID1'];
        $yearsOfExperience1 = $_POST['YearsOfExperience1'];
        $position = $_POST['Position'];
        $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 AircraftCrew (AircraftName, AircraftType, AircraftOperator, CallSign, LengthMeters, Status, Mileage, MTOW, YearOfManufacture, Name1, NCAALicID1, YearsOfExperience1, Position, Uemail) 
                                VALUES (:AircraftName, :AircraftType, :AircraftOperator, :CallSign, :LengthMeters, :Status, :Mileage, :MTOW, :YearOfManufacture, :Name1, :NCAALicID1, :YearsOfExperience1, :Position, :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(':Name1', $name1);
        $stmt->bindParam(':NCAALicID1', $ncaaLicID1);
        $stmt->bindParam(':YearsOfExperience1', $yearsOfExperience1);
        $stmt->bindParam(':Position', $position);
        $stmt->bindParam(':Uemail', $uemail);

        $stmt->execute();

        // Redirect back to the form page with a success message
        header("Location: https://ncaa.frmlimited.net/reports/users/Crews/index");
        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 Crew report</small></h2>
    
     <!-- Button to trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addAircraftModal">
        Add Aircraft Crew 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" name="AircraftName" required><br>

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

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

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

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

    <label for="Status">Status:</label>
    <select name="Status" required>
      <option value="Active">Active</option>
      <option value="Inactive">Inactive</option>
    </select><br>

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

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

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

    <!-- Maintenance Personnel Information -->
    <label for="Name1">Maintenance Personnel Name:</label>
    <input type="text" name="Name1" required><br>

    <label for="NCAALicID1">NCAA License ID:</label>
    <input type="text" name="NCAALicID1" required><br>

    <label for="YearsOfExperience1">Years of Experience:</label>
    <input type="number" name="YearsOfExperience1" required><br>

    <label for="Position">Position:</label>
   
   		
    <select name="Position" required>
        <option value="" selected disabled>Please select Position</option>
      <option value="PILOT">PILOT</option>
      <option value="ATTENDANT">ATTENDANT</option>
      <option value="FLIGHT ENGINEER">FLIGHT ENGINEER</option>
      <!-- Add more options if needed -->
    </select><br>
            <!-- User Information -->
          
            <input type="email" id="Uemail" value=" <?php echo Auth::user()->email; ?>" readonly hidden  name="Uemail" required>
            
           

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

           
            
            
           
        </form>
                </div>
            </div>
        </div>
    </div>
    
    <!-- <h2 class="table-header">Tower Report</h2> -->
      <table id="Report" class="styled-table">
                        <thead>
                            
                             <tr>
                                            <th>S/No</th>
            <th>Aircraft Name</th>
            <th>Aircraft Type</th>
            <th>Aircraft Operator</th>
            <th>Call-Sign</th>
            <th>Length (Meters)</th>
            <th>Status</th>
            <th>Mileage</th>
            <th>MTOW</th>
            <th>Year Of Manufacture</th>
            <th>Name</th>
            <th>NCAA Lic ID</th>
            <th>Years of Experience</th>
            <th>Position</th>
                            </tr>
                        </thead>

                        <tfoot>
                             <tr>
                                            <th>S/No</th>
            <th>Aircraft Name</th>
            <th>Aircraft Type</th>
            <th>Aircraft Operator</th>
            <th>Call-Sign</th>
            <th>Length (Meters)</th>
            <th>Status</th>
            <th>Mileage</th>
            <th>MTOW</th>
            <th>Year Of Manufacture</th>
            <th>Name</th>
            <th>NCAA Lic ID</th>
            <th>Years of Experience</th>
            <th>Position</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 AircraftCrew 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['AircraftType'] . '</td>';
        echo '<td>' . $row['AircraftOperator'] . '</td>';
        echo '<td>' . $row['CallSign'] . '</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['Name1'] . '</td>';
        echo '<td>' . $row['NCAALicID1'] . '</td>';
        echo '<td>' . $row['YearsOfExperience1'] . '</td>';
        echo '<td>' . $row['Position'] . '</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/tenants/index.blade.php ENDPATH**/ ?>