<?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 id, buttonid, name, streamurl, streamport, streamip FROM PresetRadioStream LEFT JOIN users ON users.uid = PresetRadioStream.uid WHERE radiotoken=? LIMIT 5")){
        	$stmt -> bind_param("s", $radioid);
        	$stmt -> execute();
        	$stmt -> bind_result($id, $bid, $name, $streamurl, $streamport, $streamip);
        	while($result = $stmt -> fetch()){
        	    array_push($array, array(   id=> $id, 
        	                                bid => $bid, 
        	                                name => $name, 
        	                                ip => $streamip,
                                            port => $streamport,
                                            url => $streamurl,
        	                               ) 
        	               );
        	 };
        	$stmt -> close();
        }
        print(json_encode($array, JSON_UNESCAPED_SLASHES));
    }
    
    