set audit_name [lindex $argv 0]
set audit_file [lindex $argv 1]
set position 0
set show 1
if { $audit_file == "GET" } {
GuidoForm LoadFile {
-default_buttons
-defaults_management false
-label "Load Audit Trail From File"
-layout BoxLayout X_AXIS
-help_id 814
GuidoLabel info {
-label "Select Audit"
}
GuidoFiller f66 {
-width 1
}
GuidoFileBrowserField auditFile {
-display_length 16
-format none
-max_length 256
}
}
set status ""
$LoadFile interact
set status [ $LoadFile getStatus ]
if { $status == "apply" } {
set file "[$auditFile getCurrentValue]"
set buffer [ GuidoExecServer "ViewAuditFile" [subst {  auditName = "$audit_name" file = $file}] ]
set audit_file $file
set position [GuidoGetParamBufferValue $buffer "position"]
} else {
set show 0
}
} elseif { $audit_file != "" } {
set buffer [ GuidoExecServer "ViewAuditFile" [subst { auditName = "$audit_name" file = $audit_file}] ]
set audit_file $audit_file
set position [GuidoGetParamBufferValue $buffer "position"]
}
global AuditTrail
proc getSelectedFunctions {} {
global audit_name
global audit_tree
set node ""
set idx 0
GuidoExecServer "RemoveSelectedAuditFunctions" [subst  { auditName = "$audit_name" } ]
while { 1 } {
set node [ $audit_tree getSelectedNodes $idx]
incr idx
if { $node == -1  } {
break;
}
set nodeLabel [$node getLabelText]
GuidoExecServer "AddSelectedAuditFunction" [subst  { auditName = "$audit_name" nodeName =  "$nodeLabel" } ]
}
}
proc getSelectedNodes {} {
global audit_name
global audit_tree
set node ""
set idx 0
GuidoExecServer "RemoveSelectedAuditNodes" [subst  { auditName = "$audit_name" } ]
while { 1 } {
set node [ $audit_tree getSelectedNodes $idx]
incr idx
if { $node == -1  } {
break;
}
if {[$node isLeaf]} {
set parent [$node getParent]
set grandparent [$parent getParent]
set label [ $grandparent getLabelText]
set root [ $audit_tree getRootNode ]
set rootlabel [ $root getLabelText ]
if { $rootlabel == $label } {
set functionLabel [ $parent getLabelText]
} else {
set functionLabel $label
}
} else {
set functionLabel [ $node getLabelText ]
}
set nodeLabel [$node getLabelText]
GuidoExecServer "AddSelectedAuditNode" [subst  { auditName = "$audit_name" functionName =  "$functionLabel" nodeName = "$nodeLabel" } ]
}
}
proc getUpdatedNodes {} {
global audit_name
global audit_tree
set node ""
set idx 0
set buffer [ GuidoExecServer "GetUpdatedNodes" [subst  { auditName = "$audit_name" } ]  ]
while { 1 } {
set node [ $audit_tree getSelectedNodes $idx]
incr idx
if { $node == -1  } {
break;
}
set field "[GuidoGetParamBufferValue $buffer node$idx ]"
set function "[GuidoGetParamBufferValue $buffer func$idx ]"
if {[$node isLeaf]} {
$node setLabel "$field"
} else {
$node setLabel "$function"
}
}
}
proc renameApply { frmHandle value newNameFld functionLabel } {
global audit_name
global audit_tree
if { $value == "apply" } {
set newName "[$newNameFld getCurrentValue]"
regsub -all {\"} $newName {^} newName
set buffer [ GuidoExecServer "SetAuditFieldValue" [subst { auditName = "$audit_name" functionName = "$functionLabel" changeName = "$newName" } ]  ]
getUpdatedNodes
$frmHandle hide
$frmHandle destroy
}
if { $value == "cancel" } {
$frmHandle hide
$frmHandle destroy
}
if { $value == "help" } {
$frmHandle setStatus $frmStatus
}
}
proc renameAuditNode { frm } {
global audit_tree
global audit_name
getSelectedNodes
set selectedNode [ $audit_tree getSelectedNode ]
if { $selectedNode == "" } {
return
}
set nodeLabel [ $selectedNode getLabelText ]
set parent [$selectedNode getParent]
set grandparent [$parent getParent]
set label [ $grandparent getLabelText]
set root [ $audit_tree getRootNode ]
set rootlabel [ $root getLabelText ]
if { $rootlabel == $label } {
set functionLabel [ $parent getLabelText]
} else {
set functionLabel $label
}
regsub -all {\"} $nodeLabel {^} nodeLabel
set buffer [ GuidoExecServer "GetAuditFieldValue" [subst { auditName = "$audit_name" nodeName =  "$nodeLabel" functionName = "$functionLabel" } ]  ]
set functionValue "[GuidoGetParamBufferValue $buffer value ]"
GuidoForm renameForm {
-help_id 814
-label FRM_RENAME_AUDIT_FIELD
-defaults_management true
-tip AUDIT_RENAME_FORM_TIP
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoPanel selectDDBFilePanel {
-layout BoxLayout X_AXIS
GuidoField newNameFld {
-display_length 25
-format none
-default "$functionValue"
-label FRM_NEW_AUDIT_FIELD
-null false
}
}
GuidoPanel ButtonPanel {
-layout FlowLayout center 0 3
GuidoButton applyButton {
-caption "Rename"
-icon "icons/16/activate.png"
-display_length 10
-action valueChanged {[renameApply $renameForm "apply" "$newNameFld" "$functionLabel" ]}
}
GuidoButton cancelButton {
-caption "Cancel"
-icon "icons/cancel.png"
-display_length 10
-action valueChanged {[renameApply $renameForm "cancel" "$newNameFld" "$functionLabel" ]}
}
GuidoButton helpButton {
-caption "Help"
-icon "icons/16/help.png"
-display_length 10
-action valueChanged {[renameApply $renameForm "help" "$newNameFld" "$functionLabel" ]}
}
}
}
}
$renameForm show modal
}
proc reallydeleteAuditComment { frm value } {
if { $value == "apply" } {
global audit_name
global audit_tree
getSelectedNodes
set buffer [ GuidoExecServer "SetAuditComment" [subst  { auditName = "$audit_name" comment = "" } ]  ]
getUpdatedNodes
}
$frm hide
$frm destroy
}
proc deleteAuditComment { frm } {
global audit_tree
set node [ $audit_tree getSelectedNode ]
if { $node == "" } {
return
}
set parent [$node getParent]
if { $parent == "" } {
return
}
GuidoForm confirm {
-label "Delete audit comment"
GuidoFiller f {
-height 1
}
GuidoLabel l {
-label "This will delete the comment(s) permanently"
}
GuidoFiller f {
-height 1
}
GuidoPanel ButtonPanel {
-layout FlowLayout center 0 3
GuidoButton applyButton {
-caption "Delete"
-icon "icons/16/activate.png"
-display_length 10
-action valueChanged {[reallydeleteAuditComment $confirm "apply" ]}
}
GuidoButton cancelButton {
-caption "Cancel"
-icon "icons/cancel.png"
-display_length 10
-action valueChanged {[reallydeleteAuditComment $confirm "cancel" ]}
}
GuidoButton helpButton {
-caption "Help"
-icon "icons/16/help.png"
-display_length 10
-action valueChanged {[reallydeleteAuditComment $confirm "help" ]}
}
}
}
set status ""
$confirm show modal
}
proc commentApply { frmHandle value newNameFld } {
global audit_name
global audit_tree
set selectedNode [$audit_tree getSelectedNode]
set nodeLabel [ $selectedNode getLabelText]
if { $value == "apply" } {
set newName "[$newNameFld getCurrentValue]"
set buffer [ GuidoExecServer "SetAuditComment" [subst  { auditName = "$audit_name" comment = "$newName" } ]  ]
getUpdatedNodes
$frmHandle hide
$frmHandle destroy
}
if { $value == "cancel" } {
$frmHandle hide
$frmHandle destroy
}
if { $value == "help" } {
$frmHandle setStatus $frmStatus
}
}
proc changeAuditComment { frm } {
global audit_tree
global audit_name
getSelectedNodes
set node [ $audit_tree getSelectedNode ]
if { $node == "" } {
return
}
set parent [$node getParent]
if { $parent == "" } {
return
}
set nodeName [$node getLabelText]
set buffer [ GuidoExecServer "GetAuditComment" [subst  { auditName = "$audit_name" nodeName = "$nodeName" } ]  ]
set nodeComment "[GuidoGetParamBufferValue $buffer comment ]"
GuidoForm commentForm {
-help_id 814
-label FRM_EDIT_AUDIT_COMMENT
-defaults_management true
-tip AUDIT_COMMENT_FORM_TIP
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoPanel selectDDBFilePanel {
-layout BoxLayout X_AXIS
GuidoField newNameFld {
-display_length 15
-format none
-default "$nodeComment"
-label FRM_AUDIT_COMMENT
-max_length 36
-tip AUDIT_NEW_COMMENT_TIP
}
}
GuidoPanel ButtonPanel {
-layout FlowLayout center 0 3
GuidoButton applyButton {
-caption "Rename"
-icon "icons/16/activate.png"
-display_length 10
-action valueChanged {[commentApply $commentForm "apply" "$newNameFld" ]}
}
GuidoButton cancelButton {
-caption "Cancel"
-icon "icons/cancel.png"
-display_length 10
-action valueChanged {[commentApply $commentForm "cancel" "$newNameFld" ]}
}
GuidoButton helpButton {
-caption "Help"
-icon "icons/16/help.png"
-display_length 10
-action valueChanged {[commentApply $commentForm "help" "$newNameFld" ]}
}
}
}
}
$commentForm show modal
}
proc formApply { frmHandle value type} {
global formatType
global details
global audit_name
global location
if { $value == "apply" } {
if { $type == "report" } {
set fileName "[$location getCurrentValue]"
set output "[$details getCurrentValue]"
set format_type "[$formatType getCurrentValue]"
GuidoApp app "AUDIT EXPORT"
$app setParam export "report"
$app setParam title "Audit Report"
$app setParam file_name $fileName
$app setParam format_type $format_type
$app setParam output $output
$app setParam audit_name $audit_name
set result [$app invoke]
$app destroy
} elseif { $type == "macro" } {
set fileName "[$location getCurrentValue]"
GuidoApp app "AUDIT EXPORT"
$app setParam file_name $fileName
$app setParam audit_name $audit_name
$app setParam export "macro"
set result [$app invoke]
$app destroy
}
$frmHandle hide
$frmHandle destroy
}
if { $value == "cancel" } {
$frmHandle hide
$frmHandle destroy
GuidoExecServer "RemoveSelectedAuditFunctions" [subst  { auditName = "$audit_name" } ]
GuidoExecServer "RemoveSelectedAuditNodes" [subst  { auditName = "$audit_name" } ]
}
if { $value == "help" } {
$frmHandle setStatus $frmStatus
}
}
proc save { title fileTypes type} {
global location
global formatType
global details
global audit_name
GuidoForm saveForm {
-help_id 814
-defaults_management true
-tip AUDIT_SAVE_FORM_TIP
if { $type == "report" } {
-label "Save Report"
} else {
-label "Save Macro"
}
-layout BoxLayout Y_AXIS
GuidoPanel outerPanel1 {
-layout CentreLineLayout
GuidoFileBrowserField location {
-display_length 26
-file_mask "*.tcl"
-label "Name :"
-format none
-tip AUDIT_LOCATION_TIP
-max_length 252
-translate none
}
if { $type == "report" } {
GuidoComboBox formatType {
-format string
-label "Format"
-display_length 24
-exclusive true
-value_in ".not - Surpac Note File" ".csv - Comma Separated (Spreadsheet)" ".htm - Hypertext Markup Language (Web)" ".html - Hypertext Markup Language (Web)" ".rtf - Rich Text Format (Microsoft Word)" ".pdf - Adobe Acrobat" ".ps - Postscript"
-null false
-tip AUDIT_REPORT_FORMAT_TIP
}
GuidoComboBox details {
-format string
-label "Output"
-display_length 24
-exclusive true
-value_in "Summary of Functions" "Functions with Form Data"
-null false
-tip AUDIT_REPORT_DETAILS_TIP
}
}
}
GuidoPanel ButtonPanel {
-layout FlowLayout center 0 3
GuidoButton applyButton {
-caption "Save"
-icon "icons/16/save_as.png"
-display_length 10
-action valueChanged {[formApply $saveForm "apply" $type]}
}
GuidoButton cancelButton {
-caption "Cancel"
-icon "icons/cancel.png"
-display_length 10
-action valueChanged {[formApply $saveForm "cancel" $type]}
}
GuidoButton helpButton {
-caption "Help"
-icon "icons/16/help.png"
-display_length 10
-action valueChanged {[formApply $saveForm "help" $type]}
}
}
}
$saveForm show modal
}
proc saveAudit { frm type } {
getSelectedFunctions
if { $type == "report" } {
save "Save Report File" "*.csv *.not *.ps *.pdf *.htm *.html *.rtf" $type
} elseif { $type == "macro" } {
save "Save Macro" "*.tcl" $type
}
}
GuidoPopupMenu branchPopupOptions {
GuidoMenuItem CommentItem {
-label FRM_AUDIT_CHANGE_COMMENT
-action mouseReleased { [changeAuditComment $AuditTrail ] }
}
GuidoMenuItem DeleteCommentItem {
-label FRM_AUDIT_DELETE_COMMENT
-action mouseReleased { [deleteAuditComment $AuditTrail ] }
}
}
GuidoPopupMenu leafPopupOptions {
GuidoMenuItem RenameItem {
-label "Rename"
-action mouseReleased { [renameAuditNode $AuditTrail ] }
}
}
proc drawFunctions { formHandle } {
global audit_name
global audit_tree
global audit_branch
global branchPopupOptions
set rootNode [$audit_tree getRootNode]
set buffer [ GuidoExecServer "GetAuditNumFunctions" [subst { auditName = "$audit_name" } ] ]
set numFunctions "[GuidoGetParamBufferValue $buffer numFunctions ]"
for {set func_num 0} {$func_num < $numFunctions } {incr func_num} {
set buffer [ GuidoExecServer "GetAuditFunction" [subst  { auditName = "$audit_name" functionNum = $func_num }  ]  ]
set functionName "[GuidoGetParamBufferValue $buffer functionName ]"
GuidoTreeBranch function$func_num {
-label "$functionName"
-menu $branchPopupOptions
-menu_enabled true
}
upvar 0 function$func_num function
$rootNode addChild $function
}
$rootNode removeChild $audit_branch
$formHandle updateFieldList
}
proc getFunctionData { formHandle } {
global audit_tree
global audit_name
set idx 0
set formTitle "None"
set formFields "None"
set form_num 0
set node [ $audit_tree getSelectedNode ]
if { $node == "" } {
return
}
if {[$node isLeaf]} {
return
}
set count [ $node getChildCount]
if { $count > 0 } {
return
}
set nodeLabel [$node getLabelText]
set buffer [ GuidoExecServer "GetSelectedAuditData" [subst  { auditName = "$audit_name" nodeName =  "$nodeLabel" } ] ]
set field_num 0
set formTitle "[GuidoGetParamBufferValue $buffer formTitle$form_num ]"
if { $formTitle != "" } {
while { $formTitle != "" } {
GuidoTreeBranch frmTitle$form_num {
-label "$formTitle"
-menu_enabled false
set formFields "[GuidoGetParamBufferValue $buffer formFields$form_num$field_num ]"
while { $formFields != "" } {
GuidoTreeLeaf frmFields$form_num {
-label "$formFields"
-menu_enabled false
}
incr field_num
set formFields "[GuidoGetParamBufferValue $buffer formFields$form_num$field_num ]"
}
}
upvar 0 frmTitle$form_num form
$node addChild $form
incr form_num
set field_num 0
set formTitle "[GuidoGetParamBufferValue $buffer formTitle$form_num ]"
}
} elseif { $formFields != "" && $form_num == 0 && [ string length $formFields ] > 3 } {
set field_num 0
set formFields "[GuidoGetParamBufferValue $buffer formFields$form_num$field_num ]"
while { $formFields != "" } {
GuidoTreeLeaf frmFields$form_num {
-label "$formFields"
-menu_enabled false
}
incr field_num
set formFields "[GuidoGetParamBufferValue $buffer formFields$form_num$field_num ]"
upvar 0 frmFields$form_num form
$node addChild $form
}
}
$formHandle updateFieldList
}
if { $audit_name == "BLOCK_MODEL_AUDIT" } {
GuidoApp check_bm "CHECK BM CONNECTED"
$check_bm setParam functionName "BLOCK_MODEL_AUDIT"
set result [$check_bm invoke]
$check_bm destroy
if { $result != "0" } {
set show 0
}
}
global audit_name
global saveForm
GuidoForm AuditTrail {
-default_buttons
-defaults_management false
-label "Audit Trail"
-action initial {[drawFunctions $AuditTrail] }
-layout BoxLayout Y_AXIS
-help_id 814
GuidoLabel info {
-label FRM_AUDIT_EXPORT
-font_style bold
}
GuidoLabel info2 {
-label FRM_AUDIT_OPTIONS
-font_style bold
}
GuidoPanel main {
-layout BoxLayout X_AXIS
GuidoPanel left {
-layout BoxLayout Y_AXIS
GuidoScrollPane sp {
-height 17
-width 60
set modelName ""
if { $audit_name == "BLOCK_MODEL_AUDIT" } {
set buffer [ GuidoExecServer "GetBlockModelParameters" { } ]
set modelName "[GuidoGetParamBufferValue $buffer Name ]"
} else {
set modelName $audit_file
}
GuidoTree audit_tree {
-label $modelName
-leaf_menu $leafPopupOptions
-action valueChanged {[getFunctionData $AuditTrail] }
GuidoTreeBranch audit_branch {
-menu_enabled false
}
}
}
}
GuidoFiller f1 {
-width 0.5
}
GuidoPanel right {
-layout BoxLayout Y_AXIS
GuidoButton change_comment {
-icon "icons/16/edit.png"
-display_length 15
-caption FRM_AUDIT_CHANGE_COMMENT
-action valueChanged { [ changeAuditComment $AuditTrail ] }
-height 1
-tip AUDIT_CHANGE_COMMENT_TIP
}
GuidoFiller f1 {
-height 0.3
}
GuidoButton delete_comment {
-icon "icons/16/delete.png"
-display_length 15
-caption FRM_AUDIT_DELETE_COMMENT
-action valueChanged { [ deleteAuditComment $AuditTrail ] }
-height 1
-tip AUDIT_DELETE_COMMENT_TIP
}
GuidoFiller f1 {
-height 0.3
}
GuidoButton save_macro {
-icon "icons/16/save_as.png"
-display_length 15
-caption FRM_AUDIT_SAVE_MACRO
-action valueChanged { [ saveAudit $AuditTrail "macro"] }
-height 1
-tip AUDIT_SAVE_MACRO_TIP
}
}
}
GuidoFiller filler_height_1 {
-height 1
}
$audit_tree setTreeIcons "icons/Form.gif" "icons/Database.gif" "icons/GraphicsStreamingIdle.gif"
GuidoFiller space {
-height 0.3
}
}
if { $show } {
set status ""
$AuditTrail interact
set status [ $AuditTrail getStatus ]
if { $status == "apply" && $audit_name == "VIEW_AUDIT" && $position >= 0 } {
set buffer [ GuidoExecServer "CloseAuditFile" [subst {auditName = $audit_name fileName = $audit_file action = "save" position = $position }] ]
} elseif { $audit_name == "VIEW_AUDIT" } {
set buffer [ GuidoExecServer "CloseAuditFile" [subst {auditName = $audit_name fileName = $audit_file action = "close" position = $position }] ]
}
}
$AuditTrail hide
$AuditTrail destroy
