<?php
	include_once('includes/db_connect.php');
	include_once('includes/global_functions.php');
    $radioid = $_GET['radioid'];
    $radiomac = $_GET['radiomac'];
        
    if($radioid == "" && $radiomac == ""){
        print(json_encode([error => "Not a valid radioid"]));
        die();
    }else{
        if($radiomac != ""){
            $radiomac = str_replace(':', '', $radiomac);
            $radioid = substr($radiomac, 6 , 11);
        }
        
        $array = array();
       	if($stmt = $mysqli -> prepare("SELECT username FROM Twitch LEFT JOIN users ON Twitch.uid = users.uid WHERE users.radiotoken = ?")){
        	$stmt -> bind_param("s", $radioid);
        	$stmt -> execute();
        	$stmt -> bind_result($TwitchUsername);
        	while($result = $stmt -> fetch()){
        	    array_push($array, array(   username =>$TwitchUsername) 
        	               );
        	 };
        	$stmt -> close();
       	}
        print(json_encode($array, JSON_UNESCAPED_SLASHES));
    }
    
    