<?php
include '../../../auth.php';
?>
<!DOCTYPE html>
<html>
   <head>
      <meta charset="UTF-8">
      <link rel="stylesheet" href="../../../script/tocas/tocas.css">
      <script type='text/javascript' src="../../../script/tocas/tocas.js"></script>
      <script src="../../../script/jquery.min.js"></script>
      <title>WIFI</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   </head>


<body>
<div class="ts fluid borderless slate">
	<div class="ts segment" style="width:100%;">
		<div class="ts header">
			Add new Wi-Fi network
			<div class="sub header">Connect Wi-Fi.</div>
		</div>
	</div>
	<div class="ts container">


	</div>
</div>
<br>
<div class="ts container">
<form id="form" class="ts form" id="wifi" action="">
    <div class="field">
        <label>Encryption method</label>
        <select name="encryption" id="encryption">
			<option>Select</option>
            <option id="WPA2">WPA2</option>
            <option id="802.1x">802.1x</option>
            <option id="no">no</option>
        </select>
    </div>
	<div id="info"></div>
</form>
	<br><button class="ts button" onclick="submit()">Add</button>	
		
	</div>
	
<div id="msgbox" class="ts bottom right snackbar">
    <div class="content">
        Your request is processing now.
    </div>
</div>
<script>
startup();



function startup(){
//Please ADD ALL LOAD ON STARTUP SCRIPT HERE

}

$( "#encryption" ).change(function() {
  form(this);
});

function form(method){
if($(method).val() == "WPA2"){
	$( "#info" ).html('<div class="sixteen wide field"><input id="ssid" name="ssid" placeholder="SSID" type="text"></div><div class="sixteen wide field"><input id="psk" name="psk" placeholder="Password" type="password"></div>');
}else if($(method).val() == "802.1x"){
	$( "#info" ).html('<div class="sixteen wide field"><input id="ssid" name="ssid" placeholder="SSID" type="text"></div><div class="sixteen wide field"><input id="identity" name="identity" placeholder="Username" type="text"></div><div class="sixteen wide field"><input ut id="psk" name="psk" placeholder="Password" type="password"></div>');
}else if($(method).val() == "no"){
	$( "#info" ).html('<div class="sixteen wide field"><input id="ssid" name="ssid" placeholder="SSID" type="text"></div>');
}
}

function msg(content) {
		ts('.snackbar').snackbar({
			content: content,
			actionEmphasis: 'negative',
		});
}
	
function submit(){
	$.post( "opr.php?opr=addwifi", $( "#form" ).serialize()).done(function() {
		msg("WPA Updated. Restarting wireless interface services.");
	$.ajax({url:"opr.php?opr=restart",async:false});
		msg('Added Wi-Fi Network.');
		scannetwork();
  })
  .fail(function() {
    msg( "Failed" );
  });
}	
</script>

</body>
</html>