&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
&ANALYZE-RESUME
{adecomm/appserv.i}
DEFINE VARIABLE h_Astra                    AS HANDLE          NO-UNDO.
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR "Check Version Notes Wizard" DataLogicProcedure _INLINE
/* Actions: af/cod/aftemwizcw.w ? ? ? ? */
/* MIP Update Version Notes Wizard
Check object version notes.
af/cod/aftemwizpw.w
*/
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR "Update-Object-Version" DataLogicProcedure _INLINE
/* Actions: ? ? ? ? af/sup/afverxftrp.p */
/* This has to go above the definitions sections, as that is what it modifies.
   If its not, then the definitions section will have been saved before the
   XFTR code kicks in and changes it */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR "Definition Comments Wizard" DataLogicProcedure _INLINE
/* Actions: ? af/cod/aftemwizcw.w ? ? ? */
/* Program Definition Comment Block Wizard
Welcome to the Program Definition Comment Block Wizard. Press Next to proceed.
af/cod/aftemwizpw.w
*/
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS DataLogicProcedure 
/*********************************************************************
* Copyright (C) 2000 by Progress Software Corporation ("PSC"),       *
* 14 Oak Park, Bedford, MA 01730, and other contributors as listed   *
* below.  All Rights Reserved.                                       *
*                                                                    *
* The Initial Developer of the Original Code is PSC.  The Original   *
* Code is Progress IDE code released to open source December 1, 2000.*
*                                                                    *
* The contents of this file are subject to the Possenet Public       *
* License Version 1.0 (the "License"); you may not use this file     *
* except in compliance with the License.  A copy of the License is   *
* available as of the date of this notice at                         *
* http://www.possenet.org/license.html                               *
*                                                                    *
* Software distributed under the License is distributed on an "AS IS"*
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. You*
* should refer to the License for the specific language governing    *
* rights and limitations under the License.                          *
*                                                                    *
* Contributors:                                                      *
*                                                                    *
*********************************************************************/
/*---------------------------------------------------------------------------------
  File: gsmcmlogcp.p

  Description:  gsm_comment Data Logic Procedure Library

  Purpose:      A procedure library (PLIP) to support the maintenance of the gsm_comment table
                The following internal procedures may be added or modified
                to act as validation to creation, modification, or deletion of
                records in the database table
                
                Client-side:
                rowObjectValidate***
                
                Server-side upon create:
                createPreTransValidate***
                createBeginTransValidate
                createEndTransValidate
                createPostTransValidate
                
                Server-side upon write (create and modify):
                writePreTransValidate***
                writeBeginTransValidate
                writeEndTransValidate
                writePostTransValidate
                
                Server-side upon delete:
                deletePreTransValidate
                deleteBeginTransValidate
                deleteEndTransValidate
                deletePostTransValidate
                
                *** The rowObjectValidate, createPreTransValidate and writePreTransValidate
                internal procedures are automatically generated by the SDO generator

  Parameters:

  History:
  --------
  (v:010000)    Task:    90000033   UserRef:    POSSE
                Date:   20/04/2001  Author:     Phil Magnay

  Update Notes: Data Logic Procedure Auto-Generation

  (v:010001)    Task:   101000035   UserRef:    
                Date:   09/28/2001  Author:     Johan Meyer

  Update Notes: Change use the information in entity_key_field for tables that do not have object numbers.

---------------------------------------------------------------------------------*/
/*                   This .W file was created with the Progress UIB.             */
/*-------------------------------------------------------------------------------*/

/* ***************************  Definitions  ************************** */
/* MIP-GET-OBJECT-VERSION pre-processors
   The following pre-processors are maintained automatically when the object is
   saved. They pull the object and version from Roundtable if possible so that it
   can be displayed in the about window of the container */

&scop object-name       gsmcmlogcp.p
DEFINE VARIABLE lv_this_object_name AS CHARACTER INITIAL "{&object-name}":U NO-UNDO.
&scop object-version    000000

/* Astra object identifying preprocessor */
&glob   AstraPlip    yes

DEFINE VARIABLE cObjectName         AS CHARACTER NO-UNDO.

ASSIGN cObjectName = "{&object-name}":U.

&scop   mip-notify-user-on-plip-close   NO


/* Data Preprocessor Definitions */
&GLOB DATA-LOGIC-TABLE gsm_comment
&GLOB DATA-FIELD-DEFS  "af/obj2/gsmcmfullo.i"

/* Error handling definitions */
{af/sup2/afcheckerr.i &define-only = YES}


