Files
shopdb/savecheckin_usb.asp
cproudlock 65b622c361 Add USB checkout system and SSO profile page
New Features:
- USB Device checkout/check-in system with barcode scanning
  - displayusb.asp: List all USB devices with status
  - addusb.asp: Add new USB devices via barcode scan
  - checkout_usb.asp/savecheckout_usb.asp: Check out USB to SSO
  - checkin_usb.asp/savecheckin_usb.asp: Check in with wipe confirmation
  - usb_history.asp: Full checkout history with filters
  - api_usb.asp: JSON API for AJAX lookups
- displayprofile.asp: SSO profile page showing user info and USB history
- Date/time format changed to 12-hour (MM/DD/YYYY h:mm AM/PM)
- SSO links in USB history now link to profile page via search

Database:
- New machinetypeid 44 for USB devices
- New usb_checkouts table for tracking checkouts

Cleanup:
- Removed v2 folder (duplicate/old files)
- Removed old debug/test files
- Removed completed migration documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 11:16:14 -05:00

110 lines
3.5 KiB
Plaintext

<%
'=============================================================================
' FILE: savecheckin_usb.asp
' PURPOSE: Process USB check-in request
' SECURITY: Parameterized queries, input validation
' CREATED: 2025-12-07
'=============================================================================
%>
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/response.asp"-->
<%
' Get form values
Dim checkoutid, waswiped, notes
checkoutid = Trim(Request.Form("checkoutid"))
waswiped = Trim(Request.Form("waswiped"))
notes = Trim(Request.Form("notes"))
' Validate checkoutid
If checkoutid = "" Or Not IsNumeric(checkoutid) Then
objConn.Close
ShowError "Invalid checkout ID.", "checkin_usb.asp"
Response.End
End If
' Validate waswiped - must be checked (value = "1")
Dim wipedValue
If waswiped = "1" Then
wipedValue = 1
Else
objConn.Close
ShowError "You must confirm the USB has been wiped before check-in.", "checkin_usb.asp"
Response.End
End If
' Verify the checkout record exists and is still open
Dim checkSQL, cmdCheck, rsCheck
checkSQL = "SELECT uc.checkoutid, uc.machineid, uc.sso, m.serialnumber, m.alias " & _
"FROM usb_checkouts uc " & _
"JOIN machines m ON uc.machineid = m.machineid " & _
"WHERE uc.checkoutid = ? AND uc.checkin_time IS NULL"
Set cmdCheck = Server.CreateObject("ADODB.Command")
cmdCheck.ActiveConnection = objConn
cmdCheck.CommandText = checkSQL
cmdCheck.CommandType = 1
cmdCheck.Parameters.Append cmdCheck.CreateParameter("@checkoutid", 3, 1, , CLng(checkoutid))
Set rsCheck = cmdCheck.Execute
If rsCheck.EOF Then
rsCheck.Close
Set rsCheck = Nothing
Set cmdCheck = Nothing
objConn.Close
ShowError "Checkout record not found or already checked in.", "checkin_usb.asp"
Response.End
End If
Dim serialnumber, usbAlias, sso
serialnumber = rsCheck("serialnumber") & ""
usbAlias = rsCheck("alias") & ""
sso = rsCheck("sso") & ""
rsCheck.Close
Set rsCheck = Nothing
Set cmdCheck = Nothing
' Update checkout record with check-in info
Dim updateSQL, cmdUpdate
updateSQL = "UPDATE usb_checkouts SET checkin_time = NOW(), was_wiped = ?, checkin_notes = ? WHERE checkoutid = ?"
Set cmdUpdate = Server.CreateObject("ADODB.Command")
cmdUpdate.ActiveConnection = objConn
cmdUpdate.CommandText = updateSQL
cmdUpdate.CommandType = 1
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@waswiped", 3, 1, , wipedValue)
If notes = "" Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@notes", 200, 1, 1000, Null)
Else
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@notes", 200, 1, 1000, notes)
End If
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@checkoutid", 3, 1, , CLng(checkoutid))
On Error Resume Next
cmdUpdate.Execute
If Err.Number = 0 Then
Set cmdUpdate = Nothing
objConn.Close
' Build display name
Dim displayName
If usbAlias <> "" And usbAlias <> serialnumber Then
displayName = serialnumber & " (" & usbAlias & ")"
Else
displayName = serialnumber
End If
ShowSuccess "USB '" & Server.HTMLEncode(displayName) & "' checked in successfully. Previously held by SSO " & Server.HTMLEncode(sso) & ".", "displayusb.asp", "USB Check-in"
Else
Dim updateErr
updateErr = Err.Description
Set cmdUpdate = Nothing
objConn.Close
ShowError "Error checking in USB: " & Server.HTMLEncode(updateErr), "checkin_usb.asp"
End If
%>