Compile function NDW_NOTIFICATION_EVENTS(CtrlEntId, Event, @PARAMS) /*********************************************************************************************************************** This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written permission from Infineon. Name : NDW_Notification_Events Description : This function acts as a commuter module for all events related to this window. Notes : Commuter Modules are automatically called from the Promoted_Events function which is called by the application-specific promoted event handler. This makes it possible to add QuickEvents that need to execute Basic+ logic without having use the Form Designer to make the association, although this is limited to the events which are currently promoted. If the form needs to call the commuter module directly then the QuickEvent parameters should be formatted like this: '@SELF','@EVENT',['@PARAM1','@PARAMx'] Parameters : CtrlEntId [in] -- The fully qualified name of the control calling the promoted event Event [in] -- The event being executed. See the Notes section regarding "PRE" events Param1-15 [in] -- Additional event parameter holders EventFlow [out] -- Set to 1 or 0 so the calling event knows whether or not to chain forward. See comments in EVENT_SETUP insert History : (Date, Initials, Notes) 09/30/24 djs Created initial commuter module. ***********************************************************************************************************************/ #pragma precomp SRP_PreCompiler #window NDW_NOTIFICATION $Insert EVENT_SETUP $Insert APP_INSERTS $Insert MSG_EQUATES $Insert POPUP_EQUATES $Insert NOTIFICATION_EQUATES $Insert LSL_USERS_EQUATES EQU READONLY_GREEN$ TO 192 + (220*256) + (192*65536) Declare function Admin_User, Database_Services, Error_Services, Active_Directory_Services, SRP_Array Declare subroutine PlaceDialog, Error_Services, Database_Services, Btree.Extract, ErrMsg GoToEvent Event for CtrlEntId else // Event not implemented end Return EventFlow or 1 //----------------------------------------------------------------------------- // EVENT HANDLERS //----------------------------------------------------------------------------- Event WINDOW.CREATE(CreateParam) AdminUser = Xlate('LSL_USERS', @USER4, LSL_USERS_ADMIN_USER$, 'X') If Not(AdminUser) then ErrMsg('You do not have the proper security to enter Message Notifications...' ) Post_Event(@Window, 'CLOSE') end else PlaceDialog(-2, -2) ColorArray = Send_Message(@Window:'.EDT_LSL_USERS', "COLOR_BY_POS", 2, 0) ColorArray<1> = READONLY_GREEN$ Send_Message(@Window:'.EDT_LSL_USERS', "COLOR_BY_POS", 1, 0, ColorArray) Send_Message(@Window:'.EDT_LSL_USERS', "COLOR_BY_POS", 2, 0, ColorArray) Send_Message(@Window:'.EDT_AD_GROUPS', "COLOR_BY_POS", 1, 0, ColorArray) Send_Message(@Window:'.EDT_AD_GROUPS', "COLOR_BY_POS", 2, 0, ColorArray) Send_Message(@Window:'.EDT_AD_GROUPS', "COLOR_BY_POS", 3, 0, ColorArray) end End Event Event WINDOW.READ() EventFlow = EVENT_CONTINUE$ OrigRec = Get_Property(@Window, '@RECORD') EditRec = Get_Property(@Window, '@EDIT_RECORD') If OrigRec NE EditRec then Response = Msg(@Window, '', 'YES_NO_CANCEL', '', 'OpenInsight':@FM:'Would you like to save changes to the entry?') Begin Case Case Response EQ Yes$ // Save changes and read new record NewKey = Get_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT') Set_Property(@Window, '@NEW_KEY', NewKey) Send_Event(@Window, 'WRITE') Case Response EQ No$ // Abandon changes and read new form Null Case Otherwise$ // Cancel - Stop Read Event EventFlow = EVENT_STOP$ End Case end If EventFlow EQ EVENT_CONTINUE$ then GoSub UnlockRec Key = Get_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT') NewRec = Get_Property(@Window, '@NEW_REC') If Key EQ '' then Key = Get_Property(@Window, '@NEW_KEY') Set_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT', NewKey) Set_Property(@Window, '@NEW_KEY', '') end Begin Case Case Key EQ '' Set_Property(@Window:'.EDT_LSL_USERS', 'ENABLED', False$) Case RowExists('NOTIFICATION', Key) // Populate form HaveLock = Database_Services('GetKeyIDLock', 'NOTIFICATION', Key, True$) If HaveLock then Set_Property(@Window, '@HAVE_LOCK', HaveLock) Set_Property(@Window, '@LOCK_KEY', Key) Set_Property(@Window:'.EDL_DESCRIPTION', 'ENABLED', True$) Set_Property(@Window:'.CHK_USE_AD', 'ENABLED', True$) Set_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', True$) Set_Property(@Window:'.PUB_CLEAR', 'ENABLED', True$) Set_Property(@Window:'.PUB_DELETE', 'ENABLED', True$) Set_Property(@Window:'.PUB_SAVE', 'ENABLED', True$) NotifyRec = Database_Services('ReadDataRow', 'NOTIFICATION', Key) If Error_Services('NoError') then Set_Property(@Window, '@RECORD', NotifyRec) Set_Property(@Window, '@EDIT_RECORD', NotifyRec) Set_Property(@Window:'.EDL_DESCRIPTION', 'TEXT', NotifyRec) UseAD = NotifyRec Set_Property(@Window:'.CHK_USE_AD', 'DEFPROP', UseAD) LimitOnShift = NotifyRec Set_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', 'DEFPROP', LimitOnShift) LSLUsers = NotifyRec LSLUsernames = Xlate('LSL_USERS', LSLUsers, 'FIRST_LAST', 'X') LSLUsersArray = LSLUsers : @FM : LSLUsernames Set_Property(@Window:'.EDT_LSL_USERS', 'ARRAY', LSLUsersArray) ADGroups = NotifyRec GroupList = '' If ADGroups NE '' then For each ADGroup in ADGroups using @VM setting vPos GroupList<-1> = Active_Directory_Services('GetADGroupsByString', ADGroup, 'INFINEON') Next ADGroup end Set_Property(@Window:'.EDT_AD_GROUPS', 'LIST', GroupList) GoSub EnableControls end else Msg(@Window, '', 'OK', '', 'Error':@FM:'Error locking NOTIFICATION record "':Key:'" for update!') end end else Msg(@Window, '', 'OK', '', 'Error':@FM:'Error reading NOTIFICATION record "':Key:'"!') end Case NewRec Null Case Otherwise$ // User is creating a new record Set_Property(@Window, 'REDRAW', False$) Send_Event(@Window, 'CLEAR') Set_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT', Key) Set_Property(@Window, '@LOCK_KEY', Key) Set_Property(@Window, '@NEW_REC', True$) GoSub EnableControls Set_Property(@Window:'.PUB_LU_ID', 'FOCUS', True$) Set_Property(@Window, 'REDRAW', True$) End Case end end event Event WINDOW.CLEAR(bSaveKey, bSuppressWarning, bMaintainFocus) EventFlow = EVENT_CONTINUE$ OrigRec = Get_Property(@Window, '@RECORD') EditRec = Get_Property(@Window, '@EDIT_RECORD') If OrigRec NE EditRec then Response = Msg(@Window, '', 'YES_NO_CANCEL', '', 'OpenInsight':@FM:'Would you like to save changes to the entry?') Begin Case Case Response EQ 1 // Yes - Save changed and close form Send_Event(@Window, 'WRITE') Case Response EQ 0 // No - Abandon changes and clear form Null Case Otherwise$ // Cancel - Stop Clear Event EventFlow = EVENT_STOP$ End Case end If EventFlow EQ EVENT_CONTINUE$ then Set_Property(@Window, '@NEW_REC', False$) GoSub UnlockRec Forward_Event() Set_Property(@Window, '@RECORD', '') Set_Property(@Window, '@EDIT_RECORD', '') GoSub EnableControls Set_Property(@Window:'.PUB_DELETE' , 'ENABLED', False$) Set_Property(@Window:'.PUB_CLEAR' , 'ENABLED', True$) Set_Property(@Window:'.EDL_DESCRIPTION' , 'ENABLED', False$) Set_Property(@Window:'.CHK_USE_AD' , 'ENABLED', False$) Set_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', 'ENABLED', False$) Set_Property(@Window:'.PUB_ADD_USERS' , 'ENABLED', False$) Set_Property(@Window:'.REM_ADD_USERS' , 'ENABLED', False$) Set_Property(@Window:'.GRB_AD_GROUPS' , 'ENABLED', False$) Set_Property(@Window:'.EDT_AD_GROUPS' , 'ENABLED', False$) Set_Property(@Window:'.PUB_ADD_GROUPS' , 'ENABLED', False$) Set_Property(@Window:'.REM_ADD_GROUPS' , 'ENABLED', False$) end end event Event WINDOW.WRITE() Key = Get_Property(@Window, '@LOCK_KEY') NotifyRec = Get_Property(@Window, '@RECORD') NotifyRec = Get_Property(@Window:'.EDL_DESCRIPTION', 'TEXT') UserArray = Get_Property(@Window:'.EDT_LSL_USERS', 'ARRAY') UserIds = UserArray<1> NotifyRec = UserIds GroupArray = Get_Property(@Window:'.EDT_AD_GROUPS', 'ARRAY') GroupIds = GroupArray<1> NotifyRec = GroupIds NotifyRec = Get_Property(@Window:'.CHK_USE_AD', 'DEFPROP') NotifyRec = Get_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', 'DEFPROP') Database_Services('WriteDataRow', 'NOTIFICATION', Key, NotifyRec, True$, False$, True$) If Error_Services('NoError') then GoSub UnlockRec Set_Property(@Window, '@RECORD', GroupRec) Set_Property(@Window, '@EDIT_RECORD', GroupRec) Send_Event(@Window, 'CLEAR') end else Msg(@Window, '', 'OK', '', 'Error':@FM:Error_Services('GetMessage')) end end event Event WINDOW.CLOSE(CancelFlag, CloseFlags) EventFlow = EVENT_CONTINUE$ OrigRec = Get_Property(@Window, '@RECORD') EditRec = Get_Property(@Window, '@EDIT_RECORD') If OrigRec NE EditRec then Response = Msg(@Window, '', 'YES_NO_CANCEL', '', 'OpenInsight':@FM:'Would you like to save changes to the entry?') Begin Case Case Response EQ 1 // Yes - Save changed and close form Send_Event(@Window, 'WRITE') Case Response EQ 0 // No - Abandon changes and close form Null Case Otherwise$ // Cancel - Stop Close Event EventFlow = EVENT_STOP$ End Case end If EventFlow EQ EVENT_CONTINUE$ then GoSub UnlockRec end event Event PUB_SAVE.CLICK() Post_Event(@Window, 'WRITE') end event Event PUB_CLEAR.CLICK() GoSub UnlockRec Post_Event(@Window, 'CLEAR') end event Event PUB_LU_ID.CLICK() EventFlow = EVENT_CONTINUE$ OrigRec = Get_Property(@Window, '@RECORD') EditRec = Get_Property(@Window, '@EDIT_RECORD') If OrigRec NE EditRec then Response = Msg(@Window, '', 'YES_NO_CANCEL', '', 'OpenInsight':@FM:'Would you like to save changes to the entry?') Begin Case Case Response EQ Yes$ // Save changes and read new record Send_Event(@Window, 'WRITE') Case Response EQ No$ // Abandon changes and read new form Null Case Otherwise$ // Cancel - Stop Read Event EventFlow = EVENT_STOP$ End Case end If EventFlow EQ EVENT_CONTINUE$ then TypeOver = '' TypeOver = 1 NotifyID = Popup(@WINDOW,TypeOver,'NOTIFICATION') If NotifyID NE '' then Set_Property(@Window, '@RECORD', '') Set_Property(@Window, '@EDIT_RECORD', '') Set_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT', NotifyID) Post_Event(@Window, 'READ') end end end event Event EDL_NOTIFICATION_ID.OPTIONS() EventFlow = EVENT_CONTINUE$ OrigRec = Get_Property(@Window, '@RECORD') EditRec = Get_Property(@Window, '@EDIT_RECORD') If OrigRec NE EditRec then Response = Msg(@Window, '', 'YES_NO_CANCEL', '', 'OpenInsight':@FM:'Would you like to save changes to the entry?') Begin Case Case Response EQ Yes$ // Save changes and read new record Send_Event(@Window, 'WRITE') Case Response EQ No$ // Abandon changes and read new form Null Case Otherwise$ // Cancel - Stop Read Event EventFlow = EVENT_STOP$ End Case end If EventFlow EQ EVENT_CONTINUE$ then TypeOver = '' TypeOver = 1 NotifyID = Popup(@WINDOW,TypeOver,'NOTIFICATION') IF NotifyID NE '' THEN Set_Property(@Window, '@RECORD', '') Set_Property(@Window, '@EDIT_RECORD', '') Set_Property(CtrlEntId, 'TEXT', NotifyID) Post_Event(@Window, 'READ') end end end event Event EDT_LSL_USERS.ROWSELCHANGED(SelRow, SelState) GoSub EnableControls end event Event EDT_AD_GROUPS.ROWSELCHANGED(SelRow, SelState) GoSub EnableControls end event Event EDL_NOTIFICATION_ID.LOSTFOCUS(Flag, FocusID) If Flag EQ 1 then GoSub UnlockRec Post_Event(@Window, 'READ') end end event Event PUB_ADD_USERS.CLICK() CurrUserIDs = Get_Property(@Window:'.EDT_LSL_USERS','ARRAY')<1> CurrUserIDsTrimmed = '' FOR I = 1 TO COUNT(CurrUserIDs,@VM) + (CurrUserIDs NE '') IF CurrUserIDs<1,I> NE '' THEN CurrUserIDsTrimmed<1,I> = CurrUserIDs<1,I> END NEXT I CurrUserIDs = CurrUserIDsTrimmed NewUserIDs = Popup(@WINDOW,'','SHOW_USERS') If ( (NewUserIDs NE '') and (NewUserIDs NE CHAR(27)) ) then For I = 1 TO COUNT(NewUserIDs,@VM) + (NewUserIDs NE '') NewUserID = NewUserIDs<1,I> Locate NewUserID in CurrUserIDs by 'AL' using @VM setting POS else CurrUserIDs = INSERT(CurrUserIDs,1,POS,0,NewUserID) end Next I LSLNames = Xlate('LSL_USERS', CurrUserIDs, 'FIRST_LAST', 'X') NewArray = CurrUserIDs : @FM : LSLNames Set_Property(@Window:'.EDT_LSL_USERS', 'ARRAY', NewArray) Post_Event(@Window:'.EDT_LSL_USERS', 'CHANGED') end end event Event PUB_REM_USERS.CLICK() SelRows = Get_Property(@Window:'.EDT_LSL_USERS', 'SELPOS') SelRows = SelRows<2> SelData = '' NewList = '' If SelRows NE '' then DataList = Get_Property(@Window:'.EDT_LSL_USERS', 'LIST') For each Row in DataList using @FM setting RowIndex If Not(InList(SelRows, RowIndex, @VM)) then NewList<-1> = Row Next Row Set_Property(@Window:'.EDT_LSL_USERS', 'LIST', NewList) GoSub EnableControls Post_Event(@Window:'.EDT_LSL_USERS', 'CHANGED') end end event Event PUB_ADD_GROUPS.CLICK() GroupArray = Get_Property(@Window:'.EDT_AD_GROUPS', 'ARRAY') GroupIds = GroupArray<1> SelGroups = Dialog_Box('NDW_ACTIVE_DIRECTORY_GROUPS', @Window, GroupIds:@RM:'DL') If SelGroups NE '' then Set_Property(@Window:'.EDT_AD_GROUPS', 'LIST', SelGroups) Def = "" Def = -2 Def = -2 Def = "Updating LSL user list..." Def = "U" MsgUp = Msg(@window, Def) ;* display the processing message GroupArray = Get_Property(@Window:'.EDT_AD_GROUPS', 'ARRAY') GroupIds = GroupArray<1> LSLUserNames = '' LSLNames = '' If GroupIds NE '' then For each GroupId in GroupIds using @VM MemberList = Active_Directory_Services('GetADGroupMembersByGroupName', GroupId, 'INFINEON') MemberList = SRP_Array('Rotate', MemberList, @FM, @VM) ADUserNames = MemberList<1> Open 'DICT.LSL_USERS' to hDict then For each ADUserName in ADUserNames using @VM setting vPos Query = 'DOMAIN_USERNAME':@VM:ADUserName:@FM Flag = '' LSLUsername = '' Btree.Extract(Query, 'LSL_USERS', hDict, LSLUsername, '', Flag) If LSLUsername NE '' then LSLUsernames<0, -1> = LSLUsername<0, 1> Next ADUserName end Next GroupId If LSLUsernames NE '' then LSLUsernames = SRP_Array('Clean', LSLUsernames, 'TrimAndMakeUnique', @VM) LSLUsernames = SRP_Array('SortSimpleList', LSLUsernames, 'AscendingText', @VM) LSLNames = Xlate('LSL_USERS', LSLUsernames, 'FIRST_LAST', 'X') end end Array = LSLUsernames : @FM : LSLNames Set_Property(@Window:'.EDT_LSL_USERS', 'ARRAY', Array) Msg(@window, MsgUp) ;* take down the processing message Post_Event(@Window:'.EDT_AD_GROUPS', 'CHANGED') end end event Event PUB_REM_GROUPS.CLICK() SelRows = Get_Property(@Window:'.EDT_AD_GROUPS', 'SELPOS') SelRows = SelRows<2> SelData = '' NewList = '' If SelRows NE '' then DataList = Get_Property(@Window:'.EDT_AD_GROUPS', 'LIST') For each Row in DataList using @FM setting RowIndex If Not(InList(SelRows, RowIndex, @VM)) then NewList<-1> = Row Next Row Set_Property(@Window:'.EDT_AD_GROUPS', 'LIST', NewList) GoSub EnableControls Post_Event(@Window:'.EDT_AD_GROUPS', 'CHANGED') end end event Event CHK_USE_AD.CLICK() EditRecord = Get_Property(@Window, '@EDIT_RECORD') UseAD = Get_Property(CtrlEntId, 'CHECK') EditRecord = UseAD Set_Property(@Window, '@EDIT_RECORD', EditRecord) GoSub EnableControls end event Event CHK_LIMIT_TO_ACTIVE_SHIFT.CLICK() EditRecord = Get_Property(@Window, '@EDIT_RECORD') UseAD = Get_Property(CtrlEntId, 'CHECK') EditRecord = UseAD Set_Property(@Window, '@EDIT_RECORD', EditRecord) end event Event EDT_AD_GROUPS.CHANGED(NewData) EditRecord = Get_Property(@Window, '@EDIT_RECORD') ADGroupsArray = Get_Property(CtrlEntId, 'ARRAY') GroupNames = ADGroupsArray<1> EditRecord = GroupNames Set_Property(@Window, '@EDIT_RECORD', EditRecord) end event Event EDT_LSL_USERS.CHANGED(NewData) EditRecord = Get_Property(@Window, '@EDIT_RECORD') LSLUsersArray = Get_Property(CtrlEntId, 'ARRAY') LSLUsernames = LSLUsersArray<1> EditRecord = LSLUsernames Set_Property(@Window, '@EDIT_RECORD', EditRecord) end event Event EDL_DESCRIPTION.CHANGED(NewData) EditRecord = Get_Property(@Window, '@EDIT_RECORD') EditRecord = NewData Set_Property(@Window, '@EDIT_RECORD', EditRecord) end event //----------------------------------------------------------------------------- // Internal GoSubs //----------------------------------------------------------------------------- EnableControls: NotifyID = Get_Property(@Window:'.EDL_NOTIFICATION_ID', 'TEXT') UseAD = Get_Property(@Window:'.CHK_USE_AD', 'DEFPROP') Enabled = (NotifyID NE '') Set_Property(@Window:'.PUB_CLEAR' , 'ENABLED', Enabled) Set_Property(@Window:'.EDL_DESCRIPTION', 'ENABLED', Enabled) Set_Property(@Window:'.CHK_USE_AD' , 'ENABLED', Enabled) If UseAD NE True$ then Set_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', 'DEFPROP', False$) Set_Property(@Window:'.CHK_LIMIT_TO_ACTIVE_SHIFT', 'ENABLED', UseAD) Set_Property(@Window:'.PUB_ADD_USERS', 'ENABLED', (UseAD NE True$)) Set_Property(@Window:'.EDT_LSL_USERS', 'ENABLED', Enabled) If NotifyID NE '' then Backcolor = WHITE$ end else Backcolor = GREY$ end Set_Property(@Window:'.EDT_LSL_USERS' , 'BACKCOLOR', Backcolor) Set_Property(@Window:'.GRB_AD_GROUPS' , 'ENABLED', (UseAD EQ True$)) Set_Property(@Window:'.PUB_ADD_GROUPS', 'ENABLED', (UseAD EQ True$)) Set_Property(@Window:'.EDT_AD_GROUPS' , 'ENABLED', (UseAD EQ True$)) If ( Enabled and (UseAD EQ True$) ) then Backcolor = WHITE$ end else Backcolor = GREY$ end Set_Property(@Window:'.EDT_AD_GROUPS', 'BACKCOLOR', Backcolor) DelBtnEnabled = False$ SelRows = Get_Property(@Window:'.EDT_LSL_USERS', 'SELPOS') SelRows = SelRows<2> SelData = '' If SelRows NE '' then Data = Get_Property(@Window:'.EDT_LSL_USERS', 'LIST') Convert @VM to '' in Data For each Row in SelRows using @VM If Data NE '' then SelData<-1> = Data end Next Row If (SelData NE '') and (UseAD NE True$) then DelBtnEnabled = True$ end Set_Property(@Window:'.PUB_REM_USERS', 'ENABLED', DelBtnEnabled) DelBtnEnabled = False$ SelRows = Get_Property(@Window:'.EDT_AD_GROUPS', 'SELPOS') SelRows = SelRows<2> SelData = '' If SelRows NE '' then Data = Get_Property(@Window:'.EDT_AD_GROUPS', 'LIST') Convert @VM to '' in Data For each Row in SelRows using @VM If Data NE '' then SelData<-1> = Data end Next Row If (SelData NE '') and (UseAD EQ True$) then DelBtnEnabled = True$ end Set_Property(@Window:'.PUB_REM_GROUPS', 'ENABLED', DelBtnEnabled) return UnlockRec: Key = Get_Property(@Window, '@LOCK_KEY') If Key NE '' then HaveLock = Get_Property(@Window, '@HAVE_LOCK') If HaveLock then Database_Services('ReleaseKeyIDLock', 'NOTIFICATION', Key) end end return