<?php
	if($_SERVER['REQUEST_METHOD'] == "POST"){
	    $name = safeString($_POST["Name"]);
		$bid = safeString($_POST["bid"]);	    
	    $streamurl = $_POST["StreamUrl"];
	    $streamport = safeString($_POST["StreamPort"]);

		$streamsplit = parse_url($streamurl);
		$streamip = gethostbyname($streamsplit["host"]);
		$streamurl = $streamsplit["path"];
		
	    if($stmt = $mysqli -> prepare("INSERT INTO PresetRadioStream(name, buttonid, streamip, streamurl, streamport, uid) VALUES(?,?,?,?,?,?)")){
	    	$stmt ->bind_param("sissii", $name, $bid, $streamip,  $streamurl, $streamport, $userid);
	    	$stmt ->execute();
	    	$stmt ->close();
	    }
	}
?>

<div class="col-lg-12">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>Prefix toevoegen</h5>
		</div>
		<div class="ibox-content">
			<form method="POST" action="" class="form-horizontal">
				<div class="form-group">
					<label class="col-sm-2 control-label">Naam</label>
					<div class="col-sm-10">
						<input type="text" required name = "Name" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Knop nummer</label>
					<div class="col-sm-10">
						<select name = "bid" class="form-control">
							<option value="1">1</option>	
							<option value="2">2</option>	
							<option value="3">3</option>	
							<option value="4">4</option>	
							<option value="5">5</option>	
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Streamurl</label>
					<div class="col-sm-8">
						<input type="text" required name = "StreamUrl" class="form-control">
					</div>
					<div class="col-sm-2">
						<input type="number" min"0" max="9999" value="80" required name = "StreamPort" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-4 col-sm-offset-2">
						<button class="btn btn-primary" type="submit">Prefix opslaan</button>
						<button class="btn btn-primary" type="reset">Reset</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>