<!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">
   <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>
   <!-- Chart -->
   <script src="/js/chart.min.js"></script>
   
</head>

<body class="bg-light text-dark">
  <?php include $_SERVER['DOCUMENT_ROOT']."/../../include/db_connect.php" ; ?>  <!-- Database connexion -->
  <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 vh-100 position-sticky top-0" 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%;">HOME</span></h1>
        
        <!-- Main content -->
        <?php 
               $conn = DB_ENTRY02();
               $sql = $conn->query("SELECT count(*) as w2k3 FROM globalcrossover where os like '%2003%' and dpt = 'INFRA'"); $w2k3 = mysqli_fetch_array($sql)['w2k3'];
               $sql = $conn->query("SELECT count(*) as w2k8 FROM globalcrossover where os like '%2008%' and dpt = 'INFRA'"); $w2k8 = mysqli_fetch_array($sql)['w2k8'];
               $sql = $conn->query("SELECT count(*) as w2k12 FROM globalcrossover where os like '%2012%' and dpt = 'INFRA'"); $w2k12 = mysqli_fetch_array($sql)['w2k12'];
               $sql = $conn->query("SELECT count(*) as w2k16 FROM globalcrossover where os like '%2016%' and dpt = 'INFRA'"); $w2k16 = mysqli_fetch_array($sql)['w2k16'];
               $sql = $conn->query("SELECT count(*) as w2k19 FROM globalcrossover where os like '%2019%' and dpt = 'INFRA'"); $w2k19 = mysqli_fetch_array($sql)['w2k19'];
               $sql = $conn->query("SELECT count(*) as w2k22 FROM globalcrossover where os like '%2022%' and dpt = 'INFRA'"); $w2k22 = mysqli_fetch_array($sql)['w2k22'];
               $sql = $conn->query("SELECT count(*) as w2k3 FROM globalcrossover where os like '%2003%' and dpt = 'APPLI'"); $w2k3a = mysqli_fetch_array($sql)['w2k3'];
               $sql = $conn->query("SELECT count(*) as w2k8 FROM globalcrossover where os like '%2008%' and dpt = 'APPLI'"); $w2k8a = mysqli_fetch_array($sql)['w2k8'];
               $sql = $conn->query("SELECT count(*) as w2k12 FROM globalcrossover where os like '%2012%' and dpt = 'APPLI'"); $w2k12a = mysqli_fetch_array($sql)['w2k12'];
               $sql = $conn->query("SELECT count(*) as w2k16 FROM globalcrossover where os like '%2016%' and dpt = 'APPLI'"); $w2k16a = mysqli_fetch_array($sql)['w2k16'];
               $sql = $conn->query("SELECT count(*) as w2k19 FROM globalcrossover where os like '%2019%' and dpt = 'APPLI'"); $w2k19a = mysqli_fetch_array($sql)['w2k19'];
               $sql = $conn->query("SELECT count(*) as w2k22 FROM globalcrossover where os like '%2022%' and dpt = 'APPLI'"); $w2k22a = mysqli_fetch_array($sql)['w2k22'];
               $sql = $conn->query("SELECT count(*) as linux FROM globalcrossover where os not like '%windows%' and os <> 'AIX' and AD='Y'"); $linux = mysqli_fetch_array($sql)['linux'];
               $sql = $conn->query("SELECT count(*) as aix FROM globalcrossover where os = 'AIX' and AD='Y'"); $aix = mysqli_fetch_array($sql)['aix'];
               $sql = $conn->query("SELECT count(*) as total FROM globalcrossover where os is not null"); $total = mysqli_fetch_array($sql)['total'];
               $sql = $conn->query("SELECT count(*) as virtual FROM globalcrossover where virtual = 'Y'"); $virtual = mysqli_fetch_array($sql)['virtual'];
               $sql = $conn->query("SELECT count(*) as physical FROM globalcrossover where virtual = 'N'"); $physical = mysqli_fetch_array($sql)['physical'];
               $dataserver = "$w2k8,$w2k12,$w2k16,$w2k19,$w2k22";
               $dataservera = "$w2k8a,$w2k12a,$w2k16a,$w2k19a,$w2k22a";
               $datalinux = "$linux,$aix";
               $type = "$physical,$virtual";
            ?>
         <span id="dataSVI" class="invisible"><?php echo $dataserver ?></span>
         <span id="dataSVA" class="invisible"><?php echo $dataservera ?></span>
         <span id="dataLI" class="invisible"><?php echo $datalinux ?></span>        
         <span id="dataType" class="invisible"><?php echo $type ?></span>        
          <div class="row flex-nowrap text-center">
            <div class="col"> <!-- CARTE AD -->
              <div class="card border-primary mb-3">
                <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> ActiveDirectory</h5></div>
                <div class="card-body">
                  <?php 
                    DB_ENTRY02();
                    $result = $conn->query("SELECT count(*) as nbad FROM adcomputers");
                    $nbADactive = mysqli_fetch_array($result)['nbad'];
                    $result = $conn->query("SELECT count(*) as nbADinactive FROM adcomputers WHERE enabled = 'False'");
                    $nbADinactive = mysqli_fetch_array($result)['nbADinactive'];
                  ?>
                  <p class="card-text text-center"><b><a href="/dashboard/AD-Detail.php""><?php echo $nbADactive; ?></b> Devices <small>(<?php echo $nbADinactive; ?> inactifs)</small></a></p>
                </div>
              </div>  
            </div>  

            <div class="col"> <!-- CARTE GLPI -->
              <div class="card border-primary mb-3">
                <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> GLPI</h5></div>
                <div class="card-body">
                  <?php
                    $conn = DB_GLPI();
                    $result = $conn->query("SELECT count(name) as nbglpi FROM glpi_computers WHERE entities_id = 6 AND is_deleted = 0 AND states_ID = 2 AND computertypes_id in(7,19) and name <> ''");
                    $nbglpi = mysqli_fetch_array($result)['nbglpi'];
                    mysqli_close($conn);
                  ?>
                  <p class="card-text text-center"><b><a href="/dashboard/GLPI-Detail.php"><?php echo $nbglpi; ?></b> Devices</a></p>
                </div>
              </div>  
            </div>

            <div class="col"> <!-- CARTE SCCM -->
              <div class="card border-primary mb-3">
                <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> SCCM</h5></div>
                <div class="card-body">
                  <?php 
                    $conn = DB_SCCM();
                    $sql = 'SELECT count(*) as nbsccm FROM dbo.v_GS_COMPUTER_SYSTEM';
                    $rs=odbc_exec($conn,$sql); 
                    $nbsccm = odbc_result($rs,"nbsccm");
                  ?>
                  <p class="card-text text-center"><b><a href="/dashboard/SCCM-Detail.php"><?php echo $nbsccm; ?></b> Agents</a></p>
                </div>
              </div>  
            </div>

            <div class="col"> <!-- CARTE NESSUS -->
                <div class="card border-primary mb-3">
                  <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> NESSUS</h5></div>
                  <div class="card-body">
                    <?php 
                      $conn = DB_ENTRY02();
                      $result = $conn->query("SELECT count(*) as nbnessus FROM GlobalCrossover where epo like '%.%'");
                      $nbnessus = mysqli_fetch_array($result)['nbnessus'];
                    ?>
                    <p class="card-text text-center"><b><a href="/dashboard/Nessus-Detail.php"><?php echo $nbnessus; ?></b> Agents</a></p>
                  </div>
                </div>  
            </div>

            <div class="col"> <!-- CARTE SentinelOne -->
                <div class="card border-primary mb-3">
                  <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> SentinelOne</h5></div>
                  <div class="card-body">
                    <?php 
                      $result = $conn->query("SELECT count(*) as nbS1 FROM GlobalCrossover where S1 like '%.%'");
                      $nbS1 = mysqli_fetch_array($result)['nbS1'];
                    ?>
                    <p class="card-text text-center"><b><a href="/dashboard/S1-Detail.php"><?php echo $nbS1; ?></b> Agents</a></p>
                  </div>
                </div>  
            </div>
            
            <div class="col"> <!-- CARTE NetBackup -->
                <div class="card border-primary mb-3">
                  <div class="card-header text-dark"><h5><i class="fs-4 bi-pc text-primary"></i> NetBackup</h5></div>
                  <div class="card-body">
                    <?php 
                      $conn = DB_ENTRY01();
                      $result = $conn->query("SELECT count(distinct server) as nbnbu FROM nb_jobs_full");
                      $nbnbu = mysqli_fetch_array($result)['nbnbu'];
                      mysqli_close($conn);
                    ?>
                    <p class="card-text text-center"><b><a href="/dashboard/NBU-Detail.php"><?php echo $nbnbu; ?></b> Clients</a></p>
                  </div>
                </div>  
            </div>
          </div>
            
          <hr>
          
          <div class="row flex-nowrap text-center">
            <div class="col">
              <div class="card border-secondary mb-3">
                <div class="card-header text-dark"><h3>OS Windows INFRA</h3></div>
                <div class="card-body">
                  <canvas id="ChartServer" ></canvas>
                </div>
              </div>
            </div>
            <div class="col">
              <div class="card border-secondary mb-3">
                <div class="card-header text-dark"><h3>OS Windows APPLI</h3></div>
                <div class="card-body">
                  <canvas id="ChartServerA" ></canvas>
                </div>
              </div>
            </div>
            <div class="col">
              <div class="card border-secondary mb-3">
                <div class="card-header text-dark"><h3>OS Linux/AIX</h3></div>
                <div class="card-body">
                  <canvas id="ChartLinux"></canvas>
                </div>
              </div>
            </div>
            <div class="col">
              <div class="card border-secondary mb-3">
                <div class="card-header text-dark"><h3>Device Type</h3></div>
                <div class="card-body">
                  <canvas id="ChartType"></canvas>
                </div>
              </div>
            </div>
          </div>
        </div>  
        <!-- End of main content -->
      </div>
    </div>
  <script src="/js/switch.js"></script>
