+
USB Checkout History
+<%
+' Connect to shopdb for USB history
+Dim objConnShopdb, shopdbAvailable
+shopdbAvailable = False
+
+On Error Resume Next
+Set objConnShopdb = Server.CreateObject("ADODB.Connection")
+objConnShopdb.ConnectionString = "Driver={MySQL ODBC 9.4 Unicode Driver};" & _
+ "Server=192.168.122.1;Port=3306;Database=shopdb;" & _
+ "User=570005354;Password=570005354;Option=3;"
+objConnShopdb.Open
+If Err.Number = 0 Then
+ shopdbAvailable = True
Else
- ' Look up person in appowners table
- Dim cmdOwner, rsOwner, personName
- Dim ownerSQL
- ownerSQL = "SELECT appowner FROM appowners WHERE sso = ? AND isactive = 1"
+ Err.Clear
+End If
+On Error Goto 0
- 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)
+If shopdbAvailable And IsNumeric(sso) Then
+ ' 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 rsOwner = cmdOwner.Execute
+ Set cmdStats = Server.CreateObject("ADODB.Command")
+ cmdStats.ActiveConnection = objConnShopdb
+ cmdStats.CommandText = statsSQL
+ cmdStats.CommandType = 1
+ cmdStats.Parameters.Append cmdStats.CreateParameter("@sso", 200, 1, 20, sso)
- If Not rsOwner.EOF Then
- personName = rsOwner("appowner") & ""
- Else
- personName = ""
- End If
+ On Error Resume Next
+ Set rsStats = cmdStats.Execute
- rsOwner.Close
- Set rsOwner = Nothing
- Set cmdOwner = Nothing
+ If Err.Number = 0 And Not rsStats.EOF Then
+ If IsNull(rsStats("total_checkouts")) Then
+ totalCheckouts = 0
+ Else
+ totalCheckouts = CLng(rsStats("total_checkouts") & "")
+ End If
- ' 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 = ?"
+ If IsNull(rsStats("active_checkouts")) Then
+ activeCheckouts = 0
+ Else
+ activeCheckouts = CLng(rsStats("active_checkouts") & "")
+ End If
- 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)
+ If IsNull(rsStats("avg_duration")) Then
+ avgDuration = 0
+ Else
+ avgDuration = CLng(rsStats("avg_duration") & "")
+ End If
+ Else
+ totalCheckouts = 0
+ activeCheckouts = 0
+ avgDuration = 0
+ End If
+ On Error Goto 0
- Set rsStats = cmdStats.Execute
+ If Not rsStats Is Nothing Then rsStats.Close
+ Set rsStats = Nothing
+ Set cmdStats = Nothing
- 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
+ ' 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
%>
+
+
+
+
+
+
<%=totalCheckouts%>
+ Total Checkouts
+
+
+
+
+ <% If activeCheckouts > 0 Then %>
+
+ <% Else %>
+
+ <% End If %>
+
<%=activeCheckouts%>
+ Currently Out
+
+
+
+
+
+
<%=avgDurationText%>
+ Avg Duration
+
+
+
-
-
-
-
-
-
-
-
-
-
- <% 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 |
-
-
-
-
+
+
+
+
+ | USB Device |
+ Checkout |
+ Check-in |
+ Duration |
+ Wiped |
+
+
+
<%
- ' 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"
+ ' 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 cmdHistory = Server.CreateObject("ADODB.Command")
+ cmdHistory.ActiveConnection = objConnShopdb
+ cmdHistory.CommandText = historySQL
+ cmdHistory.CommandType = 1
+ cmdHistory.Parameters.Append cmdHistory.CreateParameter("@sso", 200, 1, 20, sso)
- Set rsHistory = cmdHistory.Execute
+ On Error Resume Next
+ Set rsHistory = cmdHistory.Execute
+ On Error Goto 0
- Dim rowCount
- rowCount = 0
+ Dim rowCount
+ rowCount = 0
- While Not rsHistory.EOF
- rowCount = rowCount + 1
- Dim serialNum, usbAlias, checkoutTime, checkinTime, durationMinutes, reason
- Dim durationText, wipedText, statusClass
+ If Not rsHistory Is Nothing Then
+ Do While Not rsHistory.EOF
+ rowCount = rowCount + 1
+ Dim serialNum, usbAlias, checkoutTime, checkinTime, durationMinutes
+ Dim durationText, wipedText, statusClass
- serialNum = rsHistory("serialnumber") & ""
- usbAlias = rsHistory("alias") & ""
- reason = rsHistory("checkout_reason") & ""
+ serialNum = rsHistory("serialnumber") & ""
+ usbAlias = rsHistory("alias") & ""
- If IsNull(rsHistory("duration_minutes")) Or rsHistory("duration_minutes") = "" Then
- durationMinutes = 0
- Else
- durationMinutes = CLng(rsHistory("duration_minutes"))
- End If
+ If IsNull(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 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 check-in time and determine status
+ 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 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
+ ' Format wiped status
+ If IsNull(rsHistory("was_wiped")) Then
+ wipedText = "-"
+ ElseIf rsHistory("was_wiped") = 1 Then
+ wipedText = "Yes"
+ Else
+ wipedText = "No"
+ End If
+
+ ' Build device display
+ Dim deviceDisplay
+ If usbAlias <> "" And usbAlias <> serialNum Then
+ deviceDisplay = Server.HTMLEncode(serialNum) & "
" & Server.HTMLEncode(usbAlias) & ""
+ Else
+ deviceDisplay = Server.HTMLEncode(serialNum)
+ End If
%>
-
-
- " title="View all checkouts for this device">
- <%=Server.HTMLEncode(serialNum)%>
+
+ | <%=deviceDisplay%> |
+ <%=checkoutTime%> |
+ <%=checkinTime%> |
+ <%=durationText%> |
+ <%=wipedText%> |
+
+<%
+ rsHistory.MoveNext
+ Loop
+
+ rsHistory.Close
+ Set rsHistory = Nothing
+ End If
+ Set cmdHistory = Nothing
+
+ If rowCount = 0 Then
+%>
+
+ |
+ No USB checkout history
+ |
+
+<%
+ End If
+
+ ' Close shopdb connection
+ objConnShopdb.Close
+ Set objConnShopdb = Nothing
+Else
+ ' ShopDB not available
+%>
+
+ USB checkout history not available.
+
+<%
+End If
+%>
+ |
+
+
+
+
+
+ View Full History
-
-
<%=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
-%>
-
-
-
-
-
-
+
+
-