From a8fed88a18f9e894fb51b2920a5abeb050c6b7b5 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Sun, 7 Dec 2025 11:59:02 -0500 Subject: [PATCH] Fix displayprofile.asp to work with production employees database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Restored original structure using wjf_employees-sql.asp include - Added USB History tab with separate shopdb connection - Fixed 500 error caused by trying to handle missing employees DB - Employee profile now works on production, USB history gracefully degrades if shopdb unavailable - Added DataTables for USB checkout history display - Uses 12-hour date format (MM/DD/YYYY h:mm AM/PM) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- displayprofile.asp | 816 +++++++++++++++++++++++++++------------------ 1 file changed, 491 insertions(+), 325 deletions(-) diff --git a/displayprofile.asp b/displayprofile.asp index a744be5..f52a55b 100644 --- a/displayprofile.asp +++ b/displayprofile.asp @@ -2,33 +2,30 @@ - + <% - theme = Request.Cookies("theme") - IF theme = "" THEN - theme="bg-theme1" - END IF + theme = Request.Cookies("theme") + IF theme = "" THEN + theme="bg-theme1" + END IF - ' Get SSO parameter - Dim ssoParam - ssoParam = Trim(Request.QueryString("sso")) - - ' Validate SSO - must be 9 digits - Dim validSSO - validSSO = False - If ssoParam <> "" And Len(ssoParam) = 9 And IsNumeric(ssoParam) Then - validSSO = True - End If + sso = Request.Querystring("sso") %> -
+
+
+
+
+
+
+
@@ -38,362 +35,528 @@
+
-<% -If Not validSSO Then -%>
-
-
-
- -

Invalid SSO

-

Please provide a valid 9-digit SSO number.

- Go to Dashboard -
-
-
-
+
+
+
+ <% + + strSQL = "SELECT * from employees WHERE SSO="&sso + set rs = objconn.Execute(strSQL) + if rs.eof THEN + strSQL = "SELECT * from employees WHERE SSO=1" + set rs = objconn.Execute(strSQL) + END IF + +%> + + " alt="Card image cap"> +
+
+
<%Response.Write(rs("First_Name"))%> <%Response.Write(rs("Last_Name"))%>
+
+<% +' Easter Egg for SSO 570005354 +Dim showEasterEgg +showEasterEgg = False +On Error Resume Next +IF IsNumeric(sso) THEN + IF CLng(sso) = 570005354 THEN + showEasterEgg = True + END IF +END IF +On Error Goto 0 + +IF showEasterEgg THEN +%> +
+
+
ACHIEVEMENT UNLOCKED
+ Secret Developer Stats +
+
+
+
+
+

Caffeine Consumption147%

+
+
+
+
+
+
+
+
+
+
+
+

Bug Fixing Speed95%

+
+
+
+
+
+
+
+
+
+
+
+

Google-Fu99%

+
+
+
+
+
+
+
+
+
+
+
+

Database Tinkering88%

+
+
+
+
+
+
+
+
+
+
+
+

Debugging100%

+
+
+
+
+
+
+
+
+
+
+
+

Production Deployment Courage73%

+
+
+
+
+
+
+
+
+ Legacy Code Archaeologist + Documentation Writer (Rare!) +
+
+<% +ELSE +%> +
+
+
+ Advanced Technical Machinist +
+
+
+

Advanced Technical Machinist100%

+
+
+
+
+
+
+
+
+
skill img
+
+
+

Bootstrap 4 50%

+
+
+
+
+
+
+
+
+
skill img
+
+
+

AngularJS 70%

+
+
+
+
+
+
+
+
+
skill img
+
+
+

React JS 35%

+
+
+
+
+
+
+ +
+<% +END IF +%> +
+ +
+ +
+
+
+ +
+
+
Profile
+
+
+
<%Response.Write(rs("First_Name"))%> <%Response.Write(rs("Last_Name"))%>
+
SSO
+
Shift
+
Role
+
Team
+
PayNo
+
+
+
 
+
<%Response.Write(rs("SSO"))%>
+
<%Response.Write(rs("shift"))%>
+
<%Response.Write(rs("Role"))%>
+
<%Response.Write(rs("Team"))%>
+
<%Response.Write(rs("Payno"))%>
+
+
+ +
+ +
+
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 SerialUSB NameCheckout TimeCheck-in TimeDurationWipedReason
+ + + + + + + + + + <% - ' 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 %> - - + + + + + + +<% + rsHistory.MoveNext + Loop + + rsHistory.Close + Set rsHistory = Nothing + End If + Set cmdHistory = Nothing + + If rowCount = 0 Then +%> + + + +<% + End If + + ' Close shopdb connection + objConnShopdb.Close + Set objConnShopdb = Nothing +Else + ' ShopDB not available +%> +
+ USB checkout history not available. +
+<% +End If +%> + +
USB DeviceCheckoutCheck-inDurationWiped
- " title="View all checkouts for this device"> - <%=Server.HTMLEncode(serialNum)%> +
<%=deviceDisplay%><%=checkoutTime%><%=checkinTime%><%=durationText%><%=wipedText%>
+ No USB checkout history +
+
+ +
+ + 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 -%> - - - -
- - +
+
-
+
-<% -End If ' validSSO -%> +
+ + +
+
-
+
+ + + - - - - - -
-
-
+ +
+
+
+
-
-
- -
+ + + - - - - - - - - + + + + - - - + + + + - - + + + + + +