
<?php
  include "../Pages/stuff.php";
  $con = mysqli_connect($server,$user,$password,$db);

  $rid = $_GET['rid'];
  $pid = $_GET['pid'];
  $etid = $_GET['etid'];
  $is_custom = $_GET['is_custom'];

  // 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};");
    }
    
    // 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};");
    }
  }

  // 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};");
    }
    
    // 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};");
    }
  }
  
  // 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};");
    }
    
    // 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,MYSQLI_ASSOC);
  $out = json_encode($row);
  echo $out;
?>