<?php
    header('Content-Type: application/json');
    header("Access-Control-Allow-Origin: *");
    
    require '../php/database.php';

    //query to get data from the table
    $query = sprintf("SELECT pinsAvailable.pinID, pinsAvailable.pinTypeID, pinsAvailable.gpio, pinsAvailable.assigned, pinsAvailable.name, pinsAvailable.iconID, pinsAvailable.invert, pinsType.pinTypeName
    FROM pinsAvailable
    LEFT JOIN pinsType
    ON pinsAvailable.pinTypeID = pinsType.pinTypeID
    WHERE pinsAvailable.pinTypeID = 6 AND pinsAvailable.assigned = 1 
        OR pinsAvailable.pinTypeID = 7 AND pinsAvailable.assigned = 1 
        OR pinsAvailable.pinTypeID = 8 AND pinsAvailable.assigned = 1 
        OR pinsAvailable.pinTypeID = 9 AND pinsAvailable.assigned = 1 
        OR pinsAvailable.pinTypeID = 14 AND pinsAvailable.assigned = 1 
    ORDER BY `name` ASC");

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

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

    //free memory associated with result
    $result->close();

    //close connection
    $mysqli->close();
    // print_r(json_encode($dataWindow));
    //now print the data
    print json_encode($dataWindow);