<?php

# This script checks the criteria preset from the SQL database, 
# and provides the relevant information back to the html to set up initial values.

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

$user_id = get_userid($con);
$res = mysqli_query($con,"SELECT latest_model FROM users WHERE id = {$user_id}");
$row = mysqli_fetch_array($res);
$mid = $row['latest_model'];

$res = mysqli_query($con,"SELECT preset FROM models WHERE id={$mid}");
$row = mysqli_fetch_array($res);
$pid = $row['preset'];
if ($pid>0) {  
  $res = mysqli_query($con,"SELECT name,is_custom,
    in01,in02,in03,in04,in05,in06,in07,in08,in09,in10,
    in11,in12,in13,in14,in15,in16,in17,in18,in19,in20,
    in21,in22,in23,in24,in25,in26,in27,in28,in29,in30 FROM presets WHERE id={$pid}");
  $row = mysqli_fetch_array($res);
  $out = json_encode($row);
  echo $out;
}
else {
  $row['is_custom'] = -1;
  $out = json_encode($row);
  echo $out;
}

?>