Files
shopdb/editnotification.asp
cproudlock 28e8071570 Add Employee Recognition feature to notifications system
- Add Recognition notification type (ID 5) with blue color
- Add employeesso field to notifications table
- Create carousel display for Recognition on shopfloor dashboard
- Show employee names (lookup from wjf_employees) instead of SSO
- Auto-set starttime to NOW and endtime to 4AM next day
- Auto-enable shopfloor display for Recognition type
- Add Achievements tab to employee profile (displayprofile.asp)
- Hide Recognition from calendar view
- Add lookupemployee.asp AJAX endpoint for name preview
- Fix datetime double-formatting bug in save/update files
- Fix URL parameter loading on shopfloor dashboard init

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 07:27:37 -05:00

410 lines
18 KiB
Plaintext

<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
<%
' Get and validate notificationid
Dim notificationid
notificationid = Request.Querystring("notificationid")
' Basic validation - must be numeric and positive
If Not IsNumeric(notificationid) Or CLng(notificationid) < 1 Then
Response.Redirect("displaynotifications.asp")
Response.End
End If
' Get the notification details using parameterized query
Dim strSQL, rs
strSQL = "SELECT * FROM notifications WHERE notificationid = ?"
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(CLng(notificationid)))
If rs.EOF Then
rs.Close
Set rs = Nothing
objConn.Close
Response.Redirect("displaynotifications.asp")
Response.End
End If
' Convert datetime to datetime-local format (YYYY-MM-DDTHH:MM)
Dim startFormatted, endFormatted
If IsNull(rs("starttime")) Or rs("starttime") = "" Then
startFormatted = ""
Else
' Handle both MySQL format and VBScript Date format
If VarType(rs("starttime")) = 7 Then
' VarType 7 is Date - format it properly
startFormatted = Year(rs("starttime")) & "-" & _
Right("0" & Month(rs("starttime")), 2) & "-" & _
Right("0" & Day(rs("starttime")), 2) & "T" & _
Right("0" & Hour(rs("starttime")), 2) & ":" & _
Right("0" & Minute(rs("starttime")), 2)
Else
' String format - try to convert
startFormatted = Left(Replace(rs("starttime"), " ", "T"), 16)
End If
End If
If IsNull(rs("endtime")) Or rs("endtime") = "" Then
endFormatted = ""
Else
' Handle both MySQL format and VBScript Date format
If VarType(rs("endtime")) = 7 Then
' VarType 7 is Date - format it properly
endFormatted = Year(rs("endtime")) & "-" & _
Right("0" & Month(rs("endtime")), 2) & "-" & _
Right("0" & Day(rs("endtime")), 2) & "T" & _
Right("0" & Hour(rs("endtime")), 2) & ":" & _
Right("0" & Minute(rs("endtime")), 2)
Else
' String format - try to convert
endFormatted = Left(Replace(rs("endtime"), " ", "T"), 16)
End If
End If
%>
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
</head>
<%
Dim theme
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
%>
<body class="bg-theme <%Response.Write(theme)%>">
<!-- start loader -->
<div id="pageloader-overlay" class="visible incoming"><div class="loader-wrapper-outer"><div class="loader-wrapper-inner" ><div class="loader"></div></div></div></div>
<!-- end loader -->
<!-- Start wrapper-->
<div id="wrapper">
<!--#include file="./includes/leftsidebar.asp"-->
<!--Start topbar header-->
<!--#include file="./includes/topbarheader.asp"-->
<!--End topbar header-->
<div class="clearfix"></div>
<div class="content-wrapper">
<div class="container-fluid">
<div class="row mt-3">
<div class="col-lg-8 offset-lg-2">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h5 class="card-title" style="margin:0;">
<i class="zmdi zmdi-edit"></i> Edit Notification
</h5>
<a href="./displaynotifications.asp" class="btn btn-sm btn-secondary">
<i class="zmdi zmdi-arrow-left"></i> Cancel
</a>
</div>
<form method="post" action="./updatenotificationdirect.asp">
<input type="hidden" name="notificationid" value="<%=notificationid%>">
<div class="form-group">
<label for="notification">Message <span class="text-danger">*</span></label>
<textarea class="form-control" id="notification" name="notification" rows="3"
required maxlength="500"><%=Server.HTMLEncode(rs("notification") & "")%></textarea>
<small class="form-text text-muted">This message will appear on the dashboard</small>
</div>
<div class="form-group">
<label for="notificationtypeid">Type <span class="text-danger">*</span></label>
<select class="form-control" id="notificationtypeid" name="notificationtypeid" required>
<%
Dim rsTypes, currentTypeId
currentTypeId = rs("notificationtypeid")
Set rsTypes = objConn.Execute("SELECT notificationtypeid, typename, typedescription FROM notificationtypes WHERE isactive = 1 ORDER BY notificationtypeid")
While Not rsTypes.EOF
Dim isSelectedType
isSelectedType = ""
If CLng(rsTypes("notificationtypeid")) = CLng(currentTypeId) Then
isSelectedType = " selected"
End If
%>
<option value="<%=rsTypes("notificationtypeid")%>"<%=isSelectedType%>><%=rsTypes("typename")%><%If Not IsNull(rsTypes("typedescription")) Then%> - <%=rsTypes("typedescription")%><%End If%></option>
<%
rsTypes.MoveNext
Wend
rsTypes.Close
Set rsTypes = Nothing
%>
</select>
<small class="form-text text-muted">Classification type for this notification</small>
</div>
<div class="form-group">
<label for="businessunitid">Business Unit <span class="text-muted">(Optional - blank applies to all)</span></label>
<select class="form-control" id="businessunitid" name="businessunitid">
<option value="">-- All Business Units --</option>
<%
Dim rsBusinessUnits, currentBusinessUnitId
currentBusinessUnitId = rs("businessunitid") & ""
Set rsBusinessUnits = objConn.Execute("SELECT businessunitid, businessunit FROM businessunits WHERE isactive = 1 ORDER BY businessunit")
Dim isSelectedBU
While Not rsBusinessUnits.EOF
isSelectedBU = ""
If currentBusinessUnitId <> "" And IsNumeric(currentBusinessUnitId) Then
If CLng(rsBusinessUnits("businessunitid")) = CLng(currentBusinessUnitId) Then
isSelectedBU = " selected"
End If
End If
%>
<option value="<%=rsBusinessUnits("businessunitid")%>"<%=isSelectedBU%>><%=rsBusinessUnits("businessunit")%></option>
<%
rsBusinessUnits.MoveNext
Wend
rsBusinessUnits.Close
Set rsBusinessUnits = Nothing
%>
</select>
<small class="form-text text-muted">Select a specific business unit or leave blank to apply to all</small>
</div>
<div class="form-group">
<label for="appid">Related Application <span class="text-muted">(Optional)</span></label>
<select class="form-control" id="appid" name="appid">
<option value="">-- No Application --</option>
<%
Dim rsApps, currentAppId
currentAppId = rs("appid") & ""
Set rsApps = objConn.Execute("SELECT appid, appname FROM applications WHERE isactive = 1 ORDER BY appname")
While Not rsApps.EOF
If currentAppId <> "" And CStr(rsApps("appid")) = currentAppId Then
Response.Write("<option value=""" & rsApps("appid") & """ selected>" & Server.HTMLEncode(rsApps("appname") & "") & "</option>")
Else
Response.Write("<option value=""" & rsApps("appid") & """>" & Server.HTMLEncode(rsApps("appname") & "") & "</option>")
End If
rsApps.MoveNext
Wend
rsApps.Close
Set rsApps = Nothing
%>
</select>
<small class="form-text text-muted">Link this notification to a specific application (e.g., for software updates)</small>
</div>
<div class="form-group" id="ticketnumberGroup">
<label for="ticketnumber">Ticket Number</label>
<input type="text" class="form-control" id="ticketnumber" name="ticketnumber"
value="<%=Server.HTMLEncode(rs("ticketnumber") & "")%>"
maxlength="50" placeholder="GEINC123456 or GECHG123456">
<small class="form-text text-muted">Optional ServiceNow ticket number</small>
</div>
<div class="form-group" id="employeessoGroup" style="display:none;">
<label for="employeesso">Employee SSO(s) <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="employeesso" name="employeesso"
value="<%=Server.HTMLEncode(rs("employeesso") & "")%>"
maxlength="100" placeholder="123456789 or 123456789, 987654321">
<small class="form-text text-muted">Enter one or more SSOs separated by commas</small>
<div id="employeePreview" class="mt-2" style="display:none;">
<span class="badge badge-info" id="employeeNames"></span>
</div>
</div>
<div class="form-row" id="timeFieldsRow">
<div class="form-group col-md-6">
<label for="starttime">Start Time <span class="text-danger">*</span></label>
<div class="input-group">
<input type="datetime-local" class="form-control" id="starttime" name="starttime"
value="<%=startFormatted%>" required>
<div class="input-group-append">
<button type="button" class="btn btn-outline-primary" onclick="setNow('starttime')" title="Set to current date/time">
<i class="zmdi zmdi-time"></i> Now
</button>
</div>
</div>
<small class="form-text text-muted">When notification becomes visible</small>
</div>
<div class="form-group col-md-6">
<label for="endtime">End Time <span class="text-muted">(Optional - indefinite if blank)</span></label>
<div class="input-group">
<input type="datetime-local" class="form-control" id="endtime" name="endtime"
value="<%=endFormatted%>">
<div class="input-group-append">
<button type="button" class="btn btn-outline-primary" onclick="setNow('endtime')" title="Set to current date/time">
<i class="zmdi zmdi-time"></i> Now
</button>
<button type="button" class="btn btn-outline-secondary" onclick="clearEndtime()" title="Clear to make indefinite">
<i class="zmdi zmdi-close"></i>
</button>
</div>
</div>
<small class="form-text text-muted">Leave blank for indefinite (will display until you set an end date)</small>
</div>
</div>
<div class="form-group">
<input type="hidden" name="isactive_submitted" value="1">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="isactive" name="isactive" value="1" <%If CBool(rs("isactive")) = True Then Response.Write("checked") End If%>>
<label class="custom-control-label" for="isactive">Active</label>
</div>
<small class="form-text text-muted">Uncheck to hide notification without deleting</small>
</div>
<div class="form-group">
<input type="hidden" name="isshopfloor_submitted" value="1">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="isshopfloor" name="isshopfloor" value="1" <%If CBool(rs("isshopfloor")) = True Then Response.Write("checked") End If%>>
<label class="custom-control-label" for="isshopfloor">Show on Shopfloor Dashboard</label>
</div>
<small class="form-text text-muted">Check this to display on the shopfloor TV dashboard (72-hour window)</small>
</div>
<hr>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary btn-lg">
<i class="zmdi zmdi-check"></i> Update Notification
</button>
<a href="./displaynotifications.asp" class="btn btn-secondary btn-lg">
<i class="zmdi zmdi-close"></i> Cancel
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- End Row -->
</div>
<!-- End container-fluid-->
</div><!--End content-wrapper-->
<!--Start Back To Top Button-->
<a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
<!--End Back To Top Button-->
<!--Start footer-->
<footer class="footer">
<div class="container">
<div class="text-center">
</div>
</div>
</footer>
<!--End footer-->
</div><!--End wrapper-->
<!-- Bootstrap core JavaScript-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<script>
// Format: YYYY-MM-DDTHH:MM
function formatDateTime(date) {
var year = date.getFullYear();
var month = ('0' + (date.getMonth() + 1)).slice(-2);
var day = ('0' + date.getDate()).slice(-2);
var hours = ('0' + date.getHours()).slice(-2);
var minutes = ('0' + date.getMinutes()).slice(-2);
return year + '-' + month + '-' + day + 'T' + hours + ':' + minutes;
}
// Set field to current date/time
function setNow(fieldId) {
var now = new Date();
document.getElementById(fieldId).value = formatDateTime(now);
}
// Clear end time to make notification indefinite
function clearEndtime() {
document.getElementById('endtime').value = '';
}
// Handle notification type change for Recognition
document.addEventListener('DOMContentLoaded', function() {
var typeSelect = document.getElementById('notificationtypeid');
typeSelect.addEventListener('change', handleTypeChange);
handleTypeChange(); // Initial check
// Employee lookup on SSO input
var ssoInput = document.getElementById('employeesso');
ssoInput.addEventListener('input', function() {
clearTimeout(window.lookupTimeout);
window.lookupTimeout = setTimeout(lookupEmployees, 500);
});
// Trigger initial lookup if SSO has value
if (ssoInput.value.trim()) {
lookupEmployees();
}
});
function handleTypeChange() {
var typeSelect = document.getElementById('notificationtypeid');
var selectedText = typeSelect.options[typeSelect.selectedIndex].text;
var isRecognition = selectedText.toLowerCase().indexOf('recognition') !== -1;
// Show/hide SSO field
document.getElementById('employeessoGroup').style.display = isRecognition ? 'block' : 'none';
document.getElementById('employeesso').required = isRecognition;
// Show/hide time fields and ticket number for Recognition
document.getElementById('timeFieldsRow').style.display = isRecognition ? 'none' : 'flex';
document.getElementById('ticketnumberGroup').style.display = isRecognition ? 'none' : 'block';
// For Recognition, remove required from starttime
document.getElementById('starttime').required = !isRecognition;
// Auto-check shopfloor dashboard for Recognition
if (isRecognition) {
document.getElementById('isshopfloor').checked = true;
}
}
function lookupEmployees() {
var ssoInput = document.getElementById('employeesso');
var ssos = ssoInput.value.trim();
var previewDiv = document.getElementById('employeePreview');
var namesSpan = document.getElementById('employeeNames');
if (!ssos) {
previewDiv.style.display = 'none';
return;
}
fetch('./lookupemployee.asp?sso=' + encodeURIComponent(ssos))
.then(function(response) { return response.json(); })
.then(function(data) {
if (data.success && data.names) {
namesSpan.textContent = data.names;
namesSpan.className = 'badge badge-info';
previewDiv.style.display = 'block';
} else {
namesSpan.textContent = data.error || 'Employee not found';
namesSpan.className = 'badge badge-warning';
previewDiv.style.display = 'block';
}
})
.catch(function(err) {
previewDiv.style.display = 'none';
});
}
</script>
</body>
</html>
<%
rs.Close
Set rs = Nothing
objConn.Close
%>