{af/sup2/afglobals.i}

DEFINE VARIABLE glHasObjectField   AS LOGICAL    NO-UNDO.
DEFINE VARIABLE ghDataSource       AS HANDLE     NO-UNDO.
DEFINE VARIABLE gcStoreWhereClause AS CHARACTER  NO-UNDO.
DEFINE VARIABLE gcEntityMnemonic   AS CHARACTER  NO-UNDO.
DEFINE VARIABLE glAutoDisplay      AS LOGICAL    NO-UNDO.
DEFINE VARIABLE gcDescription      AS CHARACTER  NO-UNDO.
DEFINE VARIABLE ghSDO              AS HANDLE     NO-UNDO.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE DataLogicProcedure
&Scoped-define DB-AWARE yes


/* Db-Required definitions. */
&IF DEFINED(DB-REQUIRED) = 0 &THEN
    &GLOBAL-DEFINE DB-REQUIRED TRUE
&ENDIF
&GLOBAL-DEFINE DB-REQUIRED-START   &IF {&DB-REQUIRED} &THEN
&GLOBAL-DEFINE DB-REQUIRED-END     &ENDIF





/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME


/* ************************  Function Prototypes ********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD deleteRow DataLogicProcedure 
FUNCTION deleteRow RETURNS LOGICAL
  ( INPUT pcRowIdent AS CHARACTER)  FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD isQueryGoingToWork DataLogicProcedure 
FUNCTION isQueryGoingToWork RETURNS LOGICAL
  (pcWhere  AS CHARACTER,
   pcBuffer AS cHARACTER,
   pcAndOr  AS CHARACTER) FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD joinEntity DataLogicProcedure 
FUNCTION joinEntity RETURNS LOGICAL
   (  )  FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD normalizeDenormalizeList DataLogicProcedure 
FUNCTION normalizeDenormalizeList RETURNS CHARACTER
  (pcPropertyList   AS CHARACTER) FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD setPropertyinCommaList DataLogicProcedure 
FUNCTION setPropertyinCommaList RETURNS CHARACTER
  (pcPropertyList   AS CHARACTER,
   pcProperty       AS CHARACTER,
   pcAction         AS CHARACTER) FORWARD.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: DataLogicProcedure
   Allow: 
   Frames: 0
   Add Fields to: Neither
   Other Settings: CODE-ONLY COMPILE APPSERVER DB-AWARE
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB) 
  CREATE WINDOW DataLogicProcedure ASSIGN
         HEIGHT             = 25.48
         WIDTH              = 45.8.
/* END WINDOW DEFINITION */
                                                                        */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB DataLogicProcedure 
/* ************************* Included-Libraries *********************** */

