diff --git a/api.asp b/api.asp index 7f83b79..be7ca55 100644 --- a/api.asp +++ b/api.asp @@ -45,6 +45,8 @@ Select Case action GetDashboardData() Case "getShopfloorPCs" GetShopfloorPCs() + Case "getHighUptimePCs" + GetHighUptimePCs() Case "getRecordedIP" GetRecordedIP() Case "updateMachinePositions" @@ -57,6 +59,8 @@ Select Case action GetUDCMachineStats() Case "getUDCManualTiming" GetUDCManualTiming() + Case "getDeployableApps" + GetDeployableApps() Case Else SendError "Invalid action: " & action End Select @@ -272,6 +276,10 @@ Sub UpdateCompleteAsset() pctypeId = 9 Case "PART MARKER", "PARTMARKER" pctypeId = 10 + Case "DASHBOARD" + pctypeId = 11 + Case "LOBBY DISPLAY", "LOBBYDISPLAY", "LOBBY-DISPLAY" + pctypeId = 12 Case "MEASURING", "MEASURING TOOL" pctypeId = 7 Case Else @@ -831,24 +839,52 @@ Sub GetShopfloorPCs() ' Returns list of all active PCs with shop floor IPs (10.134.*) for remote management ' This includes all PC types: Shopfloor, CMM, Wax Trace, Keyence, etc. ' PCs are identified by machinetypeid >= 33, pctypeid can be NULL + ' Optional filters: pctypeid, businessunitid On Error Resume Next Dim rsPC, strSQL, pcList, pcCount, pcData + Dim filterPcTypeId, filterBusinessUnitId, whereClause + + ' Get optional filter parameters + filterPcTypeId = Request.QueryString("pctypeid") + filterBusinessUnitId = Request.QueryString("businessunitid") + + ' Build WHERE clause with optional filters + ' Dashboard (11) and Lobby Display (12) can be on any subnet, others require 10.134.* + whereClause = "WHERE m.isactive = 1 " & _ + "AND m.machinetypeid >= 33 " + + ' Add pctypeid filter if provided + If filterPcTypeId <> "" And IsNumeric(filterPcTypeId) Then + whereClause = whereClause & "AND m.pctypeid = " & CInt(filterPcTypeId) & " " + ' Skip IP filter for Dashboard (11) and Lobby Display (12) - they can be on any subnet + If CInt(filterPcTypeId) <> 11 And CInt(filterPcTypeId) <> 12 Then + whereClause = whereClause & "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') " + End If + Else + ' No pctype filter - only return shopfloor IPs (10.134.*) by default + whereClause = whereClause & "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') " + End If + + ' Add businessunitid filter if provided + If filterBusinessUnitId <> "" And IsNumeric(filterBusinessUnitId) Then + whereClause = whereClause & "AND m.businessunitid = " & CInt(filterBusinessUnitId) & " " + End If ' Query all active PCs with shop floor IP addresses (10.134.*) ' - machinetypeid >= 33 ensures we only get PCs (not equipment) ' - LEFT JOIN pctype to include PCs with NULL pctypeid ' - EXISTS subquery finds any PC with a 10.134.* address strSQL = "SELECT m.machineid, m.hostname, m.machinenumber, m.serialnumber, " & _ - "m.loggedinuser, m.lastupdated, " & _ + "m.loggedinuser, m.lastupdated, m.pctypeid, m.businessunitid, " & _ "c.address AS ipaddress, " & _ - "COALESCE(pt.typename, 'Uncategorized') AS pctype " & _ + "COALESCE(pt.typename, 'Uncategorized') AS pctype, " & _ + "COALESCE(bu.businessunit, 'TBD') AS businessunit " & _ "FROM machines m " & _ "LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ "LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _ - "WHERE m.isactive = 1 " & _ - "AND m.machinetypeid >= 33 " & _ - "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') " & _ + "LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _ + whereClause & _ "ORDER BY m.hostname ASC" Set rsPC = objConn.Execute(strSQL) @@ -874,6 +910,17 @@ Sub GetShopfloorPCs() pcData = pcData & """ipaddress"":""" & EscapeJSON(rsPC("ipaddress") & "") & """," pcData = pcData & """loggedinuser"":""" & EscapeJSON(rsPC("loggedinuser") & "") & """," pcData = pcData & """pctype"":""" & EscapeJSON(rsPC("pctype") & "") & """," + If IsNull(rsPC("pctypeid")) Then + pcData = pcData & """pctypeid"":null," + Else + pcData = pcData & """pctypeid"":" & rsPC("pctypeid") & "," + End If + pcData = pcData & """businessunit"":""" & EscapeJSON(rsPC("businessunit") & "") & """," + If IsNull(rsPC("businessunitid")) Then + pcData = pcData & """businessunitid"":null," + Else + pcData = pcData & """businessunitid"":" & rsPC("businessunitid") & "," + End If ' Handle lastupdated date If Not IsNull(rsPC("lastupdated")) Then @@ -896,6 +943,103 @@ Sub GetShopfloorPCs() Response.Write "{""success"":true,""count"":" & pcCount & ",""data"":[" & pcList & "]}" End Sub +Sub GetHighUptimePCs() + ' Returns list of PCs with uptime >= specified days (for reboot management) + On Error Resume Next + + Dim rsPC, strSQL, pcList, pcCount, pcData + Dim minUptime + + ' Get minimum uptime parameter (required) + minUptime = Request.QueryString("minUptime") + If minUptime = "" Or Not IsNumeric(minUptime) Then + minUptime = 10 ' Default to 10 days + Else + minUptime = CInt(minUptime) + End If + + ' Query PCs with high uptime + strSQL = "SELECT m.machineid, m.hostname, m.machinenumber, m.serialnumber, " & _ + "m.loggedinuser, m.lastupdated, m.lastboottime, m.pctypeid, m.businessunitid, " & _ + "DATEDIFF(NOW(), m.lastboottime) AS uptime_days, " & _ + "c.address AS ipaddress, " & _ + "COALESCE(pt.typename, 'Uncategorized') AS pctype, " & _ + "COALESCE(bu.businessunit, 'TBD') AS businessunit " & _ + "FROM machines m " & _ + "LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ + "LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _ + "LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _ + "WHERE m.isactive = 1 " & _ + "AND m.pctypeid IS NOT NULL " & _ + "AND m.lastboottime IS NOT NULL " & _ + "AND DATEDIFF(NOW(), m.lastboottime) >= " & minUptime & " " & _ + "ORDER BY uptime_days DESC, m.hostname ASC" + + Set rsPC = objConn.Execute(strSQL) + + If Err.Number <> 0 Then + SendError "Database error: " & Err.Description + Exit Sub + End If + + ' Build JSON array of PCs + pcList = "" + pcCount = 0 + + Do While Not rsPC.EOF + If pcList <> "" Then pcList = pcList & "," + + ' Build individual PC object + pcData = "{" + pcData = pcData & """machineid"":" & rsPC("machineid") & "," + pcData = pcData & """hostname"":""" & EscapeJSON(rsPC("hostname") & "") & """," + pcData = pcData & """machinenumber"":""" & EscapeJSON(rsPC("machinenumber") & "") & """," + pcData = pcData & """serialnumber"":""" & EscapeJSON(rsPC("serialnumber") & "") & """," + pcData = pcData & """ipaddress"":""" & EscapeJSON(rsPC("ipaddress") & "") & """," + pcData = pcData & """loggedinuser"":""" & EscapeJSON(rsPC("loggedinuser") & "") & """," + pcData = pcData & """pctype"":""" & EscapeJSON(rsPC("pctype") & "") & """," + pcData = pcData & """uptime_days"":" & rsPC("uptime_days") & "," + + ' Handle lastboottime date + If Not IsNull(rsPC("lastboottime")) Then + pcData = pcData & """lastboottime"":""" & rsPC("lastboottime") & """," + Else + pcData = pcData & """lastboottime"":null," + End If + + If IsNull(rsPC("pctypeid")) Then + pcData = pcData & """pctypeid"":null," + Else + pcData = pcData & """pctypeid"":" & rsPC("pctypeid") & "," + End If + pcData = pcData & """businessunit"":""" & EscapeJSON(rsPC("businessunit") & "") & """," + If IsNull(rsPC("businessunitid")) Then + pcData = pcData & """businessunitid"":null," + Else + pcData = pcData & """businessunitid"":" & rsPC("businessunitid") & "," + End If + + ' Handle lastupdated date + If Not IsNull(rsPC("lastupdated")) Then + pcData = pcData & """lastupdated"":""" & FormatDateTime(rsPC("lastupdated"), 2) & " " & FormatDateTime(rsPC("lastupdated"), 4) & """" + Else + pcData = pcData & """lastupdated"":null" + End If + + pcData = pcData & "}" + pcList = pcList & pcData + pcCount = pcCount + 1 + + rsPC.MoveNext + Loop + + rsPC.Close + Set rsPC = Nothing + + ' Send response + Response.Write "{""success"":true,""count"":" & pcCount & ",""minUptime"":" & minUptime & ",""data"":[" & pcList & "]}" +End Sub + Sub GetRecordedIP() On Error Resume Next Err.Clear @@ -1574,9 +1718,9 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber) rsResult.Close Set rsResult = Nothing - ' Check if relationship already exists (PC -> Equipment) + ' Check if relationship already exists (Equipment -> PC, matching existing data pattern) strSQL = "SELECT relationshipid FROM machinerelationships " & _ - "WHERE machineid = " & CLng(pcMachineid) & " AND related_machineid = " & CLng(equipmentMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid) + "WHERE machineid = " & CLng(equipmentMachineid) & " AND related_machineid = " & CLng(pcMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid) LogToFile "CreatePCMachineRelationship: Checking for duplicate: " & strSQL Set rsResult = objConn.Execute(strSQL) @@ -1592,8 +1736,9 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber) rsResult.Close Set rsResult = Nothing - ' Create new Controls relationship (PC -> Equipment) - ' Fixed: PC should be machineid, Equipment should be related_machineid + ' Create new Controls relationship (Equipment -> PC) + ' Equipment is machineid (source), PC is related_machineid (target) + ' This matches existing relationship data pattern in the database Dim cmdInsert Set cmdInsert = Server.CreateObject("ADODB.Command") cmdInsert.ActiveConnection = objConn @@ -1601,8 +1746,8 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber) "machineid, related_machineid, relationshiptypeid, isactive" & _ ") VALUES (?, ?, ?, 1)" - cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid)) cmdInsert.Parameters.Append cmdInsert.CreateParameter("@equipmentid", 3, 1, , CLng(equipmentMachineid)) + cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid)) cmdInsert.Parameters.Append cmdInsert.CreateParameter("@reltypeid", 3, 1, , CLng(relationshiptypeid)) cmdInsert.Execute @@ -2142,6 +2287,10 @@ Function GetPCTypeIdFromPCType(pcTypeString) GetPCTypeIdFromPCType = 9 Case "PART MARKER", "PARTMARKER" GetPCTypeIdFromPCType = 10 + Case "DASHBOARD" + GetPCTypeIdFromPCType = 11 + Case "LOBBY DISPLAY", "LOBBYDISPLAY", "LOBBY-DISPLAY" + GetPCTypeIdFromPCType = 12 Case "MEASURING", "MEASURING TOOL" GetPCTypeIdFromPCType = 7 ' Default other measuring tools to Keyence Case "STANDARD", "" diff --git a/apishopfloor.asp b/apishopfloor.asp index 8a991a7..e31f3fd 100644 --- a/apishopfloor.asp +++ b/apishopfloor.asp @@ -62,44 +62,88 @@ Do While Not rs.EOF isResolved = rs("is_resolved") If isCurrent = 1 Then - If Not isFirstCurrent Then jsonOutput = jsonOutput & "," - isFirstCurrent = False - - jsonOutput = jsonOutput & "{" - jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," - jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," - jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," - jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," - jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," - jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," - jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," - jsonOutput = jsonOutput & """isshopfloor"":true," - jsonOutput = jsonOutput & """resolved"":" & LCase(CStr(CBool(isResolved))) & "," - If Not IsNull(rs("minutes_since_end")) Then - jsonOutput = jsonOutput & """minutes_since_end"":" & rs("minutes_since_end") & "," - Else - jsonOutput = jsonOutput & """minutes_since_end"":null," - End If - jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," - jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," - jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," - ' Handle employeesso - can be SSO or NAME:customname - Dim empSsoRaw, empName, empPicture + ' Check if this is a Recognition with multiple employees + Dim typeName, empSsoRaw + typeName = rs("typename") & "" empSsoRaw = rs("employeesso") & "" - If Left(empSsoRaw, 5) = "NAME:" Then - ' Custom name - extract name, no picture - empName = Mid(empSsoRaw, 6) - empPicture = "" - jsonOutput = jsonOutput & """employeesso"":null," + + If LCase(typeName) = "recognition" And Len(empSsoRaw) > 0 And InStr(empSsoRaw, ",") > 0 Then + ' Split into individual cards for each employee + Dim ssoArr, idx + ssoArr = Split(empSsoRaw, ",") + + For idx = 0 To UBound(ssoArr) + Dim singleSSO, singleName, singlePicture + singleSSO = Trim(ssoArr(idx)) + singleName = LookupSingleEmployeeName(singleSSO) + singlePicture = LookupSingleEmployeePicture(singleSSO) + + If Not isFirstCurrent Then jsonOutput = jsonOutput & "," + isFirstCurrent = False + + jsonOutput = jsonOutput & "{" + jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," + jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," + jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," + jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," + jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," + jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," + jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," + jsonOutput = jsonOutput & """isshopfloor"":true," + jsonOutput = jsonOutput & """resolved"":" & LCase(CStr(CBool(isResolved))) & "," + If Not IsNull(rs("minutes_since_end")) Then + jsonOutput = jsonOutput & """minutes_since_end"":" & rs("minutes_since_end") & "," + Else + jsonOutput = jsonOutput & """minutes_since_end"":null," + End If + jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," + jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," + jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," + jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(singleSSO) & "," + jsonOutput = jsonOutput & """employeename"":" & StrOrNull(singleName) & "," + jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(singlePicture) & "" + jsonOutput = jsonOutput & "}" + Next Else - ' SSO - lookup name and picture - empName = LookupEmployeeNames(empSsoRaw) - empPicture = LookupEmployeePictures(empSsoRaw) - jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(empSsoRaw) & "," + ' Single employee or non-recognition - build normally + If Not isFirstCurrent Then jsonOutput = jsonOutput & "," + isFirstCurrent = False + + jsonOutput = jsonOutput & "{" + jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," + jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," + jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," + jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," + jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," + jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," + jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," + jsonOutput = jsonOutput & """isshopfloor"":true," + jsonOutput = jsonOutput & """resolved"":" & LCase(CStr(CBool(isResolved))) & "," + If Not IsNull(rs("minutes_since_end")) Then + jsonOutput = jsonOutput & """minutes_since_end"":" & rs("minutes_since_end") & "," + Else + jsonOutput = jsonOutput & """minutes_since_end"":null," + End If + jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," + jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," + jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," + ' Handle employeesso - can be SSO or NAME:customname + Dim empName, empPicture + If Left(empSsoRaw, 5) = "NAME:" Then + ' Custom name - extract name, no picture + empName = Mid(empSsoRaw, 6) + empPicture = "" + jsonOutput = jsonOutput & """employeesso"":null," + Else + ' SSO - lookup name and picture + empName = LookupEmployeeNames(empSsoRaw) + empPicture = LookupEmployeePictures(empSsoRaw) + jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(empSsoRaw) & "," + End If + jsonOutput = jsonOutput & """employeename"":" & StrOrNull(empName) & "," + jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(empPicture) & "" + jsonOutput = jsonOutput & "}" End If - jsonOutput = jsonOutput & """employeename"":" & StrOrNull(empName) & "," - jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(empPicture) & "" - jsonOutput = jsonOutput & "}" End If rs.MoveNext @@ -118,37 +162,76 @@ Do While Not rs.EOF isUpcoming = rs("is_upcoming") If isUpcoming = 1 Then - If Not isFirstUpcoming Then jsonOutput = jsonOutput & "," - isFirstUpcoming = False + ' Check if this is a Recognition with multiple employees + Dim upTypeName, upEmpSsoRaw + upTypeName = rs("typename") & "" + upEmpSsoRaw = rs("employeesso") & "" - jsonOutput = jsonOutput & "{" - jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," - jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," - jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," - jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," - jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," - jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," - jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," - jsonOutput = jsonOutput & """isshopfloor"":true," - jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," - jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," - jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," - ' Handle employeesso - can be SSO or NAME:customname - empSsoRaw = rs("employeesso") & "" - If Left(empSsoRaw, 5) = "NAME:" Then - ' Custom name - extract name, no picture - empName = Mid(empSsoRaw, 6) - empPicture = "" - jsonOutput = jsonOutput & """employeesso"":null," + If LCase(upTypeName) = "recognition" And Len(upEmpSsoRaw) > 0 And InStr(upEmpSsoRaw, ",") > 0 Then + ' Split into individual cards for each employee + Dim upSsoArr, upIdx + upSsoArr = Split(upEmpSsoRaw, ",") + + For upIdx = 0 To UBound(upSsoArr) + Dim upSingleSSO, upSingleName, upSinglePicture + upSingleSSO = Trim(upSsoArr(upIdx)) + upSingleName = LookupSingleEmployeeName(upSingleSSO) + upSinglePicture = LookupSingleEmployeePicture(upSingleSSO) + + If Not isFirstUpcoming Then jsonOutput = jsonOutput & "," + isFirstUpcoming = False + + jsonOutput = jsonOutput & "{" + jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," + jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," + jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," + jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," + jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," + jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," + jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," + jsonOutput = jsonOutput & """isshopfloor"":true," + jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," + jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," + jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," + jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(upSingleSSO) & "," + jsonOutput = jsonOutput & """employeename"":" & StrOrNull(upSingleName) & "," + jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(upSinglePicture) & "" + jsonOutput = jsonOutput & "}" + Next Else - ' SSO - lookup name and picture - empName = LookupEmployeeNames(empSsoRaw) - empPicture = LookupEmployeePictures(empSsoRaw) - jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(empSsoRaw) & "," + ' Single employee or non-recognition - build normally + If Not isFirstUpcoming Then jsonOutput = jsonOutput & "," + isFirstUpcoming = False + + jsonOutput = jsonOutput & "{" + jsonOutput = jsonOutput & """notificationid"":" & rs("notificationid") & "," + jsonOutput = jsonOutput & """notification"":""" & JSEscape(rs("notification") & "") & """," + jsonOutput = jsonOutput & """starttime"":""" & ISODate(st) & """," + jsonOutput = jsonOutput & """endtime"":" & ISODateOrNull(et) & "," + jsonOutput = jsonOutput & """ticketnumber"":" & StrOrNull(rs("ticketnumber")) & "," + jsonOutput = jsonOutput & """link"":" & StrOrNull(rs("link")) & "," + jsonOutput = jsonOutput & """isactive"":" & LCase(CStr(CBool(rs("isactive")))) & "," + jsonOutput = jsonOutput & """isshopfloor"":true," + jsonOutput = jsonOutput & """typename"":""" & JSEscape(rs("typename") & "") & """," + jsonOutput = jsonOutput & """typecolor"":""" & JSEscape(rs("typecolor") & "") & """," + jsonOutput = jsonOutput & """businessunit"":" & StrOrNull(rs("businessunit")) & "," + ' Handle employeesso - can be SSO or NAME:customname + Dim upEmpName, upEmpPicture + If Left(upEmpSsoRaw, 5) = "NAME:" Then + ' Custom name - extract name, no picture + upEmpName = Mid(upEmpSsoRaw, 6) + upEmpPicture = "" + jsonOutput = jsonOutput & """employeesso"":null," + Else + ' SSO - lookup name and picture + upEmpName = LookupEmployeeNames(upEmpSsoRaw) + upEmpPicture = LookupEmployeePictures(upEmpSsoRaw) + jsonOutput = jsonOutput & """employeesso"":" & StrOrNull(upEmpSsoRaw) & "," + End If + jsonOutput = jsonOutput & """employeename"":" & StrOrNull(upEmpName) & "," + jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(upEmpPicture) & "" + jsonOutput = jsonOutput & "}" End If - jsonOutput = jsonOutput & """employeename"":" & StrOrNull(empName) & "," - jsonOutput = jsonOutput & """employeepicture"":" & StrOrNull(empPicture) & "" - jsonOutput = jsonOutput & "}" End If rs.MoveNext @@ -195,6 +278,119 @@ Function StrOrNull(s) End If End Function +' Look up a single employee name from SSO or NAME: prefix +Function LookupSingleEmployeeName(ssoInput) + If IsNull(ssoInput) Or Len(ssoInput & "") = 0 Then + LookupSingleEmployeeName = "" + Exit Function + End If + + Dim sso + sso = Trim(ssoInput & "") + + ' Check if this is a custom NAME: entry + If Left(UCase(sso), 5) = "NAME:" Then + LookupSingleEmployeeName = Mid(sso, 6) + Exit Function + End If + + ' Try DB lookup for numeric SSO + If IsNumeric(sso) And Len(sso) > 0 Then + Dim empConn, empCmd, empRs, firstName, lastName + + On Error Resume Next + Set empConn = Server.CreateObject("ADODB.Connection") + empConn.ConnectionString = GetEmployeeConnectionString() + empConn.Open + + If Err.Number = 0 Then + Set empCmd = Server.CreateObject("ADODB.Command") + empCmd.ActiveConnection = empConn + empCmd.CommandText = "SELECT First_Name, Last_Name FROM employees WHERE SSO = ?" + empCmd.CommandType = 1 + empCmd.Parameters.Append empCmd.CreateParameter("@sso", 3, 1, , CLng(sso)) + + Set empRs = empCmd.Execute() + If Err.Number = 0 And Not empRs.EOF Then + firstName = empRs("First_Name") & "" + lastName = empRs("Last_Name") & "" + LookupSingleEmployeeName = firstName & " " & lastName + Else + LookupSingleEmployeeName = sso + End If + + If Not empRs Is Nothing Then + If empRs.State = 1 Then empRs.Close + Set empRs = Nothing + End If + Set empCmd = Nothing + empConn.Close + Else + LookupSingleEmployeeName = sso + End If + Set empConn = Nothing + On Error GoTo 0 + Else + LookupSingleEmployeeName = sso + End If +End Function + +' Look up a single employee picture from SSO +Function LookupSingleEmployeePicture(ssoInput) + If IsNull(ssoInput) Or Len(ssoInput & "") = 0 Then + LookupSingleEmployeePicture = "" + Exit Function + End If + + Dim sso + sso = Trim(ssoInput & "") + + ' NAME: entries have no picture + If Left(UCase(sso), 5) = "NAME:" Then + LookupSingleEmployeePicture = "" + Exit Function + End If + + ' Try DB lookup for numeric SSO + If IsNumeric(sso) And Len(sso) > 0 Then + Dim empConn, empCmd, empRs, picture + + On Error Resume Next + Set empConn = Server.CreateObject("ADODB.Connection") + empConn.ConnectionString = GetEmployeeConnectionString() + empConn.Open + + If Err.Number = 0 Then + Set empCmd = Server.CreateObject("ADODB.Command") + empCmd.ActiveConnection = empConn + empCmd.CommandText = "SELECT Picture FROM employees WHERE SSO = ?" + empCmd.CommandType = 1 + empCmd.Parameters.Append empCmd.CreateParameter("@sso", 3, 1, , CLng(sso)) + + Set empRs = empCmd.Execute() + If Err.Number = 0 And Not empRs.EOF Then + picture = empRs("Picture") & "" + LookupSingleEmployeePicture = picture + Else + LookupSingleEmployeePicture = "" + End If + + If Not empRs Is Nothing Then + If empRs.State = 1 Then empRs.Close + Set empRs = Nothing + End If + Set empCmd = Nothing + empConn.Close + Else + LookupSingleEmployeePicture = "" + End If + Set empConn = Nothing + On Error GoTo 0 + Else + LookupSingleEmployeePicture = "" + End If +End Function + ' Look up employee name(s) from SSO(s) Function LookupEmployeeNames(ssoInput) If IsNull(ssoInput) Or Len(ssoInput & "") = 0 Then