<?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 `modeID`, `modeName`, `sun`, `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `enabled` FROM `lightModes` ORDER BY ".modeName." ASC");

  // $query = sprintf("SELECT `modeID`, `modeNumber`, `modeName`, `start`, `end`, `sun`, `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `enabled` FROM `lightModes` ORDER BY ".modeNumber." 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));