
<?php

// drop down box to select driver
    require '../php/database.php';

    $typeID = intval($_GET['q']);
    $driverID = intval($_GET['d']);

    $query = sprintf("SELECT `driverTypeID` FROM `drivers` WHERE driverID = '$driverID'");

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

    //loop through the returned data and place in variable to send back to frontend
    $dataWindow = array();
    while ($row = $result->fetch_assoc()) {
        $driverType = $row['driverTypeID'];
    }



    $query = sprintf("SELECT pinTypeID, pinTypeName, pinType FROM pinsType ORDER BY pinTypeName ASC");
    $result = $mysqli->query($query);
    echo $driverID;
    echo "<select class='settingsDropdown settingsTextFields' id='pinTypeID' name='pinTypeID' onchange='openPinTypeDropdown(this.value)'>";
    // <option value="0">Not Applicable</option>
    // echo "<option value=0 style=color:red>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp (select driver)</option>";
    while ($row = $result->fetch_assoc()) {

        unset($id, $name);
        $optionPinType = $row['pinType'];

        // first statement is for raspberry pi
        // second statement is for pca9685
        if (($driverType == 0) || (($driverType == 1) && ($optionPinType == 0))) {
            $pinTypeID = $row['pinTypeID'];
            $pinTypeName = $row['pinTypeName']; 
            if ($typeID == $pinTypeID) {  // mark select option as active
                echo '<option value="'.$pinTypeID.'" selected="selected">'.$pinTypeName.'</option>';
            }
            else {
                echo '<option value="'.$pinTypeID.'">'.$pinTypeName.'</option>';
            }
        }
    }
        
    echo "</select>";     
    //free memory associated with result
    $result->close();
    
    //close connection
    $mysqli->close();

?>