</body>

<script>
  let dataSV = document.getElementById("dataSVI").innerHTML.split(",");
  let labelsSV = ['2008', '2012', '2016', '2019', '2022'];
  new Chart("ChartServer", {
  type: 'doughnut',
  data: {
   labels: labelsSV,
   datasets: [{
      backgroundColor: ['#ff0000','#ff0000','#00ff00','#00ff00','#00ff00'],
      data: dataSV
   }]
  }
});

  let dataSVA = document.getElementById("dataSVA").innerHTML.split(",");
  let labelsSVA = ['2008', '2012', '2016', '2019', '2022'];
  new Chart("ChartServerA", {
  type: 'doughnut',
  data: {
   labels: labelsSVA,
   datasets: [{
      backgroundColor: ['#ff0000','#ff0000','#00ff00','#00ff00','#00ff00'],
      data: dataSVA
   }]
  }
});

  let dataLI = document.getElementById("dataLI").innerHTML.split(",");
  let labelsLI = ['Linux', 'AIX'];
  new Chart("ChartLinux", {
  type: 'doughnut',
  data: {
   labels: labelsLI,
   datasets: [{
      backgroundColor: ['#00ff00','#ff8c00'],
      data: dataLI
   }]
  }
});

  let dataType = document.getElementById("dataType").innerHTML.split(",");
  let labelsType = ['Physical', 'Virtual'];
  new Chart("ChartType", {
  type: 'doughnut',
  data: {
   labels: labelsType,
   datasets: [{
      backgroundColor: ['#2596be','#eab676'],
      data: dataType
   }]
  }
});


</script>

