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

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Page Title -->
  <title>Web Infra Reports</title>
  <link rel="shortcut icon" type="image/png" href="/include/favicon-32x32.png">

  <!-- JQuery -->
  <script src="/js/jquery-3.6.1.min.js"></script>
  <!-- Bootstrap -->
  <link rel="stylesheet" href="/css/bootstrap.min.css">
  <link rel="stylesheet" href="/css/bootstrap-icons/bootstrap-icons.css">
  <link rel="stylesheet" href="/css/preloader.css">
  <script src="/js/bootstrap.bundle.min.js"></script>
  <!-- Bootstrap-tables -->
  <link rel="stylesheet" href="/css/bootstrap-table.min.css">
  <script src="/js/bootstrap-table.min.js"></script>
  <script src="/js/bootstrap-table-fr-FR.min.js"></script>
  <script src="/js/tableExport.min.js"></script>
  <script src="/js/bootstrap-table-export.min.js"></script>
  <script src="/js/libs/js-xlsx/xlsx.core.min.js"></script>

</head>

<body class="bg-light text-dark">
  <?php include $_SERVER['DOCUMENT_ROOT'] . "/include/preloader.inc.html"; ?> <!-- Preloader -->
  <?php include $_SERVER['DOCUMENT_ROOT'] . "/include/db_connect.php"; ?> <!-- Database connexion -->
  <?php //include $_SERVER['DOCUMENT_ROOT']."/include/functions.inc.php" ;  ?> <!-- Functions -->
  <div class="container-fluid">
    <div class="row flex-nowrap">
      <!-- Left NAVBAR -->
      <div class="col-auto col-md-2 col-xl-2 px-sm-2 px-0 bg-dark" style="-ms-flex: 0 0 230px;flex: 0 0 230px;">
        <?php include $_SERVER['DOCUMENT_ROOT'] . "/navbar.html"; ?> <!-- Left Navbar -->
      </div>
      <!-- Display -->
      <div class="col py-3">
        <!-- Page Title -->
        <h1><span class="badge text-bg-secondary font-weight-bold" style="width:100%;">Global Crossover <small>(Updated every 15mn)</small></span></h1>

        <!-- Main content -->
        <div class="row" style="zoom: 80%">
          <!-- Get DATAs -->
          <?php
          DB_ENTRY02();
          $result = $conn->query("select * from GlobalCrossover where server not like 'WS%' order by server ");
          if (isset($_GET['filter'])) {
            switch ($_GET['filter']) {
              case "AD":
                $result = $conn->query("select * from GlobalCrossover where AD is null or (ADlu is not null and DATEDIFF(now(),ADlu) > 45) order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : AD non compliant</span></center></h2>";
                break;
              case "OS":
                $result = $conn->query("select * from GlobalCrossover where OS like '%2003%' or OS like '%2008%' order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : OS non compliant</span></center></h2>";
                break;
              case "GLPI":
                $result = $conn->query("select * from GlobalCrossover where GLPI is null or GLPIlu is null or DATEDIFF(now(),GLPIlu) > 7 order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : GLPI/FI non compliant</span></center></h2>";
                break;
              case "SCCM":
                $result = $conn->query("select * from GlobalCrossover where SCCM is null or (SCCMlu is not null and DATEDIFF(now(),SCCMlu) > 7) order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : SCCM non compliant</span></center></h2>";
                break;
              case "NESSUS":
                $result = $conn->query("select * from GlobalCrossover where EPO is null order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : NESSUS non compliant</span></center></h2>";
                break;
              case "NBU":
                $result = $conn->query("select * from GlobalCrossover where NBU is null or (NBUlu is not null and DATEDIFF(now(),NBUlu) > 30) order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : Backup non compliant</span></center></h2>";
                break;
              case "SCOM":
                $result = $conn->query("select * from GlobalCrossover where SCOM is null order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : SCOM non compliant</span></center></h2>";
                break;
              case "zabbix":
                $result = $conn->query("select * from GlobalCrossover where zabbix is null order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : Zabbix non compliant</span></center></h2>";
                break;
              case "S1":
                $result = $conn->query("select * from GlobalCrossover where S1 is null or (S1lu is not null and DATEDIFF(now(),S1lu) > 7) order by server");
                echo "<h2><center><span class='badge text-bg-danger font-weight-bold'>Filter : SentinelOne non compliant</span></center></h2>";
                break;
              default:
            }
          }
          ?>

          <table class='table table-bordered table-hover table-sm' id='t1' data-toggle="table" data-search="true"
            data-show-columns="true" data-pagination="true" data-export-types="['xlsx','csv','json']"
            data-loading-template="loadingTemplate" data-page-list="[20, 50, 100, All]" data-page-size="Tout"
            data-height="620" data-show-export="true" data-sortable="true">
            <thead>
              <th data-field="Name" data-sortable="true">Name</th>
              <th data-field="OS" data-sortable="true">Operating System</th>
              <th data-field="Criticity" data-sortable="true">Criticity</th>
              <th data-field="Departement" data-sortable="true" data-visible="false">Departement</th>
              <th data-field="AD" data-sortable="true">AD</th>
              <th data-field="ADlu" data-sortable="true" data-visible="false">AD Last Logon</th>
              <th data-field="GLPI" data-sortable="true">GLPI</th>
              <th data-field="GLPIlu" data-sortable="true" data-visible="false" data-footer-formatter="FI">Last FI
                Inventory</th>
              <th data-field="SCCM" data-sortable="true">SCCM<br></th>
              <th data-field="SCCMlu" data-sortable="true" data-visible="false">SCCM Last Heartbeat</th>
              <th data-field="NESSUS" data-sortable="true">NESSUS</th>
              <th data-field="Backup" data-sortable="true">Backup</th>
              <th data-field="NBUlu" data-sortable="true" data-visible="false">Last Backup</th>
              <th data-field="SCOM" data-sortable="true">SCOM</th>
              <th data-field="Zabbix" data-sortable="true">Zabbix</th>
              <th data-field="S1" data-sortable="true">SentinelOne</th>
              <th data-field="S1lu" data-sortable="true" data-visible="false">S1 Last Update</th>
            </thead>

            <tbody>
              <!-- Display DATAs -->
              <?php

              $ok = 0;
              $total = 0;
              $nOS = 0;
              $nAD = 0;
              $nSCCM = 0;
              $nGLPI = 0;
              $nFI = 0;
              $nNESSUS = 0;
              $nNBU = 0;
              $nDPM = 0;
              $nS1 = 0;
              while ($row = mysqli_fetch_array($result)) {
                $total++;
                echo "<tr>";
                if (isset($row['AD']) && isset($row['GLPI']) && isset($row['SCCM']) && isset($row['EPO']) && (isset($row['NBU']) || isset($row['DPM'])) && isset($row['SCOM'])) {
                  echo "<td class='bg-success text-white'><b><a href='\crossover\Detail.php?server=" . $row['Server'] . "' target='_blank' class='link-light'>" . $row['Server'] . "</a></b></td>";
                  //echo "<td class='bg-success text-white'><b>".$row['Server']."</b></td>";
                  $ok++;
                } else {
                  echo "<td><b><a href='\crossover\Detail.php?server=" . $row['Server'] . "' target='_blank'>" . $row['Server'] . "</a></b></td>";
                  //echo "<td><b>".$row['Server']."</b></td>";
                }
                if ($row['OS']) {
                  if (preg_match('(XP|2003|Windows NT|2000|2008|Windows 7|2012)', $row['OS']) !== 1) {
                    $nOS++;
                    echo "<td>" . $row['OS'] . "</td>";
                  } else {
                    echo "<td class='bg-warning text-black'>" . $row['OS'] . "</td>";
                  }
                } else {
                  echo "<td class='bg-warning'>&nbsp;</td>";
                }
                echo "<td>" . $row['crit'] . "</td>";
                echo "<td>" . $row['dpt'] . "</td>";

                // AD
                if ($row['AD'] == 'Y') {
                  $date1 = date_create($row['ADlu']);
                  $diff = date_diff($date1, date_create(date("Y-m-d")));
                  if ($diff->format("%R%a") > 45) {
                    echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>OK</td>";
                    echo "<td class='bg-danger text-white'>" . $row['ADlu'] . " (" . $diff->format("%R%a") . " days)</td>";
                  } else {
                    $nAD++;
                    echo "<td class='bg-success text-white'>OK</td>";
                    echo "<td class='bg-success text-white'>" . $row['ADlu'] . "</td>";
                  }
                } else {

                  if (isset($row['AD'])) {
                    $nAD++;
                    echo "<td class='bg-secondary'><small>" . $row['AD'] . "</small></td>";
                    echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                    $nSCCM++;
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                    echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                  }
                }

                // GLPI
                if ($row['GLPI'] == 'Y') {
                  $date1 = date_create($row['GLPIlu']);
                  $diff = date_diff($date1, date_create(date("Y-m-d")));
                  if ($diff->format("%R%a") > 7) {
                    echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>OK</td>";
                    echo "<td class='bg-danger text-white'>" . $row['GLPIlu'] . " (" . $diff->format("%R%a") . " days)</td>";
                  } else {
                    if ($row['GLPIlu'] <> "" || $row['FI'] <> "") {
                      echo "<td class='bg-success text-white'>OK</td>";
                      $nFI++;
                      echo "<td class='bg-success text-white'>" . $row['GLPIlu'] . "</td>";
                    } else {
                      echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(255,193,7,1) 100%);'>OK</td>";
                      echo "<td class='bg-warning text-black'>Missing</td>";
                    }
                  }
                  $nGLPI++;
                } else {
                  if (isset($row['GLPI'])) {
                    echo "<td class='bg-secondary'><small>" . $row['GLPI'] . "</small></td>";
                    echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                    $nGLPI++;
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                    echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                  }
                }

                // SCCM
                if ($row['SCCM'] == 'Y') {
                  $date1 = date_create($row['SCCMlu']);
                  $diff = date_diff($date1, date_create(date("Y-m-d")));
                  if ($diff->format("%R%a") > 7) {
                    echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>OK</td>";
                    echo "<td class='bg-danger text-white'>" . $row['SCCMlu'] . " (" . $diff->format("%R%a") . " days)</td>";
                  } else {
                    echo "<td class='bg-success text-white'>OK</td>";
                    echo "<td class='bg-success text-white'>" . $row['SCCMlu'] . "</td>";
                    $nSCCM++;
                  }
                } else {
                  if (isset($row['SCCM'])) {
                    echo "<td class='bg-secondary'><small>" . $row['SCCM'] . "</small></td>";
                    echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                    $nSCCM++;
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                    echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                  }
                }

                // NESSUS
                if (strpos($row['EPO'], '.') !== false ) {
                  echo "<td class='bg-success text-white'>".$row['EPO']."</td>";
                } else {
                  if (isset($row['EPO']) && $row['EPO'] != 'Y' && $row['EPO'] != 'N') {
                    echo "<td class='bg-secondary'><small>" . $row['EPO'] . "</small></td>";
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                    $nNESSUS++;
                  }
                }

                // BACKUP
                if ($row['NBU'] == 'Y') {
                  $date1 = date_create($row['NBUlu']);
                  $diff = date_diff($date1, date_create(date("Y-m-d")));
                  if ($diff->format("%R%a") > 30) {
                    echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>OK (NBU)</td>";
                    echo "<td class='bg-danger text-white'>" . $row['NBUlu'] . " (" . $diff->format("%R%a") . " days)</td>";
                  } else {
                    echo "<td class='bg-success text-white'>OK (NBU)</td>";
                    echo "<td class='bg-success text-white'>" . $row['NBUlu'] . "</td>";
                    $nNBU++;
                  }
                } else {
                  if ($row['DPM'] == 'Y') {
                    $date1 = date_create($row['DPMlu']);
                    $diff = date_diff($date1, date_create(date("Y-m-d")));
                    if ($diff->format("%R%a") > 30) {
                      echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>OK (DPM)</td>";
                      echo "<td class='bg-danger text-white'>" . $row['DPMlu'] . " (" . $diff->format("%R%a") . " days)</td>";
                    } else {
                      echo "<td class='bg-success text-white'>OK (DPM)</td>";
                      echo "<td class='bg-success text-white'>" . $row['DPMlu'] . "</td>";
                      $nDPM++;
                    }
                  } else {
                    if (isset($row['NBU'])) {
                      echo "<td class='bg-secondary'><small>" . $row['NBU'] . "</small></td>";
                      echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                    } else {
                      if (isset($row['DPM'])) {
                        echo "<td class='bg-secondary'><small>" . $row['DPM'] . "</small></td>";
                        echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                      }
                      echo "<td class='bg-warning text-black'>Missing</td>";
                      echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                    }
                  }
                }

                // SCOM
                if ($row['SCOM'] == 'Y') {
                  echo "<td class='bg-success text-white'>OK</td>";
                } else {
                  if (isset($row['SCOM'])) {
                    echo "<td class='bg-secondary'><small>" . $row['SCOM'] . "</small></td>";
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                  }
                }

                // zabbix
                if ($row['zabbix'] == 'Y' || strpos($row['zabbix'], '.') !== false ) {
                  echo "<td class='bg-success text-white'>".str_replace('Y','OK',$row['zabbix'])."</td>";
                } else {
                  if (isset($row['zabbix'])) {
                    echo "<td class='bg-secondary'><small>" . $row['zabbix'] . "</small></td>";
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                  }
                }

                // S1
                if ($row['S1'] == 'Y' || strpos($row['S1'], '.') !== false) {
                  $date1 = date_create($row['S1lu']);
                  $diff = date_diff($date1, date_create(date("Y-m-d")));
                  if ($diff->format("%R%a") > 7) {
                    echo "<td class='text-white' style='background: linear-gradient(90deg, rgba(25,135,84,1) 50%, rgba(220,53,69,1) 100%);'>".str_replace('Y','OK',$row['S1'])."</td>";
                    echo "<td class='bg-danger text-white'>" . $row['S1lu'] . " (" . $diff->format("%R%a") . " days)</td>";
                  } else {
                    echo "<td class='bg-success text-white'>".str_replace('Y','OK',$row['S1'])."</td>";
                    echo "<td class='bg-success text-white'>" . $row['S1lu'] . "</td>";
                    $nS1++;
                  }
                } else {
                  if (isset($row['S1'])) {
                    if($row['S1'] == "N"){$row['S1'] = "Non Supported OS";}
                    echo "<td class='bg-secondary'><small>" . $row['S1'] . "</small></td>";
                    echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                    $nS1++;
                  } else {
                    echo "<td class='bg-warning text-black'>Missing</td>";
                    echo "<td class='bg-warning text-black'>&nbsp;</td>";
                  }
                }
                echo "</tr>";
              }
              ?>
            </tbody>

          </table>
        </div>
        <button id="button" type="button" class="btn btn-primary btn-sm invisible"><i
            class="bi bi-arrow-clockwise"></i><b> Generate KPI</b></button>
        <div class="row flex-nowrap text-center" style="zoom: 80%">
          <div class="col"> <!-- CARTE Devices -->
            <div class="card border-secondary mb-3">
              <div class="card-header  text-dark"><b>All Devices</b></div>
              <a href="/crossover/GlobalCrossover.php">
                <div class="card-body">
                  <h2><span class="badge text-bg-primary font-weight-bold" id="KPIDEVICE"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE OS -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>Supported OS</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=OS">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIOS"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE AD -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>AD</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=AD">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIAD"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE GLPI/FI -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>GLPI/FI</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=GLPI">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIGLPI"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE SCCM -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>SCCM</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=SCCM">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPISCCM"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE EPO -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>NESSUS</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=NESSUS">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIEPO"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE Backup (NBU + DPM) -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>Backup</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=NBU">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPINBU"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE SCOM -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>SCOM</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=SCOM">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPISCOM"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE Zabbix -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>Zabbix</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=zabbix">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIzabbix"></span></h2>
                </div>
              </a>
            </div>
          </div>
          <div class="col"> <!-- CARTE SentinelOne -->
            <div class="card border-secondary mb-3">
              <div class="card-header text-dark"><b>SentinelOne</b></div>
              <a href="/crossover/GlobalCrossover.php?filter=S1">
                <div class="card-body">
                  <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIS1"></span></h2>
                </div>
              </a>
            </div>
          </div>
        </div>
        <!-- End of main content -->
      </div>
    </div>
  </div>
  <script src="/js/switch.js"></script>

</body>

<script src="/crossover/Crossover-KPI.js"></script>
<script>
  var $table = $('#t1')
  var $button = $('#button')

  $table.on('search.bs.table', function () {
    var $button = $('#button')
    $button.click();
  })

  $(window).on('load', function () {
    $('.preloader').addClass('preloader-deactivate');
  });

  document.addEventListener("DOMContentLoaded", function () { setTimeout(function () { document.getElementById('button').click(); }, 1000); });
</script>

</HTML>