<html>
<head>

<?php
  $con = mysqli_connect($server,$user,$password,$db);
  $rid = $_GET['rid'];

  $res = mysqli_query($con,"SELECT results.name,
                                   results.preset,
                                   presets.is_custom,
                                   models.name,
                                   estates.name,
                                   estates.type 
                            FROM results 
                            INNER JOIN presets ON results.preset=presets.id
                            INNER JOIN models ON results.model=models.id 
                            INNER JOIN estates ON models.estate=estates.id 
                            WHERE results.id={$rid}");
  $row = mysqli_fetch_array($res);
  $pname = $row[0];
  $pid = $row[1];
  $is_custom = $row[2];
  $mname = $row[3];
  $ename = $row[4];
  $etid = $row[5];
?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
window.onload = function(){

  $.ajax({
    var srid = <?php echo "$rid"; ?>;
    url: "./Scripts/check_request_inputs.php",
    type: "GET",
    data: { rid: srid },
    dataType: "json",
    success: function(result){

      var setid = result.etid;

      // Domestic.
      if (setid==4 || setid==5) {
        
        set_box("space_heating",result.in01);
        set_box("lighting",result.in02);
        set_box("equipment",result.in03);
        set_box("DHW",result.in04);

        // Emissions.
        set_box("CO2",result.in05);
        set_box("NOX",result.in06);
        set_box("SOX",result.in07);
        set_box("O3",result.in08);

        // Thermal comfort.
        set_box("max_Top_liv",result.in09);
        set_box("min_Top_liv",result.in10);
        set_box("max_Top_kit",result.in11);
        set_box("min_Top_kit",result.in12);
        set_box("max_Top_bed",result.in13);
        set_box("min_Top_bed",result.in14);
        set_box("max_Top_bath",result.in15);
        set_box("min_Top_bath",result.in16);
        set_box("max_Top_WC",result.in17);
        set_box("min_Top_WC",result.in18);
        set_box("max_Top_hall",result.in19);
        set_box("min_Top_hall",result.in20);

        // Indoor air quality.      
        set_box("min_fresh_air",result.in21);
        document.getElementById("air_supply_units").value = result.in22;
        document.getElementById("air_supply_units").setAttribute("disabled",true);
        document.getElementById('air_supply_units').setAttribute('class','greyed-cell grey-text');
        // document.getElementById("air_supply_units_fwd").value = result.in22;
        set_box("max_CO2_conc",result.in23);
      }

      // Ofice
      elseif (setid==2) {

        // Energy.
        set_box("HVAC",result.in01);
        set_box("lighting",result.in02);
        set_box("equipment",result.in03);
        set_box("DHW",result.in04);

        // Emissions.
        set_box("CO2",result.in05);
        set_box("NOX",result.in06);
        set_box("SOX",result.in07);
        set_box("O3",result.in08);

        // Thermal comfort.
        set_box("max_Top",result.in09);
        set_box("min_Top",result.in10);

        // Indoor air quality.      
        set_box("min_fresh_air",result.in11);
        document.getElementById("air_supply_units").value = result.in12;
        document.getElementById("air_supply_units").setAttribute("disabled",true);
        document.getElementById('air_supply_units').setAttribute('class','greyed-cell grey-text');
        // document.getElementById("air_supply_units_fwd").value = result.in12;
        set_box("max_CO2_conc",result.in13);

      }

      // District heat.
      elseif (setid==3) {
        
        set_box("gen_efficiency",result.in01);
        set_box("net_loss",result.in02);
        set_box("load_temp",result.in03);
      }

    },
    error: function(jqXHR,errtyp,errstr){
      console.log('check_request_inputs failed');
      console.log(errtyp);
      console.log(errstr);
    }
  });
}
function set_box(id,val){  
  document.getElementById(id).value = val;
  document.getElementById(id).setAttribute("readonly", true);
  document.getElementById(id).setAttribute("class", "greyed-cell grey-text");
  // document.getElementById(id.concat("_a")).setAttribute("onClick","");
}
</script>
</head>

<body>
<?php echo ("<h4 style='color:gray;'>{$ename}: {$mname}: {$pname}</h4>");?>
<h5 style="color:gray">Data cannot be modified after resilience testing is requested.</h5>

<?php
  if ($etid==4 || $etid==5) {
    include "Pages/domestic_table.html"
  }
  else if ($etid==2) {
    include "Pages/office_table.html"
  }
  else if ($etid==3) {
    include "Pages/distHeat_table.html"
  }
?>












<table style='color:gray;' id="the_table">
<tr><td width='25%'><strong>Zone</strong></td><td width='25%'><strong>Index</strong></td><td width='25%''><strong>Maximum</strong></td><td width='25%'><strong>Minimum</strong></td></tr>
<tr><td width='25%'><i>Energy</i></td><td width='25%'></td><td width='25%' style='text-align:center'>kWh/m<sup>2</sup>/year</td><td width='25%'></td></tr>
<tr>
  <td width='25%' rowspan='4'>Whole building</td>
  <?php
    if ($etid==4 || $etid==5) {
      echo ("<td width='25%'>space heating<sup><a title='Scottish Government. 2017. Building Standards technical handbook: domestic buildings.' style='color:gray;' target='_blank' href='https://www.gov.scot/publications/building-standards-2017-domestic'>1</a></sup></td>");
      echo ("<td width='25%'><input type='text' disabled name='space_heating' id='space_heating' value='$space_heating' class='greyed-cell grey-text' style='text-align:center'></td>");
    }
    else if ($etid==2) {
      echo ("<td width='25%'>HVAC</td>");
      echo ("<td width='25%'><input type='text' disabled name='HVAC' id='HVAC' value='$HVAC' class='greyed-cell grey-text' style='text-align:center'></td>");
    }
  ?>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>lighting</td>
  <td width='25%'><input type='text' disabled name='lighting' id='lighting' value='<?php echo $lighting;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>equipment</td>
  <td width='25%'><input type='text' disabled name='equipment' id='equipment' value='<?php echo $equipment;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>DHW</td>
  <td width='25%'><input type='text' disabled name='DHW' id='DHW' value='<?php echo $DHW;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr></tr><tr></tr>
<tr></tr><tr></tr>
<tr><td width='25%'><i>Emissions</i></td><td width='25%'></td><td width='25%' style='text-align:center'>kg/year</td><td width='25%'></td></tr>
<tr>
  <td width='25%' rowspan='4'>Whole building</td>
  <td width='25%'>CO<sub>2</sub></td>
  <td width='25%'><input type='text' disabled name='CO2' id='CO2' value='<?php echo $CO2;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>NO<sub>x</sub></td>
  <td width='25%'><input type='text' disabled name='NOX' id='NOX' value='<?php echo $NOX;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>SO<sub>x</sub></td>
  <td width='25%'><input type='text' disabled name='SOX' id='SOX' value='<?php echo $SOX;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr>
  <td width='25%'>O<sub>3</sub></td>
  <td width='25%'><input type='text' disabled name='O3' id='O3' value='<?php echo $O3;?>' class='greyed-cell grey-text' style='text-align:center'></td>
  <td width='25%' style='text-align:center'></td>
</tr>
<tr></tr><tr></tr><tr></tr><tr></tr>
<?php
  if ($etid==4 || $etid==5) {
    echo ("
      <tr>
        <td width='25%' colspan='2'>
          <i>
            Thermal Comfort
            <sup>
              <a style='color:gray;' title='CIBSE. 2015. Guide A Environmental Design.' target='_blank' href='https://www.cibse.org/knowledge/knowledge-items/detail?id=a0q20000008I79JAAS'>2</a>,
              <a style='color:gray;' title='CIBSE. 2013. TM52 the limits of thermal comfort: avoiding overheating in European buildings.' target='_blank' href='https://www.cibse.org/Knowledge/knowledge-items/detail?id=a0q20000008I7f5AAC'>3</a>
            </sup>
          </i>
        </td>
        <td width='25%' style='text-align:center'><sup>o</sup>C</td>
        <td width='25%' style='text-align:center'><sup>o</sup>C</td>
      </tr>
      <tr>
        <td width='25%'>Living room</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_liv' id='max_Top_liv' value='$max_Top_liv' class='greyed-cell grey-text' style='text-align:center;white-space:nowrap;'></td>
        <td width='25%'><input type='text' disabled name='min_Top_liv' id='min_Top_liv' value='$min_Top_liv' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>Kitchen</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_kit' id='max_Top_kit' value='$max_Top_kit' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'><input type='text' disabled name='min_Top_kit' id='min_Top_kit' value='$min_Top_kit' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>Bedroom</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_bed' id='max_Top_bed' value='$max_Top_bed' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'><input type='text' disabled name='min_Top_bed' id='min_Top_bed' value='$min_Top_bed' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>Bathroom</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_bath' id='max_Top_bath' value='$max_Top_bath' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'><input type='text' disabled name='min_Top_bath' id='min_Top_bath' value='$min_Top_bath' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>WC</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_WC' id='max_Top_WC' value='$max_Top_WC' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'><input type='text' disabled name='min_Top_WC' id='min_Top_WC' value='$min_Top_WC' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>Hall</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top_hall' id='max_Top_hall' value='$max_Top_hall' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'><input type='text' disabled name='min_Top_hall' id='min_Top_hall' value='$min_Top_hall' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
    ");
  }
  else if ($etid==2) {
    echo ("
      <tr>
        <td width='25%' colspan='2'>
          <i>
            Thermal Comfort
            <sup>
              <a style='color:gray;' title='CIBSE. 2015. Guide A Environmental Design.' target='_blank' href='https://www.cibse.org/knowledge/knowledge-items/detail?id=a0q20000008I79JAAS'>1</a>
            </sup>
          </i>
        </td>
        <td width='25%' style='text-align:center'><sup>o</sup>C</td>
        <td width='25%' style='text-align:center'><sup>o</sup>C</td>
      </tr>
      <tr>
        <td width='25%'>Occupied zones</td>
        <td width='25%'>operative temperature</td>
        <td width='25%'><input type='text' disabled name='max_Top' id='max_Top' value='$max_Top' class='greyed-cell grey-text' style='text-align:center;white-space:nowrap;'></td>
        <td width='25%'><input type='text' disabled name='min_Top' id='min_Top' value='$min_Top' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
    ");
  }
?>
<tr></tr><tr></tr><tr></tr><tr></tr>
<?php
  if ($etid==4 || $etid==5) {
    echo ("
      <tr><td width='25%'><i>Air Quality</i></td><td width='25%'></td>
        <td width='25%' style='text-align:center'>PPM</td><td width='25%' id='air_supply_units' name='air_supply_units' style='text-align:center'>$air_supply_units</td>
      </tr>
      <tr>
        <td width='25%' rowspan=2>Whole building</td>
        <td width='25%'>fresh air supply<sup><a style='color:gray;' title='HM Government. 2010. Approved document F1 means of ventilation.' target='_blank' href='https://www.gov.uk/government/publications/ventilation-approved-document-f'>4</a></sup></td>
        <td width='25%'></td>
        <td width='25%'><input type='text' disabled name='min_fresh_air' id='min_fresh_air' value='$min_fresh_air' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>CO<sub>2</sub> concentration<sup><a style='color:gray;' title='CIBSE. 2015. Guide A Environmental Design.' target='_blank' href='https://www.cibse.org/knowledge/knowledge-items/detail?id=a0q20000008I79JAAS'>2</a></sup></td>
        <td width='25%'><input type='text' disabled name='max_CO2_conc' id='max_CO2_conc' value='$max_CO2_conc' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'></td>
      </tr>
    ");
  }
  else if ($etid==2) {
    echo ("
      <tr><td width='25%'><i>Air Quality</i></td><td width='25%'></td>
        <td width='25%' style='text-align:center'>PPM</td><td width='25%' id='air_supply_units' name='air_supply_units' style='text-align:center'>$air_supply_units</td>
      </tr>
      <tr>
        <td width='25%' rowspan=2>Whole building</td>
        <td width='25%'>fresh air supply<sup><a style='color:gray;' title='HM Government. 2010. Approved document F1 means of ventilation.' target='_blank' href='https://www.gov.uk/government/publications/ventilation-approved-document-f'>2</a></sup></td>
        <td width='25%'></td>
        <td width='25%'><input type='text' disabled name='min_fresh_air' id='min_fresh_air' value='$min_fresh_air' class='greyed-cell grey-text' style='text-align:center'></td>
      </tr>
      <tr>
        <td width='25%'>CO<sub>2</sub> concentration<sup><a style='color:gray;' title='CIBSE. 2015. Guide A Environmental Design.' target='_blank' href='https://www.cibse.org/knowledge/knowledge-items/detail?id=a0q20000008I79JAAS'>1</a></sup></td>
        <td width='25%'><input type='text' disabled name='max_CO2_conc' id='max_CO2_conc' value='$max_CO2_conc' class='greyed-cell grey-text' style='text-align:center'></td>
        <td width='25%'></td>
      </tr>
    ");
  }
?>
</table>











</body>
</html>
