<!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>

   <!-- 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>
   <?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</span></h1>
        
        <!-- Main content -->
        <div class="row" style="zoom: 80%">
          <!-- Get DATAs -->  
          <?php
            // get all departements
            DB_Data_Read();
            $sql = "select distinct substring(dpt,1,Charindex('-',dpt)-1) as dpt1 from globalcrossover where dpt like '%-%' order by dpt1";
            $rs=odbc_exec($conn,$sql);
            $opt = "<select class='form-select' id='DPT' name='DPT'><option selected></option>";
            while ($row = odbc_fetch_array($rs)) {
               if(isset($row['dpt1'])){
                  $opt .= "<option value='".$row['dpt1']."*'%>".$row['dpt1']."<b>*</b></option>" ;
               }
            }
            $opt .= "<option disabled>──────────</option>" ;
            $sql = "select distinct dpt from globalcrossover where dpt <> '' order by dpt";
            $rs=odbc_exec($conn,$sql);
            while ($row = odbc_fetch_array($rs)) {
               $opt .= "<option value='".$row['dpt']."'>".$row['dpt']."</option>" ;
            }





            $opt .="</select>" ;

            $vir="checked";$phy="checked";$dpt="";
            $where = ""; $typ="";
            if(isset($_GET['AA'])){
               $aa="checked"; $where .= "crit = 'AA' or ";
            }else{$aa="unchecked";}
            if(isset($_GET['A'])){
               $a="checked"; $where .= "crit = 'A' or ";
            }else{$a="unchecked";}
            if(isset($_GET['B'])){
               $b="checked"; $where .= "crit = 'B' or ";
            }else{$b="unchecked";}
            if(isset($_GET['C'])){
               $c="checked"; $where .= "crit = 'C' or ";
            }else{$c="unchecked";}
            if(isset($_GET['no'])){
               $no="checked"; $where .= "(crit = '' or crit is null) or ";
            }else{$no="unchecked";}
            $crit = rtrim($where, "or ");

            if(isset($_GET['PHY'])){
               $phy="checked"; 
               if(!isset($_GET['VIR'])){
                  $typ .= " AND virtual = 'N'";
               }
            }else{$phy="unchecked";}
            
            if(isset($_GET['VIR'])){
               $vir="checked"; 
               if(!isset($_GET['PHY'])){
                  $typ .= " AND virtual = 'Y'";
               }
            }else{$vir="unchecked";}

            
            DB_Data_Read();
            if($crit <> ""){
               $sql = "SELECT * FROM GlobalCrossover where ($crit) and Server <> '' ";
            }else{
               $sql = "SELECT * FROM GlobalCrossover where Server <> '' ";
            }
            if($typ <> ""){
               $sql .= $typ ;
            }

            if(isset($_GET['DPT']) && $_GET['DPT'] <> ""){
               $dpt = strtoupper($_GET['DPT']);
               $d = str_replace('*','',$dpt) ;
               $sql .= " AND dpt like '$d%' " ;
            }else{
               $dpt="";
            }

            $sql .= " order by Server";
            //echo $sql ;
            
            $rs=odbc_exec($conn,$sql);  
          ?>

            <!-- Criticity selection -->
            <form class="row row-cols-lg-auto g-3 align-items-center" action="/crossover/GlobalCrossover.php">
               <div class="col-12"></div>   
               <div class="col-12 border rounded">
                  <small>
                     <b>Criticity Filter : </b>
                     <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input" type="checkbox" role="switch" id="AA" <?php echo $aa;?> name="AA" value="1">
                        <label class="form-check-label" for="AA">AA</label>
                     </div>
                     <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input" type="checkbox" role="switch" id="A" <?php echo $a;?> name="A" value="1">
                        <label class="form-check-label" for="A">A</label>
                     </div>
                     <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input" type="checkbox" role="switch" id="B" <?php echo $b;?> name="B" value="1">
                        <label class="form-check-label" for="B">B</label>
                     </div>
                     <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input" type="checkbox" role="switch" id="C" <?php echo $c;?> name="C" value="1">
                        <label class="form-check-label" for="C">C</label>
                     </div>
                     <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input" type="checkbox" role="switch" id="no" <?php echo $no;?> name="no" value="1">
                        <label class="form-check-label" for="no">Empty</label>
                     </div>
                  </small>
               </div>
               <div class="col-12"></div>
               <div class="col-12 border rounded">
                  <small>
                     <b>Type : </b>
                        <div class="form-check form-check-inline form-switch">
                           <input class="form-check-input" type="checkbox" role="switch" id="PHY" <?php echo $phy;?> name="PHY" value="1">
                           <label class="form-check-label" for="PHY">Physical</label>
                        </div>
                        <div class="form-check form-check-inline form-switch">
                           <input class="form-check-input" type="checkbox" role="switch" id="VIR" <?php echo $vir;?> name="VIR" value="1">
                           <label class="form-check-label" for="VIR">Virtual</label>
                        </div>
                  </small>
               </div>

               <div class="col-12"></div>
               <div class="col-12">
                  <?php echo str_replace('<option selected></option>','<option selected>'.$dpt.'</option><option></option>',$opt); ?>
               </div>

               <div class="col-12"></div>
               <div class="col-12">
                  <button type="submit" class="btn btn-primary btn-small ">Apply</button>
               </div>
               
            </form>

          <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">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="EPO" data-sortable="true">EPO</th>
              <th data-field="EPOlu" data-sortable="true" data-visible="false">EPO Last Update</th>
              <th data-field="Backup" data-sortable="true">Backup</th>
              <th data-field="NBUlu" data-sortable="true" data-visible="false">Last Backup</th>
            </thead>

            <tbody>
              <!-- Display DATAs -->
              <?php
                $ok=0;$total=0;$nOS=0;$nAD=0;$nSCCM=0;$nGLPI=0;$nFI=0;$nEPO=0;$nNBU=0;$nDPM=0;
                while ($row = odbc_fetch_array($rs)) {
                  $total++ ;
                  echo "<tr>";
                     if(isset($row['AD']) && isset($row['GLPI']) && isset($row['SCCM']) && isset($row['EPO']) && isset($row['NBU'])){
                        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>";
                        $ok++;
                     }else{
                        echo "<td><b><a href='\crossover\Detail.php?server=".$row['Server']."' target='_blank'>".$row['Server']."</a></b></td>";
                     }
                     if($row['OS']){
                        if(preg_match('(XP|2003|Windows NT|2000|2008|7)', $row['OS']) !== 1) {
                           $nOS++; 
                           echo "<td>".$row['OS']."</td>";
                        } else {
                           echo "<td class='bg-warning'>".$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") > 60){
                           echo "<td class='text-success' 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-success'>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-warning'>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-success' 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'] <> ""){
                              echo "<td class='bg-success text-success'>OK</td>";
                              $nFI++;
                              echo "<td class='bg-success text-white'>".$row['GLPIlu']."</td>";  
                           }else{
                              echo "<td class='text-success' 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-warning'>Missing</td>";
                           }
                        }
                        $nGLPI++;
                     }else{
                        echo "<td class='bg-warning text-warning'>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-success' 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-success'>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-warning'>Missing</td>";
                           echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                        }
                     }

                     // EPO
                     if($row['EPO'] == 'Y'){
                        $date1=date_create($row['EPOlu']);
                        $diff=date_diff($date1,date_create(date("Y-m-d")));
                        if($diff->format("%R%a") > 7){
                           echo "<td class='text-success' 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['EPOlu']." (".$diff->format("%R%a")." days)</td>";
                        }else{ 
                           echo "<td class='bg-success text-success'>OK</td>";
                           echo "<td class='bg-success text-white'>".$row['EPOlu']."</td>"; 
                           $nEPO++; 
                        }
                     }else{
                        if(isset($row['EPO'])){
                           echo "<td class='bg-secondary'><small>".$row['EPO']."</small></td>";
                           echo "<td class='bg-secondary text-secondary'>&nbsp;</td>";
                           $nEPO++;
                        }else{
                           echo "<td class='bg-warning text-warning'>Missing</td>";
                           echo "<td class='bg-warning text-warning'>&nbsp;</td>";
                        }
                     }

                     // 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-warning'>Missing</td>";
                              echo "<td class='bg-warning text-warning'>&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 "><b>Devices</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIDEVICE"></span></h2>
                  </div>
               </div>
            </div>
            <div class="col"> <!-- CARTE OS -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>Supported OS</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIOS"></span></h2>
                  </div>
               </div>
            </div>
            <div class="col"> <!-- CARTE AD -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>AD</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIAD"></span></h2>
                  </div>
               </div>
            </div>  
            <div class="col"> <!-- CARTE GLPI/FI -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>GLPI/FI</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIGLPI"></span></h2>
                  </div>
               </div>
            </div>
            <div class="col"> <!-- CARTE SCCM -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>SCCM</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPISCCM"></span></h2>
                  </div>
               </div>
            </div>
            <div class="col"> <!-- CARTE EPO -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>EPO</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPIEPO"></span></h2>
                  </div>
               </div>
            </div>
            <div class="col"> <!-- CARTE NBU -->
               <div class="card border-secondary mb-3">
                  <div class="card-header"><b>Backup</b></div>
                  <div class="card-body">
                     <h2><span class="badge text-bg-secondary font-weight-bold" id="KPINBU"></span></h2>
                  </div>
               </div>
            </div>
         </div> 
        <!-- End of main content -->
      </div>
    </div>
  </div>
  <?php echo '<script type="text/javascript">', "$('#button').click();", '</script>' ;?>
