<%@ Language=VBScript %> <% Option Explicit Dim theme, strSQL, rs, objConn, rsRel %> <% theme = Request.Cookies("theme") IF theme = "" THEN theme="bg-theme1" END IF %>
Locations
<% ' Get all active locations with PC counts and relationship counts strSQL = "SELECT m.machineid, m.machinenumber, m.alias, m.machinenotes, m.mapleft, m.maptop, " & _ " (SELECT COUNT(*) FROM machinerelationships mr " & _ " JOIN machines pc ON mr.related_machineid = pc.machineid " & _ " WHERE mr.machineid = m.machineid AND mr.isactive = 1 AND pc.pctypeid IS NOT NULL AND pc.isactive = 1) AS pc_count, " & _ " (SELECT COUNT(*) FROM machinerelationships mr " & _ " JOIN machines child ON mr.related_machineid = child.machineid " & _ " WHERE mr.machineid = m.machineid AND mr.isactive = 1 AND child.islocationonly = 1 AND child.isactive = 1) AS sublocation_count " & _ "FROM machines m " & _ "WHERE m.islocationonly = 1 AND m.isactive = 1 AND m.machinenumber <> 'TBD' " & _ "ORDER BY m.machinenumber" Set rs = objConn.Execute(strSQL) ' Build a dictionary of all relationships for location machines ' Key = machineid, Value = array of relationship info Dim relDict, relSQL Set relDict = Server.CreateObject("Scripting.Dictionary") relSQL = "SELECT mr.machineid AS loc_id, child.machineid AS child_id, child.machinenumber AS child_name, " & _ " child.hostname AS child_hostname, child.alias AS child_alias, " & _ " child.pctypeid, child.islocationonly, " & _ " rt.relationshiptype, rt.relationshiptypeid, " & _ " GROUP_CONCAT(DISTINCT c.address ORDER BY c.address SEPARATOR ', ') AS child_ip " & _ "FROM machinerelationships mr " & _ "JOIN machines loc ON mr.machineid = loc.machineid " & _ "JOIN machines child ON mr.related_machineid = child.machineid " & _ "JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _ "LEFT JOIN communications c ON child.machineid = c.machineid AND c.comstypeid IN (1, 3) AND c.isactive = 1 " & _ "WHERE loc.islocationonly = 1 AND loc.isactive = 1 AND mr.isactive = 1 AND child.isactive = 1 " & _ "GROUP BY mr.machineid, child.machineid, child.machinenumber, child.hostname, child.alias, " & _ " child.pctypeid, child.islocationonly, rt.relationshiptype, rt.relationshiptypeid " & _ "ORDER BY mr.machineid, rt.relationshiptypeid, child.machinenumber" Set rsRel = objConn.Execute(relSQL) Dim curLocId Do While Not rsRel.EOF curLocId = CStr(rsRel("loc_id")) If Not relDict.Exists(curLocId) Then relDict.Add curLocId, "" End If ' Build pipe-delimited entries: child_id|child_name|child_hostname|child_alias|child_ip|pctypeid|islocationonly|relationshiptype Dim entry entry = rsRel("child_id") & "|" & (rsRel("child_name") & "") & "|" & (rsRel("child_hostname") & "") & "|" & _ (rsRel("child_alias") & "") & "|" & (rsRel("child_ip") & "") & "|" & _ (rsRel("pctypeid") & "") & "|" & (rsRel("islocationonly") & "") & "|" & (rsRel("relationshiptype") & "") If relDict(curLocId) <> "" Then relDict(curLocId) = relDict(curLocId) & "~" & entry Else relDict(curLocId) = entry End If rsRel.MoveNext Loop rsRel.Close Set rsRel = Nothing %>
<% Do While Not rs.EOF Dim locName, locAlias, locNotes, pcCount, subCount, hasMap, mid, totalRels mid = rs("machineid") locName = rs("machinenumber") & "" locAlias = rs("alias") & "" locNotes = rs("machinenotes") & "" pcCount = CLng(rs("pc_count") & "") subCount = CLng(rs("sublocation_count") & "") hasMap = Not (IsNull(rs("mapleft")) Or IsNull(rs("maptop"))) totalRels = pcCount + subCount ' Check if this location has any relationships in our dict Dim hasRels, midStr midStr = CStr(mid) hasRels = relDict.Exists(midStr) And relDict(midStr) <> "" %> class="loc-parent" data-mid="<%=mid%>" style="cursor:pointer;"<% End If %>> <% ' Render hidden detail rows for this location's relationships If hasRels Then Dim entries, i, parts entries = Split(relDict(midStr), "~") For i = 0 To UBound(entries) parts = Split(entries(i), "|") ' parts: 0=child_id, 1=child_name, 2=child_hostname, 3=child_alias, 4=child_ip, 5=pctypeid, 6=islocationonly, 7=relationshiptype Dim cId, cName, cHost, cAlias, cIp, cIsPC, cIsLoc, cRelType, cBadgeClass, cIcon, cLink cId = parts(0) cName = parts(1) cHost = parts(2) cAlias = parts(3) cIp = parts(4) cIsPC = (parts(5) <> "") cIsLoc = (parts(6) = "1" Or parts(6) = "True") cRelType = parts(7) ' Determine icon and badge If cIsLoc Then cIcon = "zmdi zmdi-pin text-info" cBadgeClass = "badge-info" cLink = "displaymachine.asp?machineid=" & cId ElseIf cIsPC Then cIcon = "zmdi zmdi-desktop-windows text-primary" cBadgeClass = "badge-primary" cLink = "displaypc.asp?machineid=" & cId Else cIcon = "zmdi zmdi-memory text-warning" cBadgeClass = "badge-warning" cLink = "displaymachine.asp?machineid=" & cId End If ' Display name: use hostname for PCs if available, else machinenumber Dim displayName If cIsPC And cHost <> "" Then displayName = cHost Else displayName = cName End If %> <% Next End If rs.MoveNext Loop rs.Close Set rs = Nothing Set relDict = Nothing %>
Location Alias PCs Sub-locations Map Notes Actions
<% If hasRels Then %> <% End If %> <%=Server.HTMLEncode(locName)%> <%=Server.HTMLEncode(locAlias)%> <% If pcCount > 0 Then %> <%=pcCount%> <% Else %> 0 <% End If %> <% If subCount > 0 Then %> <%=subCount%> <% Else %> 0 <% End If %> <% If hasMap Then %> <% Else %> <% End If %> <% If Len(locNotes) > 40 Then Response.Write(Server.HTMLEncode(Left(locNotes, 40)) & "...") Else Response.Write(Server.HTMLEncode(locNotes)) End If %>
<% objConn.Close %>