<%
If Not validSSO Then
%>
<%
Else
' Look up person in appowners table
Dim cmdOwner, rsOwner, personName
Dim ownerSQL
ownerSQL = "SELECT appowner FROM appowners WHERE sso = ? AND isactive = 1"
Set cmdOwner = Server.CreateObject("ADODB.Command")
cmdOwner.ActiveConnection = objConn
cmdOwner.CommandText = ownerSQL
cmdOwner.CommandType = 1
cmdOwner.Parameters.Append cmdOwner.CreateParameter("@sso", 200, 1, 20, ssoParam)
Set rsOwner = cmdOwner.Execute
If Not rsOwner.EOF Then
personName = rsOwner("appowner") & ""
Else
personName = ""
End If
rsOwner.Close
Set rsOwner = Nothing
Set cmdOwner = Nothing
' Get USB checkout statistics
Dim cmdStats, rsStats
Dim totalCheckouts, activeCheckouts, avgDuration
Dim statsSQL
statsSQL = "SELECT " & _
"COUNT(*) AS total_checkouts, " & _
"SUM(CASE WHEN checkin_time IS NULL THEN 1 ELSE 0 END) AS active_checkouts, " & _
"AVG(TIMESTAMPDIFF(MINUTE, checkout_time, COALESCE(checkin_time, NOW()))) AS avg_duration " & _
"FROM usb_checkouts WHERE sso = ?"
Set cmdStats = Server.CreateObject("ADODB.Command")
cmdStats.ActiveConnection = objConn
cmdStats.CommandText = statsSQL
cmdStats.CommandType = 1
cmdStats.Parameters.Append cmdStats.CreateParameter("@sso", 200, 1, 20, ssoParam)
Set rsStats = cmdStats.Execute
If Not rsStats.EOF Then
If IsNull(rsStats("total_checkouts")) Or rsStats("total_checkouts") = "" Then
totalCheckouts = 0
Else
totalCheckouts = CLng(rsStats("total_checkouts"))
End If
If IsNull(rsStats("active_checkouts")) Or rsStats("active_checkouts") = "" Then
activeCheckouts = 0
Else
activeCheckouts = CLng(rsStats("active_checkouts"))
End If
If IsNull(rsStats("avg_duration")) Or rsStats("avg_duration") = "" Then
avgDuration = 0
Else
avgDuration = CLng(rsStats("avg_duration"))
End If
Else
totalCheckouts = 0
activeCheckouts = 0
avgDuration = 0
End If
rsStats.Close
Set rsStats = Nothing
Set cmdStats = Nothing
' Format average duration
Dim avgDurationText
If avgDuration < 60 Then
avgDurationText = avgDuration & " min"
ElseIf avgDuration < 1440 Then
avgDurationText = Int(avgDuration / 60) & "h " & (avgDuration Mod 60) & "m"
Else
avgDurationText = Int(avgDuration / 1440) & "d " & Int((avgDuration Mod 1440) / 60) & "h"
End If
%>
<% If personName <> "" Then %>
<%=Server.HTMLEncode(personName)%>
SSO: <%=Server.HTMLEncode(ssoParam)%>
<% Else %>
SSO: <%=Server.HTMLEncode(ssoParam)%>
User not found in directory
<% End If %>
<%=totalCheckouts%>
Total USB Checkouts
<% If activeCheckouts > 0 Then %>
<% Else %>
<% End If %>
<%=activeCheckouts%>
Currently Checked Out
<%=avgDurationText%>
Avg Checkout Duration
USB Checkout History
| USB Serial |
USB Name |
Checkout Time |
Check-in Time |
Duration |
Wiped |
Reason |
<%
' Get USB checkout history for this SSO
Dim cmdHistory, rsHistory
Dim historySQL
historySQL = "SELECT uc.*, m.serialnumber, m.alias, " & _
"TIMESTAMPDIFF(MINUTE, uc.checkout_time, COALESCE(uc.checkin_time, NOW())) AS duration_minutes " & _
"FROM usb_checkouts uc " & _
"JOIN machines m ON uc.machineid = m.machineid " & _
"WHERE uc.sso = ? " & _
"ORDER BY uc.checkout_time DESC"
Set cmdHistory = Server.CreateObject("ADODB.Command")
cmdHistory.ActiveConnection = objConn
cmdHistory.CommandText = historySQL
cmdHistory.CommandType = 1
cmdHistory.Parameters.Append cmdHistory.CreateParameter("@sso", 200, 1, 20, ssoParam)
Set rsHistory = cmdHistory.Execute
Dim rowCount
rowCount = 0
While Not rsHistory.EOF
rowCount = rowCount + 1
Dim serialNum, usbAlias, checkoutTime, checkinTime, durationMinutes, reason
Dim durationText, wipedText, statusClass
serialNum = rsHistory("serialnumber") & ""
usbAlias = rsHistory("alias") & ""
reason = rsHistory("checkout_reason") & ""
If IsNull(rsHistory("duration_minutes")) Or rsHistory("duration_minutes") = "" Then
durationMinutes = 0
Else
durationMinutes = CLng(rsHistory("duration_minutes"))
End If
' Format checkout time (MM/DD/YYYY h:mm AM/PM)
If Not IsNull(rsHistory("checkout_time")) Then
checkoutTime = Month(rsHistory("checkout_time")) & "/" & Day(rsHistory("checkout_time")) & "/" & Year(rsHistory("checkout_time")) & " " & FormatDateTime(rsHistory("checkout_time"), 3)
Else
checkoutTime = "-"
End If
' Format check-in time and determine status (MM/DD/YYYY h:mm AM/PM)
If Not IsNull(rsHistory("checkin_time")) Then
checkinTime = Month(rsHistory("checkin_time")) & "/" & Day(rsHistory("checkin_time")) & "/" & Year(rsHistory("checkin_time")) & " " & FormatDateTime(rsHistory("checkin_time"), 3)
statusClass = ""
Else
checkinTime = "Still Out"
statusClass = "table-warning"
End If
' Format duration
If durationMinutes < 60 Then
durationText = durationMinutes & " min"
ElseIf durationMinutes < 1440 Then
durationText = Int(durationMinutes / 60) & "h " & (durationMinutes Mod 60) & "m"
Else
durationText = Int(durationMinutes / 1440) & "d " & Int((durationMinutes Mod 1440) / 60) & "h"
End If
' Format wiped status
If IsNull(rsHistory("was_wiped")) Then
wipedText = "-"
ElseIf rsHistory("was_wiped") = 1 Then
wipedText = "Yes"
Else
wipedText = "No"
End If
%>
" title="View all checkouts for this device">
<%=Server.HTMLEncode(serialNum)%>
|
<%=Server.HTMLEncode(usbAlias)%> |
<%=checkoutTime%> |
<%=checkinTime%> |
<%=durationText%> |
<%=wipedText%> |
<% If reason <> "" Then %>
<%=Server.HTMLEncode(Left(reason, 40))%><% If Len(reason) > 40 Then Response.Write("...") End If %>
<% Else %>
-
<% End If %>
|
<%
rsHistory.MoveNext
Wend
rsHistory.Close
Set rsHistory = Nothing
Set cmdHistory = Nothing
If rowCount = 0 Then
%>
No USB checkout history for this SSO.
|
<%
End If
%>
<%
End If ' validSSO
%>