<html>
<head>
<?php
  include "stuff.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];

  // Domestic.
  if ($etid==4 || $etid==5) {
    // If we have a custom assessment, get criteria from model_inputs.
    if ($is_custom==1) {
      $res = mysqli_query($con,"SELECT in01,in02,in03,in04,in05,in06,in07,in08,in09,in10,in11,in12,in13,in14,in15,in16,in17,in18,in19,in20,in21,in22,in23 FROM model_inputs WHERE result = {$rid};");
      $row = mysqli_fetch_array($res);
      $space_heating=$row[0];
      $lighting=$row[1];
      $equipment=$row[2];
      $DHW=$row[3];
      $CO2=$row[4];
      $NOX=$row[5];
      $SOX=$row[6];
      $O3=$row[7];
      $max_Top_liv=$row[8];
      $min_Top_liv=$row[9];
      $max_Top_kit=$row[10];
      $min_Top_kit=$row[11];
      $max_Top_bed=$row[12];
      $min_Top_bed=$row[13];
      $max_Top_bath=$row[14];
      $min_Top_bath=$row[15];
      $max_Top_WC=$row[16];
      $min_Top_WC=$row[17];
      $max_Top_hall=$row[18];
      $min_Top_hall=$row[19];
      $min_fresh_air=$row[20];
      $air_supply_units=$row[21];
      $max_CO2_conc=$row[22];
    }
    
    // If not, get criteria directly from the preset.
    else {
      $res = mysqli_query($con,"SELECT in01,in02,in03,in04,in05,in06,in07,in08,in09,in10,in11,in12,in13,in14,in15,in16,in17,in18,in19,in20,in21,in22,in23 FROM presets WHERE id = {$pid};");
      $row = mysqli_fetch_array($res);
      $space_heating=$row[0];
      $lighting=$row[1];
      $equipment=$row[2];
      $DHW=$row[3];
      $CO2=$row[4];
      $NOX=$row[5];
      $SOX=$row[6];
      $O3=$row[7];
      $max_Top_liv=$row[8];
      $min_Top_liv=$row[9];
      $max_Top_kit=$row[10];
      $min_Top_kit=$row[11];
      $max_Top_bed=$row[12];
      $min_Top_bed=$row[13];
      $max_Top_bath=$row[14];
      $min_Top_bath=$row[15];
      $max_Top_WC=$row[16];
      $min_Top_WC=$row[17];
      $max_Top_hall=$row[18];
      $min_Top_hall=$row[19];
      $min_fresh_air=$row[20];
      $air_supply_units=$row[21];
      $max_CO2_conc=$row[22];
    }
  }

  // Office.  
  else if ($etid==2) {
    // If we have a custom assessment, get criteria from model_inputs.
    if ($is_custom==1) {
      $res = mysqli_query($con,"SELECT in01,in02,in03,in04,in05,in06,in07,in08,in09,in10,in11,in12,in13 FROM model_inputs WHERE result = {$rid};");
      $row = mysqli_fetch_array($res);
      $HVAC=$row[0];
      $lighting=$row[1];
      $equipment=$row[2];
      $DHW=$row[3];
      $CO2=$row[4];
      $NOX=$row[5];
      $SOX=$row[6];
      $O3=$row[7];
      $max_Top=$row[8];
      $min_Top=$row[9];
      $min_fresh_air=$row[10];
      $air_supply_units=$row[11];
      $max_CO2_conc=$row[12];
    }
    
    // If not, get criteria directly from the preset.
    else {
      $res = mysqli_query($con,"SELECT in01,in02,in03,in04,in05,in06,in07,in08,in09,in10,in11,in12,in13 FROM presets WHERE id = {$pid};");
      $row = mysqli_fetch_array($res);
      $HVAC=$row[0];
      $lighting=$row[1];
      $equipment=$row[2];
      $DHW=$row[3];
      $CO2=$row[4];
      $NOX=$row[5];
      $SOX=$row[6];
      $O3=$row[7];
      $max_Top=$row[8];
      $min_Top=$row[9];
      $min_fresh_air=$row[10];
      $air_supply_units=$row[11];
      $max_CO2_conc=$row[12];
    }
  }
  
  // District heating.  
  else if ($etid==3) {
    // If we have a custom assessment, get criteria from model_inputs.
    if ($is_custom==1) {
      $res = mysqli_query($con,"SELECT in01,in02,in03 FROM model_inputs WHERE result = {$rid};");
      $row = mysqli_fetch_array($res);
      $gen_efficiency=$row[0];
      $net_loss=$row[1];
      $load_temp=$row[2];
    }
    
    // If not, get criteria directly from the preset.
    else {
      $res = mysqli_query($con,"SELECT in01,in02,in03 FROM presets WHERE id = {$pid};");
      $row = mysqli_fetch_array($res);
      $gen_efficiency=$row[0];
      $net_loss=$row[1];
      $load_temp=$row[2];
    }
  }
?>
</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>
<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>
