<!DOCTYPE html>
<html lang="en">
<head>
  <!--#include file="./includes/header.asp"-->
  <!--#include file="./includes/sql.asp"-->
</head>

<%
	theme = Request.Cookies("theme")
	IF theme = "" THEN
		theme="bg-theme1"
	END IF

	search	=	Request.Querystring("search")

'----------------------------------------------------Is this the IP address of a printer??? ----------------------------------------------

		IF search <> "" THEN	
			strSQL	=	"Select printerid FROM printers where ipaddress='" &search &"'"
			set rs = objconn.Execute(strSQL)
			IF NOT rs.EOF THEN
				printerid		=	rs("printerid")
				objConn.Close
				Response.Redirect "./displayprinter.asp?printerid="&printerid
			END IF
		END IF	
'-------------------------------------------------------Is this the IP address of a PC---------------------------------------------------
		IF search <> "" THEN
			' PHASE 2: Query communications table instead of networkinterfaces
			strSQL	=	"SELECT c.machineid FROM communications c JOIN machines m ON c.machineid = m.machineid WHERE c.address='" &search &"' AND m.pctypeid IS NOT NULL LIMIT 1"
			set rs = objconn.Execute(strSQL)
			IF NOT rs.EOF THEN
				machineid		=	rs("machineid")
				objConn.Close
				Response.Redirect "./displaypc.asp?machineid="&machineid
			END IF
		END IF	

'-----------------------------------------------------------------------------------------------------------------------------------------

		subnetid	=	Request.Querystring("subnetid")
		strSQL 	=	"SELECT *,INET_NTOA(ipstart) AS subnetstart FROM subnets,subnettypes WHERE subnets.subnettypeid=subnettypes.subnettypeid AND subnets.isactive=1 AND subnetid="&subnetid
		set rs = objconn.Execute(strSQL)
		ipdiff		=	rs("ipend")-rs("ipstart")
		'response.write(ipdiff)


%>	



<body class="bg-theme <%Response.Write(theme)%>">

<!-- start loader -->
   <div id="pageloader-overlay" class="visible incoming"><div class="loader-wrapper-outer"><div class="loader-wrapper-inner" ><div class="loader"></div></div></div></div>
   <!-- end loader -->
<!-- Start wrapper-->
 <div id="wrapper">
  <!--#include file="./includes/leftsidebar.asp"-->
<!--Start topbar header-->
  <!--#include file="./includes/topbarheader.asp"-->
<!--End topbar header-->
<div class="clearfix"></div>
	
  <div class="content-wrapper">
    <div class="container-fluid">
      <div class="row mt-4">
        <div class="col-lg-auto">
          <div class="card">
            <div class="card-body">
            <ul class="nav nav-tabs nav-tabs-primary top-icon nav-justified">
                <li class="nav-item">
                    <a href="javascript:void();" data-target="#edit" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-edit"></i> <span class="hidden-xs">Edit Subnet</span></a>
                </li>
            </ul>
            <div class="tab-content p-3">
                  	<div class="tab-pane" id="edit">
			  <div class="table-responsive">
               			<table class="table table-hover">
                 			<thead>
                    				<tr>
                      					<th scope="col">Vlan #</th>
                      					<th scope="col">Zone</th>
                     					<th scope="col">Network</th>
                      					<th scope="col">CIDR</th>
                      					<th scope="col">Description</th>
                   				</tr>
                 			 </thead>
                  		<tbody>
                    			<tr>
		      				<form method="post" action="./updatesubnetdirect.asp?subnetid=<%Response.Write(subnetid)%>">
                      				<th scope="row"><input class="form-control" type="text" name="vlan" size="4" value="<%Response.Write(rs("vlan"))%>"></th>
                      					<td><select name="subnettypeid"  class="btn btn-light px-3">
									<option value="<%Response.Write(rs("subnettypeid"))%>"><%Response.Write(rs("subnettype"))%></option>
<%
			strSQL2	=	"Select * FROM subnettypes where isactive=1 ORDER BY subnettype ASC"
			set rs2 = objconn.Execute(strSQL2)
			while not rs2.eof
					Response.Write("<option  class='btn' value='"&rs2("subnettypeid")&"'>"&rs2("subnettype")&"</option>")
			rs2.movenext
			wend
%>
				</select>
			</td>
                      <td><input class="form-control" type="text" name="ipstart" size="24" value="<%Response.Write(rs("subnetstart"))%>"></td>
                      <td><select name="cidr"  class="btn btn-light px-3">
                                                <option value="<%Response.Write(rs("cidr"))%>,<%Response.Write(ipdiff)%>"><%Response.Write(rs("cidr"))%></option>
                                                <option value="/30,3">/30</option>
                                                <option value="/29,7">/29</option>    
                                                <option value="/28,15">/28</option>
                                                <option value="/27,31">/27</option>
                                                <option value="/26,63">/26</option>    
                                                <option value="/25,127">/25</option> 
                                                <option value="/24,253">/24</option>
                                                <option value="/23,511">/23</option>    
                                                <option value="/22,1023">/22</option>   
                                                <option value="/21,2047">/21</option>
                                                <option value="/20,4095">/20</option>    
                                        </select>
			</td>
                      <td><input class="form-control" type="text" name="description" size="40" value="<%Response.Write(rs("description"))%>"></td>
                    </tr> 
                  </tbody>
                </table>
<div class="col-lg-4">
	<BR>
        <input type="submit" class="btn btn-primary" value="Update Subnet">
</div>
<BR>
</div>
</form>
		</div>
              <h5 class="card-title">Subnet Details</h5>
			  <div class="table-responsive">
               <table class="table table-hover">
                  <thead>
                    <tr>
                      <th scope="col">Vlan #</th>
                      <th scope="col">Zone</th>
                      <th scope="col">Network</th>
                      <th scope="col">CIDR</th>
                      <th scope="col">Description</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <th scope="row"><%Response.Write(rs("vlan"))%></th>
                      <td><%Response.Write(rs("subnettype"))%>	</td>
                      <td><%Response.Write(rs("subnetstart"))%></td>
                      <td><%Response.Write(rs("cidr"))%></td>
                      <td><%Response.Write(rs("description"))%></td>
                    </tr>
                  </tbody>
                </table>
            </div>
            </div>
          </div>
        </div>    <!-- End container-fluid-->
   </div><!--End content-wrapper-->
   <!--Start Back To Top Button-->
    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
    <!--End Back To Top Button-->
	
	<!--Start footer-->
	<footer class="footer">
      <div class="container">
        <div class="text-center">
        </div>
      </div>
    </footer>
	<!--End footer-->
  </div><!--End wrapper-->


  <!-- Bootstrap core JavaScript-->
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/popper.min.js"></script>
  <script src="assets/js/bootstrap.min.js"></script>
	
  <!-- simplebar js -->
  <script src="assets/plugins/simplebar/js/simplebar.js"></script>
  <!-- sidebar-menu js -->
  <script src="assets/js/sidebar-menu.js"></script>
  
  <!-- Custom scripts -->
  <script src="assets/js/app-script.js"></script>
	
</body>
</html>
<% 	objConn.Close %>