{src/adm2/logic.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


 


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK DataLogicProcedure 


/* ***************************  Main Block  ******************************* */

{ry/app/ryplipmain.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* **********************  Internal Procedures  *********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE dataAvailable DataLogicProcedure 
PROCEDURE dataAvailable :
/*------------------------------------------------------------------------------
  Purpose:     Super Override
  Parameters:  
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE INPUT PARAMETER pcRelative AS CHARACTER NO-UNDO.
  
  DEFINE VARIABLE cAsDivision AS CHARACTER  NO-UNDO.
  
  {get AsDivision cAsDivision ghSDO}.

  IF ((pcRelative <> 'SAME':U) 
  AND (pcRelative <> 'DIFFERENT':U)) 
  AND cAsDivision <> 'SERVER':U 
  OR ((pcRelative = 'DIFFERENT':U) 
  AND (SOURCE-PROCEDURE = ghDataSource)) THEN
  DO:
    {fn joinEntity ghSDO}.
    {fn openQuery ghSDO}.
  END.
  ELSE 
  DO:
    RUN SUPER(pcRelative).
  END.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

{&DB-REQUIRED-START}

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE deletePostTransValidate DataLogicProcedure  _DB-REQUIRED
PROCEDURE deletePostTransValidate :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE VARIABLE httEntityMnemonic AS HANDLE     NO-UNDO.
  
  DEFINE BUFFER gsm_comment FOR gsm_comment.
  
  httEntityMnemonic = DYNAMIC-FUNCTION ("getEntityCacheBuffer" IN gshGenManager, b_gsm_comment.owning_entity_mnemonic, "":U).
  httEntityMnemonic:FIND-FIRST("WHERE ttEntityMnemonic.entity_mnemonic = '":U + b_gsm_comment.owning_entity_mnemonic + "'":U, NO-LOCK) NO-ERROR.
          
  IF NOT CAN-FIND(FIRST gsm_comment NO-LOCK 
    WHERE gsm_comment.owning_entity_mnemonic = b_gsm_comment.owning_entity_mnemonic
      AND gsm_comment.comment_obj <> b_gsm_comment.comment_obj) THEN
    ASSIGN httEntityMnemonic:BUFFER-FIELD('HasComment':U):BUFFER-VALUE     = FALSE
           httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = FALSE.
  ELSE
    IF NOT CAN-FIND(FIRST gsm_comment NO-LOCK 
      WHERE gsm_comment.owning_entity_mnemonic = b_gsm_comment.owning_entity_mnemonic
        AND gsm_comment.comment_obj <> b_gsm_comment.comment_obj
        AND gsm_comment.auto_display) THEN
      ASSIGN httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = FALSE.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

{&DB-REQUIRED-END}

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE destroyObject DataLogicProcedure 
PROCEDURE destroyObject :
/*------------------------------------------------------------------------------
  Purpose:     Super Override
  Parameters:  
  Notes:       
------------------------------------------------------------------------------*/
  /* Code placed here will execute PRIOR to standard behavior. */
  
  /*make sure that when this container is closed that the property specifying
    whether or not this maintenance suite is running is set accordingly */    
  IF VALID-HANDLE(ghDatasource) THEN
      DYNAMIC-FUNCTION("setUserProperty":U IN ghDatasource, "CommentsContainer":U, "":U) NO-ERROR.
  
  RUN SUPER.

  /* Code placed here will execute AFTER standard behavior.    */
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE getPriDataSource DataLogicProcedure 
PROCEDURE getPriDataSource :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE VARIABLE cAttrValue            AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE hContainerSource      AS HANDLE     NO-UNDO.
  {get DataSource ghDataSource}.
  IF NOT VALID-HANDLE(ghDataSource) THEN 
  DO:
    {get ContainerSource hContainerSource}.
    {get runAttribute cAttrValue hContainerSource}.
    ghDataSource = WIDGET-HANDLE(cAttrValue).
  END.
  IF NOT VALID-HANDLE(ghDataSource) THEN
    RETURN.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE initializeObject DataLogicProcedure 
PROCEDURE initializeObject :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE VARIABLE cValueList            AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cUpdatableTable       AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cEntityFields         AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cEntityValues         AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE lInitialized          AS LOGICAL       NO-UNDO.
  DEFINE VARIABLE cAsDivision           AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE hContainerSource      AS HANDLE        NO-UNDO.
  DEFINE VARIABLE cAttrValue            AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE hToolbar              AS HANDLE        NO-UNDO.

  ASSIGN ghSDO = TARGET-PROCEDURE.
  {get AsDivision cAsDivision}.

  IF cAsDivision <> 'SERVER':U 
  THEN DO:
      /*Problem with PrimarySDO link, so this uses the DataSource which is retrieved
        as a RunAttribute, as a DataSource, if getDataSource returns invalid value */
      RUN getPriDataSource IN TARGET-PROCEDURE.
         
      /* Set a Property in the DataSource conaining the handle of this procedure
         to  say that the Comments is running for this datasource so we don't launch
         it, if it is already running */
      {get ContainerSource hContainerSource}.
      
      {get ContainerToolbarSource hToolbar hContainerSource}.
      
      RUN addLink IN TARGET-PROCEDURE ( hToolbar , 'Navigation':U , ghDataSource ).
      
      DYNAMIC-FUNCTION("setUserProperty":U IN ghDatasource, "CommentsContainer":U, STRING(hContainerSource)).
      
      SUBSCRIBE TO "DataAvailable":U IN ghDatasource.
      
      {set ServerSubmitValidation YES}.
      
      ASSIGN cUpdatableTable = ENTRY(1,{fn getEnabledTables ghDataSource}) NO-ERROR.
      RUN getEntityDetail IN gshGenMAnager (INPUT cUpdatableTable, OUTPUT cEntityFields, OUTPUT cEntityValues).
      
      ASSIGN glHasObjectField = (ENTRY(LOOKUP("table_has_object_field",cEntityFields,CHR(1)),cEntityValues,CHR(1)) = "YES":U) NO-ERROR.        
      
      {fn joinEntity}.
  END.

  RUN SUPER.

  /* Running a manual openQuery as there is no foreignFields to be set as their is no one-to-one match */
  IF cAsDivision <> 'SERVER':U 
  THEN 
  DO:
      {fn openQuery}.
  END.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE killPlip DataLogicProcedure 
PROCEDURE killPlip :
/*------------------------------------------------------------------------------
  Purpose:     entry point to instantly kill the plip if it should get lost in memory
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  {ry/app/ryplipkill.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE objectDescription DataLogicProcedure 
PROCEDURE objectDescription :
/*------------------------------------------------------------------------------
  Purpose:     Pass out a description of the PLIP, used in Plip temp-table
  Parameters:  <none>
  Notes:       This should be changed manually for each plip
------------------------------------------------------------------------------*/

  DEFINE OUTPUT PARAMETER cDescription AS CHARACTER NO-UNDO.

  ASSIGN cDescription = "Dynamics gsm_comment Data Logic Procedure".

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE plipSetup DataLogicProcedure 
PROCEDURE plipSetup :
/*------------------------------------------------------------------------------
  Purpose:    Run by main-block of PLIP at startup of PLIP
  Parameters: <none>
  Notes:       
------------------------------------------------------------------------------*/

  {ry/app/ryplipsetu.i}  

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE plipShutdown DataLogicProcedure 
PROCEDURE plipShutdown :
/*------------------------------------------------------------------------------
  Purpose:     This procedure will be run just before the calling program 
               terminates
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  {ry/app/ryplipshut.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE rowObjectValidate DataLogicProcedure 
PROCEDURE rowObjectValidate :
/*------------------------------------------------------------------------------
  Purpose:     Procedure used to validate RowObject record client-side
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE VARIABLE cMessageList    AS CHARACTER      NO-UNDO.
  DEFINE VARIABLE cValueList      AS CHARACTER      NO-UNDO.

  IF b_gsm_comment.auto_display THEN
    ASSIGN glAutoDisplay = TRUE.
  ELSE
    ASSIGN glAutoDisplay = FALSE.
  ASSIGN gcDescription = b_gsm_comment.comment_DESCRIPTION.  
  
  IF b_gsm_comment.category_obj = 0 OR b_gsm_comment.category_obj = ? THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '1' 'gsm_comment' 'category_obj' "'Category Obj'"}.

  IF (LENGTH(b_gsm_comment.owning_reference) = 0 OR LENGTH(b_gsm_comment.owning_reference) = ?) 
  AND (b_gsm_comment.owning_obj = 0 OR b_gsm_comment.owning_obj = ?) THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '1' 'gsm_comment' 'owning_reference' "'Owning Reference/Owning Obj'"}.

  IF LENGTH(b_gsm_comment.owning_entity_mnemonic) = 0 OR LENGTH(b_gsm_comment.owning_entity_mnemonic) = ? THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '1' 'gsm_comment' 'owning_entity_mnemonic' "'Owning Entity Mnemonic'"}.

  IF LENGTH(b_gsm_comment.comment_description) = 0 OR LENGTH(b_gsm_comment.comment_description) = ? THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '1' 'gsm_comment' 'comment_description' "'Comment Description'"}.

  IF b_gsm_comment.auto_display = ? THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '1' 'gsm_comment' 'auto_display' "'Auto Display'"}.

  IF  b_gsm_comment.expiry_date <> ?
  AND b_gsm_comment.expiry_date < TODAY
  THEN
    ASSIGN
      cMessageList = cMessageList + (IF NUM-ENTRIES(cMessageList,CHR(3)) > 0 THEN CHR(3) ELSE '':U) + 
                    {af/sup2/aferrortxt.i 'AF' '33' 'gsm_comment' 'auto_display' "'Expiry date'" "STRING(TODAY)" }.

  ERROR-STATUS:ERROR = NO.
  RETURN cMessageList.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE submitCommit DataLogicProcedure 
PROCEDURE submitCommit :
/*------------------------------------------------------------------------------
  Purpose:     Super Override
  Parameters:  
  Notes:       
------------------------------------------------------------------------------*/

  DEFINE INPUT PARAMETER pcRowIdent AS CHARACTER NO-UNDO.
  DEFINE INPUT PARAMETER plReopen   AS LOGICAL   NO-UNDO.

  /* Code placed here will execute PRIOR to standard behavior. */
  
  RUN SUPER( INPUT pcRowIdent, INPUT plReopen).

  /* Code placed here will execute AFTER standard behavior.    */
  
  RUN updateProperties IN TARGET-PROCEDURE.
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE updateProperties DataLogicProcedure 
PROCEDURE updateProperties :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE VARIABLE cRowUserProp            AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cEntityFields           AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cForEach                AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cFieldList              AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cCommentProperty        AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cAutoComProperty        AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE lRefresh                AS LOGICAL    NO-UNDO.
  DEFINE VARIABLE lHasComment             AS LOGICAL    NO-UNDO.
  DEFINE VARIABLE httEntityMnemonic       AS HANDLE     NO-UNDO.
  DEFINE VARIABLE hRowObject              AS HANDLE     NO-UNDO.

  ASSIGN
      hRowObject       = {fn getRowObject ghDataSource}
      cRowUserProp     = hRowObject:BUFFER-FIELD('RowUserProp':U):BUFFER-VALUE
      cRowUserProp     = {fnarg normalizeDenormalizeList cRowUserProp}
      cAutoComProperty = {fnarg getPropertyFromList     "cRowUserProp, 'gsmcmauto':U" gshGenManager}
      cCommentProperty = {fnarg getPropertyFromList     "cRowUserProp, 'gsmcm':U"     gshGenManager}
      lHasComment      = {fnarg rowAvailable            'CURRENT':U}
      lRefresh         = FALSE.

  /* lHasComment basically tells us if there is at least one record in the browse, or none. 
      if there is, check that the ttRowObject.RowUserProp for the parent, has the  comment 
      property set. If AutoComment is checked, make sure that the AutoComment property is 
      also set. */

  IF lHasComment THEN
  DO:
    IF cCommentProperty <> "yes":U THEN
      ASSIGN
          cRowUserProp = {fnarg setPropertyValueInList "cRowUserProp, 'gsmcm':U, 'yes':U, '':U" gshGenManager}
          lRefresh     = TRUE.

    IF glAutoDisplay AND cAutoComProperty <> gcDescription THEN
      ASSIGN
          cRowUserProp = {fnarg setPropertyValueInList "cRowUserProp, 'gsmcmauto':U, gcDescription, '':U" gshGenManager}
          lRefresh     = TRUE.

    /* if AutoComment has just been deselected, make sure that the RowObject property is set 
       accordingly. */                                                 
    IF NOT glAutoDisplay AND cAutoComProperty <> "" THEN
      ASSIGN
          cRowUserProp = {fnarg setPropertyValueInList "cRowUserProp, 'gsmcmauto':U, 'no':U, 'REMOVE':U" gshGenManager}
          lRefresh     = TRUE.
  END.
  ELSE
  DO:
  /* if there are no records in the browse, then a record has been deleted, so set the Comment 
     property to NO in the parents rowObject.cRowUserProp field. */
    IF cCommentProperty = "yes":U THEN
      ASSIGN
          cRowUserProp = {fnarg setPropertyValueInList "cRowUserProp, 'gsmcm':U, 'no':U, '':U" gshGenManager}
          lRefresh     = TRUE.

    /* if there are no records in the browse, but the AutoComment property is set, switch it off.*/
    IF cAutoComProperty <> "" THEN
      ASSIGN cRowUserProp ={fnarg setPropertyValueInList "cRowUserProp, 'gsmcmauto':U, 'no':U, 'REMOVE':U" gshGenManager}
             lRefresh     = TRUE.
  END.

  /* lRefresh was only set, if something crucial changed, and the Tollbar needs to be updated. So 
     only run this piece of code, when neccessary. */                   
  IF lRefresh THEN
  DO:
    ASSIGN
        cEntityFields       = {fn getEntityfields ghDataSource}
        cRowUserProp        = {fnarg normalizeDenormalizeList cRowUserProp}
        cEntityFields       = (IF cEntityFields = ? THEN  "":U ELSE cEntityFields)
        httEntityMnemonic   = {fnarg getEntityCacheBuffer "gcEntityMnemonic, '':U" gshGenManager}
        hRowObject:BUFFER-FIELD('RowUserProp':U):BUFFER-VALUE = cRowUserProp.

    httEntityMnemonic:FIND-FIRST("WHERE entity_mnemonic = '":U + gcEntityMnemonic + "'":U, NO-LOCK) NO-ERROR.

    /* httEntityMnemonic is a handle to the Buffer of the EntityMnemonic temp-table, which is kept 
       running throughout the session  and tells maintenance suite's whether or not the Tables concerned 
       have comments, autocomments,audits etc. So this needs to be updated in order for the toolbar to 
       correclty reflect Comments, and autocomments for the session.*/
         
    IF (NOT(lHasComment) AND INDEX(cEntityFields,"HasComment":U) > 0) OR
       (    lHasComment  AND INDEX(cEntityFields,"HasComment":U) = 0) THEN
    ttEntityMnemonic-block:
    DO:
      IF NOT lHasComment THEN
      DO:
        cForEach = "FOR EACH gsm_comment NO-LOCK WHERE gsm_comment.owning_entity_mnemonic = '":U + gcEntityMnemonic + "'":U.

        RUN getRecordDetail IN gshGenManager ( INPUT cForEach, OUTPUT cFieldList) NO-ERROR.

        IF LOOKUP("gsm_comment.owning_entity_mnemonic":U, cFieldList, CHR(3)) > 0 THEN
          LEAVE ttEntityMnemonic-block.
        ELSE
          cEntityFields = {fnarg setPropertyInCommaList "cEntityFields, 'HasComment':U, 'DELETE':U"}.
      END.
      ELSE
        cEntityFields = {fnarg setPropertyInCommaList "cEntityFields, 'HasComment':U, 'ADD':U"}.

      /* The entityFields propertylist also needs to be correctly set, so that the cRowUserProp fields 
         are correctly populated when the query is resolved. */

      IF httEntityMnemonic:AVAILABLE THEN
        httEntityMnemonic:BUFFER-FIELD('HasComment':U):BUFFER-VALUE = (IF lHasComment THEN "yes":U ELSE "no":U).
    END.

    cForEach = "FOR EACH gsm_comment NO-LOCK ":U
             + "   WHERE gsm_comment.owning_entity_mnemonic = '":U + gcEntityMnemonic
             + "'    AND gsm_comment.auto_display           = TRUE":U.

    RUN getRecordDetail IN gshGenManager ( INPUT cForEach, OUTPUT cFieldList) NO-ERROR.

    IF INDEX(cEntityFields,"AutoComment":U) > 0 THEN
    DO:
      IF (lHasComment AND NOT(glAutoDisplay)) OR NOT(lHasComment) THEN
      DO:
        IF LOOKUP("gsm_comment.owning_entity_mnemonic":U,cFieldList,CHR(3)) = 0  AND httEntityMnemonic:AVAILABLE  THEN
          ASSIGN httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = FALSE
                 cEntityFields = {fnarg setPropertyinCommaList "cEntityFields, 'AutoComment':U, 'DELETE':U"}.
      END.
    END.
    ELSE
      IF lHasComment AND glAutoDisplay THEN
        ASSIGN httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = TRUE
               cEntityFields = {fnarg setPropertyinCommaList "cEntityFields, 'AutoComment':U, 'ADD':U"}.

    /* All properties and values with regard to Comments and AutoComments are correctly set, so now 
       Tell the parent there is Data available so it will refresh the toolbar amongst other things. */

    {set entityFields cEntityFields ghDataSource} NO-ERROR.
    
    RUN dataAvailable IN ghDataSource (INPUT "VALUE-CHANGED":U).

  END.

  ASSIGN glAutoDisplay = FALSE
         gcDescription = "".

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

{&DB-REQUIRED-START}

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE writePostTransValidate DataLogicProcedure  _DB-REQUIRED
PROCEDURE writePostTransValidate :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE VARIABLE httEntityMnemonic AS HANDLE     NO-UNDO.
  
  DEFINE BUFFER gsm_comment FOR gsm_comment.
  
  httEntityMnemonic = DYNAMIC-FUNCTION ("getEntityCacheBuffer" IN gshGenManager, b_gsm_comment.owning_entity_mnemonic, "":U).
  httEntityMnemonic:FIND-FIRST("WHERE ttEntityMnemonic.entity_mnemonic = '":U + b_gsm_comment.owning_entity_mnemonic + "'":U, NO-LOCK) NO-ERROR.
  
  IF NOT CAN-FIND(FIRST gsm_comment NO-LOCK 
    WHERE gsm_comment.owning_entity_mnemonic = b_gsm_comment.owning_entity_mnemonic
      AND gsm_comment.comment_obj <> b_gsm_comment.comment_obj) THEN
    ASSIGN httEntityMnemonic:BUFFER-FIELD('HasComment':U):BUFFER-VALUE = TRUE.
    
  IF b_gsm_comment.auto_display THEN 
    ASSIGN httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = TRUE.
  ELSE
    IF NOT CAN-FIND(FIRST gsm_comment NO-LOCK 
      WHERE gsm_comment.owning_entity_mnemonic = b_gsm_comment.owning_entity_mnemonic
        AND gsm_comment.comment_obj <> b_gsm_comment.comment_obj
        AND gsm_comment.auto_display) THEN
      ASSIGN httEntityMnemonic:BUFFER-FIELD('HasAutoComment':U):BUFFER-VALUE = FALSE.
    
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

{&DB-REQUIRED-END}

/* ************************  Function Implementations ***************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION deleteRow DataLogicProcedure 
FUNCTION deleteRow RETURNS LOGICAL
  ( INPUT pcRowIdent AS CHARACTER) :
/*------------------------------------------------------------------------------
  Purpose: Override to refresh parent
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE VARIABLE lCommentOK    AS LOGICAL        NO-UNDO.

  lCommentOK = SUPER( INPUT pcRowIdent ) NO-ERROR.

  IF lCommentOK THEN
  DO:
    IF VALID-HANDLE(ghDataSource) THEN 
      RUN updateProperties IN TARGET-PROCEDURE.
  END.

  RETURN lCommentOK.

END FUNCTION.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION isQueryGoingToWork DataLogicProcedure 
FUNCTION isQueryGoingToWork RETURNS LOGICAL
  (pcWhere  AS CHARACTER,
   pcBuffer AS cHARACTER,
   pcAndOr  AS CHARACTER):
/*------------------------------------------------------------------------------
   Purpose:    Due to the order in which things are instantiated, updating the 
               SDO query is only going to work later.  This function will let us
               know if our new WHERE clause is going to validate or not.
 
   Parameters: 
     pcWhere     - Expression to add (may also be an "OF" phrase)  
     pcBuffer    - optional buffer specification
     pcAndOr     - Specifies the operator that is used to add the new
                   expression to existing expression(s)
                   - AND (default) 
                   - OR         
   Notes:      
------------------------------------------------------------------------------*/
  DEFINE VARIABLE cQueryString AS CHARACTER NO-UNDO.
  DEFINE VARIABLE cBuffer      AS CHARACTER  NO-UNDO.
  
  {get QueryString cQueryString}.      

  IF cQueryString = "":U 
  OR cQueryString = ? 
  THEN DO:
      {get QueryWhere cQueryString}.    
      IF cQueryString = "":U 
      OR cQueryString = ? THEN
          {get OpenQuery cQueryString}.
  END.

  /* Unless buffer is defined, use the first buffer reference in the expression*/

  IF pcBuffer <> ?
  THEN DO:
      cBuffer = {fnarg resolveBuffer pcBuffer}.

      IF cBuffer = "":U 
      OR cBuffer = ? THEN
          RETURN FALSE.
  END.

  RETURN TRUE.

END FUNCTION.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION joinEntity DataLogicProcedure 
FUNCTION joinEntity RETURNS LOGICAL
   (  ) :
/*------------------------------------------------------------------------------
  Purpose: Join to data source  
    Notes:  
------------------------------------------------------------------------------*/
  DEFINE VARIABLE cOwningEntityMnemonic AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cKeyFields            AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cTable                AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cWhere                AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE cKeyValue             AS CHARACTER     NO-UNDO.
  DEFINE VARIABLE iLoop                 AS INTEGER       NO-UNDO.
  
  {get KeyFields cKeyFields ghDataSource}.
  {get KeyTableId cOwningEntityMnemonic ghDataSource}.
  
  ASSIGN gcEntityMnemonic = cOwningEntityMnemonic
         cKeyValue        = DYNAMIC-FUNCTION("colValues":U IN ghDataSource, cKeyfields)
                            /* Strip out the RowIdent part */
         cKeyValue        = SUBSTRING(cKeyValue,INDEX(cKeyValue,CHR(1)) + 1).

  IF glHasObjectField 
  THEN DO:
      ASSIGN cKeyValue = STRING(DECIMAL(cKeyValue))
             cWhere = "gsm_comment.owning_entity_mnemonic = '":U + cOwningEntityMnemonic + "' AND ":U + 
                      "gsm_comment.owning_obj = '":U + cKeyValue + "'":U.
  END.
  ELSE DO:
      ASSIGN cKeyValue = REPLACE(cKeyValue,CHR(1),CHR(2)).
      ASSIGN
         cWhere = "gsm_comment.owning_entity_mnemonic = '":U + cOwningEntityMnemonic + "' AND ":U + 
                  "gsm_comment.owning_reference = '":U + TRIM(cKeyValue) + "'  ".
  END.
  
  DYNAMIC-FUNCTION("setUserProperty":U IN TARGET-PROCEDURE, "OwningEntityMnemonic":U, cOwningEntityMnemonic).
  DYNAMIC-FUNCTION("setUserProperty":U IN TARGET-PROCEDURE, "OwningReference":U, cKeyValue).
  DYNAMIC-FUNCTION("setUserProperty":U IN TARGET-PROCEDURE, "TableHasObjField":U, STRING(glHasObjectField)).

    /** If the where clause that has been build is null or blank, then force the query to
     *  open with no data, becasue we don't want to display all comments to the user.
     *  ----------------------------------------------------------------------- **/
    IF cWhere EQ ? OR cWhere EQ "":U THEN
        ASSIGN cWhere = " FALSE ":U.
    
  /* Applying the filter for Owning Entity Mnemonics */
  IF cWhere > '':U
  AND gcStoreWhereClause <> cWhere
  AND DYNAMIC-FUNCTION("isQueryGoingToWork":U IN TARGET-PROCEDURE, cWhere, "gsm_comment":U, "AND":U) = YES THEN
  DO:
    ASSIGN gcStoreWhereClause = cWhere.
    DYNAMIC-FUNCTION("setQueryWhere":U IN TARGET-PROCEDURE,"":U).
    DYNAMIC-FUNCTION("addQueryWhere":U IN TARGET-PROCEDURE, INPUT cWhere, "":U, "AND":U).

    ASSIGN cWhere = cWhere +  CHR(3) + CHR(3) + "AND":U.
    {set manualAddQueryWhere cWhere}.
  END.

  RETURN TRUE.   /* Function return value. */

END FUNCTION.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION normalizeDenormalizeList DataLogicProcedure 
FUNCTION normalizeDenormalizeList RETURNS CHARACTER
  (pcPropertyList   AS CHARACTER):
/*------------------------------------------------------------------------------
  Purpose:  Used to Normalize and denormalize a Property list, by switching
            CHR(3) and CHR(4) delimiters around.
    Notes:  
------------------------------------------------------------------------------*/

  DEFINE VARIABLE cNewPropertyList AS CHARACTER  NO-UNDO.

  ASSIGN cNewpropertyList = REPLACE(pcPropertyList,CHR(3),CHR(1))
         cNewpropertyList = REPLACE(cNewpropertyList,CHR(4),CHR(3))
         cNewpropertyList = REPLACE(cNewpropertyList,CHR(1),CHR(4)).

  RETURN cNewpropertyList.

END FUNCTION.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION setPropertyinCommaList DataLogicProcedure 
FUNCTION setPropertyinCommaList RETURNS CHARACTER
  (pcPropertyList   AS CHARACTER,
   pcProperty       AS CHARACTER,
   pcAction         AS CHARACTER):
/*------------------------------------------------------------------------------
  Purpose:  To Set an entry in the a comma delimited list.
            if pcAction = "ADD", add it if its not there, else leave it alone
            If pcAction = "DELETE", remove from list.
    Notes:  
------------------------------------------------------------------------------*/

  DEFINE VARIABLE cNewPropertyList      AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE cEntry                AS CHARACTER  NO-UNDO.
  DEFINE VARIABLE iNumEntries           AS INTEGER    NO-UNDO.
  DEFINE VARIABLE iEntry                AS INTEGER    NO-UNDO.
  DEFINE VARIABLE lFound                AS LOGICAL    NO-UNDO.

  ASSIGN iNumEntries = NUM-ENTRIES(pcPropertyList,",")
         lFound      = FALSE.

  DO iEntry = 1 TO iNumEntries:
    ASSIGN cEntry   = ENTRY(iEntry, pcPropertyList,",").

    IF cEntry = pcProperty THEN
    DO:
      ASSIGN lFound = TRUE.
      IF pcAction = "DELETE"  THEN NEXT.
    END.

    IF cNewPropertyList = "" THEN
      ASSIGN cNewPropertyList = cEntry.
    ELSE
      ASSIGN cNewPropertyList = cNewPropertyList + "," + cEntry.

  END.

  IF NOT lFound AND pcAction = "ADD" THEN
  DO:
    IF cNewPropertyList = "" OR cNewPropertyList = ? THEN
      ASSIGN cNewPropertyList = pcProperty.
    ELSE
      ASSIGN cNewPropertyList = cNewPropertyList + "," + pcProperty.
  END.

  RETURN cNewPropertyList.   /* Function return value. */

END FUNCTION.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

