home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / audit.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  119 lines

  1. /*
  2.  * File......: AUDIT.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_AUDIT()
  24.  *  $CATEGORY$
  25.  *     Audit
  26.  *  $ONELINER$
  27.  *     Update an audit trail
  28.  *  $SYNTAX$
  29.  *      GT_Audit( cTable , cOperation , lSecond )
  30.  *  $ARGUMENTS$
  31.  *      cTable     - Table to be audited
  32.  *      cOperation - Operation that has been performed
  33.  *      lSecond    - Should a second index be maintained
  34.  *  $RETURNS$
  35.  *      NIL
  36.  *  $DESCRIPTION$
  37.  *      The current record in cTable is written to the audit table (in
  38.  *      AUDIT\) together with the date, time and username of the current
  39.  *      operator.
  40.  *      If lSecond is .T., an index identified as LEFT( cTable , 7 ) + "1"
  41.  *      is opened and maintained.  The normal index (cTable) will be on
  42.  *      auditdate+audittime, and the second index will be on the normal key
  43.  *      of cTable.
  44.  *
  45.  *      cTable must be SELECTed before calling.
  46.  *  $EXAMPLES$
  47.  *
  48.  *  $SEEALSO$
  49.  *
  50.  *  $INCLUDE$
  51.  *      GT_LIB.CH
  52.  *  $END$
  53.  */
  54.  
  55. #include "GT_LIB.ch"
  56.  
  57. FUNCTION GT_Audit( cTable , cOperation , lSecond )
  58. MEMVAR cUserName
  59.  
  60. /****************************************************************************
  61.  Purpose - Audit current record in table cTable
  62.  Returns - None
  63.  Author  - M K Colloby
  64.  Created - 3/3/92
  65. ******************************************************************************
  66.  Parameters - cTable      - Table to be audited
  67.               cOperation  - Operation performed
  68.               lSecond     - If .T., use two indexes
  69.  Locals     - aFields     - Array to hold fields in cTable
  70.               nCount      - Counting variable
  71.  PUBLICS    - cUserName   - Name of user performing operation
  72. ****************************************************************************/
  73.  
  74. LOCAL aFields  :={}
  75. LOCAL aIndexes := { "audit\" + cTable }
  76. LOCAL nCount   := 0
  77.  
  78. // Select the table
  79. SELECT ( cTable )
  80.  
  81. // Copy the contents of the data table into the array
  82. FOR nCount := 1 TO FCOUNT()
  83.     AADD( aFields , FIELDGET( nCount ) )
  84. NEXT
  85.  
  86. IF lSecond
  87.     AADD( aIndexes , "audit\" + ALLTRIM( LEFT( cTable , 7 ) ) + "1" )
  88. ENDIF
  89.  
  90. // Open the Audit table
  91. GT_UseDbf( "audit\" + cTable , aIndexes , "audit" , .F. , .F. , .F. , 5 )
  92.  
  93. // Add a blank record
  94. GT_AddRec( 5 )
  95.  
  96. // Update the key fields
  97. REPLACE audit->auditdate WITH DATE()
  98. REPLACE audit->audittime WITH TIME()
  99. REPLACE audit->audituser WITH cUserName
  100. REPLACE audit->auditops  WITH cOperation
  101.  
  102. // This code block stuffs the contents of the array a_fields into the current
  103. // table, but places them four fields to the right of their ordinal position
  104. // in the array - this gets them past the first four key fields
  105. AEVAL( aFields , { |value, count| FIELDPUT( count + 4 , value ) } )
  106.  
  107. // Unlock the audit table record
  108. UNLOCK
  109.  
  110. // Release the audit table
  111. SELECT "audit"
  112. USE
  113.  
  114. // Go back to the source table
  115. SELECT ( cTable )
  116.  
  117. RETURN NIL
  118. *
  119.