<?php

  //setting header to json
  header('Content-Type: application/json');
  header("Access-Control-Allow-Origin: *");


  // $id = $_POST["id"];  // get internal sensor id from js
  // $driverID = $_POST["driver"];  // get value
  require '../php/database.php';

  //query to get data from the table
  // $query = sprintf("SELECT `modeDetailsID`, `pinID`, `start`, `startLevel` FROM `lightModeDetails` ORDER BY pinID ASC, start ASC");
  $query = sprintf("SELECT `modeID`, `pinID`, `start`, `startLevel`, `enabled` FROM `lightModes` ORDER BY pinID ASC, start ASC");
  // $query = sprintf("SELECT `modeID`, `pinID`, `start`, `end`, `startLevel`, `endLevel` FROM `lightModeDetails` ORDER BY ".modeID." ASC");

  //execute query
  $result = $mysqli->query($query);

  //loop through the returned data
  $dataWindow = array();
  foreach ($result as $row) {
    $dataWindow[] = $row;
  }

  //now print the data
  print json_encode($dataWindow);
  // free memory associated with result
  $result->close();

  //close connection
  $mysqli->close();
  // print_r(json_encode($dataWindow));