<!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
%>
<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="row">
        <div class="col-xl-auto">
          <div class="card">
            <div class="card-body">
<%
    Dim filterType
    filterType = Request.QueryString("filter")
    If filterType = "" Then filterType = "installable"
%>
              <div style="margin-bottom:15px;">
                <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">
                  <h5 class="card-title" style="margin:0;">Applications</h5>
                  <div>
                    <a href="./addapplication.asp" class="btn btn-primary">
                      <i class="zmdi zmdi-plus-circle"></i> Add Application
                    </a>
                  </div>
                </div>
                <div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">
                  <select id="filterSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('filter', this.value)">
                    <option value="installable" <%If filterType = "installable" Then Response.Write("selected") End If%>>Installable Applications</option>
                    <option value="all" <%If filterType = "all" Then Response.Write("selected") End If%>>All Applications</option>
                  </select>
                  <% If filterType <> "" And filterType <> "installable" Then %>
                  <a href="displayapplications.asp" class="btn btn-outline-secondary btn-sm">
                    <i class="zmdi zmdi-close"></i> Clear
                  </a>
                  <% End If %>
                </div>
              </div>
			  <div class="table-responsive">
              <table class="table table-hover">
                <thead>
                  <tr>
                    <th scope="col">Files</th>
                    <th scope="col">Docs</th>
                    <th scope="col">App Name</th>
                    <th scope="col">Support DL</th>
                    <th scope="col">App Owner</th>
                  </tr>
                </thead>
                <tbody>

<%
	' Build SQL query based on filter
	Dim strSQL
	strSQL = "SELECT * FROM applications,supportteams, appowners WHERE " &_
			"applications.supportteamid=supportteams.supporteamid AND " &_
			"supportteams.appownerid=appowners.appownerid AND applications.isactive=1"

	' Add isinstallable filter if showing only installable apps (default)
	If filterType = "installable" Then
		strSQL = strSQL & " AND applications.isinstallable=1"
	End If

	strSQL = strSQL & " Order By appname ASC"

	set rs = objconn.Execute(strSQL)
	
	while not rs.eof
		response.write("<tr>")
	' Show download icon if installpath is set, or if applicationlink is set as fallback
	IF Not IsNull(rs("installpath")) And rs("installpath") <> "" THEN
		response.write("<td><a href='" &rs("installpath") &"' title='Link To Installation Files' target='_blank'><i class='zmdi zmdi-download' style='color:#fff;' title='Click for Installation Files'></i></a></td>")
	ELSEIF Not IsNull(rs("applicationlink")) And rs("applicationlink") <> "" THEN
		response.write("<td><a href='" &rs("applicationlink") &"' title='Link To Application' target='_blank'><i class='zmdi zmdi-download' style='color:#fff;' title='Click for Application Link'></i></a></td>")
	ELSE
		response.write("<td>&nbsp;</td>")
	END IF
	IF Not IsNull(rs("documentationpath")) And rs("documentationpath") <> "" THEN
		response.write("<td><a href='" &rs("documentationpath") &"' target='_blank'><i class='zmdi zmdi-info-outline' style='color:#fff;' title='Click for Documentation'></i></a></td>")
	ELSE
		response.write("<td>&nbsp;</td>")
	END IF
	response.write("<td title='" &rs("applicationnotes") &"'><a href='displayapplication.asp?appid=" &rs("appid") &"'>" &rs("appname") &"</a></td>")
	response.write("<td font size='10px'>")
	response.write(rs("teamname"))
	response.write("</td>")
	response.write("<td>")
	response.write("<a href='MSTeams:/l/chat/0/0?users=" &rs("sso") &"@geaerospace.com' title='Click here to Chat on Teams'>" &rs("appowner") &"</a>")
	response.write("</td>")
	response.write("<td>")
	response.write(rs("sso"))
	response.write("</td>")
	response.write("</tr>")
	rs.movenext
	wend
	objConn.Close 

%>
                </tbody>
              </table>
            </div>
            </div>
          </div>
        </div>
      </div><!--End Row-->

    <!-- 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>
    </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>

  <!-- Filter update script -->
  <script>
  function updateFilter(param, value) {
      var url = new URL(window.location.href);
      var params = new URLSearchParams(url.search);

      if (value === '') {
          params.delete(param);
      } else {
          params.set(param, value);
      }

      window.location.href = 'displayapplications.asp' + (params.toString() ? '?' + params.toString() : '');
  }
  </script>

</body>
</html>
