<?PHP
/* Copyright 2010, Lime Technology LLC.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 */
/* Adapted by Bergware International (May 2012) */
?>
<form name="network_settings" method="POST" action="/update.htm" target="progressFrame">
<table class="settings">
  <tr>
  <td>MAC address:</td>
  <td><?=$var['HWADDR'];?></td>
  </tr>
  <tr>
  <td>Obtain IP address automatically: </td>
  <td><select name="USE_DHCP" size="1" onchange="checkNetworkSettings(this.form);">
  <?=mk_option($var['USE_DHCP'], "yes", "Yes");?>
  <?=mk_option($var['USE_DHCP'], "no", "No");?>
  </select></td>
  </tr>
  <tr>
  <td>IP address:</td>
  <td><input type="text" name="IPADDR" maxlength="40" value="<?=$var['IPADDR'];?>"></td>
  </tr>
  <tr>
  <td>Network mask:</td>
  <td><input type="text" name="NETMASK" maxlength="40" value="<?=$var['NETMASK'];?>"></td>
  </tr>
  <tr>
  <td>Gateway:</td>
  <td><input type="text" name="GATEWAY" maxlength="40" value="<?=$var['GATEWAY'];?>"></td>
  </tr>
  <tr>
  <td>Obtain DNS server address automatically: </td>
  <td><select name="DHCP_KEEPRESOLV" size="1" onchange="checkNetworkSettings(this.form);">
  <?=mk_option($var['DHCP_KEEPRESOLV'], "yes", "No");?>
  <?=mk_option($var['DHCP_KEEPRESOLV'], "no", "Yes");?>
  </select></td>
  </tr>
  <tr>
  <td>DNS server 1:</td>
  <td><input type="text" name="DNS_SERVER1" maxlength="80" value="<?=$var['DNS_SERVER1'];?>"></td>
  </tr>
  <tr>
  <td>DNS server 2:</td>
  <td><input type="text" name="DNS_SERVER2" maxlength="80" value="<?=$var['DNS_SERVER2'];?>"></td>
  </tr>
  <tr>
  <td>DNS server 3:</td>
  <td><input type="text" name="DNS_SERVER3" maxlength="80" value="<?=$var['DNS_SERVER3'];?>"></td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" name="changeNetwork" value="Apply"><button type="button" onClick="done();">Done</button></td>
  </tr>
</table>
</form>

<script>
$(document).ready(function() {
  checkNetworkSettings(document.network_settings);
});
function checkNetworkSettings(form) {
  if (form.USE_DHCP.value=="yes") {
    form.IPADDR.disabled=true;
    form.NETMASK.disabled=true;
    form.GATEWAY.disabled=true;
    form.DHCP_KEEPRESOLV.disabled=false;
    if (form.DHCP_KEEPRESOLV.value == "yes") {
      form.DNS_SERVER1.disabled=false;
      form.DNS_SERVER2.disabled=false;
      form.DNS_SERVER3.disabled=false;
    } else {
      form.DNS_SERVER1.disabled=true;
      form.DNS_SERVER2.disabled=true;
      form.DNS_SERVER3.disabled=true;
    }
  } else {
    form.IPADDR.disabled=false;
    form.NETMASK.disabled=false;
    form.GATEWAY.disabled=false;
    form.DHCP_KEEPRESOLV.value = "yes";
    form.DHCP_KEEPRESOLV.disabled=true;
    form.DNS_SERVER1.disabled=false;
    form.DNS_SERVER2.disabled=false;
    form.DNS_SERVER3.disabled=false;
  }
}
</script>