<!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 IT</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/all.php"; ?> <!-- Include All -->

  <!-- HTML -->
  <div class="container-fluid" id="content">
    <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"; ?>
      </div>
      <!-- Display -->
      <div class="col py-3">
        <!-- Page Title -->
        <h2><span class="badge text-bg-secondary " style="width:100%;" >VM Storage (migration phase)</span></h2>

        <!-- Main content -->
        <div class="container-fluid">
          <!-- MODAL WAIT -->
          <div class="modal fade bs-example-modal-sm" id="wait" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" style="padding-top: 15%;">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-header">
                    <h4 class="modal-title mb-1 text-dark text-uppercase">
                      <center><i class="bi bi-hourglass-split"></i><br> Work in progress ...</center>
                    </h4>
                  </div>
                  <div class="modal-body">
                    <div class="progress">
                        <div class="progress-bar progress-bar-secondary progress-bar-striped progress-bar-animated" style="width: 100%"></div>
                    </div>
                  </div>
              </div>
            </div>
          </div>
          <!-- TABLE -->
          <div>
          <table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table" data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']" data-show-export="true" data-sortable="true" data-sort-name="vm">
            <thead> <!-- Header -->
              <th data-field='vm' data-sortable='true'>VM</th>   
              <th data-field='Last Backup' data-sortable='true'>Legacy Host</th>
              <th data-field='Last Result' data-sortable='true'>Destination Host</th>
              <th data-field='Last Good' data-sortable='true'>VHDX Storage</th>
              <th data-field='Size' data-sortable='true'>VNX Luns</th>
              <th data-field='Host' data-sortable='true'>SVC Luns</th>
            </thead>

            <tbody> <!-- Body -->
              <?php
                $answers = Invoke_Infra("SELECT * FROM cmdb_vms where (owner like '%DUN%' or owner like '%mdk%') and owner not like '%VMH-WM%' and owner not like '%WKG%' and DecomTime is null order by name");
                $clusters = Invoke_WebInfraTools("select distinct hostname from storage_lun where hostname like '%-c1%'");
                $lunsVNX = Invoke_WebInfraTools("select * from storage_lun where baie = 'VNX'");
                $lunsSVC = Invoke_WebInfraTools("select * from storage_lun where baie = 'SVC'");
                foreach ($answers as $row) {
                    echo "<tr>";
                        echo "<td>".$row['Name']."</td>";
                        if(strpos($row['Owner'],"SYN") !== false || strpos($row['Owner'],"MIG") !== false){
                            echo "<td></td><td>".$row['Owner']."</td>";
                        }else{
                            echo "<td>".$row['Owner']."</td><td></td>";
                        }
                        echo "<td>".str_replace(".vhdx,"," : ",str_replace("|","GB<br>",$row['VHDXs']))."GB</td>";
                        if($row['WWPNs'] != ""){
                            echo "<td>";
                            foreach($lunsVNX as $lun){
                                if($lun['hostname'] == $row['Name']){
                                    echo explode("_",$lun['name'])[1]." : ".$lun['size']."GB<br>\n";
                                }
                            }
                            echo "</td>";
                            echo "<td>";
                            foreach($lunsSVC as $lun){
                                if($lun['hostname'] == $row['Name']){
                                    echo $lun['name']." : ".$lun['size']."GB<br>\n";
                                }
                            }
                            echo "</td>";

                        }else{echo "<td></td><td></td>";}
                    echo "</tr>";
                }
                foreach ($clusters as $row) {
                  $lunsVNX = Invoke_WebInfraTools("select * from storage_lun where baie = 'VNX' and hostname = '".$row['hostname']."' order by name");
                  $lunsSVC = Invoke_WebInfraTools("select * from storage_lun where baie = 'SVC' and hostname = '".$row['hostname']."' order by name");
                  echo "<tr>";
                      echo "<td>".$row['hostname']." (Cluster)</td>";
                      echo "<td></td><td></td><td></td>";
                      echo "<td>";
                        foreach($lunsVNX as $lun){
                          if($lun['hostname'] == $row['hostname']){
                            echo explode("_",$lun['name'])[1]." : ".$lun['size']."GB<br>\n";
                          }
                        }
                        echo "</td>";
                        echo "<td>";
                        foreach($lunsSVC as $lun){
                          if($lun['hostname'] == $row['hostname']){
                            echo $lun['name']." : ".$lun['size']."GB<br>\n";
                          }
                        }
                        echo "</td>";
                  }
                  echo "</tr>";
              ?>
              </tbody>
            </table>
            <br>
          </div>
        </div>
        <!-- End of main content -->
      </div>
    </div>
  </div>
  <?php
    $ERR = "VMs backups  (<span class='text-danger'>".$er." issues</span> - <span class='text-warning'>".$outdated." outdated </span>- <span class='text-info'>".$excluded.' excluded</span>)';
  ?>
</body>
<script src="/js/switch.js"></script>
</HTML>

<SCRIPT>
  $(document).ready(function() {
    $('#t1').DataTable({
      scrollY: '50vh',
      scrollCollapse: true,
      paging: false,
    });
  });

  $(function () {
    var options = $('#t1').bootstrapTable('getOptions');
    options.height= document.getElementById('content').clientHeight-170;
    $('#t1').bootstrapTable('refreshOptions',options);
  });

  function tableresize() {
    var options = $('#t1').bootstrapTable('getOptions');
    options.height= document.getElementById('content').clientHeight-170;
    $('#t1').bootstrapTable('refreshOptions',options);
  };

  window.addEventListener("resize", tableresize);

  document.getElementById("ERR").innerHTML = "<?php echo $ERR ; ?>";
 
</script>