</body>

<script>
   function dateDiffInDays(a) {
      const _MS_PER_DAY = 1000 * 60 * 60 * 24;
      return Math.floor((Date.now() - new Date(a)) / _MS_PER_DAY);
   }

  var $table = $('#t1')
  var $button = $('#button')
 
  $(function() {
    $button.click(function () {
      $data = $table.bootstrapTable('getData')
      $dl = $data.length
      $nSCCM=0; $nAD=0; $nGLPI=0;$nEPO=0;$nNBU=0;$nOS=0;
      for( $i=0 ; $i < $dl ; $i++ ){
         if ($data[$i]['AD'] !== 'Missing') { $nAD++ ; }
         if ((dateDiffInDays($data[$i]['ADlu'].split(" ")[0]) > 60 || $data[$i]['ADlu'] == 'Missing') && $data[$i]['SCCM'] == 'OK'){ $nAD-- ;}
         if ($data[$i]['SCCM'] !== 'Missing') { $nSCCM++ ; }
         if ((dateDiffInDays($data[$i]['SCCMlu'].split(" ")[0]) > 7 || $data[$i]['SCCMlu'] == 'Missing') && $data[$i]['SCCM'] == 'OK'){ $nSCCM-- ;}
         if ($data[$i]['GLPI'] !== 'Missing') { $nGLPI++ ; }
         if ((dateDiffInDays($data[$i]['GLPIlu'].split(" ")[0]) > 7 || $data[$i]['GLPIlu'] == 'Missing') && $data[$i]['GLPI'] == 'OK'){ $nGLPI-- ;}
         if ($data[$i]['EPO'] !== 'Missing') { $nEPO++ ; }
         if ((dateDiffInDays($data[$i]['EPOlu'].split(" ")[0]) > 7 || $data[$i]['EPOlu'] == 'Missing') && $data[$i]['EPO'] == 'OK'){ $nEPO-- ;}
         if ($data[$i]['Backup'] !== 'Missing') { $nNBU++ ; }
         if ((dateDiffInDays($data[$i]['NBUlu'].split(" ")[0]) > 30 || $data[$i]['NBUlu'] == 'Missing') && $data[$i]['Backup'].split(" ")[0] == 'OK'){ $nNBU-- ;}
         if (($data[$i]['OS'].includes('XP') || $data[$i]['OS'].includes('2000') || $data[$i]['OS'].includes('2003') || $data[$i]['OS'].includes('2008') || $data[$i]['OS'].includes('7') || $data[$i]['OS'].includes('Windows NT')) == false) { $nOS++ ;}
      }
      
      document.getElementById("KPIAD").innerHTML = Math.round($nAD/$dl*100) + "%";
      if(Math.round($nAD/$dl*100) >=90){ 
         document.getElementById("KPIAD").className = "badge text-bg-success font-weight-bold";
      }else if(Math.round($nAD/$dl*100) >=75){
         document.getElementById("KPIAD").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPIAD").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPIGLPI").innerHTML = Math.round($nGLPI/$dl*100) + "%";
      if(Math.round($nGLPI/$dl*100) >=90){ 
         document.getElementById("KPIGLPI").className = "badge text-bg-success font-weight-bold";   
      }else if(Math.round($nGLPI/$dl*100) >=75){
         document.getElementById("KPIGLPI").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPIGLPI").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPISCCM").innerHTML = Math.round($nSCCM/$dl*100) + "%";
      if(Math.round($nSCCM/$dl*100) >=90){ 
         document.getElementById("KPISCCM").className = "badge text-bg-success font-weight-bold";   
      }else if(Math.round($nSCCM/$dl*100) >=75){
         document.getElementById("KPISCCM").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPISCCM").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPIEPO").innerHTML = Math.round($nEPO/$dl*100) + "%";
      if(Math.round($nEPO/$dl*100) >=90){ 
         document.getElementById("KPIEPO").className = "badge text-bg-success font-weight-bold";   
      }else if(Math.round($nEPO/$dl*100) >=75){
         document.getElementById("KPIEPO").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPIEPO").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPINBU").innerHTML = Math.round($nNBU/$dl*100) + "%";
      if(Math.round($nNBU/$dl*100) >=90){ 
         document.getElementById("KPINBU").className = "badge text-bg-success font-weight-bold";   
      }else if(Math.round($nNBU/$dl*100) >=75){
         document.getElementById("KPINBU").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPINBU").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPIOS").innerHTML = Math.round($nOS/$dl*100) + "%";
      if(Math.round($nOS/$dl*100) >=90){ 
         document.getElementById("KPIOS").className = "badge text-bg-success font-weight-bold";   
      }else if(Math.round($nOS/$dl*100) >=75){
         document.getElementById("KPIOS").className = "badge text-bg-warning font-weight-bold";
      }else{
         document.getElementById("KPIOS").className = "badge text-bg-danger font-weight-bold";
      } 

      document.getElementById("KPIDEVICE").innerHTML = $dl;
   })
  })

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

</script>

<!-- remove preloader after loading -->
<script>
      $(window).on('load', function() {
      	$('.preloader').addClass('preloader-deactivate');
      });
   </script>

