<?php $__env->startSection('content'); ?>
<?php
 $servername = "localhost:3306";
                        $username = "ncaa_controlportal";
                        $password = "?)*Sx8_GBX1C";
                        $dbname = "ncaa_portal";
                        
                        // Create connection
                        $conn = new mysqli($servername, $username, $password, $dbname);

?>
?>
<div class="content">
          <div class="row">
            <!-- Row #1 -->
            <div class="col-6 col-md-4 col-xl-4">
              <a class="block block-rounded text-center" href="<?php echo e(route('reports.users.towers.index')); ?>">
                <div class="block-content ribbon ribbon-bookmark ribbon-glass ribbon-left bg-gd-dusk">
                  <div class="ribbon-box">
                       <?php
                       $email = Auth::user()->email; // Assuming this is your actual email value
                      // SQL query to count records in the database table
                    $sql = "SELECT COUNT(*) as recordCount FROM Aircraft WHERE Oemail = '$email'";
                    $result = $conn->query($sql);
                    
                    if ($result->num_rows > 0) {
                        $row = $result->fetch_assoc();
                        $recordCount = $row['recordCount'];
                    
                        echo $recordCount;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                  </div>
                  <p class="mt-2 mb-3">
                    <i class="si si-bar-chart fa-2x text-white-75"></i>
                  </p>
                  <p class="fw-semibold text-white">Aircraft</p>
                </div>
              </a>
            </div>
            <div class="col-6 col-md-4 col-xl-2">
              <a class="block block-rounded text-center" href="<?php echo e(route('reports.users.tenants.index')); ?>">
                <div class="block-content ribbon ribbon-bookmark ribbon-glass ribbon-left bg-gd-dusk">
                <div class="ribbon-box">
                     <?php
                      // SQL query to count records in the database table
                    $sql5 = "SELECT COUNT(*) as recordCount FROM AircraftCrew WHERE Uemail = '$email'";
                    $result5 = $conn->query($sql5);
                    
                    if ($result->num_rows > 0) {
                        $row5 = $result5->fetch_assoc();
                        $recordCount5 = $row5['recordCount'];
                    
                        echo $recordCount5;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                </div>
                  <p class="mt-2 mb-3">
                    <i class="si si-bar-chart fa-2x text-white-75"></i>
                  </p>
                  <p class="fw-semibold text-white">Crews</p>
                </div>
              </a>
            </div>
            <div class="col-6 col-md-4 col-xl-2">
              <a class="block block-rounded text-center" href="<?php echo e(route('reports.users.maintenances.index')); ?>">
                <div class="block-content ribbon ribbon-bookmark ribbon-glass ribbon-left bg-gd-sea">
                  <div class="ribbon-box">
                         <?php
                       $email = Auth::user()->email; // Assuming this is your actual email value
                      // SQL query to count records in the database table
                    $sql11 = "SELECT COUNT(*) as recordCount FROM RoutineMaintenance WHERE Uemail = '$email'";
                    $result11 = $conn->query($sql11);
                    
                    if ($result11->num_rows > 0) {
                        $row11 = $result11->fetch_assoc();
                        $recordCount11 = $row11['recordCount'];
                    
                        echo $recordCount11;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                  </div>
                  <p class="mt-2 mb-3">
                    <i class="si si-bar-chart fa-2x text-white-75"></i>
                  </p>
                  <p class="fw-semibold text-white">Routined Maintenance</p>
                </div>
              </a>
            </div>
            <div class="col-6 col-md-4 col-xl-2">
              <a class="block block-rounded text-center" href="<?php echo e(route('reports.ScheduledMaintanance.index')); ?>">
                <div class="block-content ribbon ribbon-bookmark ribbon-glass ribbon-left bg-gd-lake">
                <div class="ribbon-box"><?php echo e($auditcount); ?></div>
                  <p class="mt-2 mb-3">
                    <i class="si si-bar-chart fa-2x text-white-75"></i>
                  </p>
                  <p class="fw-semibold text-white">Scheduled Maintanance</p>
                </div>
              </a>
            </div>
            <div class="col-6 col-md-4 col-xl-2">
              <a class="block block-rounded text-center" href="<?php echo e(route('reports.users.insurances.index')); ?>">
                <div class="block-content ribbon ribbon-bookmark ribbon-glass ribbon-left bg-gd-emerald">
                <div class="ribbon-box">
                      <?php
                       $email = Auth::user()->email; // Assuming this is your actual email value
                      // SQL query to count records in the database table
                    $sqlins = "SELECT COUNT(*) as recordCount2 FROM AircraftInsurance WHERE Uemail = '$email'";
                    $result2 = $conn->query($sqlins);
                    
                    if ($result2->num_rows > 0) {
                        $row2 = $result2->fetch_assoc();
                        $recordCount2 = $row2['recordCount2'];
                    
                        echo $recordCount2;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                    
                    </div>
                  <p class="mt-2 mb-3">
                    <i class="si si-bar-chart fa-2x text-white-75"></i>
                  </p>
                  <p class="fw-semibold text-white">Insurance</p>
                </div>
              </a>
            </div>
           
            <!-- END Row #1 -->
          </div>
        
          <div class="row">
            <!-- Row #4 -->
            <div class="col-md-6">
              <a class="block block-rounded">
                <div class="block-content block-content-full">
                  <!-- <i class="si si-game-controller fa-2x text-pulse"></i> -->
                  <div class="fs-sm fw-semibold text-uppercase">Scheduled Upcoming Maintenance</div>
                  <div class="row py-3 text-center">
                    <div class="col-6 border-end">
                      <div class="fs-3 fw-semibold">
                          <?php
                           
                      
// Get today's date
$todayDate = date("Y-m-d");

// SQL query to select all rows from your table
$sql22 = "SELECT * FROM RoutineMaintenance WHERE Uemail = '$email'";

$result22 = $conn->query($sql22);

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

    // Iterate through each row
    while ($row = $result22->fetch_assoc()) {
        // Convert MaintenanceSchedule1 to date and check if it's within 7 days of today
        $maintenanceSchedule1Date = date("Y-m-d", strtotime($row['MaintenanceSchedule1']));
        if (abs(strtotime($todayDate) - strtotime($maintenanceSchedule1Date)) <= 7 * 24 * 60 * 60) {
            $countWithin7Days++;
        }

        // Convert MaintenanceSchedule2 to date and check if it's within 7 days of today
        $maintenanceSchedule2Date = date("Y-m-d", strtotime($row['MaintenanceSchedule2']));
        if (abs(strtotime($todayDate) - strtotime($maintenanceSchedule2Date)) <= 7 * 24 * 60 * 60) {
            $countWithin7Days++;
        }
        
        // Add similar checks for MaintenanceSchedule3 to MaintenanceSchedule8 if needed
    }

    echo $countWithin7Days;
} else {
    echo "No results found.";
}

                      
                      
                          ?>
                          
                      </div>
                      <div class="fs-sm fw-semibold text-uppercase text-muted">This Week</div>
                    </div>
                    <div class="col-6">
                      <div class="fs-3 fw-semibold">
                           <?php
                           
                      
// Get today's date
$todayDate = date("Y-m-d");


// Get the date for 30 days from today
$thirtyDaysLater = date("Y-m-d", strtotime("+30 days", strtotime($todayDate)));


// SQL query to select all rows from your table
$sql22 = "SELECT * FROM RoutineMaintenance WHERE Uemail = '$email'";

$result22 = $conn->query($sql22);

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

    // Iterate through each row
    while ($row = $result22->fetch_assoc()) {
           // Convert MaintenanceSchedule1 to date and check if it's within 30 days of today
        $maintenanceSchedule1Date = date("Y-m-d", strtotime($row['MaintenanceSchedule1']));
        if (strtotime($todayDate) <= strtotime($maintenanceSchedule1Date) && strtotime($maintenanceSchedule1Date) <= strtotime($thirtyDaysLater)) {
            $countWithin30Days++;
        }

        // Convert MaintenanceSchedule2 to date and check if it's within 30 days of today
        $maintenanceSchedule2Date = date("Y-m-d", strtotime($row['MaintenanceSchedule2']));
        if (strtotime($todayDate) <= strtotime($maintenanceSchedule2Date) && strtotime($maintenanceSchedule2Date) <= strtotime($thirtyDaysLater)) {
            $countWithin30Days++;
        }
        
        
        // Add similar checks for MaintenanceSchedule3 to MaintenanceSchedule8 if needed
    }





    echo $countWithin30Days;
} else {
    echo "No results found.";
}

                      
                      
                          ?>
                      </div>
                      <div class="fs-sm fw-semibold text-uppercase text-muted">This Month</div>
                    </div>
                  </div>
                </div>
              </a>
            </div>
            <div class="col-md-6">
              <a class="block block-rounded">
                <div class="block-content block-content-full">
                  <div class="text-end">
                    <!-- <i class="si si-wallet fa-2x text-success"></i> -->
                    <div class="fs-sm fw-semibold text-uppercase">Upcoming  Maintenance</div>
                  </div>
                  <div class="row py-3 text-center">
                        
                         <!-- Barthy Input for list -->
                            <?php
               $email = Auth::user()->email; // Assuming this is your actual email value            
                      
// Get today's date
$todayDate = date("Y-m-d");

// SQL query to select all rows from your table
$sql223 = "SELECT * FROM RoutineMaintenance WHERE Uemail = '$email'";

$result223 = $conn->query($sql223);
 echo "<table>";
            echo "<tr>";
            echo "<th> Aircraft Name <th>";
            echo "<th> Scheduled Date <th>";
            echo "</tr>";
if ($result->num_rows > 0) {
    $countWithin7Days = 0;

    // Iterate through each row
    while ($row = $result223->fetch_assoc()) {
       
        // Convert MaintenanceSchedule1 to date and check if it's within 7 days of today
        $maintenanceSchedule1Date = date("Y-m-d", strtotime($row['MaintenanceSchedule1']));
        if (abs(strtotime($todayDate) - strtotime($maintenanceSchedule1Date)) <= 7 * 24 * 60 * 60) {
            
            echo "<tr>";
            echo "<td>".($row['AircraftName']). "<td>";
            echo "<td>".($row['MaintenanceSchedule1']). "<td>";
        }

        // Convert MaintenanceSchedule2 to date and check if it's within 7 days of today
        $maintenanceSchedule2Date = date("Y-m-d", strtotime($row['MaintenanceSchedule2']));
        if (abs(strtotime($todayDate) - strtotime($maintenanceSchedule2Date)) <= 7 * 24 * 60 * 60) {
            echo "<td>".($row['AircraftName']). "<td>";
            echo "<td>".($row['MaintenanceSchedule2']). "<td>";
        }
        
        // Add similar checks for MaintenanceSchedule3 to MaintenanceSchedule8 if needed
        
            echo "</tr>";
            echo "</table>";
    }

    
} 
                      
                      
                          ?>
            

                      
                      <div class="fs-sm fw-semibold text-uppercase text-muted">This week</div>
                    
                    
                  </div>
                </div>
              </a>
            </div>
            <!-- END Row #4 -->
          </div>
          <div class="row">
            <!-- Row #3 -->
            <div class="col-xl-8 d-flex align-items-stretch">
              <div class="block block-rounded block-themed block-mode-loading-dark block-transparent bg-image w-100" style="background-image: url(<?php echo e(asset('media/photos/plane.jpg')); ?>)">
                <div class="block-header bg-black-50">
                  <h3 class="block-title">
                    National Civil Aviation <small class="text-white">Portal</small>
                  </h3>
                  <!-- <div class="block-options">
                    <button type="button" class="btn-block-option" data-toggle="block-option" data-action="state_toggle" data-action-mode="demo">
                      <i class="si si-refresh"></i>
                    </button>
                    < <button type="button" class="btn-block-option">
                      <i class="si si-wrench"></i>
                    </button> ->
                  </div> -->
                </div>
                <!-- <div class="block-content bg-black-50 p-1">
                  <!- Lines Chart Container functionality is initialized in js/pages/be_pages_dashboard.min.js which was auto compiled from _js/pages/be_pages_dashboard.js -->
                  <!-- For more info and examples you can check out http://www.chartjs.org/docs/ ->
                  <canvas id="js-chartjs-dashboard-lines"></canvas>
                </div> -->
              </div>
            </div>
            <div class="col-xl-4 d-flex align-items-stretch">
              <div class="block block-rounded block-transparent bg-primary-dark d-flex align-items-center w-100">
                <div class="block-content block-content-full">
                  <div class="py-3 px-3 border-black-op-b d-flex justify-content-between align-items-center">
                    <div>
                      <div class="fs-3 fw-semibold text-success"> <?php
                       $email = Auth::user()->email; // Assuming this is your actual email value
                      // SQL query to count records in the database table
                    $sql = "SELECT COUNT(*) as recordCount FROM Aircraft WHERE Oemail = '$email'";
                    $result = $conn->query($sql);
                    
                    if ($result->num_rows > 0) {
                        $row = $result->fetch_assoc();
                        $recordCount = $row['recordCount'];
                    
                        echo $recordCount;
                    } else {
                        echo 0;
                    }
                      
                      ?></div>
                      <div class="fs-sm fw-semibold text-uppercase text-success-light">Aircrafts</div>
                    </div>
                    <div class="mt-3 d-none d-sm-block">
                      <i class="si si-book-open fa-2x text-success"></i>
                    </div>
                  </div>
                  <div class="py-3 px-3 border-black-op-b d-flex justify-content-between align-items-center">
                    <div>
                      <div class="fs-3 fw-semibold text-danger">
                           <?php
                      // SQL query to count records in the database table
                    $sql5 = "SELECT COUNT(*) as recordCount FROM AircraftCrew WHERE Uemail = '$email'";
                    $result5 = $conn->query($sql5);
                    
                    if ($result->num_rows > 0) {
                        $row5 = $result5->fetch_assoc();
                        $recordCount5 = $row5['recordCount'];
                    
                        echo $recordCount5;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                           </div>
                      <div class="fs-sm fw-semibold text-uppercase text-danger-light">Crews</div>
                    </div>
                    <div class="mt-3 d-none d-sm-block">
                      <i class="si si-book-open fa-2x text-danger"></i>
                    </div>
                  </div>
                  <div class="py-3 px-3 border-black-op-b d-flex justify-content-between align-items-center">
                    <div>
                      <div class="fs-3 fw-semibold text-warning">
                           <?php
                       $email = Auth::user()->email; // Assuming this is your actual email value
                      // SQL query to count records in the database table
                    $sql11 = "SELECT COUNT(*) as recordCount FROM RoutineMaintenance WHERE Uemail = '$email'";
                    $result11 = $conn->query($sql11);
                    
                    if ($result11->num_rows > 0) {
                        $row11 = $result11->fetch_assoc();
                        $recordCount11 = $row11['recordCount'];
                    
                        echo $recordCount11;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                      </div>
                      <div class="fs-sm fw-semibold text-uppercase text-warning-light">Routine Maintanance</div>
                    </div>
                    <div class="mt-3 d-none d-sm-block">
                      <i class="si si-book-open fa-2x text-warning"></i>
                    </div>
                  </div>
                  <div class="py-3 px-3 border-black-op-b d-flex justify-content-between align-items-center">
                    <div>
                      <div class="fs-3 fw-semibold text-info"><?php echo e($auditcount); ?></div>
                      <div class="fs-sm fw-semibold text-uppercase text-info-light">Scheduled Maintanance</div>
                    </div>
                    <div class="mt-3 d-none d-sm-block">
                      <i class="si si-book-open fa-2x text-info"></i>
                    </div>
                  </div>
                  <div class="py-3 px-3  d-flex justify-content-between align-items-center">
                    <div>
                      <div class="fs-3 fw-semibold text-elegance">
                           <?php
                      // SQL query to count records in the database table
                       $email = Auth::user()->email; // Assuming this is your actual email value
                    $sqlins = "SELECT COUNT(*) as recordCount2 FROM AircraftInsurance WHERE Uemail = '$email'";
                    $result2 = $conn->query($sqlins);
                    
                    if ($result2->num_rows > 0) {
                        $row2 = $result2->fetch_assoc();
                        $recordCount2 = $row2['recordCount2'];
                    
                        echo $recordCount2;
                    } else {
                        echo 0;
                    }
                      
                      ?>
                      </div>
                      <div class="fs-sm fw-semibold text-uppercase text-elegance-light">Insurance</div>
                    </div>
                    <div class="mt-3 d-none d-sm-block">
                      <i class="si si-book-open fa-2x text-elegance"></i>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- END Row #3 -->
          </div>
          <div class="row">
            <!-- Row #4 >
            <div class="col-md-4">
              <div class="block block-rounded block-transparent bg-primary">
                <div class="block-content block-content-full">
                  <div class="py-3 text-center">
                    <div class="mb-3">
                      <i class="fa fa-envelope-open fa-4x text-primary-lighter"></i>
                    </div>
                    <div class="fs-4 fw-semibold text-white">19.5k Subscribers</div>
                    <div class="text-white-75">Your main list is growing!</div>
                    <div class="pt-3">
                      <a class="btn btn-alt-primary" href="javascript:void(0)">
                        <i class="fa fa-cog opacity-50 me-1"></i> Manage list
                      </a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-4">
              <div class="block block-rounded block-transparent bg-info">
                <div class="block-content block-content-full">
                  <div class="py-3 text-center">
                    <div class="mb-3">
                      <i class="fa fab fa-twitter fa-4x text-info-light"></i>
                    </div>
                    <div class="fs-4 fw-semibold text-white">+98 followers</div>
                    <div class="text-white-75">You are doing great!</div>
                    <div class="pt-3">
                      <a class="btn btn-alt-info" href="javascript:void(0)">
                        <i class="fa fa-users opacity-50 me-1"></i> Check them out
                      </a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-4">
              <div class="block block-rounded block-transparent bg-success">
                <div class="block-content block-content-full">
                  <div class="py-3 text-center">
                    <div class="mb-3">
                      <i class="fa fa-check fa-4x text-success-light"></i>
                    </div>
                    <div class="fs-4 fw-semibold text-white">Personal Plan</div>
                    <div class=" text-white-75">This is your current active plan</div>
                    <div class="pt-3">
                      <a class="btn btn-alt-success" href="javascript:void(0)">
                        <i class="fa fa-arrow-up opacity-50 me-1"></i> Upgrade to VIP
                      </a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- END Row #4 -->
          </div>
        </div>
        <!-- END Page Content -->
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js_after'); ?>
<script src="<?php echo e(asset('js/plugins/chartjs/Chart.bundle.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/plugins/slick/slick.min.js')); ?>"></script>
<!-- <script src="<?php echo e(asset('js/pages/be_pages_dashboard.min.js')); ?>"></script> -->

<!-- Page JS Code -->

<script src="<?php echo e(asset('js/pages/be_pages_dashboard.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.backend', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ncaa/public_html/resources/views/dashboards-user/index.blade.php ENDPATH**/ ?>