Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
11.16% covered (danger)
11.16%
25 / 224
CRAP
13.40% covered (danger)
13.40%
332 / 2478
formdin_autoload
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
TForm
0.00% covered (danger)
0.00%
0 / 1
11.21% covered (danger)
11.21%
25 / 223
899270.82
13.21% covered (danger)
13.21%
325 / 2461
 __construct
0.00% covered (danger)
0.00%
0 / 1
23.47
90.37% covered (success)
90.37%
122 / 135
 showCloseButtonOnForm
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 14
 showHeaderHelpOnline
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 showHeaderMaximizeButtonOnForm
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 6
 showHeaderBarButtonArea
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 setFormIds
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 5
 ajustaModulo
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 tboxNoOverFlow
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 verifySessionEnd
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 9
 showAjaxErrosMessages
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 14
 showFormBorder
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 9
 showPopUpMessage
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 14
 show
0.00% covered (danger)
0.00%
0 / 1
78680
0.00% covered (danger)
0.00%
0 / 620
 setWidth
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 setHeight
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 setAutoComplete
0.00% covered (danger)
0.00%
0 / 1
2162
0.00% covered (danger)
0.00%
0 / 86
 addJavascript
0.00% covered (danger)
0.00%
0 / 1
26.30
57.14% covered (warning)
57.14%
12 / 21
 getJavascript
0.00% covered (danger)
0.00%
0 / 1
2.26
60.00% covered (warning)
60.00%
3 / 5
 getField
0.00% covered (danger)
0.00%
0 / 1
182
0.00% covered (danger)
0.00%
0 / 22
 getLabel
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 18
 validate
0.00% covered (danger)
0.00%
0 / 1
420
0.00% covered (danger)
0.00%
0 / 35
 setFocusField
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 10
 getFocusField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMessage
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 8
 setPopUpMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getPopUpMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 addMessage
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 7
 getMessages
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 disableFields
0.00% covered (danger)
0.00%
0 / 1
420
0.00% covered (danger)
0.00%
0 / 30
 getUfs
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
88 / 88
 combinarSelects
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 32
 setOnlineSearch
0.00% covered (danger)
0.00%
0 / 1
156
0.00% covered (danger)
0.00%
0 / 45
 setOnlineCrud
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 10
 clearFields
0.00% covered (danger)
0.00%
0 / 1
552
0.00% covered (danger)
0.00%
0 / 27
 setFieldValue
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
 getFieldValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setValue
0.00% covered (danger)
0.00%
0 / 1
3.14
75.00% covered (success)
75.00%
3 / 4
 getValue
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 5
 createBvars
0.00% covered (danger)
0.00%
0 / 1
992
0.00% covered (danger)
0.00%
0 / 48
 setOptionsSelect
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 4
 setRequired
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 2
 getRequired
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 closeGroup
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 setShowCloseButton
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 hideCloseButton
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 showCloseButton
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getShowCloseButton
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 update
0.00% covered (danger)
0.00%
0 / 1
1122
0.00% covered (danger)
0.00%
0 / 39
 clearButtons
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 removeField
0.00% covered (danger)
0.00%
0 / 1
240
0.00% covered (danger)
0.00%
0 / 25
 deleteField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setShowHeader
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 getShowHeader
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setAutoIncludeJsCss
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getAutoIncludeJsCss
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setFlat
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFlat
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setPrototypeId
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getPrototypeId
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getDialogId
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 getJsCss
0.00% covered (danger)
0.00%
0 / 1
462
0.00% covered (danger)
0.00%
0 / 49
 addJsFile
0.00% covered (danger)
0.00%
0 / 1
19.75
58.33% covered (warning)
58.33%
7 / 12
 addCssFile
0.00% covered (danger)
0.00%
0 / 1
16.40
60.00% covered (warning)
60.00%
6 / 10
 setShowHtmlTag
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getShowHtmlTag
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getCssFileFormDefault
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getPathJsCssFiles
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 29
 includeJsCss
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 12
 getMaxWidth
0.00% covered (danger)
0.00%
0 / 1
342
0.00% covered (danger)
0.00%
0 / 37
 getCurrentContainer
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 8
 addPdfFile
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 clearOnlineSearch
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 setEncType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getEncType
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 showPdfs
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 13
 setOnClose
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnClose
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 setOnBeforeClose
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnBeforeClose
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 redirect
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 37
 setFieldEvent
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 6
 setNoWrap
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getNoWrap
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setFade
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFade
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setOverflowY
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOverFlowY
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 6
 setOverflowX
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOverFlowX
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 6
 setConfirmOnClose
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getConfirmOnClose
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 enableRichEdit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 disableRichEdit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getRichEdit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setRichEdit
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
2 / 2
 enableOnlineDoc
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 7
 disableOnlineDoc
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setOnlineDoc
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getOnlineDoc
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getOnlineDocDiv
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 13
 processActionGetModulo
0.00% covered (danger)
0.00%
0 / 1
182
0.00% covered (danger)
0.00%
0 / 14
 processActionGetAction
0.00% covered (danger)
0.00%
0 / 1
420
0.00% covered (danger)
0.00%
0 / 21
 processAction
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 9
 restart
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setVar
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 4
 getVar
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 getRealPath
0.00% covered (danger)
0.00%
0 / 1
1482
0.00% covered (danger)
0.00%
0 / 74
 addJsCssModule
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 12
 setColumns
0.00% covered (danger)
0.00%
0 / 1
4.37
71.43% covered (success)
71.43%
5 / 7
 getColumns
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getcolumnWidth
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
 setMethod
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 addDisplayControl
0.00% covered (danger)
0.00%
0 / 1
25.49
41.18% covered (warning)
41.18%
7 / 17
 getDisplayControls
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 addButton
0.00% covered (danger)
0.00%
0 / 1
380
0.00% covered (danger)
0.00%
0 / 44
 addButtonAjax
0.00% covered (danger)
0.00%
0 / 1
306
0.00% covered (danger)
0.00%
0 / 26
 setAction
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 RemoveAction
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 13
 clearJavascript
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 enableF5
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 disableF5
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getF5Enabled
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 processApf
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 1
 processarApfFields
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 1
 setHint
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
 enableCustomHint
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 disableCustomHint
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setCustomHintEnabled
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getCustomHintEnabled
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setColorHighlightBackground
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getColorHighlightBackground
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setAutoSize
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getAutoSize
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 get
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 set
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setTooltip
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 setVO
0.00% covered (danger)
0.00%
0 / 1
272
0.00% covered (danger)
0.00%
0 / 35
 getHeaderCell
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getHeaderButtonCell
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getHeaderBarButtonArea
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getFooterButtons
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getFooterCell
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setShowMessageForm
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getShowMessageForm
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setShowMessageAlert
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getShowMessageAlert
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setVerticalAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getVerticalAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setHorizontalAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getHorizontalAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 clearJsFiles
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 clearCssFiles
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 addError
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 11
 setError
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getErrors
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 removeMessageArea
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 setOnDrawRow
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnDrawRow
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setOnDrawField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnDrawField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setReturnAjaxData
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getReturnAjaxData
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 3
 addReturnAjaxData
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
 setOnlineDocHeight
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnlineDocHeight
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setOnlineDocWidth
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnlineDocWidth
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 unformatNumber
0.00% covered (danger)
0.00%
0 / 1
90
0.00% covered (danger)
0.00%
0 / 17
 setOnMaximize
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getOnMaximize
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setFormGridOffLine
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getFormGridOffLine
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMaximize
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getMaximize
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setPublicMode
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getPublicMode
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
2 / 2
 setRequiredFieldText
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getRequiredFieldText
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 addShortCut
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 parseShortcut
0.00% covered (danger)
0.00%
0 / 1
110
0.00% covered (danger)
0.00%
0 / 26
 setAppFitFormHeight
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getAppFitFormHeight
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setLabelsAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getLabelsAlign
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 addHiddenField
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 addTextField
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 addMemoField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addRichTextEditor
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 addDateField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addGroupField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 8
 addHtmlField
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 addHtmlGride
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 10
 addCpfField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 addCnpjField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 addCpfCnpjField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 addCepField
0.00% covered (danger)
0.00%
0 / 1
210
0.00% covered (danger)
0.00%
0 / 44
 addSelectField
0.00% covered (danger)
0.00%
0 / 1
6.56
75.00% covered (success)
75.00%
6 / 8
 addRadioField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 addCheckField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addPageControl
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
 addNumberField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 addEmailField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addFoneField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addCoordGMSField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addPasswordField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addProcessoField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addNumeroTJDFTField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addFileField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
 addMaskField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addLinkField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addTimeField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addColorPickerField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addTreeField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 7
 addTag
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 addBoxField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 addCaptchaField
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 9
 addMessageField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 10
 addOpenDirField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 addTimeZoneField
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 addTextEditorField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 10
 addCalendarField
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 8
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42/**
43 * Classe para criação de formulário para entrada de dados
44 */
45$acao = !isset( $acao ) ? '' : $acao;
46
47if( !isset( $_POST[ 'moduloId' ] ) && isset( $_REQUEST[ 'moduloId' ] ) )
48{
49    $_POST[ 'moduloId' ] = $_REQUEST[ 'moduloId' ];
50}
51if( !isset( $_POST[ 'modulo' ] ) && isset( $_REQUEST[ 'modulo' ] ) )
52{
53    $_POST[ 'modulo' ] = $_REQUEST[ 'modulo' ];
54}
55if( isset( $_POST[ 'formDinAcao' ] ) )
56{
57    if( !$acao )
58    {
59        $acao = $_POST[ 'formDinAcao' ];
60    }
61}
62if( isset( $_POST[ 'moduloId' ] ) && !isset( $moduloId ) )
63{
64    $moduloId = $_POST[ 'moduloId' ];
65}
66if( isset( $_POST[ 'modulo' ] ) && !isset( $modulo ) )
67{
68    $modulo = $_POST[ 'modulo' ];
69}
70
71if ( !function_exists( 'formdin_autoload') )
72{
73    function formdin_autoload( $class_name )
74    {
75        require_once $class_name . '.class.php';
76    }
77    spl_autoload_register('formdin_autoload');
78}
79/**
80 * Classe para criação de formulários web para entrada de dados
81 * @author Luis Eugênio Barbosa
82 */
83class TForm Extends TBox
84{
85    static private $errors;
86    static private $instance;
87    static private $hasRequiredField;
88    static private $onlineDocIgnoreFields;
89    static private $onlineDocFields;
90    static private $publicMode;
91    static private $shortCuts;
92    
93    private $javascript;
94    public $table;
95    private $title;
96    public $header;
97    public $headerCloseButton;
98    private $headerBarButtonArea;
99    private $showCloseButton;
100    public $body;
101    public $footer;
102    private $name;
103    private $displayControls;
104    private $method;
105    private $action; // arquivo para onde será submetido o formulário
106    private $columns;
107    private $footerButtons;
108    private $actions; // botões das ações do formulário.
109    public $flat;
110    private $focusField;
111    private $messages;
112    private $messagePopUp;
113    private $selectsCombinados;
114    private $autocompleteFields;
115    private $onlineSearchs;
116    private $onlineCruds;
117    private $currentContainer;
118    private $showHeader;
119    private $prototypeId;
120    private $jsFiles;
121    private $cssFiles;
122    private $showOnlyTagForm;
123    private $autoIncludeJsCss;
124    private $pdfs;
125    private $enctype;
126    private $onClose;
127    private $onBeforeClose;
128    private $noWrap;
129    private $fade;
130    private $overflowY;
131    private $overflowX;
132    private $confirmOnClose;
133    private $richEdit;
134    private $onlineDoc;
135    private $onlineDocReadOnly;
136    private $arrVar;
137    private $F5Enabled;
138    private $customHintEnabled;
139    private $colorHighlightBackground;
140    private $autoSize;
141    private $message_area;
142    private $showMessageAlert;
143    private $verticalAlign;
144    private $horizontalAlign;
145    private $onDrawRow;
146    private $onDrawField;
147    private $returnAjaxData;
148    private $onlineDocHeight;
149    private $onlineDocWidth;
150    private $screenPosition;
151    private $onMaximize;
152    private $formGridOffLine;
153    private $maximize;
154    private $requiredFieldText;
155    private $appFitFormHeight;
156    private $labelsAlign;
157    
158    
159    /**
160     * Método construtor da classe
161     *
162     * <code>
163     *     $frm = new TForm('Título do Formuláio');
164     *     $frm->show();
165     * </code>
166     *
167     * @param string $strTitle - titulo do formulário
168     * @param string $strHeight - altura em pixels - padrão=400px
169     * @param string $strWidth - largura em pixels - padrão=800px
170     * @param bool $strFormName - nome do formulario para criação da tag form. Padrão=formdin
171     * @param string $strMethod - metodo GET ou POST, utilizado pelo formulario para submeter as informações. padrão=POST
172     * @param string $strAction - página/url para onde os dados serão enviados. Padrão = propria página
173     * @param boolean $boolPublicMode - ignorar mensagem fwSession_exprired da aplicação e não chamar atela de login
174     *
175     * @return TForm - instaância da classe
176     */
177    public function __construct( $strTitle=null, $strHeight=null, $strWidth=null, $strFormName=null, $strMethod=null, $strAction=null,$boolPublicMode=null )
178    {
179        // todo formulario tem que ter uma largura e uma altura
180        //$strWidth = ( int ) $strWidth == 0 ? 800 : $strWidth;
181        //$strHeight = ( int ) $strHeight == 0 ? 400 : $strHeight;
182        $strFormName = is_null( $strFormName ) ? "formdin" : $strFormName;
183        // se não tiver sido informado o nome, gerar um aleatoriamente
184        $strFormName = (( string ) $strFormName == "") ? "form" . mt_rand( 1, 100 ) : $strFormName;
185        parent::__construct( $strFormName, $strWidth, $strHeight );
186        $this->setFieldType( 'form' );
187        $this->setFlat( true );
188        $this->setMaximize(false); // não permitir maximizar com duplo clique
189        $this->setShowHtmlTag( true );
190        $this->setShowCloseButton( true );
191        $this->setShowMessageAlert(true);
192        $this->setConfirmOnClose( true );
193        $this->name = $strFormName;
194        $this->method = ($strMethod === null) ? 'POST' : $strMethod;
195        $this->action = $strAction;
196        
197        $this->setRequiredFieldText('Preenchimento Obrigatório');
198        $isForm=false; // pode ser uma aba ou um grupo
199        $isAjax = ( isset( $_REQUEST[ 'ajax' ] ) && $_REQUEST[ 'ajax' ] === 1 );
200        if( ! self::$instance )
201        {
202            $isForm=true;
203            if( !$this->getWidth())
204            {
205                $this->setWidth(800);
206            }
207            if( ! $this->getHeight())
208            {
209                $this->setHeight(400);
210            }
211            self::$instance = $this;
212            self::$hasRequiredField=false;
213            $this->setPosition(null);
214            $this->pdfs = null;
215            $this->disableF5(); // não permitir atualizar a página com F5
216            $this->setFade( 150 ); // habilitar o efeito fade-in para exibir o formulario
217            $this->addJsFile( 'ajax.js' );
218            $this->addJsFile( 'FormDin4.js' );
219            $this->addJsFile( 'FormDin4Ajax.js' );
220            
221            
222            if(!defined('MIGRATE_JQUERY')){ define('MIGRATE_JQUERY',FALSE); }
223            if(MIGRATE_JQUERY){
224                $this->addJsFile( 'jquery-1.9/jquery-1.9.1.js');
225                $this->addJsFile( 'jquery-1.9/jquery-migrate-1.4.1.js');
226                $this->addJsFile( 'jquery/js_new/jquery.metadata.js' );
227                $this->addJsFile( 'jquery/js_new/jquery.corner.js' );
228            }else{
229                $this->addJsFile( 'jquery/jquery.js' );
230                $this->addJsFile( 'jquery/jquery.metadata.js' );
231                $this->addJsFile( 'jquery/jquery.corner.js' );
232            }
233            //Font Awesome Icons
234            $this->addCssFile($this->getBase().'vendor/components/font-awesome/css/brands.min.css' );
235            $this->addCssFile($this->getBase().'vendor/components/font-awesome/css/regular.min.css' );
236            $this->addCssFile($this->getBase().'vendor/components/font-awesome/css/solid.min.css' );
237            $this->addCssFile($this->getBase().'vendor/components/font-awesome/css/fontawesome.min.css' );
238            
239            $this->addJsFile( 'jquery/jlayout/jquery.jlayout-1.3.js');
240            $this->addJsFile( 'jquery/jquery-ui-all.js');
241            $this->addJsFile( 'jquery/jAlert/jquery.alerts.js' );
242            $this->addCssFile('jquery/jAlert/jquery.alerts.css' );
243            $this->addCssFile('jquery/ui/base/base.css' );
244            $this->addJsFile( 'jquery/shortcuts/jquery.shortcuts.min.js' );
245            $this->addJsFile( 'jquery/tablesorter/jquery.tablesorter.min.js' );
246            $this->addCssFile('jquery/tablesorter/themes/blue/formdin.css' );
247            
248            //$this->addJsFile( 'jquery/simplemodal/jquery.simplemodal.js' );
249            $this->addJsFile( 'jquery/tooltip/jquery.tooltip.js' );
250            $this->addJsFile( 'jquery/jquery.meio.mask.min.js' );
251            $this->addJsFile( 'jquery/jquery.priceFormat.js' );
252            $this->addCssFile( 'jquery/tooltip/jquery.tooltip.css' );
253            $this->addCssFile( 'jquery/confirm/confirm.css' );
254            $this->addJsFile( 'calendario/calendar.js' );
255            $this->addJsFile( 'calendario/calendar-br.js' );
256            $this->addJsFile( 'calendario/calendar-setup.js' );
257            $this->addCssFile( 'calendario/calendar-win2k-cold-1.css' );
258            $this->addCssFile( 'jquery/ui/base/base.css' );
259            //$this->addJsFile( 'sorttable.js' );
260            $this->addCssFile( 'FormDin4.css' );
261            $this->addJsFile( 'lazyload/lazyload-min.js' );
262            $this->addJsFile( 'jquery/jquery.qtip.min.js' );;
263            
264            // area de mensagem no topo do formulário
265            $this->message_area = $this->addHtmlField( $this->getId() . '_msg_area',null,null,null);
266            
267            $btn = new TButton( 'btn_close_' . $this->getId() . '_msg_area', 'Fechar', null, 'fwHideMsgArea("'.$this->getName().'")', null, 'fwbtnclosered.jpg', null, 'Fechar mensagem' );
268            $btn->setCss( 'float', 'right' );
269            $btn->setCss( 'cursor', 'pointer' );
270            $btn->setCss('visibility','visible');
271            
272            $this->message_area->add( $btn );
273            $this->message_area->add( '<div id="' . $this->getId() . '_msg_area_content' . '"></div>' );
274            $this->message_area->setCss( 'visibility', 'visible' );
275            $this->message_area->setCss( 'width', '0px' );
276            $this->setPublicMode($boolPublicMode);
277            // campo oculto para guardar a página que chamou;
278            $this->addHiddenField( 'fw_back_to' )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo
279            // se for uma requisição ajax, capturar as saidas, para que a função prepareReturnAjax possa processar o contúdo
280            if( $isAjax  && ob_get_level() == 0 )
281            {
282                ob_start();
283            }
284        }
285        // exibir o titulo do formulário
286        $this->setShowHeader( true );
287        // controle interno para utilização dos recursos de janela da biblioteca prototype
288        if( isset( $_REQUEST[ 'modalWinId' ] ) )
289        {
290            $this->addHiddenField( 'modalWinId')->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo
291        }
292        if( isset( $_REQUEST[ 'prototypeId' ] ) )
293        {
294            $this->setPrototypeId( $_REQUEST[ 'prototypeId' ] );
295        }
296        $this->setAutoIncludeJsCss( true );  // incluir os arquivos css e javascripts necessários para o funcionamento do formulário
297        $this->enableCustomHint(); // habilitar os tooltips personalizados estilo balão
298        
299        // definir fundo azul claro para os campos que possuirem title ( tooltip )
300        $this->setColorHighlightBackground( '#E4F2FF' );
301        
302        // largura padrão para os campos da primeira coluna do formulário
303        $this->setColumns( array( 120 ) );
304        // criar a estrutura da tabela que formará o formulário
305        $this->table = new TTable( $this->getId() . '_table' );
306        $this->table->setCss( 'width', '100%' );
307        $this->table->setCss( 'height', '100%' );
308        $this->table->setAttribute('width','100%'); // a table de dentro do grupo deve ocupar a largura toda do grupo ou formulario
309        $this->table->setCss( "background-color", "transparent" );
310        $this->table->setCss( 'text-align', 'left' ); // alinhar os campos à esquerda
311        $this->table->setProperty( "cellspacing", "0" );
312        $this->table->setProperty( "cellpadding", "0" );
313        $this->table->setProperty( "border", "0" );
314        
315        $this->header = new TTableCell();
316        $this->header->setId( $this->getId() . '_header' );
317        
318        $this->headerBarButtonArea = new TTableCell();
319        $this->headerBarButtonArea->setClass( 'fwTitleBarButtonArea' );
320        
321        $this->header->setClass( 'fwTitleBar' );
322        $this->setTitle( $strTitle );
323        
324        // criar o corpo do formulario
325        $this->body = new TElement( "div" );
326        $this->body->setId( $this->getId() . '_body' );
327        $this->body->setCss( "height", (( int ) $this->getHeight() - 70) . "px" );
328        $this->body->setCss( "overflow", "hidden" );
329        $this->body->setCss( "overflow-y", "auto" );
330        $this->body->setCss( "overflow-x", "hidden" );
331        
332        $this->body->setCss( "margin", "0" );
333        $this->body->setCss( "padding", "0" );
334        $this->body->setCss( "border", "none" );
335        $this->body->setCss( "display", "block" );
336        $this->body->setCss( "padding-left", "3" );
337        $this->body->setCss( "padding-top", "3" );
338        if( $this->getCss( "border" ) == 'none' )
339        {
340            $this->body->setCss( "border-top", '1px solid silver' );
341            $this->body->setCss( "border-bottom", '1px solid silver' );
342        }
343        // criar o rodapé
344        $this->footer = new TTableCell();
345        $this->footer->setId( $this->getId() . '_footer' );
346        $this->footer->setProperty( "colspan", "2" );
347        $this->footer->setCss( "height", "25px" );
348        $this->footer->setCss( 'border-bottom', $this->header->getCss( 'border-bottom' ) );
349        $this->footer->setCss( 'border', 'none' );
350        $this->footer->setCss( 'text-align', 'center' );
351        if( !defined('APLICATIVO'))
352        {
353            define('APLICATIVO','FORMDIN');
354        }
355        if( isset($_POST['modulo'] ) && isset( $_SESSION[ APLICATIVO ][ $_POST[ 'modulo' ] ][ 'post' ] ) )
356        {
357            $_POST = $_SESSION[ APLICATIVO ][ $_POST[ 'modulo' ] ][ 'post' ];
358            $_POST[ 'formDinAcao' ] = '';
359            unset( $_SESSION[ APLICATIVO ][ $_POST[ 'modulo' ] ][ 'post' ] );
360        }
361        if( $isForm && !$this->getPublicMode() && isset( $_POST['fwSession_expired'] ) && $_POST['fwSession_expired']== true )
362        {
363            if( ! $isAjax )
364            {
365                $this->show();
366            }
367            die();
368        }
369        
370    }
371    
372    /**
373     * Mostra o Botão Fechar no Form
374     */
375    private function showCloseButtonOnForm($form){
376        // adicionar o botao fechar
377        if( $this->getShowCloseButton() )
378        {
379            $sub = 'null';
380            if( isset( $_REQUEST[ 'subform' ] ) && $_REQUEST[ 'subform' ] )
381            {
382                $this->addHiddenField( 'subform', 1 )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
383                $sub = '1';
384            }
385            // integração com o modulo onlinesearch que possibilita fazer cadastro on-line quando a pesquisa retorna sem resultado
386            if( isset( $_REQUEST[ 'onLineSearch' ] ) && $_REQUEST[ 'onLineSearch' ] )
387            {
388                $this->headerBarButtonArea->add( '<img src="' . $this->getBase() . 'imagens/fwbtnclosered.jpg" style="cursor:pointer;float:right;width:28px; height:15px;vertical-align:top;margin-right:2px;" title="Fechar" onClick="fwFazerAcao(\'Sair\')");">' );
389                $this->addHiddenField( 'onLineSearch', 1 )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
390            }
391            else
392            {
393                //$confirm = $this->getConfirmOnClose() ? 'true' : 'false';
394                if( ! $this->get('modalWinId') )
395                {
396                    $button = '<img id="btn_'.$form->getId().'_close" src="' . $this->getBase() . 'imagens/fwbtnclosered.jpg" style="cursor:pointer;float:right;width:20px; height:15px;vertical-align:top;margin-right:2px;" title="Fechar" onClick="fwConfirmCloseForm(\'' . $this->getId() . '\',' . $sub . ',' . $this->getOnClose() . ',' . $this->getOnBeforeClose().');">';
397                    $this->headerBarButtonArea->add( $button );
398                } else {
399                    $button = '<img src="' . $this->getBase() . 'imagens/fwbtnclosered.jpg" style="cursor:pointer;float:right;width:28px; height:15px;vertical-align:top;margin-right:2px;" title="Fechar" onClick="top.app_close_modal_window();">';
400                    $this->headerBarButtonArea->add( $button );
401                }
402            }
403        }
404    }
405    
406    private function showHeaderHelpOnline(){
407        if( $this->getHelpOnline() ) {
408            //$this->headerCloseButton->add('<img src="'.$this->getBase().'imagens/fwbtnhelp.gif" style="cursor:pointer;float:right;width:28px; height:15px;vertical-align:top;margin-right:2px;" title="Visualizar arquivo de Ajuda" onClick="fwMostrarAjuda(\''.$this->getHelpFile().'\');"/>');
409            $this->headerBarButtonArea->add( $this->getHelpOnLine() );
410        }
411    }
412    
413    private function showHeaderMaximizeButtonOnForm($form)
414    {
415        $notModal = !$this->get('modalWinId'); 
416        $boolMaximize = $this->getMaximize();
417        if( $notModal && $boolMaximize ) {
418            $button = '<img id="btn_'.$form->getId().'_max_min" src="' . $this->getBase() . 'imagens/fwbtnmaximize.png" style="cursor:pointer;float:right;width:20px; height:15px;vertical-align:top;margin-right:2px;" title="Maximizar" onClick="fwFullScreen(\''.$form->getId().'\')">';
419            $this->headerBarButtonArea->add( $button );
420        }
421    }
422    
423    /***
424     * Show 3 Buttons Help, Maximize, Close
425     */
426    private function showHeaderBarButtonArea($form)
427    {
428        $this->showCloseButtonOnForm($form);
429        $this->showHeaderMaximizeButtonOnForm($form);
430        $this->showHeaderHelpOnline();
431    }    
432    
433    private function setFormIds()
434    {
435        // colocar os ids nos objeto do formulario
436        $this->table->setId( $this->getId() . '_table' );
437        $this->header->setId( $this->getId() . '_header' );
438        $this->body->setId( $this->getId() . '_body' );
439        $this->footer->setId( $this->getId() . '_footer' );
440    }
441    
442    private function ajustaModulo()
443    {
444        // ajustar a variavel $_POST['modulo']. Quando o $_POST é passado para a classe banco
445        // no lugar do bvars, os valores das chaves retornam em caixa alta
446        if ( isset( $_POST[ 'MODULO' ] ) ) {
447            $_POST[ 'modulo' ] = $_POST[ 'MODULO' ];
448            $_GET[ 'modulo' ] = $_POST[ 'MODULO' ];
449        }
450    }
451    
452    private function tboxNoOverFlow()
453    {
454        // não deixar a classe TBox mostrar  as barras de rolagem lateral e inferior
455        if ( $this->getFieldType() != 'group' ){
456            $this->divBody->setCss( 'overflow', 'hidden' );
457        }
458    }
459    
460    private function verifySessionEnd()
461    {
462        // verificar se a classe TApplication (controller detectou que a sessão está expirdada
463        if( !$this->getPublicMode() && isset( $_POST['fwSession_expired'] ) && $_POST['fwSession_expired']== true )
464        {
465            // configurar o formulário para exibir somente a mensagem
466            $this->setTitle('Sessão Encerrada');
467            $this->setWidth(300);
468            $this->setHeight(120);
469            $this->hideCloseButton();
470            $this->removeField();
471            $this->addHtmlField('msg','<center><br><h3>Reiniciando. Aguarde...</center>')->setCss('color','#ff0000');
472            $this->addJavascript('window.setTimeout("fwApplicationRestart()",1500)');
473        }
474    }
475    
476    public function showAjaxErrosMessages(){
477        $boolAjax = ( isset( $_REQUEST[ 'ajax' ] ) && $_REQUEST[ 'ajax' ] == 1);
478        if( $boolAjax ){
479            // para funcionar com chamadas ajax sem fwAjaxRequest.
480            $_REQUEST['dataType'] = ( isset( $_REQUEST['dataType'] ) ) ? $_REQUEST['dataType'] : 'text';
481            
482            if( ! function_exists( 'prepareReturnAjax' ) ){
483                require_once($this->getBase() . 'includes/formDin4Ajax.php');
484            }
485            
486            // se tiver alguma coisa no buffer, poder ser algum echo, print ou mensagem de erro do php
487            $flagSucess=1;
488            if( $this->getErrors() ){
489                $flagSucess=0;
490                echo implode("\n", $this->getErrors() );// joga no buffer de saida
491                //die();
492            }
493            
494            if( $this->getMessages() ){
495                echo implode("\n", $this->getMessages() ); // joga no buffer de saida
496            }
497            prepareReturnAjax( $flagSucess,$this->getReturnAjaxData());
498            die;
499        }
500    }
501    
502    public function showFormBorder(){
503        // remover/exibir as barras de rolagem
504        $this->body->setCss( "overflow",'hidden');
505        $this->body->setCss( "overflow-x", $this->getOverFlowX() );
506        $this->body->setCss( "overflow-y", $this->getOverFlowY() );
507        //$this->body->setCss('border','1px dashed blue');        
508        //$this->body->setCss('background-color','red');
509        
510        if( $this->getFlat()) {
511            $this->body->setCss( 'width', $this->getWidth()-5);
512        } else {
513            $this->body->setCss( 'width', $this->getWidth()-17);
514        }
515        
516        //$this->body->setCss( 'width', $this->getMaxWidth());
517        if( $this->getAutoSize() ) {
518            $this->setOverflowY( 'auto' );
519        }
520    }  
521    
522    /**
523     * verificar se tem alguma mensagem de topo para ser exibida
524     */
525    public function showPopUpMessage()
526    {
527        if( $this->getPopUpMessage() )
528        {
529            $aMsg = $this->getPopUpMessage();
530            $aMsg[ 1 ] = isset( $aMsg[ 1 ] ) ? $aMsg[ 1 ] : 'SUCESS';
531            if( $aMsg[ 1 ] == 'ERROR' && !$aMsg[ 3 ] ) {
532                $aMsg[ 3 ] = 'ruim.gif';
533            }else if($aMsg[ 1 ] == 'ATTENTION' && !$aMsg[ 3 ]){
534                $aMsg[ 3 ] = 'icon_alert.png';
535            }
536            $aMsg[ 2 ] = isset( $aMsg[ 2 ] ) ? $aMsg[ 2 ] : 5; // duração
537            $aMsg[ 3 ] = isset( $aMsg[ 3 ] ) ? $aMsg[ 3 ] : 'sucess.gif';
538            // se não foi informado o endereço manualmente, encontrar na pasta base
539            if( strpos( $aMsg[ 3 ], '/' ) === false ) {
540                if( !file_exists( $aMsg[ 3 ] ) ) {
541                    $aMsg[ 3 ] = $this->getBase() . 'imagens/' . $aMsg[ 3 ];
542                }
543            }
544            $this->addJavascript( 'try{ parent.app_show_message("' . $aMsg[ 0 ] . '","' . $aMsg[ 1 ] . '","' . $aMsg[ 2 ] . '","' . $aMsg[ 3 ] . '");}catch(e){alert("' . $aMsg[ 0 ] . '")}' );
545        }
546    }
547    
548    
549    /**
550     * Exibe no browser ou devolve o html do formulário dependendo do parametro $print
551     *
552     * $print = true - exibe o formulário no browser
553     * $print = false - retorna o html do formulário
554     *
555     * @param boolean $print
556     * @return mixed
557     */
558    public function show( $print=true, $flat=false )
559    {
560        $this->setFormIds();
561        $this->ajustaModulo();
562        $this->tboxNoOverFlow();
563        
564        if( $this->getFieldType() == 'form' ){
565            
566            $this->showAjaxErrosMessages();
567            $this->verifySessionEnd();
568            
569            if( $this->getPublicMode() )
570            {
571                $this->addHiddenField('fwPublicMode','S');
572            }
573            if( $this->getPosition() && ! $this->pdfs )
574            {
575                //die( $this->getPosition());
576                $this->addJavascript('window.setTimeout(\'fwSet_position("'.$this->getId().'_area","'.$this->getPosition().'")\',100);');
577            }
578            if( $this->getAppFitFormHeight() )
579            {
580                //die( $this->getPosition());
581                $this->addJavascript('window.setTimeout(\'fwAppFitFormHeight()\',100);');
582            }
583            
584            // se a funcao ondrawRow estiver definia e nao existir, retirar o evento
585            if ($this->getOnDrawRow() && !function_exists($this->getOnDrawRow()))
586            {
587                $this->setOnDrawRow(null);
588            }
589            // se a funcao ondrawField estiver definia e nao existir, retirar o evento
590            if ($this->getOnDrawField() && !function_exists($this->getOnDrawField()))
591            {
592                $this->setOnDrawField(null);
593            }
594            // o form do grid offline não precisa destes scripts
595            //if( !isset($_REQUEST['gridOffline']) && ! $this->getFormGridOffLine() )
596            if( ! $this->getFormGridOffLine() )
597            {
598                $this->addJavascript( '// variáveis javascript de auxílio', -90 );
599                if( $this->getVerticalAlign() || $this->getHorizontalAlign() )
600                {
601                    $this->addJavascript( 'fwSetFormAlignment("' . $this->getVerticalAlign() . '","' . $this->getHorizontalAlign() . '")' );
602                }
603                
604                $this->addJavascript( 'aplicativo="' . APLICATIVO . '";', -89 );
605                $this->addJavascript( 'pastaBase="' . $this->getBase() . '";', -88 );
606                $this->addJavascript( 'fw_img_processando1    = \'<img width="16px" height="16px" src="\'+pastaBase+\'imagens/carregando.gif"/>\'' );
607                $this->addJavascript( 'fw_img_processando2    = \'<img width="190px" height="20px" src="\'+pastaBase+\'imagens/processando.gif"/>\'' );
608                $this->addJavascript( 'GB_ROOT_DIR             = pastaBase+\'js/greybox/\';' );
609                $this->addJavascript( 'REQUIRED_FIELD_MARK    = '.( defined('REQUIRED_FIELD_MARK') ?'\''.REQUIRED_FIELD_MARK.'\'' : 'null' ).';' );
610                //$this->addJavascript('fw_img_processando1 = \'<img width="16px" height="16px" src="'.$this->getBase().'imagens/carregando.gif"/>\'',-87);
611                //$this->addJavascript('fw_img_processando2 = \'<img width="190px" height="20px" src="'.$this->getBase().'imagens/processando.gif"/>\'',-86);
612                $this->addJavascript( 'jQuery(document).keydown(function(event) { fwCancelRefresh(event,' . $this->getF5Enabled() . ') } )', -85 );
613                $this->addJavascript( 'fwAttatchTooltip({"container":"'.$this->getId().'"})' );
614                $this->addJavascript('try{fwUnblockUI()}catch(e){}',-99);
615                // criar link para exibir a planhila com os pontos de função
616                $this->processApf();
617            }
618            // implementação para permitir aplicativos com a estrutura de visão e controle separados
619            // se existir arquivo js/css externo com o mesmo nome do modulo, no mesmo diretorio ou no diretorio js/ fazer a inclusão automática
620            $this->addJsCssModule();
621            $this->showFormBorder();
622            
623            // alterar a aparência do formulario se ele estiver sendo executado como subform - modal
624            if( isset( $_REQUEST[ 'facebox' ] ) && $_REQUEST[ 'facebox' ] )
625            {
626                $this->hideCloseButton();
627                $this->addHiddenField( 'facebox', 1 )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
628                $this->setFlat( true );
629                $this->setCss( 'background-color', 'white' );
630                $this->setCss( 'border', 'none' );
631            }
632            else if( isset( $_REQUEST[ 'modalbox' ] ) && $_REQUEST[ 'modalbox' ] )
633            {
634                $this->hideCloseButton();
635                $this->addHiddenField( 'modalbox', 1 )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
636            }
637            
638            if( $this->getPrototypeId() || $this->getDialogId() )
639            {
640                $this->setFlat( true );
641                $this->setShowHeader( false );
642                //$this->setCss( 'background-color', '#efefef' );
643                $this->setCss( 'background-color', 'transparent' );
644                $this->setCss( 'border', '0px' );
645                $_REQUEST[ 'prototypeId' ] = isset( $_REQUEST[ 'prototypeId' ] ) ? $_REQUEST[ 'prototypeId' ] : '';
646                $this->addHiddenField( 'prototypeId', $_REQUEST[ 'prototypeId' ] )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
647                $this->addHiddenField( 'dialogId', $this->getDialogId() )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
648            }
649            // este javascript tem que ser o ultimo a ser adicionado, por isso coloquei aqui
650            $this->addJsFile( 'funcoes.js' );
651            // se o formulario estiver fora de um objeto THtmlPage, inserir os javascripts e css necessários
652            if( $this->getAutoIncludeJsCss() ) {
653                $this->includeJsCss();
654            }
655            $this->setId( $this->getId() . '_area' );
656            $this->setTagType( 'div' );
657            $this->setCss( 'width', $this->getWidth() );
658            //$this->setCss('border','0px solid red');
659            // centralizar o formulário na tela - no IE não funcionou
660            //$this->setCss('margin','auto');
661            $this->table->setCss( 'background-color', $this->getCss( 'background-color' ) );
662            
663            $row = $this->table->addRow();
664            if( $this->getShowHeader() ) {
665                //$this->header->clearChildren();
666                $this->header->add( $this->getTitle() );
667                $row->add( $this->header );
668                $row->add( $this->headerBarButtonArea );
669                $this->header->setCss( 'width', $this->getWidth() - 70 );
670                if( $this->getMaximize() == true ){
671                    if( FormDinHelper::pregMatch('/\(/',$this->getOnMaximize() )==1) {
672                        $this->header->addEvent('ondblclick','fwFullScreen("'.$this->name.'","'.$this->getOnMaximize().'")');
673                    } else {
674                        $this->header->addEvent('ondblclick','fwFullScreen("'.$this->name.'","'.$this->getOnMaximize().'")');
675                    }
676                }
677            } else {
678                $this->header->setCss( 'height', 0 );
679                $this->body->setCss( "border-top", 'none' );
680            }
681            $cell = $this->table->addRow()->addCell( $this->body );
682            $cell->setProperty( 'colspan', 2 );
683            $this->table->addRow()->add( $this->footer );
684            // criar os campos ocultos padrão do modulo e da acao
685            if ( !$this->getFormGridOffLine())
686            {
687                $this->addHiddenField( 'moduloId' )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
688                $this->addHiddenField( 'modulo' )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
689                $this->addHiddenField( 'formDinAcao' );
690                if ( isset( $GLOBALS['formdin_instance_id'] ) )
691                {
692                    $this->addHiddenField( 'formdin_instance_id', $GLOBALS['formdin_instance_id'] )->setProperty('noClear','true'); // evitar que a funcao js fwClearFields() limpe este campo;
693                }
694            }
695            $areaBody = ( int ) $this->getHeight() - ( int ) $this->header->getCss( 'height' ) - ( int ) $this->footer->getCss( 'height' ) - 20;
696            $this->body->setCss( "height", $areaBody . "px" );
697            // verificar se tem algum erro para ser exibido
698            if( $this->getErrors() )
699            {
700                $flag = 0;
701                $this->setMessage( null );
702                
703                foreach( $this->getErrors() as $idField=>$msgError )
704                {
705                    // definir o foco do formulario para o primeiro campo com erro de validacao
706                    // ignorar a mensagem que tiver com espaço representando o nome da aba onode ocorreu o erro
707                    if( $flag == 0 && !strpos( $idField, " " ) )
708                    {
709                        $this->setFocusField( $idField );
710                        $flag++;
711                    }
712                    if( trim($msgError)!='' )
713                    {
714                        $qtd = CountHelper::count( $this->getMessages() );
715                        $this->addMessage( ( $qtd + 1) . ') ' . $msgError );
716                    }
717                }
718            }
719        }
720        else
721        {
722            // abas, grupos não precisam da area de mensagem
723            if( $this->message_area )
724            {
725                $this->removeField( $this->message_area->getId() );
726            }
727        }
728        // se existir um metodo, criar com a tag form
729        if( ( string ) $this->method != "" )
730        {
731            $form = new TElement( 'form' );
732            $form->setId( $this->name );
733            $form->method = $this->method;
734            $form->action = ( string ) $this->action;
735            $form->setEvents( $this->getEvents() );
736            $this->clearEvents();
737            if( $this->getEncType() )
738            {
739                $form->setProperty( 'enctype', $this->getEncType() );
740            }
741            if(  $this->getFieldType()=='tabsheet' )
742            {
743                $parentName = $this->body->getAttribute('pagecontrol').'_'.$this->name;
744            }
745            else
746            {
747                $parentName = $this->name;
748            }
749        }
750        else
751        {
752            // nao criar a tag <form>
753            $form = new TElement( 'span' );
754            if( $this->getFieldType() == 'group')
755            {
756                $form->setId($this->getId().'_span');
757            }
758            else
759            {
760                $form->setId($this->getId());
761            }
762            $parentName = $this->getId();
763        }
764        if( $this->getFormGridOffLine())
765        {
766            $form->setTagType('span');
767            $this->getDivBody()->setId($this->getAttribute('idGridOffLine').'_form_body');
768            $form->setId($this->getAttribute('idGridOffLine').'_form_fields' );
769            $form->method=null;
770            $form->action=null;
771        }
772        // adicionar a tag form ao html final
773        $this->add( $form );
774        // o formulario será estruturado em uma Table com cabecalho ,corpo e rodape
775        $form->add( $this->table );
776        $this->showHeaderBarButtonArea($form);
777        // adicionar os campos
778        if( is_array( $this->displayControls ) )
779        {
780            $currentCol         = null;
781            $hiddenFields         = null;
782            $divButtonOpen         = false;
783            $lastDisplayControl = null;
784            $tableLayout         = new TTable( $form->getId().'_layout' );
785            $tableLayout->setProperty('width','100%');
786            $tableLayout->setProperty('border','0');
787            $tableLayout->setProperty('cellpadding','0px');
788            $tableLayout->setProperty('cellspacing','0px');
789            /*$tableFields         = new TTable( $form->getId().'_fields' );
790             $tableFields->setProperty('border','1');
791             $tableFields->setProperty('cellpadding','3px');
792             $tableFields->setProperty('cellspacing','0px');
793             */
794            // adicionar a table do layout no corpo do formulário
795            $this->body->add($tableLayout);
796            // inicio
797            $rows=0;
798            foreach( $this->displayControls as $name=>$dc )
799            {
800                // se falso então campo tambem falso
801                if( $this->getEnabled() == false )
802                {
803                    $dc->getField()->setEnabled( false );
804                }
805                
806                // se o formulário tiver documentação on-line, ativar no displaycontrol
807                if( $this->getOnlineDoc() )
808                {
809                    if( !self::$onlineDocIgnoreFields || FormDinHelper::pregMatch('/,'.$dc->getField()->getId().',/',','.self::$onlineDocIgnoreFields.',' ) == 0 )
810                    {
811                        if( !self::$onlineDocFields || FormDinHelper::pregMatch('/,'.$dc->getField()->getId().',/',','.self::$onlineDocFields.',' ) > 0 )
812                        {
813                            $dc->setOnlineDoc($this->getOnlineDoc());
814                        }
815                    }
816                }
817                // se o formulário estiver definido com required, todos os campos serão obrigatórios
818                if( $this->getRequired() == true )
819                {
820                    if( method_exists( $dc->getField(), 'setRequired' ) )
821                    {
822                        $dc->getField()->setRequired( true );
823                    }
824                }
825                if( $this->getLabelsAlign() )
826                {
827                    if( method_exists( $dc->getField(), 'setLabelsAlign' ) )
828                    {
829                        if( ! $dc->getField()->getLabelsAlign())
830                        {
831                            $dc->getField()->setLabelsAlign( $this->getLabelsAlign() );
832                        }
833                    }
834                }
835                $dcField         = $dc->getField();
836                $dcLabel        = $dc->getLabel();
837                if( $dcLabel )
838                {
839                    if( ! $dcLabel->getCss('font-size') )
840                    {
841                        $dcLabel->setCss('font-size',$this->getCss('font-size') );
842                    }
843                    if( ! $dcLabel->getCss('color'))
844                    {
845                        $dcLabel->setCss('color',$this->getCss('color') );
846                    }
847                    if( ! $dcLabel->getcss('text-align') && $this->getLabelsAlign()  )
848                    {
849                        $dcLabel->setcss('text-align',$this->getLabelsAlign());
850                    }
851                    // verificar se o label está com shortcut ( tecla de atalho "&" )
852                    $this->parseShortcut( $dcLabel, $dcField->getId() );
853                }
854                $dcFieldType    = strtolower( $dc->getField()->getFieldType() );
855                
856                // ativar/desativar as barras de rolagem
857                if( $this->getFieldType() == 'tabsheet')
858                {
859                    
860                    $this->setTagType( 'div' );
861                    $this->body->setClass( $this->getClass() );
862                    $this->body->setCss( $this->getCss() );
863                    $this->body->setId( $this->getId() );
864                    $this->body->setCss('height',$this->getHeight());
865                    $h = $this->getHeight();
866                    if( $h )
867                    {
868                        $this->body->setcss('overflow','hidden');
869                        $this->body->setCss('overflow-x',$this->getOverFlowX());
870                        $this->body->setCss('overflow-y',$this->getOverFlowY());
871                    }
872                    else
873                    {
874                        // height = auto não precisa do overflow
875                        $this->body->setcss('overflow'    ,'hidden');
876                        $this->body->setCss('overflow-x','hidden');
877                        $this->body->setCss('overflow-y','hidden');
878                    }
879                    $this->setOverflowX($this->body->getCss('overflow-x'));
880                    $this->setoverflowY($this->body->getCss('overflow-y'));
881                    if( $this->body->getcss('display')=='inline')
882                    {
883                        $this->body->setcss('display','block');
884                    }
885                }
886                // ajustar a altura e largura se for null
887                if( !$dcField->getWidth() )
888                {
889                    $fieldType     = $dcField->getFieldType();
890                    if( $fieldType == "treeview" || $fieldType == 'pagecontrol' ||$fieldType == 'html' || $fieldType == 'group' || $fieldType=='fullcalendar' )
891                    {
892                        $dcField->setAttribute('fullwidth','true');
893                        $w = $this->getWidth();
894                        $parentType = $this->getFieldType();
895                        $overFlowY     = ($this->getOverFlowY() != 'hidden');
896                        $flat         = $this->getFlat();
897                        if( $parentType == 'form')
898                        {
899                            // adicionando aba ao form
900                            if( $fieldType == 'html')
901                            {
902                                $w-=22;
903                                if( $overFlowY )
904                                {
905                                    $w-=17;
906                                }
907                                if( $flat )
908                                {
909                                    $w+=12;
910                                }
911                            }
912                            else if( $fieldType == 'fullcalendar')
913                            {
914                                $w-=22;
915                                if( $overFlowY )
916                                {
917                                    $w-=17;
918                                }
919                                if( $flat )
920                                {
921                                    $w+=12;
922                                }
923                            }
924                            else if( $fieldType == 'pagecontrol')
925                            {
926                                
927                                if( $this->getFlat() )
928                                {
929                                    $w-=42;
930                                }
931                                else
932                                {
933                                    $w-=32;
934                                }
935                                if( $overFlowY )
936                                {
937                                    $w-=20;
938                                }
939                                if( $flat )
940                                {
941                                    $w+=25;
942                                }
943                            }
944                            else if( $fieldType == 'group')
945                            {
946                                //$dcField->table->setAttribute('width','100%');
947                                if( $this->getFlat())
948                                {
949                                    $w-=29;
950                                }
951                                else
952                                {
953                                    $w-=32;
954                                }
955                                if( $overFlowY )
956                                {
957                                    $w-=17;
958                                }
959                                if( $flat )
960                                {
961                                    $w+=12;
962                                }
963                            }
964                            else if( $fieldType == 'treeview' )
965                            {
966                                $w-=25;
967                                if( $overFlowY )
968                                {
969                                    $w-=17;
970                                }
971                                if( $flat )
972                                {
973                                    $w+=12;
974                                }
975                            }
976                            
977                        }
978                        else if( $parentType == 'tabsheet')
979                        {
980                            $w = $this->getParentControl()->getcss('width');
981                            // adicionando html na aba
982                            $w-=15;
983                            if( $fieldType == 'html')
984                            {
985                                if( $overFlowY )
986                                {
987                                    $w-=10;
988                                }
989                                if( $flat )
990                                {
991                                    $w+=12;
992                                }
993                            }
994                            // adicionando aba na aba
995                            else if( $fieldType == 'pagecontrol')
996                            {
997                                $w-=20;
998                                if( $overFlowY )
999                                {
1000                                    $w-=15;
1001                                }
1002                                if( $flat )
1003                                {
1004                                    $w+=15;
1005                                }
1006                            }
1007                            // adicionando grupo na aba
1008                            else if( $fieldType == 'group')
1009                            {
1010                                $w+=0;
1011                                if( $overFlowY )
1012                                {
1013                                    $w-=10;
1014                                }
1015                                if( $flat )
1016                                {
1017                                    $w+=12;
1018                                }
1019                            }
1020                            else if( $fieldType == 'treeview' )
1021                            {
1022                                $w-=5;
1023                                if( $overFlowY )
1024                                {
1025                                    $w-=7;
1026                                }
1027                                if( $flat )
1028                                {
1029                                    $w+=12;
1030                                }
1031                            }
1032                            
1033                        }
1034                        else if( $parentType == 'group')
1035                        {
1036                            //d($w,null,true);
1037                            // adicionando html na aba
1038                            if( $fieldType == 'html')
1039                            {
1040                                $w-=35;
1041                                if( $overFlowY )
1042                                {
1043                                    $w-=15;
1044                                }
1045                                if( $flat )
1046                                {
1047                                    $w+=12;
1048                                }
1049                            }
1050                            // adicionando aba na grupo
1051                            else if( $fieldType == 'pagecontrol')
1052                            {
1053                                
1054                                $w-=57;
1055                                if( $overFlowY )
1056                                {
1057                                    $w-=15;
1058                                }
1059                                if( $flat )
1060                                {
1061                                    $w+=30;
1062                                }
1063                            }
1064                            // adicionando grupo no grupo
1065                            else if( $fieldType == 'group')
1066                            {
1067                                $w-=35;
1068                                if( $overFlowY )
1069                                {
1070                                    $w-=15;
1071                                }
1072                                if( $flat )
1073                                {
1074                                    $w+=12;
1075                                }
1076                            }
1077                            else if( $fieldType == 'treeview' )
1078                            {
1079                                $w-=35;
1080                                if( $overFlowY )
1081                                {
1082                                    $w-=15;
1083                                }
1084                                if( $flat )
1085                                {
1086                                    $w+=12;
1087                                }
1088                            }
1089                        }
1090                        $dcField->setWidth( $w );
1091                    }
1092                }
1093                //if( method_exists( $dcField, 'getRequired' ) && $dcField->getRequired() )
1094                if( method_exists( $dcField, 'getRequired' ) && $dcField->getRequired() )
1095                {
1096                    self::$hasRequiredField=true;
1097                }
1098                if( $dcFieldType == "cep" )
1099                {
1100                    // retirar o botão consultar cep
1101                    if( $dcField->getEnabled() == false )
1102                    {
1103                        $dcField->clearChildren();
1104                    }
1105                }
1106                else if( $dcFieldType == "password" )
1107                {
1108                    if($dcField->getVirtualKeyboard())
1109                    {
1110                        $this->addJavascript('VKI_attach(jQuery("#'.$dcField->getId().'").get(0),'.( $dcField->getShowVirtualKeyboardImage()===true ? 'true': 'false' ).');');
1111                    }
1112                }
1113                if( $dcFieldType == 'tag' )
1114                {
1115                    continue;
1116                }
1117                // ajustar campo html se não tiver label e for newLine = true
1118                else if( $dcFieldType == 'html' )
1119                {
1120                    // se dentro do campo html tiver um objeto treeview, adicionar o javascript do objeto no onload da página
1121                    $arr = $dcField->getChildren();
1122                    if( is_array( $arr ) )
1123                    {
1124                        foreach( $arr as $k=>$v )
1125                        {
1126                            if( is_object( $v ) )
1127                            {
1128                                if( get_class( $v ) == 'TTreeView' )
1129                                {
1130                                    $this->addJavascript( $v->getJs() );
1131                                }
1132                            }
1133                        }
1134                    }
1135                    
1136                    if( ! $dcField->getWidth() )
1137                    {
1138                        if( ! $dcLabel && $dc->getNewLine() )
1139                        {
1140                            //form,tabsheet,groupbox,
1141                            if( $this->getFieldType() == 'tabsheet' )
1142                            {
1143                                //$dcField->setWidth( ( $this->getCss( 'width' ) - 15 ) ); // IE=27
1144                                //$dc->getField()->setWidth($this->getMaxWidth()-50); // IE=27
1145                            }
1146                            else if( $this->getFieldType() == 'groupbox' )
1147                            {
1148                                //$dcField->setWidth( $this->getMaxWidth() + 95 );
1149                            }
1150                            else
1151                            {
1152                                //$dcField->setWidth( $this->getMaxWidth() );
1153                            }
1154                        }
1155                    }
1156                    // criar javascript para inicializar o gride anexado ao campo html
1157                    if( is_array( $dcField->getGridFile() ) )
1158                    {
1159                        if( $dcField->getLoadingMessage() )
1160                        {
1161                            $this->addJavascript( 'jQuery("#' . $dcField->getId() . '").html("' . $dcField->getLoadingMessage() . '");' );
1162                        }
1163                        $gdId             = $dcField->getGridFile( 'id' );
1164                        $gdFile         = $dcField->getGridFile( 'file' );
1165                        $gdFormFields    = $dcField->getGridFile( 'formFields' );
1166                        $gdWidth        = ($dcField->getWidth()-3);
1167                        $fieldValues = '';
1168                        if( is_array( $gdFormFields ) )
1169                        {
1170                            foreach( $gdFormFields as $k=>$v )
1171                            {
1172                                if( is_numeric( $k ) )
1173                                {
1174                                    $fieldValues .= ( $fieldValues == '' ? '' : ',' ) . '"' . $v . '":"' . $this->get( $v ) . '"';
1175                                    
1176                                }
1177                                else
1178                                {
1179                                    $fieldValues .= ( $fieldValues == '' ? '' : ',' ) . '"' . $k . '":"' . $v . '"';
1180                                }
1181                            }
1182                            $fieldValues = (($fieldValues) != '' ? ',' : '').$fieldValues;
1183                        }
1184                        $gdCurrentPage = 1;
1185                        if( isset( $_REQUEST[ $gdId . '_jumpToPage' ] ) )
1186                        {
1187                            $gdCurrentPage = $_REQUEST[ $gdId . '_jumpToPage' ];
1188                        }
1189                        $gdCollapsed = 0;
1190                        if( isset( $_REQUEST[ $gdId . '_collapsed' ] ) )
1191                        {
1192                            $gdCollapsed = $_REQUEST[ $gdId . '_collapsed' ];
1193                        }
1194                        $this->addJavascript( 'jQuery("#' . $dcField->getId() . '").load(app_index_file,{"subform":1,"ajax":0,"gridOffline":"1","parent_field":"' . $dcField->getId() . '","' . $gdId . '_jumpToPage":"' . $gdCurrentPage . '","' . $gdId . '_collapsed":"' . $gdCollapsed . '","'.$gdId.'Width":'.$gdWidth.',"modulo":"' . $gdFile . '"' . $fieldValues . '} );' );
1195                    }
1196                }
1197                else if( $dcFieldType == 'group' )
1198                {
1199                    $dcField->setOnlineDoc( $this->getOnlineDoc() );
1200                }
1201                else if( $dcFieldType == 'pagecontrol' )
1202                {
1203                    // ativar/desativar online doc nos forms das abas e aplicar shortcuts
1204                    if( is_array( $dcField->getPages() ) )
1205                    {
1206                        forEach( $dcField->getPages() as $name=>$page )
1207                        {
1208                            $page->setOnlineDoc( $this->getOnlineDoc() );
1209                            $page->setCustomHintEnabled( $this->getCustomHintEnabled() );
1210                            $this->parseShortcut($page,$page->getId() );
1211                        }
1212                    }
1213                }
1214                else if( $dcFieldType == 'button' )
1215                {
1216                    // alinhar o botão com o campo quando o campo estiver com labelabove=true
1217                    if( $lastDisplayControl )
1218                    {
1219                        if( $lastDisplayControl->getLabelAbove() )
1220                        {
1221                            $dc->setLabelAbove( true );
1222                        }
1223                    }
1224                    $this->parseShortcut($dc->getField(),$dc->getField()->getid() );
1225                }
1226                else if( $dcFieldType == 'treeview' )
1227                {
1228                    $this->addJavascript( $dcField->getJs() );
1229                }
1230                
1231                if( method_exists( $dcField, 'getHint' ) )
1232                {
1233                    
1234                    if( $dcField->getHint() )
1235                    {
1236                        $hint = trim( $dcField->getHint() );
1237                        // destacar os campos com ajuda ao usuário alterando a cor de fundo
1238                        if( $this->getColorHighlightBackground() )
1239                        {
1240                            if( $dcField->getFieldType() != 'link')
1241                            {
1242                                if( !$dcField->getCss( 'background-color' ) )
1243                                {
1244                                    $dcField->setCss( 'background-color', $this->getColorHighlightBackground() );
1245                                }
1246                            }
1247                        }
1248                        $dcField->setProperty( 'tooltip', 'true' );
1249                    }
1250                }
1251                // se o form ou aba ou grupo estiver desabilitado, desabilitar todos os campos
1252                if( $this->getReadOnly() == true )
1253                {
1254                    if( method_exists( $dcField, 'setReadOnly' ) )
1255                    {
1256                        $dcField->setReadOnly( true );
1257                    }
1258                }
1259                else if( $this->getEnabled() == false )
1260                {
1261                    if( method_exists( $dcField, 'setEnabled' ) )
1262                    {
1263                        $dcField->setEnabled( false );
1264                    }
1265                }
1266                // definir o parent do campo para poder recuperar com javascript (jquery) os campos pertencentes a uma aba ou grupo ou form etc..se for preciso
1267                $dcField->setProperty( 'parent', $parentName );
1268                // gerar os campos ocultos no final do form
1269                if( $dcFieldType == "hidden" )
1270                {
1271                    $hiddenFields[ ] = $dcField;
1272                }
1273                else
1274                {
1275                    // inicializar o contador de colunas
1276                    if( $currentCol === null )
1277                    {
1278                        $currentCol = 0;
1279                        $dc->setNewLine( true );
1280                    }
1281                    // adicionar quebra do segundo campo em diante
1282                    if( $dc->getNewLine() )
1283                    {
1284                        $rows++;
1285                        $tableFields = new TTable('table_'.$dcField->getId().'_line');
1286                        $tableFields->setProperty('cellpadding','0px');
1287                        $tableFields->setProperty('cellspacing','0px');
1288                        $tableFields->setProperty('border','0');
1289                        $currentRow            = $tableFields->addRow();
1290                        $currentRow->setid("tr_".$dcField->getId());
1291                        $currentCell        = $currentRow->addCell();
1292                        $currentCell->setId('td_'.$dcField->getId());
1293                        $currentCell->setProperty('form_line',$rows );
1294                        $currentCell->setProperty('form_col',0);
1295                        
1296                        $boolLabelAbove = false;
1297                        $loRow = $tableLayout->addRow();
1298                        $loCell = $loRow->addCell();
1299                        $loCell->add( $tableFields );
1300                        $loCell->setProperty('form_line',$rows);
1301                        
1302                        if( $rows > 1 )
1303                        {
1304                            $loCell->setCss('padding-top','2px');
1305                        }
1306                        if( $dc->getField()->getCss('text-align')=='center' )
1307                        {
1308                            //$loCell->setProperty('align', 'center');
1309                        }
1310                        if( $dc->getField()->getProperty('align') )
1311                        {
1312                            $loCell->setProperty('align', $dc->getField()->getProperty('align')  );
1313                        }
1314                        if( $this->getOnDrawRow() && function_exists($this->getOnDrawRow() ) )
1315                        {
1316                            call_user_func($this->getOnDrawRow(),$dc,$loCell,$rows,$loRow);
1317                        }
1318                        $currentCol = 0;
1319                    }
1320                    else
1321                    {
1322                        $currentCell= $currentRow->addCell();
1323                        $currentCell->setCss('padding-left','15px');
1324                        $currentCell->setProperty('form_line',$rows );
1325                        $currentCell->setProperty('form_col',($currentCol+1));
1326                        $currentCol++;
1327                    }
1328                    if( $dc->getLabelAbove() && !$boolLabelAbove )
1329                    {
1330                        $boolLabelAbove=true;
1331                    }
1332                    if( $boolLabelAbove)
1333                    {
1334                        $currentCell->setProperty('valign','bottom');
1335                    }
1336                    
1337                    if( $this->getOnDrawField() && function_exists($this->getOnDrawField() ) )
1338                    {
1339                        call_user_func($this->getOnDrawField(),$dc,$loCell,$rows);
1340                    }
1341                    
1342                    // fazer o controle das larguras das colunas do formulário
1343                    $column = $currentCol;
1344                    if( $column > 0 )
1345                    {
1346                        $column = $column * 2;
1347                    }
1348                    if( !is_null( $this->getColumnWidth( $column  ) )  && is_object( $dcLabel ) )
1349                    {
1350                        if( $dc->getNoWrapLabel() || $this->getNoWrap() )
1351                        {
1352                            $dc->setLabelCellWidth( 'auto' );
1353                        }
1354                        else
1355                        {
1356                            $dc->setLabelCellWidth( $this->getColumnWidth( $column ) );
1357                        }
1358                        $dc->setFieldCellWidth( $this->getColumnWidth( $column + 1 ) );
1359                    }
1360                    // adicionar javascript para selects combinados
1361                    if( is_array( $this->selectsCombinados ) && $dc->getField()->getFieldType() == 'select' )
1362                    {
1363                        //print $field->getId().'<br>';
1364                        if( isset( $this->selectsCombinados[ $dcField->getId() ] ) )
1365                        {
1366                            // um campo select pode ter varios select filhos e os parametros
1367                            // para cada select filho devem ser separados por ponto e virgula
1368                            $parametros = "";
1369                            $proximoSelect = "";
1370                            foreach( $this->selectsCombinados[ $dcField->getId() ] as $fieldName=>$aDados )
1371                            {
1372                                if( $proximoSelect == "" )
1373                                {
1374                                    $proximoSelect = $fieldName;
1375                                }
1376                                $aDados[ 'valorInicial' ] = null;
1377                                $childField = $this->getField( $aDados[ 'selectFilho' ] );
1378                                if( ! $childField )     //procurar no formulário inteiro
1379                                {
1380                                    $childField = self::$instance->getField( $aDados[ 'selectFilho' ] );
1381                                }
1382                                if( $childField )
1383                                {
1384                                    $childField->setAttribute('parentSelect', $dcField->getId());
1385                                    if( !$childField->getEnabled() )
1386                                    {
1387                                        $aDados[ 'selectFilhoStatus' ] = "desabilitado";
1388                                        // se alterar o valor de um select desabilitado, alterar o tambem o valor do campo oculto relativo ao select desabilitado
1389                                        $childField->addEvent( 'onchange', "fwGetObj('" . $aDados[ 'selectFilho' ] . "').value=this.value;" );
1390                                        $aDados[ 'selectFilho' ] = $aDados[ 'selectFilho' ] . '_disabled';
1391                                    }
1392                                    
1393                                    if( $childField->getValue() )
1394                                    {
1395                                        if( is_array( $childField->getValue() ) ){
1396                                            //list($aDados['valorInicial']) = implode('|',$childField->getValue());
1397                                            $aDados[ 'valorInicial' ] = implode( '|', $childField->getValue() );
1398                                        }else{
1399                                            $aDados[ 'valorInicial' ] = $childField->getValue();
1400                                        }
1401                                    }
1402                                }
1403                                
1404                                foreach($aDados as $k=>$v){
1405                                    if( empty($v) ){
1406                                        $aDados[$k] = $v;
1407                                    }else{
1408                                        $aDados[$k] = htmlentities($v,ENT_COMPAT,ENCODINGS);
1409                                    }                                    
1410                                }
1411                                
1412                                if( $this->getPublicMode() ) {
1413                                    $aDados['fwPublicMode']='S';
1414                                }
1415                                $parametros.= ( $parametros == "") ? "" : ";";
1416                                $parametros.= str_replace( '"', '\\"', json_encode( $aDados ) );
1417                            }
1418                            //$dcField->addEvent( 'onchange', 'fwSetFocus("' . $proximoSelect . '");fwSetOpcoesSelect("' . $parametros . '")' );
1419                            $dcField->addEvent( 'onchange','fwSetOpcoesSelect("' . $parametros . '")' );
1420                            if( $dcField->getEnabled() ) {
1421                                $this->addJavascript( 'jQuery("#' . $dcField->getId() . '").change()' );
1422                            } else {
1423                                $this->addJavascript( 'jQuery("#' . $dcField->getId() . '_disabled").change()' );
1424                            }
1425                        }
1426                    }
1427                    $currentCell->add($dc);
1428                }
1429                $lastDisplayControl = $dc;
1430            }
1431            // fim
1432            if( $divButtonOpen )
1433            {
1434                //$this->body->add( '</div>' );
1435            }
1436            // adicionar javascript para serchs online aos campos ( consulta Dinamica )
1437            if( is_array( $this->onlineSearchs ) ) {
1438                if( isset( $_REQUEST[ 'onLineSearch' ] ) && $_REQUEST[ 'onLineSearch' ] )
1439                {
1440                    $this->clearOnlineSearch();
1441                    $this->addMessage( 'O formulário de cadastro on-line (' . $_REQUEST[ 'modulo' ] . '), possui campos com recurso de consulta on-line.\nNão é permitido realizar uma consulta on-line dentro de outra consulta on-line já em execução, portanto, utilize o recurso de autocomplete se possível.\nOutra forma seria adicionar um botão no formulário principal para fazer o cadastramento on-line.' );
1442                }
1443                else
1444                {
1445                    foreach( $this->onlineSearchs as $fieldName=>$aData )
1446                    {
1447                        if( $field = $this->getField( $fieldName ) )
1448                        {
1449                            $modulo = isset( $_POST[ 'modulo' ] ) ? $_POST[ 'modulo' ] : 'teste';
1450                            $sessionField = $modulo . '_' . $form->getId() . '_' . $fieldName;
1451                            $jsBefore = '';
1452                            if( !is_null( $aData[ 'beforeExecuteJs' ] ) )
1453                            {
1454                                $jsBefore = "if( typeof({$aData[ 'beforeExecuteJs' ]})=='function' && !{$aData[ 'beforeExecuteJs' ]}()){return false} ";
1455                            }
1456                            $img1 = '<img id="' . $field->getId() . '_search" style="width:12px;height:13px;cursor:pointer;" title="Consulta on-line" onClick="' . $jsBefore . 'fwModalBox(\'Consulta on-line\',\'?subform=1&modulo=' . $this->getBase() . 'callbacks/onlineSearch.php&subform=1&sessionField=' . $sessionField . '\',' . $aData[ 'windowHeight' ] . ',' . $aData[ 'windowWidth' ] . ')" src="' . $this->getBase() . 'imagens/search.gif">';
1457                            // textarea não pode utilizar o metodo add para adicionar imagens na frente do campo
1458                            if( $field->getFieldType() != 'memo' )
1459                            {
1460                                $field->add( $img1 );
1461                            }
1462                            if( !$aData[ 'disableEnterKey' ] )
1463                            {
1464                                $field->addEvent( 'onKeyPress', 'fwCallOnlineSearch(this,event)' );
1465                            }
1466                            if( !$field->getEnabled())
1467                            {
1468                                $field->setEnabled(true);
1469                                $field->setReadOnly(true);
1470                                $this->addJavascript('jQuery("#'.$field->getId().'").click(function(){jQuery("#'.$field->getId() . '_search").click();})');
1471                            }
1472                            if( $aData[ 'updateFormFields' ] )
1473                            {
1474                                // criar a string com os nomes dos campos que serão limpos quando clicar na lixeira
1475                                $aTemp = explode( ',', $aData[ 'updateFormFields' ] );
1476                                $formFields = $fieldName;
1477                                foreach( $aTemp as $i=>$fld )
1478                                {
1479                                    $aField = explode( '|', $fld );
1480                                    $aField[ 1 ] = (!isset( $aField[ 1 ] ) ? strtolower( $aField[ 0 ] ) : $aField[ 1 ] );
1481                                    $formFields.='|' . $aField[ 1 ];
1482                                }
1483                            }
1484                            $img2 = '<img id="' . $field->getId() . '_search_clear" style="width:16px;height:14px;cursor:pointer;" title="Limpar campos" onClick="fwAtualizarCampos(\'' . $formFields . '\')" src="' . $this->getBase() . 'imagens/lixeira.gif">';
1485                            if( $field->getFieldType() == 'memo' )
1486                            {
1487                                $field->setOnlineSearch( $img1 . $img2 );
1488                            }
1489                            else
1490                            {
1491                                $field->add( $img2 );
1492                            }
1493                            $aData['prototypeParentWin'] = $this->get('modalWinId');
1494                            $aData['dialogId'] = $this->get('dialogId');
1495                            if( $this->getPublicMode() )
1496                            {
1497                                $aData['fwPublicMode'] = 'S';
1498                            }
1499                            $_SESSION[ APLICATIVO ][ 'onlineSearch' ][ $sessionField ] = $aData;
1500                        }
1501                    }
1502                }
1503            }
1504            // adicionar os botões aos campos que possuem cadastro on-line
1505            if( is_array( $this->onlineCruds ) )
1506            {
1507                foreach( $this->onlineCruds as $fieldName=>$aData )
1508                {
1509                    if( $field = $this->getField( $fieldName ) )
1510                    {
1511                        $w = is_null( $aData[ 'width' ] ) ? ($this->getWidth() + 10) : $aData[ 'width' ];
1512                        $h = is_null( $aData[ 'height' ] ) ? ($this->getHeight() - 50) : $aData[ 'height' ];
1513                        $field->add( new TButton( $field->getId() . '_crud', $aData[ 'buttonLabel' ], null, "fwModalBox('" . $aData[ 'title' ] . "',app_index_file+'?showCloseButton=0&modulo=" . $aData[ 'module' ] . "','" . $h . "','" . $w . "')", null, $aData[ 'buttonImage' ], null, $aData[ 'buttonHint' ] ) );
1514                    }
1515                }
1516            }
1517            // adicionar os campos ocultos
1518            if( $hiddenFields )
1519            {
1520                $this->body->add( '<!-- campos ocultos -->' );
1521                foreach( $hiddenFields as $k=>$field )
1522                {
1523                    $this->body->add( $field );
1524                }
1525            }
1526        }
1527        
1528        if( defined('REQUIRED_FIELD_MARK') && $this->getFieldType() == 'form' && self::$hasRequiredField )
1529        {
1530            if( $this->getRequiredFieldText() ) {
1531                $this->body->add( '<center><span class="fwFieldRequiredOldStyle">'.REQUIRED_FIELD_MARK.' '.$this->getRequiredFieldText().'</span></center>');
1532            }
1533        }
1534        // adicionar os botões das ações
1535        if( ( string ) $this->actions != '' )
1536        {
1537            $this->addButton( $this->actions );
1538        }
1539        // adicionar os botoes no rodapé
1540        if( is_array( $this->footerButtons ) && $this->getEnabled() )
1541        {
1542            // criar shortcuts para os botões do rodapé
1543            foreach( $this->footerButtons as $id=>$button )
1544            {
1545                $this->parseShortcut($button,$id );
1546            }
1547            
1548            $this->footer->add( '<!-- Botões do formulário -->' );
1549            if( $this->getFieldType() == 'form' )
1550            {
1551                foreach( $this->footerButtons as $id=>$button )
1552                {
1553                    $this->footer->add( $button );
1554                }
1555            }
1556            else
1557            {
1558                // criar uma div para mostrar os botoes dentro de uma aba ou groupbox
1559                if( $this->footer->getCss( 'border-top' ) )
1560                {
1561                    $this->body->add( '<hr style="border:none;border-top:' . $this->footer->getCss( 'border-top' ) . ';">' );
1562                }
1563                else
1564                {
1565                    $this->body->add( '<hr style="border:none;border-top:1px solid #c0c0c0;">' );
1566                }
1567                $e = new TElement( 'div' );
1568                //$e->setCss( 'border', '1px solid red' );
1569                $e->setCss( 'text-align:', 'center' );
1570                foreach( $this->footerButtons as $id=>$button )
1571                {
1572                    $e->add( $button );
1573                }
1574                $this->body->add( $e );
1575            }
1576        }
1577        if( $this->getFieldType() == "form" )
1578        {
1579            
1580            // este arquivo tem que ser o ultimo js da lista por isso tem que ficar aqui.
1581            //if( !isset($_REQUEST['gridOffline']))
1582            if( ! $this->getFormGridOffLine() )
1583            {
1584                $this->addJsFile( 'funcoes.js' );
1585            }
1586            if( $this->getShowMessageAlert())
1587            {
1588                $this->addJavascript( 'fwHideMsgArea("'.$form->getName().'")',-1 );
1589            }
1590            // verificar se tem algum erro para ser exibido
1591            if( $this->getMessages() )
1592            {
1593                $msg = "";
1594                foreach( $this->getMessages() as $k=>$message )
1595                {
1596                    $msg .= $msg == "" ? "" : '\n';
1597                    $msg .= $message;
1598                }
1599                
1600                if( $this->message_area )
1601                {
1602                    //$this->message_area->setCss( 'width', $this->getWidth() - 50 );
1603                    if( $this->getErrors() )
1604                    {
1605                        $this->addJavascript( 'fwShowMsgArea({"formId":"' . $form->getName() . '","message":"' . $msg . '","alert":' . $this->getShowMessageAlert() . ',"class":"fwMessageAreaError","title":"Erro"})' );
1606                    }
1607                    else
1608                    {
1609                        $this->addJavascript( 'fwShowMsgArea({"formId":"' . $form->getName() . '","message":"' . $msg . '","alert":' . $this->getShowMessageAlert() . ',"class":"fwMessageAreaSucess","title":"Mensagem"})' );
1610                    }
1611                }
1612            }
1613            
1614            $this->showPopUpMessage();
1615            // definir o campo que receberá o foco unicial
1616            $jsFocusField = '';
1617            if( !$this->getFormGridOffLine() )
1618            {
1619                if( $this->getFocusField() )
1620                {
1621                    $jsFocusField = 'jQuery("#' . $this->getFocusField() . '").focus();';
1622                }
1623                else
1624                {
1625                    $jsFocusField = 'jQuery(":text:visible:enabled:first").focus();';
1626                }
1627            }
1628            if( isset( $_POST[ 'modulo' ] ) && isset( $_REQUEST[ 'redirect' ] ) )
1629            {
1630                //if( !isset($_REQUEST['gridOffline']))
1631                if( ! $this->getFormGridOffLine() ) {
1632                    $this->addJavascript( 'try{ parent.app_setFooterModule("' . $_POST[ 'modulo' ] . '","' . (isset( $_POST[ 'acao' ] ) ? $_POST[ 'acao' ] : '') . '");}catch(e){}' );
1633                    
1634                    if( isset( $_REQUEST[ 'redirect_message' ] ) && $_REQUEST[ 'redirect_message' ] != '' ) {
1635                        $this->addJavascript( 'try{alert("' . $_REQUEST[ 'redirect_message' ] . '");}catch(e){}' );
1636                    }
1637                }
1638            }
1639        }
1640        // os campos que forem autocomplete e tiverem valor, disparar o evento de validação
1641        if( is_array( $this->autocompleteFields ) )
1642        {
1643            $this->addJavascript( '// Inicializar e validar os campos com auto-complete' );
1644            foreach( $this->autocompleteFields as $fieldName=>$params )
1645            {
1646                if( isset( $params[ 'fillFields' ] ) && $params[ 'disableFields' ] )
1647                {
1648                    $this->disableFields( $params[ 'fillFields' ], true );
1649                }
1650                if( method_exists($this->getField( $fieldName ),'setAutoTab'))
1651                {
1652                    $this->getField( $fieldName )->setAutoTab(false);// campo autocomplete não pode ter autotab
1653                }
1654                if( $this->getField( $fieldName )->value )
1655                {
1656                    $this->addJavascript( 'fwAutoCompleteValidade(fwGetObj("' . $fieldName . '"))' );
1657                }
1658            }
1659        }
1660        if( $this->getFieldType() == "form" )
1661        {
1662            // adicionar as teclas de atalho
1663            if( is_array(self::$shortCuts))
1664            {
1665                foreach(self::$shortCuts as $key=>$objParams)
1666                {
1667                    //echo 'Tecla:'.$key.' no '.$objParams->objectId.'<br>';
1668                    $field  = $this->getField($objParams->objectId);
1669                    $js = null;
1670                    if( $field )
1671                    {
1672                        $field->setAttribute('shortcut',$key.'|'.$objParams->objectId);
1673                    }
1674                    else
1675                    {
1676                        if( isset( $this->footerButtons[ $objParams->objectId ] ))
1677                        {
1678                            $this->footerButtons[ $objParams->objectId ]->setAttribute('shortcut',$key.'|'.$objParams->objectId);
1679                        }
1680                        else
1681                        {
1682                            $js ="try { fwSetShortcut('".$key."','".$objParams->objectId."',".$objParams->changeLabel.",'".$objParams->functionJs."') } catch(e) {}";
1683                        }
1684                    }
1685                    if( $js )
1686                    {
1687                        $this->addJavascript($js);
1688                    }
1689                }
1690            }
1691            $this->addJavascript('try{fwApplyShortcuts();} catch(e) {}');
1692            $scriptAfterShow = '';
1693            $_POST[ 'ajax' ] = isset( $_POST[ 'ajax' ] ) ? $_POST[ 'ajax' ] : false;
1694            // javascript para ajustar a altura da area body em função da altura do header e footer do formulário
1695            //if( !$this->showOnlyTagForm && !$_POST[ 'ajax' ] && ! isset($_REQUEST['gridOffline'] ) )
1696            if( !$this->showOnlyTagForm && !$_POST[ 'ajax' ] && ! $this->getFormGridOffLine() )
1697            {
1698                if( $this->getShowHeader() )
1699                {
1700                    $scriptAfterShow = 'jQuery("#' . $form->getId() . '_body").height( (jQuery("#' . $form->getId() . '_area").height()-' . (($this->getFlat()) ? 10 : 25) . ')-(jQuery("#' . $form->getId() . '_header").height()+jQuery("#' . $form->getId() . '_footer").height()));';
1701                }
1702                else
1703                {
1704                    //$this->addJavascript('jQuery("#'.$form->getId().'_body").height( (jQuery("#'.$form->getId().'_area").height()-'.(($this->getFlat()) ? 15 : 25).')-(jQuery("#'.$form->getId().'_footer").height()));');
1705                    $scriptAfterShow = 'jQuery("#' . $form->getId() . '_body").height( (jQuery("#' . $form->getId() . '_area").height()-' . (($this->getFlat()) ? 15 : 25) . ')-(jQuery("#' . $form->getId() . '_footer").height()));';
1706                }
1707            }
1708            if( $this->getPrototypeId() )
1709            {
1710                $header = $this->getTitle();
1711                $header = str_replace( '<br>', '<BR>', $header );
1712                $header = str_replace( '<BR>', ' ', $header );
1713                $aDadosPrototype = array( 'winId'=>$this->getPrototypeId(), 'title'=>utf8_encode( $header ), 'width'=>$this->getWidth(), 'height'=>$this->getHeight() );
1714                $this->addJavascript( "parent.app_set_prototype_win(" . json_encode( $aDadosPrototype ) . ")" );
1715                //registra o id da janela quando estiver utilizando a classe prototype
1716                /*
1717                 $this->addJavascript("parent.lastWin.setSize({$this->getWidth()}+20,{$this->getHeight()}+20);parent.lastWin.showCenter();");
1718                 $header = $this->getTitle();
1719                 $header = str_replace('<br>','<BR>',$header);$header = str_replace('<BR>',' ',$header);
1720                 $this->addJavascript("try{ parent.lastWin.setTitle('{$header}')} catch(e){}");
1721                 */
1722            }
1723            //$this->addJavascript('jQuery("#'.$this->getId().'").show("slow",function () {'.$scriptAfterShow.'})');
1724            // formulario será exibido depois do parse via jquery
1725            if( $this->getVisible() )
1726            {
1727                // esconder e mostrar o form com efeito de fade-in
1728                $fadeDuration = 1;
1729                $this->setCss( 'display', 'block' );
1730                if( $this->getFade() > 0 )
1731                {
1732                    $this->setCss( 'display', 'none' );
1733                    $fadeDuration = $this->getFade();
1734                    $this->addJavascript( 'jQuery("#' . $this->getId() . '").fadeIn(' . $fadeDuration . ',function () {' . $scriptAfterShow . $jsFocusField . '})' );
1735                }
1736                else
1737                {
1738                    $this->addJavascript( $scriptAfterShow . $jsFocusField );
1739                }
1740                if( $this->getAutoSize() )
1741                {
1742                    $aParams = array( 'formId'=>$this->name );
1743                    if( $this->getPrototypeId() )
1744                    {
1745                        $aParams[ 'windId' ] = $this->getPrototypeId();
1746                    }
1747                    //$this->addJavascript('jQuery("#'.$this->name.'_body").bind("overflow",function (e) { fwFormDinAutoSize("'.$this->name.'",'.json_encode($aDadosPrototype).')});');
1748                    $this->addJavascript( 'try{ fwFormDinAutoSize(' . json_encode( $aParams ) . ');} catch(e) {}' );
1749                    //$this->addJavascript('jQuery("#'.$this->name.'_body").bind("overflow",function (e) { '.$overFlowFunction.'});');
1750                }
1751                // ajustar a largura dos grupos e das abas à largura do formulário.
1752                $this->addJavascript( 'try{ fwAdjustGroupsWidth(); fwAdjustTabsWidth(); fwAdjustHtmlFieldsWidth(); } catch(e) {}' );
1753                
1754            }
1755            // integração com o gride off-line versão antiga
1756            if( isset( $GLOBALS[ 'jsgride' ] ) && is_array( $GLOBALS[ 'jsgride' ] ) )
1757            {
1758                $js = '';
1759                foreach( $GLOBALS[ 'jsgride' ] as $grd=>$v )
1760                {
1761                    $gride = $GLOBALS[ 'jsgride' ][ $grd ];
1762                    $js .= $grd . "_estrutura = " . json_encode( $GLOBALS[ 'jsgride' ][ $grd ] ) . ";\n";
1763                }
1764                if( $js )
1765                {
1766                    $this->addJavascript( '// script necessário para o grid off-line' );
1767                    $this->addJavascript( $js );
1768                }
1769            }
1770        }
1771        
1772        if( is_array( $this->getJavascript() ) )
1773        {
1774            $js = new TElement( 'script' );
1775            $js->clearCss();
1776            $js->add( 'jQuery(document).ready(function() {' );
1777            $js->add( chr( 9 ) . '// javasripts que serão executados depois que o documento estiver 100% carregado. Utilizando o jquery.' );
1778            $alerts = array( );
1779            foreach( $this->getJavascript() as $k=>$strJs )
1780            {
1781                //print $strJs.'<br>';
1782                if( FormDinHelper::pregMatch( '/alert\(/', $strJs ) > 0 ) {
1783                    $alerts[] = preg_replace( '/;;/', '', $strJs );
1784                }else{
1785                    //$js->add(chr(9).str_replace(";;",";",$strJs.";"));
1786                    $js->add( chr( 9 ) . preg_replace( '/;;/', '', $strJs ) );
1787                }
1788            }
1789            foreach( $alerts as $k=>$strJs )
1790            {
1791                $js->add( chr( 9 ) . $strJs );
1792            }
1793            $js->add( '});' );
1794            if( $this->getFieldType() == "tabsheet" )
1795            {
1796                $this->body->add( $js );
1797            }
1798            else
1799            {
1800                $this->add( $js );
1801            }
1802        }
1803        
1804        // tem que habilitar o container senão ele não é exibido
1805        $this->setEnabled( true );
1806        
1807        // colocar o form dentro de uma pagina html completa com as tags html, head e body
1808        if( $this->getFieldType() == "form" && $this->getShowHtmlTag() )
1809        {
1810            $page = new THtmlPage();
1811            $this->setShowHtmlTag( false );
1812            $page->addInBody( parent::show( false, $this->getFlat() ) ) . $this->showPdfs( false, $this->getFlat() ) . $this->getOnlineDocDiv( false,$this->getOnlineDocHeight(),$this->getOnlineDocWidth() );
1813            $page->addJsCssFile( $this->getJsCss() );
1814            return $page->show( $print );
1815        }
1816        // se for aba ou groupbox não precisa das tags html, head e body
1817        else if( $this->getFieldType() == "tabsheet" )
1818        {
1819            // configurar a apresentação do form quando for um tabsheet ( aba )
1820            /*
1821             $this->setTagType( 'div' );
1822             $this->body->setClass( $this->getClass() );
1823             $this->body->setCss( $this->getCss() );
1824             $this->body->setId( $this->getId() );
1825             $parentWidth = $this->getCurrentContainer() ? $this->getCurrentContainer()->getcss('width') : $this->getCss('width');
1826             
1827             //--
1828             if( $this->body->getcss('display')=='inline')
1829             {
1830             $this->body->setcss('display','block');
1831             }
1832             */
1833            /*
1834             if( !$this->body->getcss('height') )
1835             {
1836             $this->body->setcss('height',($this->getHeight()-120).'px');
1837             }
1838             */
1839            /*
1840             if( !$this->body->getcss('height')=='auto' )
1841             {
1842             $this->body->setcss('overflow',null);
1843             $this->body->setCss('overflow-x',null);
1844             $this->body->setCss('overflow-y',null);
1845             }
1846             else
1847             {
1848             $this->body->setcss('overflow','hidden');
1849             $this->body->setCss('overflow-x',$this->getOverFlowX());
1850             $this->body->setCss('overflow-y',$this->getOverFlowY());
1851             }
1852             */
1853            
1854            return $this->body->show( $print );
1855        }
1856        else if( $this->getFieldType() == "groupbox" || $this->getFieldType() == "coordgmsx" )
1857        {
1858            // configurar a apresentação do form quando for um groupbox
1859            $this->divBody->clearCss();
1860            //$this->divBody->setCss('width',$this->getWidth());
1861            $this->divBody->setCss( 'height', $this->getHeight() );
1862            if( is_null($this->divBody->getCss('overflow')))
1863            {
1864                $this->divBody->setCss( 'overflow', 'hidden' );
1865            }
1866            $this->divBody->setCss( 'overflow-y', $this->getOverFlowY() );
1867            $this->divBody->setCss( 'overflow-x', $this->getOverFlowX() );
1868            /*
1869             $this->divBody->setCss( 'overflow', 'hidden' );
1870             $this->divBody->setCss( 'overflow-y', 'hidden' );
1871             $this->divBody->setCss( 'overflow-x', 'hidden' );
1872             */
1873            $this->body->clearCss();
1874            $cell = $this->table->addRow()->addCell( $this->body );
1875            $cell->setCss( 'vertical-align', $this->getCss( 'vertical-align' ) );
1876            $cell->setCss( 'text-align', $this->getCss( 'text-align' ) );
1877            return parent::show( $print, $this->getFlat() );
1878        }
1879        else if( $this->getFieldType() == "group" || $this->getFieldType() == "coordgms")
1880        {
1881            if( $this->getFieldType() == "coordgms" )
1882            {
1883                $this->getButtonGMap()->setEnabled(true);
1884            }
1885            
1886            
1887            // configurar a apresentação do form quando for um groupbox
1888            //$this->divBody->clearCss();
1889            //$this->divBody->setCss('width',$this->getWidth());
1890            //$this->divBody->setCss( 'height', $this->getHeight() );
1891            //if( is_null($this->divBody->getCss('overflow')))
1892            //{
1893            //    $this->divBody->setCss( 'overflow', 'hidden' );
1894            //}
1895            //$this->divBody->setCss( 'overflow-y', $this->getOverFlowY() );
1896            //$this->divBody->setCss( 'overflow-x', $this->getOverFlowX() );
1897            /*
1898             if( is_null($this->divBody->getCss('overflow')))
1899             {
1900             $this->divBody->setCss( 'overflow', 'hidden' );
1901             }
1902             $this->divBody->setCss( 'overflow-y', $this->getOverFlowY() );
1903             $this->divBody->setCss( 'overflow-x', $this->getOverFlowX() );
1904             */
1905            //$this->body->setProperty('luis','eugenio');
1906            //$this->body->setCss('overflow','auto'
1907            $this->body->clearCss(); // retirar as bordas do top e bottom
1908            $cell = $this->table->addRow()->addCell( $this->body );
1909            $this->table->clearCss();
1910            $cell->setCss( 'vertical-align', $this->getCss( 'vertical-align' ) );
1911            $cell->setCss( 'text-align', $this->getCss( 'text-align' ) );
1912            return parent::show( $print, $this->getFlat() );
1913            //return parent::show($print);
1914        }
1915        else
1916        {
1917            return parent::show( $print, $this->getFlat() ) . $this->showPdfs( $print, $this->getFlat() ) . $this->getOnlineDocDiv( $print,$this->getOnlineDocHeight(),$this->getOnlineDocWidth() );
1918        }
1919    }
1920    //-----------------------------------------------------------------------------
1921    /**
1922     * Define a largura do formulário
1923     *
1924     * @param integer $strNewValue
1925     */
1926    public function setWidth( $strNewValue=200 )
1927    {
1928        if( $this->getFieldType() == 'form' )
1929        {
1930            if( ( int ) $strNewValue < 200 )
1931            {
1932                $strNewValue = 200;
1933            }
1934        }
1935        return parent::setWidth( $strNewValue );
1936    }
1937    //-----------------------------------------------------------------------------
1938    /**
1939     * Define a altura do formulário
1940     *
1941     * @param integer $strNewValue
1942     */
1943    public function setHeight( $strNewValue=100 )
1944    {
1945        if( $this->getFieldType() == 'form' )
1946        {
1947            if( ( int ) $strNewValue < 100 )
1948            {
1949                $strNewValue = 100;
1950            }
1951        }
1952        return parent::setHeight( $strNewValue );
1953    }
1954    //-----------------------------------------------------------------------------
1955    /**
1956     * Implementa o recurso de autosugestão a um campo texto do formulário utilizando jquery
1957     * @link http://www.pengoworks.com/workshop/jquery/autocomplete_docs.txt
1958     *
1959     * @strUrl - se for informada a url que devolverá os dados para o autocomplete, o retorno deverá ser no seguinte formato:
1960     * "descriçao|chave\n"  exemplo: echo "Abacate|123\n"
1961     *
1962     * <code>
1963     *     $frm->setAutoComplete( 'num_cpf',
1964     *                   'PESSOA_FISICA, // nome da tabela
1965     *                   'NUM_CPF',
1966     *                   'NUM_PESSOA|num_pessoa,NOM_PESSOA,COD_UNIDADE_IBAMA,END_PESSOA,DES_BAIRRO,NUM_CEP,NUM_FONE,DES_EMAIL,NOM_MUNICIPIO,DAT_NASC,NOM_UNIDADE_IBAMA,COD_UNIDADE_EXERCICIO,NOM_UNIDADE_EXERCICIO,COD_UF,SIG_UF,COD_MATRICULA',
1967     *                   false,
1968     *                   null,
1969     *                   null,
1970     *                   14,
1971     *                   400,
1972     *                   2,
1973     *                   null,
1974     *                   true );
1975     * </code>
1976     *
1977     * @param string $strFieldName                  - 1: nome do campo no form(tela) irá funcionar com autocomplete
1978     * @param string $strTablePackageFuncion        - 2: tabela alvo da pesquisa ou pacote somente no oracle
1979     * @param string $strSearchField                - 3: campo de pesquisa
1980     * @param mixed $mixUpdateFields                - 4: campos do form origem que serão atualizados ao selecionar o item desejado. Separados por virgulas seguindo o padrão <campo_tabela> | <campo_formulario> , <campo_tabela> | <campo_formulario>
1981     * @param boolean $boolDisableUpdateFields      - 5: Desativa os campos que serão atuliazados depois da pesquisa
1982     * @param mixed $mixExtraSearchFields           - 6: Campos do formulário que serão adicionados como filtro. Esse campos a consulta é direta não usa like, procure usar campos do tipo INT. ATENÇÃO Segue o Padrão <campo_formulario> | <campo_tabela>, <campo_formulario> | <campo_tabela>
1983     * @param string $strCallBackFunctionJs         - 7: função javascript de callback
1984     * @param integer $intMinChars                  - 8: Default 3, numero de caracteres minimos para disparar a pesquisa
1985     * @param integer $intDelay                     - 9: Default 500, tempo após a digitação para disparar a consulta
1986     * @param integer $intMaxItensToShow            - 10: Default 50, máximo de registros que deverá ser retornado
1987     * @param integer $intCacheTime default = 0 ( sessão )
1988     * @param boolean $boolRemoveMask
1989     * @param string $strUrl                        - 13: url da função de callbacks, se ficar em branco será tratado por callbacks/autocomplete.php
1990     * @param string $strMessageNotFound            - 14: Mensagem caso não encontre nenhum registro
1991     * @param boolean $boolKeepFieldValuesOnPost    - 15:
1992     * @param boolean $boolClearOnNotFound
1993     * @param boolean $boolClearUpdateFields
1994     * @param boolean $boolSearchAnyPosition        - 18: busca o texto em qualquer posição igual Like %texto%
1995     * @param boolean $strConfigFileName            - 19: Nome do arquivo conexão com banco na pasta <APP>/includes/<nome_arquivo>.php para executar o autocomplete. 
1996     * @param boolean $trimText                     - 20: limpa o texto com trim. DEFAULT = true
1997     */
1998    public function setAutoComplete( $strFieldName
1999                                   , $strTablePackageFuncion
2000                                   , $strSearchField
2001                                   , $mixUpdateFields=null
2002                                   , $boolDisableUpdateFields=null
2003                                   , $mixExtraSearchFields=null
2004                                   , $strCallBackFunctionJs=null
2005                                   , $intMinChars=null
2006                                   , $intDelay=null
2007                                   , $intMaxItensToShow=null
2008                                   , $intCacheTime=null
2009                                   , $boolRemoveMask=null
2010                                   , $strUrl=null
2011                                   , $strMessageNotFound=null
2012                                   , $boolKeepFieldValuesOnPost=null
2013                                   , $boolClearOnNotFound=null
2014                                   , $boolClearUpdateFields=null
2015                                   , $boolSearchAnyPosition=null 
2016                                   , $strConfigFileName=null
2017                                   , $trimText = true
2018                                   )
2019    {
2020        
2021        // não criar o autocomplente se o campo não existir
2022        if( !$this->getField( $strFieldName ) ) {
2023            return;
2024        }
2025        
2026        //$strUrl = $strUrl === null ? 'app_url+app_index_file+"?modulo=' . $this->getBase() . 'callbacks/autocomplete.php' : $strUrl;
2027        
2028        $urlCallBack = 'app_index_file+"?modulo=' . $this->getBase() . 'callbacks/autocomplete.php';
2029        
2030        $strUrl   = $strUrl === null ? $urlCallBack : $strUrl;
2031        $intDelay = $intDelay === null ? 500 : ( int ) $intDelay; // 1000 = 1 segund
2032        $intMaxItensToShow = $intMaxItensToShow === null ? 50 : ( int ) $intMaxItensToShow;
2033        $intMinChars = $intMinChars === null ? 3 : ( int ) $intMinChars;
2034        $intCacheTime = $intCacheTime === null ? 0 : ( int ) $intCacheTime; // 0 = sessão
2035        $boolRemoveMask = $boolRemoveMask === null ? false : ( bool ) $boolRemoveMask;
2036        $boolDisableUpdateFields = $boolDisableUpdateFields === null ? true : ( bool ) $boolDisableUpdateFields;
2037        $boolClearOnNotFound = $boolClearOnNotFound === null ? true : ( bool ) $boolClearOnNotFound;
2038        $boolClearUpdateFields = $boolClearUpdateFields === null ? true : ( bool ) $boolClearUpdateFields;
2039        $strMessageNotFound = $strMessageNotFound === null ? 'Nenhum registro encontrado' : ( string ) $strMessageNotFound;
2040        $boolSearchAnyPosition = ( $boolSearchAnyPosition === true ? true : false );
2041        $trimText = ( $trimText === true ? true : false );
2042        if(is_null( $boolKeepFieldValuesOnPost))
2043        {
2044            //if( $_REQUEST['gridOffline'] == 1 )
2045            if( $this->getFormGridOffLine() )
2046            {
2047                $boolKeepFieldValuesOnPost=true;
2048            }
2049        }
2050        $boolKeepFieldValuesOnPost = $boolKeepFieldValuesOnPost === null ? false : (bool)$boolKeepFieldValuesOnPost;
2051        $strExtraParams = "";
2052        $strLimparCampos = "";
2053        $aTemp[ 'tablePackageFunction' ] = $strTablePackageFuncion;
2054        $aTemp[ 'searchField' ] = $strSearchField;
2055        $aTemp[ 'cacheTime' ] = $intCacheTime;
2056        $aTemp[ 'searchAnyPosition' ] = $boolSearchAnyPosition;
2057        $aTemp[ 'configFileName' ] = $strConfigFileName;
2058        $aTemp[ 'trimText' ]       = $trimText;
2059        //$aTemp['messageNotFound']    = $strMessageNotFound;
2060        if( ( string ) $strCallBackFunctionJs ){
2061            if( !strpos( $strCallBackFunctionJs, '(' ) ){
2062                $strCallBackFunctionJs.="()";
2063            }
2064            $aTemp[ 'functionJs' ] = $strCallBackFunctionJs;
2065        }
2066        if( $mixUpdateFields ){
2067            if( !is_array( $mixUpdateFields ) ) {
2068                $mixUpdateFields = explode( ',', $mixUpdateFields );
2069            }
2070            forEach( $mixUpdateFields as $k=>$v ){
2071                if( is_int( $k ) ){
2072                    $aField = explode( '|', $v );
2073                    if( !isset( $aField[ 1 ] ) ){
2074                        $aField[ 1 ] = strtolower( $aField[ 0 ] );
2075                    }
2076                    $k = strtoupper( $aField[ 0 ] );
2077                    $v = $aField[ 1 ];
2078                }
2079                // o campo que recebe o autocomplete não pode estar na lista dos campos que serão atualizados no formulário.
2080                if( $v != $strFieldName ) {
2081                    $strExtraParams = (isset( $strExtraParams ) && strlen( $strExtraParams ) > 0 ? $strExtraParams . "," : "");
2082                    $strFillFields = (isset( $strFillFields ) && strlen( $strFillFields ) > 0 ? $strFillFields . "," : "");
2083                    $strExtraParams.='"' . $k . '":"' . $v . '"'; //"COD_UF":"cod_uf"
2084                    $aTemp[ '_u_' . $k ] = $v;
2085                    $strFillFields .= $v;
2086                }
2087            }
2088        }
2089        if( $mixExtraSearchFields ) {
2090            /* o parametro $mixExtraParams deve ser utilizado para passagem de parametros extras para a url alem do conteúdo digitado no campo
2091             O formato pode ser uma string ou um array de string com ou sem valores fixos
2092             Ex: "cod_uf:53" ou  array("cod_uf",'sig_uf'=>'GO')
2093             Se o parametro passado não tiver um valor fixado, este valor será lido dinamicamente de um campo do formulario que
2094             possua o mesmo nome.
2095             */
2096            if( is_array( $mixExtraSearchFields ) ) {
2097                forEach( $mixExtraSearchFields as $k=>$v ) {
2098                    if( is_int( $k ) ) {
2099                        $k = $v;
2100                        $v = null;
2101                    }
2102                    $strExtraParams .= $strExtraParams == '' ? '' : ',';
2103                    if( ( string ) $v == "" ) {
2104                        if( $this->getField( $k ) ) {
2105                            $v = 'jQuery("#' . $k . '").get(0).value';
2106                        }
2107                    }
2108                    $strExtraParams.='"' . $k . '":' . $v;
2109                    //$aSearchFields[$k]=$v;
2110                    $aTemp[ '_w_' . $k ] = $v;
2111                }
2112            } else {
2113                if( !strpos( $mixExtraSearchFields, ":" ) ){
2114                    //$aSearchFields[$mixExtraSearchFields] ='jQuery("#'.$mixExtraSearchFields.'").get(0).value';
2115                    //$aTemp['_w_'.$mixExtraSearchFields] ='jQuery("#'.$mixExtraSearchFields.'").get(0).value';
2116                    $field = explode('|',$mixExtraSearchFields);
2117                    
2118                    
2119                    $aTemp[ '_w_' . $mixExtraSearchFields ] = '';
2120                    if( !$this->getField( $field[0] ) ){
2121                        print 'SetAutoComplete: O campo ' . $field[0] . ' não exite no formulário.';
2122                    }
2123                    
2124                    $mixExtraSearchFields = '"' . $mixExtraSearchFields . '":' . $v = 'jQuery("#' . $mixExtraSearchFields . '").get(0).value';
2125                }
2126                $strExtraParams.= $strExtraParams == '' ? '' : ',';
2127                $strExtraParams.= $mixExtraSearchFields;
2128            }
2129        }
2130        $strExtraParams = str_replace( array( '{', '}', ':"$', ').value"', '"jQuery("#', '\").get', '"{', '}"' ), array( '', '', ':$', ').value', 'jQuery("#', '").get', '{', '}' ), stripcslashes( json_encode( $aTemp ) ) );
2131        $this->addJavascript( 'jQuery("#' . $strFieldName . '").autocomplete(' . $strUrl 
2132                            . '&ajax=1", { ajax:1, delay:' . $intDelay . ', minChars:' . $intMinChars 
2133                            .' ,matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:fwAutoCompleteSelectItem'
2134                            .' ,onFindValue:fwAutoCompleteFindValue, matchCase:false, maxItemsToShow:' . $intMaxItensToShow 
2135                            .' ,autoFill:true, selectFirst:true, mustMatch:false, selectOnly:true,removeMask:' . ($boolRemoveMask ? 'true' : 'false') 
2136                            .' ,messageNotFound:"' . $strMessageNotFound . '",clearOnNotFound:' . ($boolClearOnNotFound ? 'true' : 'false')
2137                            .' ,extraParams:{' . $strExtraParams . '} });' );
2138        $this->getField( $strFieldName )->addEvent( 'ondblclick', 'fwAutoCompleteValidade(this)' );
2139        if( $boolClearUpdateFields ) {
2140            $this->getField( $strFieldName )->addEvent( 'onkeydown', 'fwSetFields("' . $strFillFields . '","",event)' );
2141        }
2142        $this->getField( $strFieldName )->setAttribute('keepFieldValues',$boolKeepFieldValuesOnPost);
2143        $this->autocompleteFields[ $strFieldName ][ 'disableFields' ] = $boolDisableUpdateFields;
2144        $this->autocompleteFields[ $strFieldName ][ 'fillFields' ] = isset( $strFillFields ) ? $strFillFields : null;
2145        
2146        if( !$this->getField( $strFieldName )->getProperty( 'title' ) ) {
2147            // colocar hint no input para auxiliar o usuário
2148            if( ( int ) $intMinChars < 5 ) {
2149                if( !$this->getField( $strFieldName )->getTooltip() ) {
2150                    $this->getField( $strFieldName )->setTooltip( 'Campo autocompletar', 'Inicie a digitação e aguarde a lista de opções!' );
2151                }
2152            }
2153        }
2154        //$this->getField($strFieldName)->addEvent('onkeyup','jQuery("'.$strFillFields.'").get(0).value="?"');
2155    }
2156    
2157    //-----------------------------------------------------------------------------
2158    /**
2159     * Método para adicionar funções javascript ao formulario que serão executadas
2160     * após o mesmo tiver sido completamente carregado pelo browser
2161     *
2162     * O parametro, $intIndex é opcional, e deve ser utilizado para estabelecer a ordem de
2163     * execução dos códigos javascripts, do menor para o maior
2164     *
2165     * Para retornar o conteudo das variáveis php $_POST,$_GET ou $_REQUEST no formato json,
2166     * basta passar o nome da função no formato: minhaFuncao(POST) ou minhaFuncao(GET) ou minhaFuncao(REQUEST);
2167     *
2168     * <code>
2169     *     addJavascript("alert('mensagem 1')");
2170     *     addJavascript("alert('mensagem 2')",10);
2171     *     addJavascript("var x=1;");
2172     *  addJavascript(POST); // retorna o $_POST no formato Json
2173     *  addJavascript(GET); // retorna o $_GET no formato Json
2174     *  addJavascript(REQUEST); // retorna o $_REGUEST no formato Json
2175     * </code>
2176     *
2177     * @param string $strJs
2178     * @param integer $intIndex
2179     */
2180    public function addJavascript( $strJs, $intIndex=null )
2181    {
2182        
2183        if( $strJs )
2184        {
2185            // adicionar parentes se tiver passado o nome da função
2186            if( !preg_match('/[ =\(]/',$strJs)) {
2187                $strJs.='()';
2188            }
2189            // quando for passado assim: minhaFuncao(POST), retornar os valores do $_POST
2190            if( preg_match('/\(POST\)/',$strJs) ){
2191                $strJs = preg_replace('/\(POST\)/','('.json_encode($_POST).')',$strJs );
2192            }else if( preg_match('/\(GET\)/',$strJs) ){
2193                $strJs = preg_replace('/\(GET\)/','('.json_encode($_GET).')',$strJs );
2194            }else if( preg_match('/\(REQUEST\)/',$strJs) ){
2195                $strJs = preg_replace('/\(REQUEST\)/','('.json_encode($_REQUEST).')',$strJs );
2196            }
2197            // adicionar ; se não tiver
2198            if( preg_match( '/;\z/', $strJs ) == 0 ){
2199                $strJs .= ';';
2200            }
2201            if( preg_match( '/GB_HIDE/i', $strJs ) > 0 ){
2202                //$strJs .= ';return;';
2203            }
2204        }
2205        if( isset( $intIndex ) )
2206        {
2207            if( isset( $this->javascript[ $intIndex ] ) )
2208            {
2209                while( isset( $this->javascript[ $intIndex ] ) && $intIndex < 1000 )
2210                {
2211                    $intIndex++;
2212                }
2213            }
2214            $this->javascript[ $intIndex ] = $strJs;
2215        }
2216        else
2217        {
2218            if( !is_array( $this->getJavascript() ) )
2219            {
2220                // começar no indice 20 para poder inserir algum javascript que precise
2221                // ser executado primeiro
2222                $this->javascript[ 20 ] = $strJs;
2223            }
2224            else
2225            {
2226                $this->javascript[ ] = $strJs;
2227            }
2228        }
2229    }
2230    //-----------------------------------------------------------------------------
2231    /**
2232     * Retorna o array com os scripts adicionados no formulario
2233     *
2234     */
2235    public function getJavascript()
2236    {
2237        $arrTemp = null;
2238        if( is_array( $this->javascript ) )
2239        {
2240            $arrTemp = ( array ) $this->javascript;
2241            ksort( $arrTemp );
2242        }
2243        return $arrTemp;
2244    }
2245    /**
2246     * Metodo para recuperar o objeto campo do formulario.
2247     *
2248     * <code>
2249     *     $f = $frm->getField('nom_pessoa');
2250     *     $f->setCss('color','red');
2251     * </code>
2252     *
2253     * @param string $strFieldName
2254     * @return object
2255     */
2256    public function getField( $strFieldName=null )
2257    {
2258        $field = null;
2259        if( is_array( $this->displayControls ) )
2260        {
2261            if( array_key_exists( $strFieldName, $this->displayControls ) )
2262            {
2263                return $this->displayControls[ $strFieldName ]->getField();
2264            }
2265            else if( array_key_exists( StringHelper::strtolower($strFieldName), $this->displayControls ) )
2266            {
2267                return $this->displayControls[ StringHelper::strtolower($strFieldName) ]->getField();
2268            }
2269            else if( array_key_exists( StringHelper::strtoupper($strFieldName), $this->displayControls ) )
2270            {
2271                return $this->displayControls[ StringHelper::strtoupper($strFieldName) ]->getField();
2272            }
2273            // varrer todo o array para pesquisar dentro de abas e grupos
2274            foreach( $this->displayControls as $id=>$dc )
2275            {
2276                //print $id.'=>'.$dc->getField()->getFieldType().'<br>';
2277                if( $dc->getField()->getFieldType() == 'pagecontrol' )
2278                {
2279                    if( $field = $dc->getField()->getField( $strFieldName ) )
2280                    {
2281                        break;
2282                    }
2283                }
2284                else if( $dc->getField()->getFieldType() == 'coordgms' )
2285                {
2286                    if( $dc->getField()->getFieldNameLon() == $strFieldName )
2287                    {
2288                        return $dc->getField();
2289                        break;
2290                    }
2291                    elseif( $dc->getField()->getFieldNameLat() == $strFieldName )
2292                    {
2293                        return $dc->getField();
2294                        break;
2295                    }
2296                }
2297                else if( $dc->getField()->getFieldType() == 'group' )
2298                {
2299                    if( $field = $dc->getField()->getField( $strFieldName ) )
2300                    {
2301                        break;
2302                    }
2303                }
2304            }
2305        }
2306        return $field;
2307    }
2308    /**
2309     * Retorna o objeto label do campo permitindo alterar suas propriedades
2310     *
2311     * <code>
2312     *     $frm->getLabel('dat_aniversario')->setCss('text-align','right');
2313     * </code>
2314     *
2315     * @param mixed $strFieldName
2316     */
2317    public function getLabel( $strFieldName=null )
2318    {
2319        $label = null;
2320        
2321        if( is_array( $this->displayControls ) )
2322        {
2323            if( array_key_exists( $strFieldName, $this->displayControls ) )
2324            {
2325                return $this->displayControls[ $strFieldName ]->getLabel();
2326            }
2327            
2328            // varrer todo o array para pesquisar dentro de abas e grupos
2329            foreach( $this->displayControls as $id=>$dc )
2330            {
2331                if( $dc->getField()->getFieldType() == 'pagecontrol' )
2332                {
2333                    if( $label = $dc->getField()->getLabel($strFieldName) )
2334                    {
2335                        break;
2336                    }
2337                }
2338                else if( $dc->getField()->getFieldType() == 'coordgms' )
2339                {
2340                    if( $dc->getField()->getFieldNameLon() == $strFieldName )
2341                    {
2342                        return $dc->getLabel();
2343                        break;
2344                    }
2345                    elseif( $dc->getField()->getFieldNameLat() == $strFieldName )
2346                    {
2347                        return $dc->getLabel();
2348                        break;
2349                    }
2350                }
2351                else if( $dc->getField()->getFieldType() == 'group' )
2352                {
2353                    if( $label = $dc->getField()->getLabel( $strFieldName ) )
2354                    {
2355                        break;
2356                    }
2357                }
2358            }
2359        }
2360        return $label;
2361    }
2362    /**
2363     * Validar os campos do formulario,Abas ou Grupos
2364     *
2365     * Os erros encontrados serão adicionados ao array estático self::errors
2366     *
2367     * O parametro $strPage deve ser utilizado para validar os campos de uma aba/grupo quando
2368     * necessario
2369     *
2370     * <code>
2371     *     if( $frm->validate() )
2372     *     {
2373     *         $frm->setMessage('Dados Ok');
2374     *     }
2375     * </code>
2376     *
2377     * @param string $strPage
2378     * @return boolean
2379     */
2380     public function validate( $strPage=null, $strFields=null, $strIgnoreFields=null )
2381     {
2382         if( !is_array( $this->displayControls ) )
2383         {
2384             return true;
2385         }
2386         //$strPage = $this->removeIllegalChars($strPage);
2387         foreach( $this->displayControls as $name=>$dc )
2388         {
2389             
2390             $field = $dc->getField();
2391             if( $field->getFieldType() == 'tag' ) // não possui validação
2392             {
2393                 
2394             }
2395             else if( $field->getFieldType() == 'helpbox' ) // não possui validação
2396             {
2397                 
2398             }
2399             else if( $field->getFieldType() == 'link' ) //não possui validação
2400             {
2401                 
2402             }
2403             else if( $field->getFieldType() == 'pagecontrol' )
2404             {
2405                 $field->validate( $strPage,$strFields, $strIgnoreFields );
2406             }
2407             else if( $field->getFieldType() == 'group' )
2408             {
2409                 $field->validate( $strPage,$strFields, $strIgnoreFields );
2410             }
2411             else
2412             {
2413                 if( $strPage === null )
2414                 {
2415                     
2416                     $aValidFields=array();
2417                     if( $strFields )
2418                     {
2419                         $aValidFields = explode(',',preg_replace('/ /','',$strFields ) );
2420                     }
2421                     $aIgnoreFields=array();
2422                     if( $strIgnoreFields )
2423                     {
2424                         $aIgnoreFields = explode(',',preg_replace('/ /','',$strIgnoreFields ) );
2425                     }
2426                     
2427                     if( !in_array($field->getId(),$aIgnoreFields) && ( ! $aValidFields || in_array($field->getId(),$aValidFields) ) && method_exists( $field, 'validate' ) && !$field->validate() )
2428                     {
2429                         $tbsName = '';
2430                         $tab = '';
2431                         // adicionar o nome da aba na mensagem de campos inválidos do formulário
2432                         //if($this->getFieldType()=='tabsheet')
2433                         //{
2434                         // a variavel $tbsName tem que conter um espaço para diferenciar do nome de um campo com erro
2435                         // e permitir setar o foco no primeiro campo que contiver um erro.
2436                         //print $this->getId().'<br>';
2437                         //$tbsName = '(Aba '.substr($this->getId(),(strpos($this->getId(),'_'))).'):';
2438                         /*
2439                          $tbsName = '(Aba '.$this->getValue().') :';
2440                          if(!array_key_exists($tbsName,$this->getErrors()))
2441                          {
2442                          self::$errors[$tbsName]=$tbsName;
2443                          }
2444                          $tab='\t';
2445                          */
2446                         //}
2447                         $label='';
2448                         if( $dc->getLabel() )
2449                         {
2450                             if( $field->getFieldType() == 'captcha' )
2451                             {
2452                                 if( $dc->getLabel()->getValue() == '' )
2453                                 {
2454                                     $label = 'C&oacute;digo de seguran&ccedil;a';
2455                                 }
2456                             }
2457                             self::$errors[ $field->getId() ] = str_replace( "::", ":", $tab . $label.$dc->getLabel()->getValue() . ':' . $field->getError() );
2458                         }
2459                         else
2460                         {
2461                             
2462                             if( $field->getFieldType() == 'hidden' )
2463                             {
2464                                 self::$errors[ $field->getId() ] = 'Campo oculto ' . $field->getId() . ':' . $field->getError();
2465                             }
2466                             else
2467                             {
2468                                 self::$errors[ $field->getId() ] = $field->getError();
2469                             }
2470                         }
2471                     }
2472                 }
2473             }
2474         }
2475         $qtd = CountHelper::count( self::$errors );
2476         return ( $qtd == 0);
2477     }
2478     //-----------------------------------------------------------------------------
2479     /**
2480      * Define o campo que receberá o foco inicial quando o formulário for exibido
2481      *
2482      * @param mixed $strFieldName
2483      */
2484     function setFocusField( $strFieldName=null )
2485     {
2486         $this->focusField = $strFieldName;
2487         // definir o campo foco unicial dos pagecontrols para quando
2488         // for montar a aba saber se o campo foco pertence a ela
2489         // e defini-la como aba inicial do pagecontrol
2490         if( is_array( $this->displayControls ) )
2491         {
2492             foreach( $this->displayControls as $idField=>$dc )
2493             {
2494                 if( $dc->getField()->getFieldType() == 'pagecontrol' )
2495                 {
2496                     $dc->getField()->setFocusField( $this->getFocusField() );
2497                 }
2498                 else if( $dc->getField()->getFieldType() == 'group' )
2499                 {
2500                     $dc->getField()->setFocusField( $this->getFocusField() );
2501                 }
2502                 else if( $dc->getField()->getFieldType() == 'coordgms' )
2503                 {
2504                     $this->focusField = $dc->getField()->getId() . '_lat_grau';
2505                 }
2506             }
2507         }
2508     }
2509     /**
2510      * Retorna o campo definido para receber o foco inicial quando o formulário for exibido
2511      *
2512      */
2513     public function getFocusField()
2514     {
2515         return $this->focusField;
2516     }
2517     /**
2518      * Define ou limpa as mensagens que serão exibidas na tela via alert() em javascript
2519      *
2520      * <code>
2521      *     $frm->setMessage(); // limpar todas as mensagns
2522      *     $frm->setMessage('Nova mensagem'); // limpa e define uma nova mensagem
2523      *     $frm->setMessage(array('Mensagem linha 1','mensagem linha 2');
2524      * </code>
2525      *
2526      * @param string $mixMessage
2527      */
2528     public function setMessage( $mixMessage=null )
2529     {
2530         if( is_array( $mixMessage ) )
2531         {
2532             $mixMessage = implode( '\n', $mixMessage );
2533             $this->setMessage( $mixMessage );
2534         }
2535         else If( is_null( $mixMessage ) )
2536         {
2537             $this->messages = null;
2538         }
2539         else
2540         {
2541             $mixMessage = preg_replace( '/"/', '', $mixMessage );
2542             $this->messages = array( $mixMessage );
2543             /* if( isset( $_REQUEST['ajax'] ) && isset( $_REQUEST['dataType'] ) && $_REQUEST['dataType'] == 'text' )
2544              {
2545              echo $mixMessage."\n";
2546              }
2547              */
2548         }
2549     }
2550     /**
2551      * Define a mensagem para ser exibida no topo da tela em uma div com efeito de auto-esconder
2552      *
2553      * intSeconds -> tempo em segundos que a mensagem ficará visível na tela. Default: 5
2554      * strType -> define a cor de fundo e boda, pode ser ERROR, SUCESS. Default: SUCESS
2555      * strImage -> icone que será exibido à esquerda da mensagem . Default:sucess.gif
2556      * <code>
2557      *     $frm->setPopupMessge('Dados gravados corretamente');
2558      * </code>
2559      * @param string $strMessage    1: Text Mensages
2560      * @param integer $intSeconds   2: tempo em segundos que a mensagem ficará visível na tela. Default: 5
2561      * @param string $strType       3: SUCESS (Default), ERROR, ATTENTION
2562      * @param string $strImage      4: path icon
2563      */
2564     public function setPopUpMessage( $strMessage=null, $intSeconds=null, $strType=null, $strImage=null )
2565     {
2566         $this->messagePopUp = array( $strMessage, $strType, $intSeconds, $strImage );
2567     }
2568     /**
2569      * Retorna a mensagem popup atual
2570      *
2571      */
2572     public function getPopUpMessage()
2573     {
2574         return $this->messagePopUp;
2575     }
2576     /**
2577      * Adiciona uma mensagem à lista, para ser exibida na tela via alert() em javascript quando o formulário for exibido
2578      *
2579      * <code>
2580      *     $frm->addMessage('Mensagem nova');
2581      *     $frm->addMessage(array('Mensagem 1', 'Mensagem 2');
2582      * </code>
2583      *
2584      * @param string $mixMessage
2585      */
2586     public function addMessage( $mixMessage=null )
2587     {
2588         if( is_array( $mixMessage ) )
2589         {
2590             $mixMessage = implode( '\n', $mixMessage );
2591         }
2592         $mixMessage = preg_replace( '/' . chr( 10 ) . '/', '\n', $mixMessage );
2593         $mixMessage = preg_replace( '/' . chr( 13 ) . '/', '', $mixMessage );
2594         $mixMessage = preg_replace( '/"/', '', $mixMessage );
2595         $this->messages[ ] = $mixMessage;
2596     }
2597     /**
2598      * Recupera a lista de mensagens que serao exibidas na tela via javascript quando o formulario for exibido
2599      *
2600      * @return array
2601      */
2602     public function getMessages()
2603     {
2604         return $this->messages;
2605     }
2606     /**
2607      * Desabilitar/Habilitar campos do formulário
2608      * Pode ser passado um campo ou varios, separados por virgula,
2609      * tambem pode ser um array de campos.
2610      * Se for passado null, todos os campos serão desabilitados.
2611      *
2612      * <code>
2613      *     $form->disableFields('nom_pessoa');
2614      *     $form->disableFields('nom_pessoa,des_endereco');
2615      *     $form->disableFields(array('nom_pessoa,des_endereco'));
2616      * </code>
2617      *
2618      * @param mixed $mixFields
2619      * @param boolean $boolNewValue
2620      */
2621     public function disableFields( $mixFields=null, $mixIgnoreFields=null, $boolNewValue=null, $boolClearOnlieSearch=null )
2622     {
2623         if( is_null( $mixFields ) )
2624         {
2625             if( $boolClearOnlieSearch === true )
2626             {
2627                 $this->clearOnlineSearch();
2628             }
2629             if( is_array( $this->displayControls ) )
2630             {
2631                 foreach( $this->displayControls as $name=>$dc )
2632                 {
2633                     $field = $dc->getField();
2634                     if( $field->getFieldType() == 'pagecontrol' )
2635                     {
2636                         $field->disableFields( null, $mixIgnoreFields, $boolNewValue );
2637                     }
2638                     else if( $field->getFieldType() == 'group' )
2639                     {
2640                         $field->disableFields( null, $mixIgnoreFields, $boolNewValue );
2641                     }
2642                     else if( $field->getFieldType() == 'tag' )
2643                     {
2644                         
2645                     }
2646                     else if( $field->getFieldType() == 'html' )
2647                     {
2648                         
2649                     }
2650                     else
2651                     {
2652                         // evitar loop infinito
2653                         $fieldName = $field->getName() ? $field->getName() : $field->getId();
2654                         if( $fieldName )
2655                         {
2656                             $this->disableFields( $fieldName, $mixIgnoreFields, $boolNewValue );
2657                         }
2658                     }
2659                 }
2660             }
2661         }
2662         else
2663         {
2664             $boolNewValue = ($boolNewValue === null) ? true : ( bool ) $boolNewValue;
2665             if( isset( $mixIgnoreFields ) && !is_array( $mixIgnoreFields ) )
2666             {
2667                 $mixIgnoreFields = explode( ',', $mixIgnoreFields );
2668             }
2669             if( is_array( $mixFields ) )
2670             {
2671                 foreach( $mixFields as $k=>$v )
2672                 {
2673                     $this->disableFields( $v, $mixIgnoreFields, $boolNewValue );
2674                 }
2675             }
2676             else
2677             {
2678                 if( strpos( $mixFields, ',' ) > 0 )
2679                 {
2680                     $mixFields = explode( ',', $mixFields );
2681                     $this->disableFields( $mixFields, $mixIgnoreFields, $boolNewValue );
2682                 }
2683                 else
2684                 {
2685                     if( $field = $this->getField( $mixFields ) )
2686                     {
2687                         if( !isset( $mixIgnoreFields ) || !in_array( $mixFields, $mixIgnoreFields ) )
2688                         {
2689                             $field->setEnabled( !$boolNewValue );
2690                         }
2691                     }
2692                 }
2693             }
2694         }
2695     }
2696     /**
2697      * Método para retornar um array com dados das UFs
2698      *
2699      * <code>
2700      *     $frm->getUfs("COD_UF,NOM_UF"); // DEFAULT retorna array com codigo e sigla
2701      *     $frm->getUfs("COD_UF,SIG_UF"); // retorna array com codigo e sigla
2702      *     $frm->getUf("SIG_UF,NOM_UF");  // retorna array com sigla e nome
2703      * </code>
2704      *
2705      * @param string $strReturnColumns
2706      * @return array
2707      */
2708     public function getUfs( $strReturnColumns=null )
2709     {
2710         $strReturnColumns = $strReturnColumns === null ? 'COD_UF,NOM_UF' : $strReturnColumns;
2711         $aCols = explode( ',', $strReturnColumns );
2712         $aUf = null;
2713         $aUf[ "COD_UF" ][ 2 ] = "12";
2714         $aUf[ "SIG_UF" ][ 2 ] = "AC";
2715         $aUf[ "NOM_UF" ][ 2 ] = "ACRE";
2716         $aUf[ "COD_UF" ][ 14 ] = "27";
2717         $aUf[ "SIG_UF" ][ 14 ] = "AL";
2718         $aUf[ "NOM_UF" ][ 14 ] = "ALAGOAS";
2719         $aUf[ "COD_UF" ][ 6 ] = "16";
2720         $aUf[ "SIG_UF" ][ 6 ] = "AP";
2721         $aUf[ "NOM_UF" ][ 6 ] = "AMAPA";
2722         $aUf[ "COD_UF" ][ 3 ] = "13";
2723         $aUf[ "SIG_UF" ][ 3 ] = "AM";
2724         $aUf[ "NOM_UF" ][ 3 ] = "AMAZONAS";
2725         $aUf[ "COD_UF" ][ 16 ] = "29";
2726         $aUf[ "SIG_UF" ][ 16 ] = "BA";
2727         $aUf[ "NOM_UF" ][ 16 ] = "BAHIA";
2728         $aUf[ "COD_UF" ][ 10 ] = "23";
2729         $aUf[ "SIG_UF" ][ 10 ] = "CE";
2730         $aUf[ "NOM_UF" ][ 10 ] = "CEARA";
2731         $aUf[ "COD_UF" ][ 27 ] = "53";
2732         $aUf[ "SIG_UF" ][ 27 ] = "DF";
2733         $aUf[ "NOM_UF" ][ 27 ] = "DISTRITO FEDERAL";
2734         $aUf[ "COD_UF" ][ 18 ] = "32";
2735         $aUf[ "SIG_UF" ][ 18 ] = "ES";
2736         $aUf[ "NOM_UF" ][ 18 ] = "ESPIRITO SANTO";
2737         $aUf[ "COD_UF" ][ 26 ] = "52";
2738         $aUf[ "SIG_UF" ][ 26 ] = "GO";
2739         $aUf[ "NOM_UF" ][ 26 ] = "GOIÁS";
2740         $aUf[ "COD_UF" ][ 8 ] = "21";
2741         $aUf[ "SIG_UF" ][ 8 ] = "MA";
2742         $aUf[ "NOM_UF" ][ 8 ] = "MARANHÃO";
2743         $aUf[ "COD_UF" ][ 25 ] = "51";
2744         $aUf[ "SIG_UF" ][ 25 ] = "MT";
2745         $aUf[ "NOM_UF" ][ 25 ] = "MATO GROSSO";
2746         $aUf[ "COD_UF" ][ 24 ] = "50";
2747         $aUf[ "SIG_UF" ][ 24 ] = "MS";
2748         $aUf[ "NOM_UF" ][ 24 ] = "MATO GROSSO DO SUL";
2749         $aUf[ "COD_UF" ][ 17 ] = "31";
2750         $aUf[ "SIG_UF" ][ 17 ] = "MG";
2751         $aUf[ "NOM_UF" ][ 17 ] = "MINAS GERAIS";
2752         $aUf[ "COD_UF" ][ 5 ] = "15";
2753         $aUf[ "SIG_UF" ][ 5 ] = "PA";
2754         $aUf[ "NOM_UF" ][ 5 ] = "PARA";
2755         $aUf[ "COD_UF" ][ 12 ] = "25";
2756         $aUf[ "SIG_UF" ][ 12 ] = "PB";
2757         $aUf[ "NOM_UF" ][ 12 ] = "PARAIBA";
2758         $aUf[ "COD_UF" ][ 21 ] = "41";
2759         $aUf[ "SIG_UF" ][ 21 ] = "PR";
2760         $aUf[ "NOM_UF" ][ 21 ] = "PARANA";
2761         $aUf[ "COD_UF" ][ 13 ] = "26";
2762         $aUf[ "SIG_UF" ][ 13 ] = "PE";
2763         $aUf[ "NOM_UF" ][ 13 ] = "PERNAMBUCO";
2764         $aUf[ "COD_UF" ][ 9 ] = "22";
2765         $aUf[ "SIG_UF" ][ 9 ] = "PI";
2766         $aUf[ "NOM_UF" ][ 9 ] = "PIAUI";
2767         $aUf[ "COD_UF" ][ 19 ] = "33";
2768         $aUf[ "SIG_UF" ][ 19 ] = "RJ";
2769         $aUf[ "NOM_UF" ][ 19 ] = "RIO DE JANEIRO";
2770         $aUf[ "COD_UF" ][ 11 ] = "24";
2771         $aUf[ "SIG_UF" ][ 11 ] = "RN";
2772         $aUf[ "NOM_UF" ][ 11 ] = "RIO GRANDE DO NORTE";
2773         $aUf[ "COD_UF" ][ 23 ] = "43";
2774         $aUf[ "SIG_UF" ][ 23 ] = "RS";
2775         $aUf[ "NOM_UF" ][ 23 ] = "RIO GRANDE DO SUL";
2776         $aUf[ "COD_UF" ][ 1 ] = "11";
2777         $aUf[ "SIG_UF" ][ 1 ] = "RO";
2778         $aUf[ "NOM_UF" ][ 1 ] = "RONDONIA";
2779         $aUf[ "COD_UF" ][ 4 ] = "14";
2780         $aUf[ "SIG_UF" ][ 4 ] = "RR";
2781         $aUf[ "NOM_UF" ][ 4 ] = "RORAIMA";
2782         $aUf[ "COD_UF" ][ 22 ] = "42";
2783         $aUf[ "SIG_UF" ][ 22 ] = "SC";
2784         $aUf[ "NOM_UF" ][ 22 ] = "SANTA CATARINA";
2785         $aUf[ "COD_UF" ][ 20 ] = "35";
2786         $aUf[ "SIG_UF" ][ 20 ] = "SP";
2787         $aUf[ "NOM_UF" ][ 20 ] = "SAO PAULO";
2788         $aUf[ "COD_UF" ][ 15 ] = "28";
2789         $aUf[ "SIG_UF" ][ 15 ] = "SE";
2790         $aUf[ "NOM_UF" ][ 15 ] = "SERGIPE";
2791         $aUf[ "COD_UF" ][ 7 ] = "17";
2792         $aUf[ "SIG_UF" ][ 7 ] = "TO";
2793         $aUf[ "NOM_UF" ][ 7 ] = "TOCANTINS";
2794         $result = null;
2795         foreach( $aUf[ $aCols[ 0 ] ] as $k=>$v )
2796         {
2797             $result[ $v ] = $aUf[ $aCols[ 1 ] ][ $k ];
2798         }
2799         return $result;
2800     }
2801     /**
2802      * Método para fazer campos selects em cascata, onde o valor do select filho depende
2803      * do valor do select pai
2804      * O parametro pacoteFuncaoOracle pode ser o nome de uma tabela ou visão
2805      * Se for utilizar a classe banco, pode ser passado o tempo do cache separado com pipe
2806      * Ex: sisteste.pkg_geral.sel_municipio|60 ( chave de 60 segundos ), para não utilizar cache
2807      * passe -1, para utilizar a sessão passe 0 ( zero )
2808      *
2809      * O parametro $strFuncaoExecutar é o nome de uma função que será chamada quando o campo pai for alterado ( onChange ).
2810      *
2811      * o Parametro $campoFormFiltro dever estar no formato: campo_formulario|campo_banco. Ex: nome_usuario|NOM_USUARIO, quando
2812      * o nome do formulário for diferente do nome do parametro do banco de dados
2813      *
2814      * O parametro $boolSelectUniqueOption ativa a seleção automática quando houver apenas uma opção disponível
2815      *
2816      * @example exemple/exCampoSelectAgrupado.php
2817      *
2818      *
2819      * @param string $selectPai             - 1: Id Campo pai no Form
2820      * @param string $selectFilho           - 2: Id Campo filho no Form
2821      * @param string $TabelaPacoteFuncao    - 3: Tabela ou View ou pacoteFuncaoOracle
2822      * @param string $colunaFiltro          - 4: Coluna filtro na tabela/view o equivalente a id Campo pai 
2823      * @param string $colunaCodigo          - 5: Coluna na tabela/view codigo do campo filho
2824      * @param string $colunaDescricao       - 6: Coluna na na tabela/view com as descrições
2825      * @param string $descPrimeiraOpcao     - 7: Descricão da primeira opção, geralmente uma msg informando que deve ser selecionado
2826      * @param string $valorPrimeiraOpcao    - 8: Valor da primeira opção geralmente um valor da lista
2827      * @param string $descNenhumaOpcao      - 9: Mensagem caso não tenho nenhuma opção correspondente.
2828      * @param string $campoFormFiltro       -10: Campos extras que serão usados como critérios de filtro
2829      * @param string $funcaoExecutar        -11: Função JavaScript que será chamado no caso de onChange
2830      * @param boolean $strConfigFileName   - 12: Nome do arquivo conexão com banco na pasta <APP>/includes/<nome_arquivo>.php para executar o autocomplete. 
2831      * @param boolean $boolSelectUniqueOption
2832      */
2833     function combinarSelects( $selectPai='cod_uf'
2834                             , $selectFilho='cod_municipio'
2835                             , $TabelaPacoteFuncao=null
2836                             , $colunaFiltro='COD_UF'
2837                             , $colunaCodigo='COD_MUNICIPIO'
2838                             , $colunaDescricao='NOM_MUNICIPIO'
2839                             , $descPrimeiraOpcao='-- Selecione --'
2840                             , $valorPrimeiraOpcao=''
2841                             , $descNenhumaOpcao='-- vazio --'
2842                             , $campoFormFiltro=''
2843                             , $funcaoExecutar=''
2844                             , $boolSelectUniqueOption=null 
2845                             , $strConfigFileName=null
2846                             )
2847     {
2848         // se o campo estiver dentro de uma aba ou de cum container, chamar o método combinar select destes
2849         $parentField = $this->getField( $selectPai );
2850         if( $parentField ) {
2851             if( $parentField->getParentControl() != $this ) {
2852                 $parentField->getParentControl()->combinarSelects( $selectPai, $selectFilho, $TabelaPacoteFuncao, $colunaFiltro, $colunaCodigo, $colunaDescricao, $descPrimeiraOpcao, $valorPrimeiraOpcao, $descNenhumaOpcao, $campoFormFiltro, $funcaoExecutar , $boolSelectUniqueOption );
2853                 return;
2854             }
2855         } else {
2856             return;
2857         }
2858         //die($selectPai);
2859         // inicializar com os valores padrão
2860         $descNenhumaOpcao = $descNenhumaOpcao == null ? '-- vazio --' : $descNenhumaOpcao;
2861         $descPrimeiraOpcao = is_null( $descPrimeiraOpcao ) ? '-- selecione --' : $descPrimeiraOpcao;
2862         $valorPrimeiraOpcao = $valorPrimeiraOpcao == null ? '' : $valorPrimeiraOpcao;
2863         $funcaoExecutar = $funcaoExecutar == null ? null : $this->removeIllegalChars( $funcaoExecutar ) . '()';
2864         $boolSelectUniqueOption = ( ( $boolSelectUniqueOption==true )  ? 1 : 0);
2865         // criticar se os campo existem
2866         $parentField = $this->getField( $selectPai );
2867         //$childField = $this->getField( $selectFilho );
2868         // todo campo filho combinado dever ter um _temp correspondente
2869         $this->addHiddenField( $selectFilho . '_temp' );
2870         $arrDados = array( );
2871         $arrDados[ 'selectPai' ] = $selectPai;
2872         $arrDados[ 'selectFilho' ] = $selectFilho;
2873         $arrDados[ 'selectFilhoStatus' ] = "habilitado";
2874         $arrDados[ 'pacoteOracle' ] = $TabelaPacoteFuncao;
2875         $arrDados[ 'colunaFiltro' ] = $colunaFiltro;
2876         $arrDados[ 'colunaCodigo' ] = $colunaCodigo;
2877         $arrDados[ 'colunaDescricao' ] = $colunaDescricao;
2878         $arrDados[ 'valorInicial' ] = "";
2879         $arrDados[ 'descPrimeiraOpcao' ] = $descPrimeiraOpcao;
2880         $arrDados[ 'valorPrimeiraOpcao' ] = $valorPrimeiraOpcao;
2881         $arrDados[ 'descNenhumaOpcao' ] = $descNenhumaOpcao;
2882         $arrDados[ 'campoFormFiltro' ] = $campoFormFiltro;
2883         $arrDados[ 'pastaBase' ] = $this->getBase();
2884         $arrDados[ 'funcaoExecutar' ] = $funcaoExecutar;
2885         $arrDados[ 'selectUniqueOption' ] = $boolSelectUniqueOption;
2886         $arrDados[ 'configFileName' ] = $strConfigFileName;
2887         $this->selectsCombinados[ $selectPai ][ $selectFilho ] = $arrDados;
2888     }
2889     
2890     /**
2891      * Adiciona botão à frente do campo para fazer pesquisa on-line no banco de dados e retornar valores
2892      * para os campos do formulario
2893      *
2894      * O parametro strAutoFillFilterField informa o nome do campo de filtro que receberá o valor digitado
2895      * pelo usuário ao chamar a consulta on-line.
2896      *
2897      * O parametro $boolAutoStart - informa que a pesquisa deve iniciada assim que a tela for
2898      * aberta sem precisar pressionar o botão pesquisar.
2899      *
2900      * O parametro $boolAutoSelect - informa que se a consulta retornar apenas um resultado este deverá ser
2901      * automaticamente selecionado e retornado para a tela
2902      *
2903      * Ex: strFilterFields (campoBanco|Rotulo|caracteres|tamanho|Obrigatório|tipo|casas decimais|parte do campo|pesquisar formatado )
2904      *                     (name|label|length|size|required|$type|decimalPlaces|partialKey|searchFormated)
2905      *     NOM_INTERRESSADO|Nome Interessado:|45||||true,NUM_ORIGINAL|Nº Original:,DES_ASSUNTO|Assunto,COD_UF|Estado:||||uf'
2906      *     o tipo pode ser: char, uf, cpf, cnpj, cpfcnpj, data, int, dec, select ou hidden
2907      *     o padrao é char de 30
2908      *
2909      * Ex: $strFormFilterFields  (campoForm|campoBanco)
2910      *     NUM_PESSOA,NUM_PESSOA=2,num_pessoa|COD_PESSOA
2911      *
2912      * O parametro @arrSql dever ser utilizado para popular os campos do tipo select.
2913      * Deve ser informado o nome do campo e a instrução sql ou o nome do pacote
2914      * Ex: array('COD_UF'=>"SELECT COD_UF,NOM_UF||'/'||SIG_UF AS SIG_UF FROM UF ORDER BY SIG_UF")
2915      *        array('COD_UF'=>"TESTE.PKG_MOEDA.SEL_UF,0,COD_UF,SIG_UF")
2916      * Juntamente com o nome do pacote, pode ser informado o tempo de cache, o campo chave, o campo descricao
2917      * separados por virgula
2918      *
2919      * O parametro $strClickCondition informa  uma condição para habilitar ou não o hiperlink nos itens do resultado da consulta
2920      * para que o usuário possa selecinar ou não aquele item
2921      *
2922      * O parametro $strOnClickJs deve ser utilizado para chamar uma função js antes de abrir a consulta dinamica.
2923      * Se esta função retornar false a tela de consulta dinãmica não será aberta
2924      *
2925      * o parametro boolDisableEnterKey - desabilita/habilita a tecla Enter para chamar a consulta dinamica do campo
2926      * deve ser utilizado em conjunto com os parametros strAutoFillFilterField,$boolAutoStart e $boolAutoSelect
2927      *
2928      * O parametro $strCrudModuleName deve ser utilizado para quando for necessãrio permitir ao usuário
2929      * fazer o cadastramento on-line do item não encontrado na pesquisa. Basta passar o nome do módulo a ser chamado.
2930      *
2931      * @param string $strFieldName        - 1: id do campo
2932      * @param string $strPackageFunction  - 2: nome da tabela/view ou pacote Orecla
2933      * @param string $strFilterFields     - 3: Ordem dos parametros separado por virgula: name|label|length|size|required|$type|decimalPlaces|partialKey|searchFormated, name|label|...
2934      * @param string $strAutoFillFilterField
2935      * @param bool $boolAutoStart         - 5: incia a pesquisa quando abre a tela
2936      * @param bool $boolAutoSelect        - 6: 
2937      * @param string $strGridColumns      - 7: colunas que irão aparecer no grid
2938      * @param string $strUpdateFormFields - 8: Campos que serão atulizados no form Original. Entrad no formato. coluna busca | campo form destino, coluna busca | campo form destino
2939      * @param string $strWindowHeader     - 9: Titulo da janela de pesquisa
2940      * @param string $strGridHeader       - 10: Titulo do Gride
2941      * @param string $strFocusFieldName   - 11: Seta o Foco no campo definido
2942      * @param bool $strWindowHeight
2943      * @param bool $strWindowWidth
2944      * @param string $strSearchButtonLabel
2945      * @param string $strFormFilterFields
2946      * @param string $strFunctionExecute
2947      * @param integer $intMaxRecord
2948      * @param string $strClickCondition
2949      * @param string $strMultiSelectKeyField
2950      * @param string $strColumnLink
2951      * @param array $arrSqls
2952      * @param string $strBeforeExecuteJs
2953      * @param bool $boolDisableEnterKey
2954      * @param string $strCrudModuleName
2955      * @param boolean $boolCaseSensitive
2956      *
2957      */
2958     public function setOnlineSearch( $strFieldName, $strPackageFunction=null, $strFilterFields=null, $strAutoFillFilterField=null, $boolAutoStart=null, $boolAutoSelect=null, $strGridColumns=null, $strUpdateFormFields=null, $strWindowHeader=null, $strGridHeader=null, $strFocusFieldName=null, $strWindowHeight=null, $strWindowWidth=null, $strSearchButtonLabel=null, $strFormFilterFields=null, $strFunctionExecute=null, $intMaxRecord=null, $strClickCondition=null, $strMultiSelectKeyField=null, $strColumnLink=null, $arrSqls=null, $strBeforeExecuteJs=null, $boolDisableEnterKey=null, $strCrudModuleName=null,$boolCaseSensitive=null )
2959     {
2960         // valores padrão;
2961         $strWindowHeight = ( is_null( $strWindowHeight )) ? 400 : $strWindowHeight;
2962         $strWindowHeight = ( ( int ) $strWindowHeight < 100 ) ? 400 : $strWindowHeight;
2963         $strWindowWidth = ( is_null( $strWindowWidth ) ) ? 600 : $strWindowWidth;
2964         $strWindowWidth = ( ( int ) $strWindowWidth < 100 ) ? 600 : $strWindowWidth;
2965         $boolAutoStart = ( is_null( $boolAutoStart ) ) ? true : $boolAutoStart;
2966         $boolCaseSensitive = ( is_null( $boolCaseSensitive ) ) ? true : $boolCaseSensitive;
2967         $boolAutoSelect = ( is_null( $boolAutoSelect ) ) ? true : $boolAutoSelect;
2968         $boolDisableEnterKey = ( is_null( $boolDisableEnterKey ) ) ? false : $boolDisableEnterKey;
2969         if( $strFunctionExecute )
2970         {
2971             $strFunctionExecute = str_replace( '"', "'", $strFunctionExecute );
2972             $strFunctionExecute = str_replace( '\\', "", $strFunctionExecute );
2973             $strFunctionExecute = addslashes( $strFunctionExecute );
2974         }
2975         if( $strBeforeExecuteJs )
2976         {
2977             $i = strpos( $strBeforeExecuteJs, '(' );
2978             if( $i > 0 )
2979             {
2980                 $strBeforeExecuteJs = substr( $strBeforeExecuteJs, 0, $i );
2981             }
2982         }
2983         $arrData = array( 'fieldName'=>$strFieldName,
2984             'packageFunction'=>$strPackageFunction,
2985             'autoFillFilterField'=>$strAutoFillFilterField,
2986             'autoStart'=>$boolAutoStart,
2987             'autoSelect'=>$boolAutoSelect,
2988             'updateFormFields'=>$strUpdateFormFields,
2989             'gridColumns'=>$strGridColumns,
2990             'focusFieldName'=>$strFocusFieldName,
2991             'filterFields'=>$strFilterFields,
2992             'windowHeight'=>$strWindowHeight,
2993             'windowWidth'=>$strWindowWidth,
2994             'windowHeader'=>$strWindowHeader,
2995             'gridHeader'=>$strGridHeader,
2996             'searchButtonLabel'=>$strSearchButtonLabel,
2997             'formFilterFields'=>$strFormFilterFields,
2998             'functionExecute'=>$strFunctionExecute,
2999             'maxRecords'=>$intMaxRecord,
3000             'clickCondition'=>$strClickCondition,
3001             'columnLink'=>$strColumnLink,
3002             'multiSelectKeyField'=>$strMultiSelectKeyField,
3003             'arrSqls'=>json_encode( $arrSqls ),
3004             'beforeExecuteJs'=>$strBeforeExecuteJs,
3005             'disableEnterKey'=>$boolDisableEnterKey,
3006             'crudModule'=>$strCrudModuleName,
3007             'caseSensitive'=>(int)$boolCaseSensitive,
3008             'prototypeParentWin'=>$this->getPrototypeId(),
3009             'dialogParentWin'=>$this->getDialogId()
3010         );
3011         $this->onlineSearchs[ $strFieldName ] = $arrData;
3012     }
3013     /**
3014      * Método para implementação de cadastro on-line durante o preenchimento do formulario.
3015      *
3016      * <code>
3017      *     $frm->setOnlineCrud('nom_pessoa','cad_pessoa','adicionar_pasta.gif',null,'Cadastrar pessoa','Cadastro de Pessoa',350,820);
3018      * </code>
3019      *
3020      * @param string $strFieldName
3021      * @param string $strModuleName
3022      * @param string $strButtonImage
3023      * @param string $strButtonLabel
3024      * @param string $strButtonHint
3025      * @param string $strWindowTitle
3026      * @param integer $intWindowHeight
3027      * @param integer $intWindowWidth
3028      */
3029     public function setOnlineCrud( $strFieldName, $strModuleName, $strButtonImage=null, $strButtonLabel=null, $strButtonHint=null, $strWindowTitle=null, $intWindowHeight=null, $intWindowWidth=null )
3030     {
3031         $arrData = array( 'fieldName'=>$strFieldName,
3032             'module'=>$strModuleName,
3033             'title'=>$strWindowTitle,
3034             'height'=>$intWindowHeight,
3035             'width'=>$intWindowWidth,
3036             'buttonLabel'=>$strButtonLabel,
3037             'buttonImage'=>$strButtonImage,
3038             'buttonHint'=>$strButtonHint
3039         );
3040         $this->onlineCruds[ $strFieldName ] = $arrData;
3041     }
3042     
3043     /**
3044      * Método para limpar os campos do formulario
3045      * Pode ser passado um campo ou varios separados por virgula.
3046      * Também pode ser um array de campos. Se for passado null,
3047      * todos os campos serão lipos
3048      *
3049      * <code>
3050      *     $form->clearFields('nom_pessoa');
3051      *     $form->clearFields('nom_pessoa,des_endereco');
3052      *     $form->clearFields(array('nom_pessoa,des_endereco'));
3053      * </code>
3054      *
3055      * @param mixed $mixFields        - 1: lista do campos que serão limpos. Apenas esses campos serão limpos
3056      * @param mixed $mixIgnoreFields  - 2: lista de campos ignorados
3057      * @param bool $boolNewValue      - 3: 
3058      */
3059     public function clearFields( $mixFields=null, $mixIgnoreFields=null, $boolNewValue=null )
3060     {
3061         if( is_null( $mixFields ) )
3062         {
3063             if( is_array( $this->displayControls ) )
3064             {
3065                 foreach( $this->displayControls as $name=>$dc )
3066                 {
3067                     $field = $dc->getField();
3068                     if( $field->getFieldType() == 'pagecontrol' )
3069                     {
3070                         $field->clearFields( $mixFields, $mixIgnoreFields, $boolNewValue );
3071                     }
3072                     else if( $field->getFieldType() == 'group' )
3073                     {
3074                         $field->clearFields( null, $mixIgnoreFields, $boolNewValue );
3075                     }
3076                     else
3077                     {
3078                         $this->clearFields( $field->getId(), $mixIgnoreFields, $boolNewValue );
3079                     }
3080                 }
3081             }
3082         }
3083         else
3084         {
3085             $boolNewValue = ($boolNewValue === null) ? true : ( bool ) $boolNewValue;
3086             if( isset( $mixIgnoreFields ) && !is_array( $mixIgnoreFields ) )
3087             {
3088                 $mixIgnoreFields = explode( ',', $mixIgnoreFields );
3089             }
3090             
3091             if( is_array( $mixFields ) )
3092             {
3093                 foreach( $mixFields as $k=>$v )
3094                 {
3095                     $this->clearFields( $v, $mixIgnoreFields, $boolNewValue );
3096                 }
3097             }
3098             else
3099             {
3100                 if( strpos( $mixFields, ',' ) > 0 )
3101                 {
3102                     $mixFields = explode( ',', $mixFields );
3103                     $this->clearFields( $mixFields, $mixIgnoreFields, $boolNewValue );
3104                 }
3105                 else
3106                 {
3107                     if( $field = $this->getField( $mixFields ) )
3108                     {
3109                         if( !isset( $mixIgnoreFields ) || array_search( $mixFields, $mixIgnoreFields ) === false )
3110                         {
3111                             if( ! $field->getProperty('noClear') )
3112                             {
3113                                 if( $field->getFieldType() == 'html' )
3114                                 {
3115                                     if( $gridFile = $field->getGridFile() )
3116                                     {
3117                                         unset( $_SESSION[ APLICATIVO ][ 'offline' ][ $gridFile[ 'id' ] ] );
3118                                     }
3119                                 }
3120                                 else if( $field->getFieldType() != 'tag' && $field->getFieldType() != 'button' && $field->getFieldType() != 'html' && $field->getId() != 'fw_back_to' && !$field->getProperty('noClear') )
3121                                 {
3122                                     $field->clear();
3123                                 }
3124                             }
3125                         }
3126                     }
3127                 }
3128             }
3129         }
3130     }
3131     //-----------------------------------------------------------------------------
3132     /**
3133      * Método para definir o valor de um campo
3134      * O parametro strTag pode ser utilizado para passar um valor a mais para a função
3135      * setValue do campo. No caso do campo coordGMS é utilizado para passar LAT ou LON
3136      * <code>
3137      *     $form->setFieldValue('coord2',-28.4541666667,'LAT');
3138      * </code>
3139      *
3140      * @param string $strFieldName
3141      * @param mixed $mixValue
3142      * @param string @strTag
3143      */
3144     public function setFieldValue( $strFieldName=null, $mixValue=null, $strTag=null )
3145     {
3146         $strFieldName = $this->removeIllegalChars( $strFieldName );
3147         $field = $this->getField( $strFieldName );
3148         if( is_object( $field ) )
3149         {
3150             if( $field->getFieldType() == 'coordgms' )
3151             {
3152                 $field->setValue( $strFieldName, $mixValue, $strTag );
3153             }
3154             else
3155             {
3156                 $this->getField( $strFieldName )->setValue( $mixValue );
3157             }
3158         }
3159     }
3160     //-----------------------------------------------------------------------------
3161     /**
3162      * Retorna o valor de um campo
3163      *
3164      * @param string $strField
3165      */
3166     public function getFieldValue( $strField=null )
3167     {
3168         return $this->getValue( $strField );
3169     }
3170     /**
3171      * Define o valor de um campo do formulário ( equivalente a setFieldValue() )
3172      *
3173      * @param string $strFieldName
3174      * @param mixed $mixValue
3175      * @param string $strTag
3176      */
3177     public function setValue( $strFieldName=null, $mixValue=null, $strTag=null )
3178     {
3179         // excecao para abas
3180         if( $this->getFieldType() == 'tabsheet' || is_null( $strFieldName ) )
3181         {
3182             parent::setValue( $mixValue );
3183         }
3184         else
3185         {
3186             $this->setFieldValue( $strFieldName, $mixValue, $strTag );
3187         }
3188     }
3189     //-----------------------------------------------------------------------------
3190     /**
3191      * Retorna o valor de um campo do formulário ( equivalente ao getFieldValue())
3192      *
3193      * @param string $strField
3194      */
3195     public function getValue( $strField=null )
3196     {
3197         // excecao para abas
3198         if( $this->getFieldType() == 'tabsheet' || is_null( $strField ) ) {
3199             return parent::getValue();
3200         } else {
3201             if( $this->getField( $strField ) ) {
3202                 return $this->getField( $strField )->getValue();
3203             }
3204         }
3205         return null;
3206     }
3207     /**
3208      * Este método deve ser utilizado para criar o array com os nomes e valores dos campos que
3209      * será utilizado como parametro "$bvars" no metodo executarPacote ou recuperarPacote
3210      *
3211      * <code>
3212      *     $bvars = $frm->createBvars('num_pessoa,nom_pessoa,uf|COD_UF');
3213      * </code>
3214      *
3215      * Quando o nome do campo do formulário não for igual ao nome do campo da tabela do banco
3216      * de dados, deve ser informado o nome do campo do formulário e o nome do campo da tabela
3217      *
3218      * O parametro boolPDO retorna o array simples para ser passado como parametro das queries da
3219      * classe pdo.
3220      *
3221      * @param string $strFields
3222      * @param string $$boolPDO
3223      * @return array
3224      */
3225     public function createBvars( $strFields=null, $boolPDO=null, $strDecimalSeparator=null )
3226     {
3227         $strDecimalSeparator = ( is_null( $strDecimalSeparator ) ? '.' : $strDecimalSeparator );
3228         if( $strDecimalSeparator != '.' && $strDecimalSeparator!=',')
3229         {
3230             $strDecimalSeparator = '.';
3231         }
3232         $bvars = (!isset( $bvars )) ? array( ) : $bvars;
3233         if( !isSet( $strFields ) )
3234         {
3235             foreach( $this->displayControls as $name=>$dc )
3236             {
3237                 $bvars = array_merge( ( array ) $bvars, $this->createBvars( $name ) );
3238             }
3239         }
3240         if( isset( $strFields ) )
3241         {
3242             // tratar campos separados por virgula
3243             if( isset( $strFields ) && strpos( $strFields, ',' ) !== false )
3244             {
3245                 $strFields = explode( ',', $strFields );
3246                 foreach( $strFields as $k=>$v )
3247                 {
3248                     $bvars = array_merge( ( array ) $bvars, $this->createBvars( trim( $v ) ) );
3249                 }
3250             }
3251             else
3252             {
3253                 $aField = explode( '|', $strFields );
3254                 $aField[ 1 ] = !isset( $aField[ 1 ] ) ? strtoupper( $aField[ 0 ] ) : $aField[ 1 ];
3255                 if( $field = $this->getField( $aField[ 0 ] ) )
3256                 {
3257                     if( $field->getFieldType() != 'pagecontrol' && $field->getFieldType() != 'group' )
3258                     {
3259                         if( $field->getFieldType() == 'fileasync' )
3260                         {
3261                             $bvars[ strtoupper( $aField[ 1 ] ) ] = $field->getContent();
3262                         }
3263                         else
3264                         {
3265                             $value = $field->getValue();
3266                             if( is_array( $value ) )
3267                             {
3268                                 // campo multiselect, check, coordGMS retorna um array de valores
3269                                 foreach( $value as $k=>$v )
3270                                 {
3271                                     if( $field->getFieldType() == 'multiselect' || $field->getFieldType() == 'check' )
3272                                     {
3273                                         $bvars[ strtoupper( $field->getId() ) ][ ] = $v;
3274                                     }
3275                                     else if( $field->getFieldType() == 'select' )
3276                                     {
3277                                         $bvars[ strtoupper( $field->getId() ) ] = $v;
3278                                     }
3279                                     else if( $field->getFieldType() == 'radio' )
3280                                     {
3281                                         $bvars[ strtoupper( $field->getId() ) ] = $v;
3282                                     }
3283                                     else if( $field->getFieldType() == 'coordgms' )
3284                                     {
3285                                         $bvars[ strtoupper( $k ) ] = $v;
3286                                     }
3287                                 }
3288                             }
3289                             else
3290                             {
3291                                 $value = $field->getValue();
3292                                 if( $field->getFieldType() == 'html' )
3293                                 {
3294                                     if( $gridFile = $field->getGridFile() )
3295                                     {
3296                                         $value = $_SESSION[ APLICATIVO ][ 'offline' ][ $gridFile[ 'id' ] ];
3297                                         unset( $value[ 'FW_BACK_TO' ] );
3298                                     }
3299                                 } else if( $field->getFieldType() == 'number' ) {
3300                                     if( $strDecimalSeparator == '.') {
3301                                         if( FormDinHelper::pregMatch('/,/',$value) == 1 ){
3302                                             $value = str_replace( ',', '.', str_replace( '.', '', $value ) );
3303                                         }
3304                                     } else {
3305                                         $value = str_replace( '.', ',', str_replace( ',', '', $value ) );
3306                                     }
3307                                 }
3308                                 $bvars[ strtoupper( $aField[ 1 ] ) ] = $value;
3309                             }
3310                         }
3311                     }
3312                     else
3313                     {
3314                         if( $field->getFieldType() == 'group' )
3315                         {
3316                             $bvars = array_merge( ( array ) $bvars, $field->createBvars() );
3317                         }
3318                     }
3319                 }
3320             }
3321         }
3322         if( $boolPDO )
3323         {
3324             $arr = null;
3325             forEach( $bvars as $k=>$v )
3326             {
3327                 $arr[] = $v;
3328             }
3329             $bvars = $arr;
3330         }
3331         return $bvars;
3332     }
3333     /**
3334      * Define um array no formato "key=>value" ou string no formato "S=SIM,N=NAO,..." ou
3335      * o nome de um pacoteFunção para recuperar do banco de dados para alimentar as opções dos
3336      * campos selects.
3337      * Quando for utilizado o pacote/função, pode ser especificada a coluna chave, a coluna descrição e
3338      * searchFields como parametros para a função do pacote que será executada.
3339      *
3340      * <code>
3341      *     $mixSearchFields="cod_uf=53,num_pessoa=20" ou array('COD_UF'=53,'NUM_PESSOA'=>20)
3342      * </code>
3343      *
3344      * @param string $strFieldName
3345      * @param mixed $mixOptions
3346      * @param string $strDisplayField
3347      * @param string $strKeyField
3348      * @param mixed $mixSearchFields
3349      */
3350     public function setOptionsSelect( $strFieldName, $mixOptions=null, $strDisplayField=null, $strKeyField=null, $mixSearchFields=null )
3351     {
3352         if( $field = $this->getField( $strFieldName ) )
3353         {
3354             if( method_exists( $field, 'setOptions' ) )
3355             {
3356                 $field->setOptions( $mixOptions, $strDisplayField, $strKeyField, $mixSearchFields );
3357             }
3358         }
3359     }
3360     /**
3361      * Define se os campos do formulario ou a aba ou o grupo serão todos obrigatórios.
3362      *
3363      * @param boolean $boolValue
3364      */
3365     public function setRequired( $boolValue=null )
3366     {
3367         $this->setAttribute('needed', ( ( bool ) $boolValue ? 'true' : 'false' ) );
3368     }
3369     /**
3370      * Retorna se o form ou grupo ou aba estão definido como obrigatórios.
3371      * Se estiverem obrigatório, todos os seus campos serão defindos como obrigatórios.
3372      *
3373      */
3374     public function getRequired()
3375     {
3376         return $this->getAttribute('needed') == "true";
3377     }
3378     /**
3379      * Este método fecha um campo grupo ou um campo aba para que os campos
3380      * seguintes fique abaixo dos mesmos e não dentro deles.
3381      *
3382      */
3383     public function closeGroup()
3384     {
3385         //$this->currentContainer = array_pop($this->currentContainer);
3386         
3387         if( is_array($this->currentContainer) && count($this->currentContainer)>0)
3388         {
3389             array_pop( $this->currentContainer );
3390         }
3391     }
3392     /**
3393      * Define se o botão fechar do formulário estará visível ou não.
3394      *
3395      * @param boolean $boolNewValue
3396      */
3397     public function setShowCloseButton( $boolNewValue=null )
3398     {
3399         $boolNewValue = $boolNewValue === null ? true : $boolNewValue;
3400         $this->showCloseButton = $boolNewValue;
3401     }
3402     /**
3403      * Desativa a exibição do botão fechar  no canto superior direito do formulario. ( equivalente a setShowCloseButton(false); )
3404      *
3405      */
3406     public function hideCloseButton()
3407     {
3408         $this->showCloseButton = false;
3409     }
3410     /**
3411      * Ativa o modo de exibição do botão fechar no canto superior direito do formulário. ( equivalente a setShowCloseButton(true); )
3412      *
3413      */
3414     public function showCloseButton()
3415     {
3416         $this->showCloseButton = true;
3417     }
3418     /**
3419      * Retorna se a exibição do botão fechar no canto superior direito do formulário está ativada ou não.
3420      *
3421      */
3422     public function getShowCloseButton()
3423     {
3424         if( isset( $_REQUEST[ 'showCloseButton' ] ) && !$_REQUEST[ 'showCloseButton' ] )
3425         {
3426             return false;
3427         }
3428         return $this->showCloseButton;
3429     }
3430     /**
3431      * Atualiza os valores dos campos do formulário com os valores do array recebido.
3432      *
3433      *
3434      * <code>
3435      *     // atualizar todos os campos
3436      *     $frm->update($res);
3437      *     // atualizar o campo nome e cpf
3438      *     $frm->update($res,'nome,cpf');
3439      *     // atualizar todos os campos menos o cpf e e matricula
3440      *     $frm->upadte($res,null,'cpf,matricula');
3441      *
3442      * </code>
3443      *
3444      * @param mixed $arrValues
3445      * @param mixed $strFields
3446      * @param mixed $strIgnoreFields
3447      */
3448     public function update( $arrValues=null, $strFields=null, $strIgnoreFields=null )
3449     {
3450         if( !$arrValues )
3451         {
3452             return;
3453         }
3454         $arrFields = explode( ',', $strFields );
3455         $arrIgnoreFields = explode( ',', $strIgnoreFields );
3456         $key = key( $arrValues );
3457         if( is_array( $arrValues[ $key ] ) ) // FORMATO DO ARRAY: [CAMPO][N]
3458         {
3459             foreach( $arrValues as $k=>$v )
3460             {
3461                 $field = $this->getField( strtolower( $k ) );
3462                 $field = !is_object( $field ) ? $this->getField( $k ) : $field;
3463                 if( $field )
3464                 {
3465                     if( method_exists( $field, 'setValue' ) )
3466                     {
3467                         if( ( is_null( $strFields ) || in_array( $field->getId(), $arrFields )) && ( is_null( $strIgnoreFields ) || !in_array( $field->getId(), $arrIgnoreFields ) ) )
3468                         {
3469                             //$field->setValue($arrValues[$k][0]);
3470                             if( $field->getFieldType() == 'check' || $field->getFieldType() == 'multiselect' )
3471                             {
3472                                 $field->setValue( $v );
3473                             }
3474                             if( $field->getFieldType() == 'coordgms' )
3475                             {
3476                                 if( isset( $arrValues[ strtoupper( $field->getFieldNameLat() ) ][ 0 ] ) )
3477                                 {
3478                                     $field->setLat( $arrValues[ strtoupper( $field->getFieldNameLat() ) ][ 0 ] );
3479                                 }
3480                                 else if( isset( $arrValues[ strtolower( $field->getFieldNameLat() ) ][ 0 ] ) )
3481                                 {
3482                                     $field->setLat( $arrValues[ strtolower( $field->getFieldNameLat() ) ][ 0 ] );
3483                                 }
3484                                 if( isset( $arrValues[ strtoupper( $field->getFieldNameLon()) ][ 0 ] ) )
3485                                 {
3486                                     $field->setLon( $arrValues[ strtoupper( $field->getFieldNameLon() ) ][ 0 ] );
3487                                 }
3488                                 else if( isset( $arrValues[ strtolower( $field->getFieldNameLon() ) ][ 0 ] ) )
3489                                 {
3490                                     $field->setLon( $arrValues[ strtolower( $field->getFieldNameLon() ) ][ 0 ] );
3491                                 }
3492                             }
3493                             else
3494                             {
3495                                 $field->setValue( $v[ 0 ] );
3496                                 $field = $this->getField( strtoupper($k) );
3497                                 if( is_object( $field ) && method_exists( $field, 'setValue' ) )
3498                                 {
3499                                     $field->setValue( $v[ 0 ] );
3500                                 }
3501                             }
3502                         }
3503                     }
3504                 }
3505             }
3506         }
3507         else // FORMATO DO ARRAY: KEY=>VALUE
3508         {
3509             foreach( $arrValues as $k=>$v )
3510             {
3511                 $field = $this->getField( strtolower($k) );
3512                 //$field = !is_object( $field ) ? $this->getField( strtoupper( $k ) ) : $field;
3513                 if( is_object( $field ) )
3514                 {
3515                     if( method_exists( $field, 'setValue' ) )
3516                     {
3517                         if( ( is_null( $strFields ) || in_array( $field->getId(), $arrFields )) && ( is_null( $strIgnoreFields ) || !in_array( $field->getId(), $arrIgnoreFields ) ) )
3518                         {
3519                             $field->setValue( $k, $v );
3520                         }
3521                     }
3522                 }
3523                 $field = $this->getField( strtoupper( $k ) );
3524                 if( is_object( $field ) )
3525                 {
3526                     if( method_exists( $field, 'setValue' ) )
3527                     {
3528                         if( ( is_null( $strFields ) || in_array( $field->getId(), $arrFields )) && ( is_null( $strIgnoreFields ) || !in_array( $field->getId(), $arrIgnoreFields ) ) )
3529                         {
3530                             $field->setValue( $k, $v );
3531                         }
3532                     }
3533                 }
3534             }
3535         }
3536     }
3537     /**
3538      * Elimina o array de botões que serão exibidos no rodapé do formulário.
3539      *
3540      */
3541     public function clearButtons()
3542     {
3543         $this->footerButtons = null;
3544     }
3545     /**
3546      * Elimina todos os campos do formulário ou apenas os campos informados no parametro mixFields, ignorando
3547      * os campos informados no parametro mixIgnoreFields.
3548      *
3549      * <code>
3550      *     $frm->removeField('campo1,campo2,campo3');
3551      *     $frm->removeField(null,'campo_x');
3552      * </code>
3553      *
3554      * @param array $mixFields
3555      * @param array $mixIgnoreFields
3556      */
3557     public function removeField( $mixFields=null, $mixIgnoreFields=null )
3558     {
3559         // excluir todos os campos menos as abas e os grupos
3560         if( is_null( $mixFields ) )
3561         {
3562             foreach( $this->displayControls as $name=>$dc )
3563             {
3564                 if( $dc->getField()->getFieldType() == 'pagecontrol' )
3565                 {
3566                     $dc->getField()->removeField( null, $mixIgnoreFields );
3567                 }
3568                 else if( $dc->getField()->getFieldType() == 'group' )
3569                 {
3570                     $dc->getField()->removeField( null, $mixIgnoreFields );
3571                 }
3572                 else
3573                 {
3574                     $this->removeField( $dc->getField()->getId(), $mixIgnoreFields );
3575                 }
3576             }
3577             return;
3578         }
3579         // excluir campo
3580         if( isset( $mixIgnoreFields ) && !is_array( $mixIgnoreFields ) )
3581         {
3582             $mixIgnoreFields = explode( ',', $mixIgnoreFields );
3583         }
3584         if( is_array( $mixFields ) )
3585         {
3586             foreach( $mixFields as $k=>$v )
3587             {
3588                 $this->removeField( $v, $mixIgnoreFields );
3589             }
3590         }
3591         else
3592         {
3593             if( strpos( $mixFields, ',' ) > 0 )
3594             {
3595                 $mixFields = explode( ',', $mixFields );
3596                 $this->removeField( $mixFields, $mixIgnoreFields );
3597             }
3598             else
3599             {
3600                 if( $field = $this->getField( $mixFields ) )
3601                 {
3602                     // se o campo estiver dentro de uma aba ou grupo, chamar o metodo delete destes
3603                     if( $field->getParentControl() != $this )
3604                     {
3605                         $field->getParentControl()->removeField( $mixFields );
3606                     }
3607                     else
3608                     {
3609                         if( !isset( $mixIgnoreFields ) || array_search( $mixFields, $mixIgnoreFields ) === false )
3610                         {
3611                             $keys = array_keys( $this->displayControls );
3612                             $pos = array_search( $mixFields, $keys );
3613                             if( $pos !== false )
3614                             {
3615                                 array_splice( $this->displayControls, $pos, 1 );
3616                             }
3617                         }
3618                     }
3619                 }
3620             }
3621         }
3622     }
3623     /**
3624      * Exclui um campo ou os campos informados do formulário, ignorando os que estiverem no parametro $mixIgnoreFields
3625      *
3626      * <code>
3627      *     $frm->deleteFields('campo1,campo2,campo3');
3628      *     $frm->deleteFields(null,'campo_x');
3629      * </code>
3630      *
3631      * @param mixed $mixFields
3632      * @param mixed $mixIgnoreFields
3633      */
3634     public function deleteField( $mixFields=null, $mixIgnoreFields=null )
3635     {
3636         $this->removeField( $mixFields = null, $mixIgnoreFields = null );
3637     }
3638     /**
3639      * Define se o formuário deverá ou não exibir o título.
3640      *
3641      * @param boolean $boolShow
3642      */
3643     public function setShowHeader( $boolShow=null )
3644     {
3645         if( is_null( $boolShow ) )
3646         {
3647             return $this->showHeader;
3648         }
3649         return $this->showHeader = ( bool ) $boolShow;
3650     }
3651     /**
3652      * Retorna se o formulário deve ou não exibir o título.
3653      *
3654      */
3655     public function getShowHeader()
3656     {
3657         return $this->showHeader;
3658     }
3659     /**
3660      * Define se o formulário deverá incluir os arquivos base/js/... necessários automaticamente em
3661      * função dos campos que foram adicionados.
3662      *
3663      * @param boolean $boolAutoInclude
3664      */
3665     public function setAutoIncludeJsCss( $boolAutoInclude=null )
3666     {
3667         $this->autoIncludeJsCss = ( bool ) $boolAutoInclude;
3668     }
3669     public function getAutoIncludeJsCss()
3670     {
3671         return $this->autoIncludeJsCss;
3672     }
3673     /**
3674      * Define o valor que setá exibido no titulo do formulário.
3675      *
3676      * @param string $strNewText
3677      */
3678     public function setTitle( $strNewText=null )
3679     {
3680         $this->title = $strNewText;
3681         return $this;
3682     }
3683     /**
3684      * Retorna o valor do titulo do formulário
3685      *
3686      */
3687     public function getTitle()
3688     {
3689         return $this->title;
3690     }
3691     /**
3692      * Define o formato das bordas do formulário.
3693      * True = borda simples
3694      * False = borda 3d
3695      *
3696      * @param boolean $boolNewValue
3697      */
3698     public function setFlat( $boolNewValue=null )
3699     {
3700         $this->flat = ( bool ) $boolNewValue;
3701         return $this;
3702     }
3703     /**
3704      * Retona se o formulário dever ser exibido com ou sem as bordas 3d
3705      *
3706      */
3707     public function getFlat()
3708     {
3709         return $this->flat;
3710     }
3711     /**
3712      * Define se a classe deverá adicionar código javascript para compatibilidade
3713      * com a biblioteca prototype window.
3714      *
3715      * @param boolean $boolNewValue
3716      */
3717     public function setPrototypeId( $strNewValue=null )
3718     {
3719         $this->prototypeId = $strNewValue;
3720     }
3721     /**
3722      * Retorna se o formulário deverá ser ou não compativel com a biblioteca prototype window
3723      *
3724      */
3725     public function getPrototypeId()
3726     {
3727         return $this->prototypeId;
3728     }
3729     /**
3730      * Retorna se o formulário deverá ser ou não compativel com a biblioteca prototype window
3731      *
3732      */
3733     public function getDialogId()
3734     {
3735         if( isset( $_REQUEST['dialogId'] ) &&  $_REQUEST['dialogId'] )
3736         {
3737             return  $_REQUEST['dialogId'];
3738         }
3739         return null;
3740     }
3741     /**
3742      * Retorna array como os arquivos js e css necessários para funcionamento
3743      * dos campos adicionados ao formulário.
3744      */
3745     public function getJsCss()
3746     {
3747         if( !$this->getFlat() )
3748         {
3749             $this->addCssFile( 'box/box.css' );
3750         }
3751         if( is_array( $this->autocompleteFields ) )
3752         {
3753             $this->addJsFile( 'jquery/jquery.autocomplete.dylan.js' );
3754             $this->addCssFile( 'jquery/jquery.autocomplete.dylan.css' );
3755         }
3756         if( $this->getOnlineDoc() )
3757         {
3758             $this->addJsFile('FormDin4OnlineDoc.js');
3759             $this->enableRichEdit(); // adiconar javascript para tinymce
3760             $this->addJavascript( "fwInitOnlieDocEditor(".(( $this->onlineDocReadOnly ) ? 'true' : 'false').")");
3761         }
3762         if( $this->getRichEdit() )
3763         {
3764             $this->addJsFile( 'jquery/tinymce/jscripts/tiny_mce/tiny_mce.js' );
3765             $this->addJsFile( 'FormDin4_tinymce.js' );
3766         }
3767         if( is_array( $this->displayControls ) )
3768         {
3769             
3770             foreach( $this->displayControls as $name=>$dc )
3771             {
3772                 if( $dc->getField()->getFieldType() == 'pagecontrol' )
3773                 {
3774                     $this->addCssFile( 'pagecontrol/pagecontrol.css' );
3775                     $arrTemp = $dc->getField()->getJsCss();
3776                     $this->addJsFile( $arrTemp[ 0 ] );
3777                     $this->addCssFile( $arrTemp[ 1 ] );
3778                 }
3779                 else if( $dc->getField()->getFieldType() == 'group' )
3780                 {
3781                     $arrTemp = $dc->getField()->getJsCss();
3782                     $this->addJsFile( $arrTemp[ 0 ] );
3783                     $this->addCssFile( $arrTemp[ 1 ] );
3784                 }
3785                 else if( $dc->getField()->getFieldType() == 'color' )
3786                 {
3787                     $this->addJsFile( 'colorPicker.js' );
3788                 }
3789                 else if( $dc->getField()->getFieldType() == 'date' )
3790                 {
3791                     /*
3792                      if( array_search( 'calendario/calendar.js', $this->jsFiles, true ) === false )
3793                      {
3794                      $this->addJsFile( 'calendario/calendar.js' );
3795                      $this->addJsFile( 'calendario/calendar-br.js' );
3796                      $this->addJsFile( 'calendario/calendar-setup.js' );
3797                      $this->addCssFile( 'calendario/calendar-win2k-cold-1.css' );
3798                      }
3799                      */
3800                 }
3801                 else if( $dc->getField()->getFieldType() == 'password' )
3802                 {
3803                     $this->addJsFile('virtualKeyboard/keyboard.js');
3804                     $this->addCssFile('virtualKeyboard/keyboard.css');
3805                 } else if( $dc->getField()->getFieldType() == 'fullcalendar' ) {
3806                     $this->addCssFile('fullcalendar/cupertino/theme.css');
3807                     $this->addCssFile('fullcalendar/fullcalendar.css');
3808                     $this->addJsFile('fullcalendar/fullcalendar.min.js');
3809                 } else if( $dc->getField()->getFieldType() == 'helpbox' ) {                     
3810                     if( is_array($this->jsFiles) && (array_search( 'jquery/facebox/facebox.js', $this->jsFiles, true ) === false) ) {
3811                         $this->addJsFile( 'jquery/facebox/facebox.js' );
3812                         $this->addCssFile( 'jquery/facebox/facebox.css' );
3813                     }
3814                 } else if( $dc->getField()->getFieldType() == 'pagecontrol' ) {
3815                     // css abas
3816                     $this->addCssFile( 'pagecontrol/pagecontrol.css' );
3817                 } else if( $dc->getField()->getFieldType() == 'opendir' ) {
3818                     $this->addJsFile("jquery/jqueryFileTree/jquery.easing.js");
3819                     $this->addJsFile("jquery/jqueryFileTree/jqueryFileTree.js");
3820                     $this->addCssFile("jquery/jqueryFileTree/jqueryFileTree.css");
3821                 } else if( $dc->getField()->getFieldType() == 'coordgms' ) {
3822                     $this->addJsFile("FormDin4Geo.js");
3823                 } else if( $dc->getField()->getFieldType() == 'cep' ) {
3824                     $this->addJsFile("FormDin4Cep.js");
3825                 }
3826             }
3827         }
3828         return array( $this->jsFiles, $this->cssFiles );
3829     }
3830     //-----------------------------------------------------------------------------
3831     /**
3832      * Adiciona um ou vários arquivos js ao formulário
3833      *
3834      * @param mixed $mixJsFile
3835      */
3836     public function addJsFile( $mixJsFile=null,$addOnTop=null )
3837     {
3838         if( is_null( $mixJsFile) || ( is_string( $mixJsFile ) && trim( $mixJsFile ) == '' ) )
3839         {
3840             return;
3841         }
3842         if( is_array( $mixJsFile ) )
3843         {
3844             foreach( $mixJsFile as $k=>$file )
3845             {
3846                 if( $file )
3847                 {
3848                     $this->addJsFile( $file,$addOnTop );
3849                 }
3850             }
3851         }
3852         else if( !is_array( $this->jsFiles ) || array_search( $mixJsFile, $this->jsFiles, true ) === false )
3853         {
3854             if( trim( $mixJsFile ) != '' )
3855             {
3856                 if( $addOnTop )
3857                 {
3858                     array_unshift($this->jsFiles,$mixJsFile);
3859                 }
3860                 else
3861                 {
3862                     $this->jsFiles[ ] = $mixJsFile;
3863                 }
3864             }
3865         }
3866     }
3867
3868    //-----------------------------------------------------------------------------
3869    /**
3870    * Adiciona um ou vários arquivos CSS ao formulário.
3871    *
3872    * @param mixed $mixCssFile
3873    */
3874    public function addCssFile( $mixCssFile=null )
3875    {         
3876        if( is_null( $mixCssFile) || ( is_string($mixCssFile) && trim( $mixCssFile) == '' ) ) {
3877            return;
3878        }
3879        if( is_array( $mixCssFile ) ) {             
3880            foreach( $mixCssFile as $k=>$file ) {
3881                if( $file ) {
3882                    $this->addCssFile( $file );
3883                }
3884            }
3885        } else if( !is_array( $this->cssFiles ) || array_search( $mixCssFile, $this->cssFiles, true ) === false ) {             
3886            if( trim($mixCssFile)!='') {
3887                $this->cssFiles[ ] = $mixCssFile;
3888            }
3889        }
3890    }
3891    
3892    /**
3893     * Define se o html gerado deverá ser somente da tag form ou o codigo html da pagina completo.
3894    *
3895    * @param boolean $boolShow
3896    */
3897    public function setShowHtmlTag( $boolShow=null )
3898    {
3899        $this->showHtmlTag = $boolShow;
3900    }
3901    
3902    public function getShowHtmlTag()
3903    {
3904        return $this->showHtmlTag;
3905    }
3906    
3907    /**
3908     * inclue o arquivo CSS default para todos os form que foi definido em 
3909     * TApplication->setCssDefaultFormFile
3910     */
3911    protected function getCssFileFormDefault()
3912    {
3913        if(defined('CSS_FILE_FORM_DEFAULT')) { 
3914            $this->addCssFile(CSS_FILE_FORM_DEFAULT);
3915        }
3916    }
3917    
3918    /**
3919     * Verifica se o arquivo existe e devolve o caminho. Se não existir
3920     * retona null
3921     * @param array $aFile
3922     * @return NULL|string
3923     */
3924    protected function getPathJsCssFiles($file)
3925    {       
3926        $fileType = false;
3927        $result = array();
3928        $result['type'] = null;
3929        $result['path'] = null;        
3930        
3931        if( strpos( $file, 'http:' ) !== false ) {
3932            $fileType = false;
3933        } else {
3934            $fileType = true;
3935            
3936            $fileName = $file;
3937            if( strpos( $file, '.css' ) ) {
3938                $tipo = 'css';
3939            } else if( strpos( $file, '.js' ) ) {
3940                $tipo = 'js';
3941            }
3942            
3943            // primeiro procurar na pasta js/ do projeto
3944            if( !file_exists( $fileName ) ) {
3945                $fileName = $this->getRoot() . $tipo . '/' . $file;
3946            }
3947            
3948            // depois procurar na pasta base/js
3949            if( !file_exists( $fileName ) ) {
3950                $fileName = $this->getBase() . $tipo . '/' . $file;
3951            }
3952            
3953            if( !file_exists( $fileName ) ) {
3954                // o css pode estar junto com o js
3955                if( $tipo == 'css' ) {
3956                    // procurar na pasta base/js
3957                    $fileName = $this->getBase() . 'js/' . $file;
3958                }
3959            }            
3960            $file = $fileName;
3961        }
3962        
3963        if ( $fileType == false ){
3964            $result['type'] = $tipo;
3965            $result['path'] = $file;
3966        } else {
3967            if ( $fileType == true && file_exists($file) ){
3968                $result['type'] = $tipo;
3969                $result['path'] = $file;
3970            } else {
3971                $message = __CLASS__.' failed to load file:'.$file;
3972                MessageHelper::logRecordSimple($message);
3973            }
3974        }
3975        return $result;
3976    }
3977
3978     /**
3979      * Método interno para gerar o codigo html de inserção dos arquivos js/css adicionados ao formulário
3980      *
3981      */
3982     protected function includeJsCss()
3983     {
3984         // verificar quais css e js serão necessários de acordo com os campos adicionados
3985         $this->getJsCss();
3986         $this->getCssFileFormDefault();
3987         $arrTemp = array_merge( $this->jsFiles, $this->cssFiles );
3988         if( is_array( $arrTemp ) ) {
3989             foreach( $arrTemp as $file ) {
3990                 $fileinfo = $this->getPathJsCssFiles($file);
3991                 if( $fileinfo['type'] == 'js' ) {
3992                     $this->add( '<script type="text/javascript" src="' . $fileinfo['path'] . '"></script>' );
3993                 } else if( $fileinfo['type'] == 'css' ) {
3994                     $this->add( '<link rel="stylesheet" type="text/css" href="' . $fileinfo['path'] . '" />' );
3995                 }
3996             }
3997             // evitar que a classe JQuery entre em confilto com outras classes
3998             $this->add( '<script>jQuery.noConflict();</script>' );
3999         }
4000     }
4001
4002     /**
4003      * Retorna a largura máxima da área interna do formulário.
4004      *
4005      */
4006     public function getMaxWidth($controlType=null)
4007     {
4008         if( ! $parent = $this->getCurrentContainer())
4009         {
4010             $parent = $this;
4011         }
4012         
4013         if( $parent->getOverFlowY()=='hidden')
4014         {
4015             $w=$parent->getWidth()-23;
4016         }
4017         else
4018         {
4019             $w = $parent->getWidth()-36;
4020         }
4021         $parentType =  $parent->getFieldType();
4022         //print 'Elem:'.$this->getId()."  parent = ".$parent->getId().' Parent type: '.$parentType.', id: '.$this->getId(). ' type:'.$controlType.'<hr>';
4023         if( $parentType == 'group' )
4024         {
4025             $w -= 10;
4026             if( $controlType == 'pagecontrol' )
4027             {
4028                 $w-=15;
4029             }
4030             else if( $controlType == 'html' )
4031             {
4032                 $w -= 2;
4033             }
4034         }
4035         else if( $parentType == 'tabsheet' )
4036         {
4037             $w-=45;
4038             if( $controlType=='group')
4039             {
4040                 $w-=0;
4041             }
4042             else if( $controlType=='pagecontrol')
4043             {
4044                 $w-=25;
4045             }
4046             else if( $controlType=='html')
4047             {
4048                 $w+=2;
4049             }
4050         }
4051         else if ($parentType=='form' )
4052         {
4053             $w=$this->getWidth();
4054             if( $controlType=='group')
4055             {
4056                 if( $parent->getOverflowY()=='hidden')
4057                 {
4058                     $w-=30;
4059                 }
4060                 else
4061                 {
4062                     $w-=45;
4063                 }
4064             }
4065             else if( $controlType=='pagecontrol')
4066             {
4067                 if( $parent->getOverflowY()=='hidden')
4068                 {
4069                     $w-=50;
4070                 }
4071                 else
4072                 {
4073                     $w-=65;
4074                 }
4075             }
4076             else if( $controlType=='html')
4077             {
4078                 if( $parent->getOverflowY()=='hidden')
4079                 {
4080                     $w-=30;
4081                 }
4082                 else
4083                 {
4084                     $w-=45;
4085                 }
4086             }
4087         }
4088         if( $parent->getFlat())
4089         {
4090             $w+=10;
4091         }
4092         return $w;
4093         
4094         
4095         
4096         /*
4097          if( ! $parent = $this->getCurrentContainer())
4098          {
4099          $parent = $this;
4100          }
4101          if( $parent->getOverFlowY()=='hidden')
4102          {
4103          $w=$parent->getWidth()-23;
4104          }
4105          else
4106          {
4107          $w = $parent->getWidth()-36;
4108          }
4109          if( $parent->getFlat())
4110          {
4111          $w+=10;
4112          }
4113          $type =  $parent->getFieldType();
4114          if( $type == 'group' )
4115          {
4116          $w -= 10;
4117          if( $controlType == 'pagecontrol' )
4118          {
4119          $w-=15;
4120          }
4121          }
4122          else if( $type == 'tabsheet' )
4123          {
4124          $w-=45;
4125          if( $controlType=='group')
4126          {
4127          $w-=15;
4128          }
4129          else if( $controlType=='pagecontrol')
4130          {
4131          $w-=35;
4132          }
4133          }
4134          return $w;
4135          
4136          */
4137         
4138         
4139         
4140     }
4141     /**
4142      * Retorna o campo aba ou o campo grupo que está aberto no momento
4143      *
4144      */
4145     public function getCurrentContainer()
4146     {
4147         if( is_array( $this->currentContainer ) && count( $this->currentContainer ) > 0 )
4148         {
4149             if( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getFieldType() == "pagecontrol" )
4150             {
4151                 // retornar a última aba aberta
4152                 if( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getPages() )
4153                 {
4154                     $aLastPage = array_slice( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getPages(), -1, 1, true );
4155                     $lastPage = $aLastPage[ key( $aLastPage ) ];
4156                     return $lastPage;
4157                 }
4158             }
4159             else
4160             {
4161                 return $this->currentContainer[ count( $this->currentContainer ) - 1 ];
4162             }
4163         }
4164         return null;
4165     }
4166     /**
4167      * Método para adicionar arquivos php que geram PDF
4168      * o PDF será exibido em um outro formulário, abaixo do formulário principal
4169      *
4170      * @param string $strFileName
4171      * @param string $strWindowTitle
4172      * @param integer $intHeight
4173      * @param integer $intWidth
4174      */
4175     public function addPdfFile( $strFileName, $strWindowTitle=null, $intHeight=null, $intWidth=null )
4176     {
4177         // aba e grupos não pode ter pdfs anexados
4178         if( $this->getFieldType() == "form" )
4179         {
4180             $strFileName = preg_replace( '/\?/', '&', $strFileName );
4181             $this->pdfs[ $strFileName ] = array( $strWindowTitle, $intHeight, $intWidth );
4182         }
4183     }
4184     //-----------------------------------------------------------------------------
4185     /**
4186      * Limpar a consulta dinâmica de um campo ou todas se o nome do campo não for informado
4187      *
4188      * @param string $strFieldName
4189      */
4190     public function clearOnlineSearch( $strFieldName=null ) {
4191         if( is_null( $strFieldName ) ) {
4192             $this->onlineSearchs = null;
4193         }
4194         else {
4195             $this->onlineSearchs[ $strFieldName ] = null;
4196             unset( $this->onlineSearchs[ $strFieldName ] );
4197         }
4198     }
4199     //-----------------------------------------------------------------------------
4200     /**
4201      * Utilizado para definr o formato de postagem do formulário
4202      *
4203      * @param string $strNewValue
4204      */
4205     public function setEncType( $strNewValue=null )
4206     {
4207         $this->enctype = $strNewValue;
4208     }
4209     //-----------------------------------------------------------------------------
4210     /**
4211      * Retorna o formato de postagem do formulário
4212      *
4213      */
4214     public function getEncType()
4215     {
4216         return $this->enctype;
4217     }
4218     //-----------------------------------------------------------------------------
4219     /**
4220      * Exibe os arquivos que geram pdf, adicionados pelo método addPdfFile(), na parte
4221      * inferior do formulário.
4222      *
4223      * @param mixed $print
4224      * @param mixed $flat
4225      */
4226     protected function showPdfs( $print=true, $flat=false )
4227     {
4228         $html = null;
4229         if( $this->pdfs )
4230         {
4231             $i = 1;
4232             foreach( $this->pdfs as $fileName=>$aDados )
4233             {
4234                 //if( strpos($fileName,'http')===false )
4235                 $fileName = trim( $fileName );
4236                 //if(    preg_match('/(?i)^https*:\/\/.+\pdf$/',$fileName )== 0 )
4237                 if( !strpos( strtolower( $fileName ), '.pdf' ) ) {
4238                     $script_uri = ServerHelper::get('SCRIPT_URI');
4239                     $fileName = $script_uri . '?modulo=' . $fileName . '&ajax=1&fpdf=1';
4240                 }
4241                 $aDados[ 1 ] = $aDados[ 1 ] ? $aDados[ 1 ] : 700;
4242                 $aDados[ 2 ] = $aDados[ 2 ] ? $aDados[ 2 ] : $this->getWidth();
4243                 $boxIframe = new TBoxIframe( $aDados[ 0 ], $fileName, $this->getId() . '_sub_' . $i++, $aDados[ 1 ], $aDados[ 2 ] );
4244                 $html .= $boxIframe->show( $print, $flat );
4245             }
4246         }
4247         return $html;
4248     }
4249     //-----------------------------------------------------------------------------
4250     /**
4251      * Define uma função javascript que será chamada quando o formulário for fechado
4252      *
4253      * @param string $strJsFunction
4254      */
4255     public function setOnClose( $strJsFunction=null )
4256     {
4257         $this->onClose = str_replace( "'", "\'", str_replace( '"', "'", $strJsFunction ) );
4258     }
4259     /**
4260      * Retorna a função javascript que será chamada quando o formulário for fechado
4261      *
4262      */
4263     public function getOnClose()
4264     {
4265         if( FormDinHelper::pregMatch('/\(/',$this->onClose) == 1 ){
4266             return "'".$this->onClose."'";
4267         }
4268         return is_null($this->onClose) ? 'null' : $this->onClose;
4269     }
4270     /**
4271      * Define uma função javascript que será chamada antes do formulário for fechado.
4272      * Se o resultado for false o fechamento será cancelado
4273      *
4274      * @param string $strJsFunction
4275      */
4276     public function setOnBeforeClose( $strJsFunction=null )
4277     {
4278         $this->onBeforeClose = str_replace( "'", "\'", str_replace( '"', "'", $strJsFunction ) );
4279     }
4280     /**
4281      * Retorna a função javascript que será chamada quando o formulário for fechado
4282      *
4283      */
4284     public function getOnBeforeClose()
4285     {
4286         if(FormDinHelper::pregMatch('/\(/',$this->onBeforeClose) == 1 ){
4287             return "'".$this->onBeforeClose."'";
4288         }
4289         return is_null($this->onBeforeClose) ? 'null' : $this->onBeforeClose;
4290     }
4291     
4292     /**
4293      * O método redirect deve ser utilizado para chamar um outro formulário dentro de uma ação do formulário
4294      * corrente, sem ter que submeter a página.
4295      * Quando o parametro $boolSaveData for true, os dados do formulário serão salvos na sessão para quando
4296      * retornar manter os campos preenchidos. O Padrão é true.
4297      * <code>
4298      *     if($acao =='Ir')
4299      *     {
4300      *         $frm->redirect('modulo2.inc','Redirect realizado com sucesso. Você está agora no 2º form.');
4301      *     }
4302      * </code>
4303      *
4304      * @param mixed $strModule      - 1: modulo de destino. Fora da pasta modulo informe o caminho completo
4305      * @param mixed $strMessage     - 2: Uma mensagem
4306      * @param boolean $boolSubmit   - 3: ação de submeter. TRUE = post, FALSE = ajax
4307      * @param array $arrVars        - 4: Array que será enviado via Post 
4308      * @param boolean $boolSaveData - 5; salva os dados formulario atual
4309      */
4310      public function redirect( $strModule=null
4311                              , $strMessage=null
4312                              , $boolSubmit=false
4313                              , $arrVars=null
4314                              , $boolSaveData=null )    {
4315          $boolSaveData = is_null( $boolSaveData ) ? false : $boolSaveData;
4316          
4317          $filePath = $this->getRealPath( $strModule );
4318          $fileExists = file_exists( $filePath );
4319          
4320          if( $fileExists ) {
4321              $currentModule = $this->getRealPath( $_POST['modulo'] );
4322              // guardar na sessão somente se estiver indo, na volta não precisa
4323              if( $boolSaveData ) {
4324                  $_SESSION[ APLICATIVO ][ $currentModule ][ 'post' ] = $_POST;
4325              }
4326              $_POST[ 'fw_back_to' ] = $currentModule;
4327              $_REQUEST[ 'redirect_message' ]     = $strMessage;
4328              $_POST[ 'modulo' ]                 = $filePath;
4329              $_GET[ 'modulo' ]                 = $filePath;
4330              $_REQUEST[ 'modulo' ]                = $filePath;
4331              $_REQUEST[ 'redirect' ]             = '1';
4332              $_SESSION[ APLICATIVO ][ 'modulo' ] = $filePath;
4333              $_POST[ 'formDinAcao' ] = null;
4334              if( !$boolSubmit )
4335              {
4336                  //$formDinModulo = $currentModule;
4337                  //$acao = $_POST[ 'formDinAcao' ];
4338                  // variaveis que serão recuperadas no formulario destino
4339                  if( is_array( $arrVars ) )
4340                  {
4341                      foreach( $arrVars as $k=>$v )
4342                      {
4343                          $_POST[ $k ] = $v;
4344                      }
4345                  }
4346                  self::$instance=null;
4347                  include($filePath);
4348                  exit( 0 );
4349              }
4350              else
4351              {
4352                  if( is_array( $arrVars ) )
4353                  {
4354                      foreach( $arrVars as $k=>$v )
4355                      {
4356                          if( is_array( $v ) )
4357                          {
4358                              foreach( $v as $k1=>$v1 )
4359                              {
4360                                  $this->addHiddenField( $k1, $v1 );
4361                              }
4362                          }
4363                          else
4364                          {
4365                              $this->addHiddenField( $k, $v );
4366                          }
4367                      }
4368                  }
4369                  // definir o novo modulo e submeter o form
4370                  $this->addHiddenField( 'modulo', $filePath );
4371                  $this->addHiddenField( 'moduloId', $filePath );
4372                  $this->addHiddenField( 'fw_back_to', $currentModule);
4373                  $this->clearJavascript();
4374                  $this->addJavascript( 'fwFazerAcao("redirect")' );
4375                  $this->setVisible( false );
4376                  $this->show();
4377                  exit();
4378                  /*
4379                   die('redirecionar para '.$strModule);
4380                   
4381                   // criar formulario e submeter
4382                   echo "\n".'<form method="POST" name="frm_temp" action="./index.php">'."\n";
4383                   $arrVars['redirect']=1;
4384                   if( !isset( $arrVars['modulo']))
4385                   {
4386                   $arrVars['modulo']=$strModule;
4387                   }
4388                   foreach($arrVars as $k=>$v )
4389                   {
4390                   if( is_array($v ))
4391                   {
4392                   foreach($v as $k1=>$v1)
4393                   {
4394                   echo '<input type=hidden name="'.$k.'['.$k1.']" value="'.$v1.'">'."\n";
4395                   }
4396                   }
4397                   else
4398                   {
4399                   echo '<input type=hidden name="'.$k.'" value="'.$v.'">'."\n";
4400                   
4401                   }
4402                   }
4403                   echo ' <script>javascript:document.frm_temp.submit();</script>';
4404                   echo '</form>'."\n";
4405                   echo '</td>'."\n";
4406                   echo '</tr>'."\n";
4407                   echo '</center>'."\n";
4408                   echo '</body>'."\n";
4409                   echo '</html>'."\n";
4410                   exit();
4411                   */
4412              }
4413          }
4414      }
4415      /**
4416       * Adiciona um evento a um campo do formulário
4417       *
4418       * @param string $strFieldName
4419       * @param string $strEventName
4420       * @param string $strFunctionJs
4421       */
4422      public function setFieldEvent( $strFieldName, $strEventName=null, $strFunctionJs=null )
4423      {
4424          $f = $this->getField( $strFieldName );
4425          if( $f )
4426          {
4427              if( $strFunctionJs )
4428              {
4429                  $f->addEvent( $strEventName, $strFunctionJs );
4430              }
4431              else
4432              {
4433                  $f->setEvent( $strEventName );
4434              }
4435          }
4436      }
4437      /**
4438       * Se noWrap estiver TRUE, os rótulos dos campos não sofrerão quebra de linha quando forem
4439       * mais largos que as medidas defindas pelo metodo $this->setColumns(), e os campos
4440       * serão alinhados de acordo com o comprimento dos mesmos
4441       *
4442       * @param boolean $boolNewValue
4443       */
4444      public function setNoWrap( $boolNewValue=null )
4445      {
4446          $this->noWrap = $boolNewValue;
4447          return $this;
4448      }
4449      /**
4450       * Retora se os rótulos do campos do formulário serão nowrap ou não.
4451       *
4452       */
4453      public function getNoWrap()
4454      {
4455          return $this->noWrap;
4456      }
4457      //-----------------------------------------------------------------------------
4458      /**
4459       * Adiciona ou retira o efeito de "fade" na exibição do formulário.
4460       *
4461       * @param integer $intNewValue
4462       */
4463      public function setFade( $intNewValue=null )
4464      {
4465          $this->fade = (int) $intNewValue;
4466          return $this;
4467      }
4468      /**
4469       * Retorna se o efeito fade está ligado ou desligado
4470       *
4471       */
4472      public function getFade()
4473      {
4474          return is_null( $this->fade ) ? 1 : (int) $this->fade;
4475      }
4476      /**
4477       * Define o valor da variável overflow que controla o aparecimento ou
4478       * não da barra de rolagem vertical do formulário
4479       *
4480       */
4481      public function setOverflowY( $newValue=null )
4482      {
4483          $this->overflowY = $newValue;
4484          return $this;
4485      }
4486      //-----------------------------------------------------------------------------
4487      /**
4488       * Retorna o valor da variável overflowy que controla o aparecimento ou
4489       * não da barra de rolagem vertical do formulário
4490       *
4491       */
4492      public function getOverFlowY()
4493      {
4494          $this->overflowY = is_null( $this->overflowY ) ? true : $this->overflowY;
4495          if( $this->overflowY === true )
4496          {
4497              return 'auto';
4498          }
4499          else if( $this->overflowY === false )
4500          {
4501              return 'hidden';
4502          }
4503          return $this->overflowY;
4504      }
4505      /**
4506       * Define o valor da variável overflow que controla o aparecimento ou
4507       * não da barra de rolagem horizontal do formulário
4508       *
4509       */
4510      public function setOverflowX( $newValue=null )
4511      {
4512          $this->overflowX = $newValue;
4513          return $this;
4514      }
4515      //-----------------------------------------------------------------------------
4516      /**
4517       * Retorna o valor da variável overflowy que controla o aparecimento ou
4518       * não da barra de rolagem horizontal do formulário
4519       *
4520       */
4521      public function getOverFlowX()
4522      {
4523          $this->overflowX = is_null( $this->overflowX ) ? true : $this->overflowX;
4524          if( $this->overflowX === true )
4525          {
4526              return 'auto';
4527          }
4528          else if( $this->overflowX === false )
4529          {
4530              return 'hidden';
4531          }
4532          return $this->overflowX;
4533      }
4534      /**
4535       * Define o valor do atributo confirmonClose que define se a mensagem de confirmação
4536       * de fechamento do formulário será exibida ou não.
4537       *
4538       */
4539      public function setConfirmOnClose( $boolNewValue=null )
4540      {
4541          $this->confirmOnClose = $boolNewValue;
4542          return $this;
4543      }
4544      /**
4545       * Retorna o valor do atributo confirmonClose que define se a mensagem de confirmação
4546       * de fechamento do formulário será exibida ou não.
4547       *
4548       */
4549      public function getConfirmOnClose()
4550      {
4551          return is_null( $this->confirmOnClose ) ? true : $this->confirmOnClose;
4552      }
4553      /**
4554       * Habilita javascript para transformação dos campos memos
4555       * em um editor de textos com recursos avançados de formatação ( WYSIWYG HTML ).
4556       * Tambem pode ser utilizada o método setRichEdit(true)
4557       *
4558       */
4559      public function enableRichEdit()
4560      {
4561          $this->richEdit = true;
4562      }
4563      /**
4564       * Deabilita recurso de edição avançada ( WYSIWYG HTML ).
4565       * Tambem pode ser utilizado o metodo setRichEdit(false);
4566       *
4567       */
4568      public function disableRichEdit()
4569      {
4570          $this->richEdit = false;
4571      }
4572      //-----------------------------------------------------------------------------
4573      /**
4574       * Retorna se o recurso de edição avançada está habilitado ou não.
4575       * @return boolean
4576       */
4577      public function getRichEdit()
4578      {
4579          return $this->richEdit;
4580      }
4581      //-----------------------------------------------------------------------------
4582      /**
4583       * Habilita/Desabilita o recurso de edição de textos com recursos avançados de formatação ( WYSIWYG HTML ).
4584       * Tambem pode ser utilizada o enableRichEdit() e disableRichEdit();
4585       *
4586       * @param bool $boolNewValue
4587       */
4588      public function setRichEdit( $boolNewValue=null )
4589      {
4590          $this->richEdit = is_null( $boolNewValue ) ? true : $boolNewValue;
4591      }
4592      /**
4593       * Habilita o icone para edição da documentção online em todos os campos do formulário.
4594       * Se for passado readonly como true, a documentação abrirá para somente leitura.
4595       *
4596       * @param boolean $boolReadOnly
4597       */
4598      public function enableOnlineDoc( $boolReadOnly=null,$intHeight=null,$intWidth=null,$strFields=null,$strIgnoreFields=null)
4599      {
4600          $this->onlineDoc=true;
4601          $this->onlineDocReadOnly = (bool) ( is_null( $boolReadOnly ) ? false : $boolReadOnly);
4602          $this->setOnlineDocHeight($intHeight);
4603          $this->setOnlineDocWidth($intWidth);
4604          self::$onlineDocFields=$strFields;
4605          self::$onlineDocIgnoreFields=$strIgnoreFields;
4606      }
4607      /**
4608       * Desabilitar a documentção on-line
4609       *
4610       */
4611      public function disableOnlineDoc()
4612      {
4613          $this->onlineDoc = false;
4614      }
4615      /**
4616       * Ativar/Desativar documentação o recurso de edição da documentção on-line dos campos
4617       *
4618       * @param mixed $boolEnabled
4619       * @param mixed $boolReadOnly
4620       */
4621      public function setOnlineDoc( $boolEnabled=null,$boolReadOnly=null)
4622      {
4623          $this->onlineDoc = $boolEnabled;
4624          $this->onlineDocReadOnly = (bool) ( is_null( $boolReadOnly ) ? false : $boolReadOnly);
4625      }
4626      /**
4627       * Recuperar o valor da propriedade onlineDoc
4628       *
4629       */
4630      public function getOnlineDoc()
4631      {
4632          return $this->onlineDoc;
4633      }
4634      /**
4635       * Retorna o codigo html necessário para exibição/edição da documentação on-line
4636       *
4637       * @param boolean $print
4638       */
4639      protected function getOnlineDocDiv( $print=true,$intHeight=null,$intWidth=null )
4640      {
4641          $style     = !is_null($intHeight)?'height:'.$intHeight.'px;':'';
4642          $style .= !is_null($intWidth)?'width:'.$intWidth.'px;':'';
4643          if( $style != '' )
4644          {
4645              $style = ' style="'.$style.'"';
4646          }
4647          if( $this->getOnlineDoc() )
4648          {
4649              $html = '<table class="fwOnlineDoc" id="fwOnlineDoc" cellpadding="3px" cellspacing="0px"'.$style.' >
4650                    <tr id="fwOnlineDocHeader" class="fwOnlineDocHeader">
4651                        <td id="fwOnlineDoc_image_left_td" height="50px" width="50px" valign="middle" align="center">
4652                            <img id="fwOnlineDoc_image_left" src="'.$this->getBase().'imagens/fwarquivo.gif" border="0" width="45px" height="45px"/>
4653                        </td>
4654                        <td  id="fwOnlineDocTitulo_td" height="50px" valign="middle" align="center">
4655                            <div id="fwOnlineDocTituloSystemName">'.TITULO_SISTEMA.'</div>
4656                            <div id="fwOnlineDocTituloModuleName">Cadastro de Pessoa Física</div>
4657                            <div id="fwOnlineDocTituloFieldName">
4658                                <input type="text" name="fwOnlineDocInputTitle" id="fwOnlineDocInputTitle" size="100" maxlength="150"   class="fwOnlineDocInput">
4659                            </div>
4660                        </td>
4661                        <td  id="fwOnlineDoc_image_right_td" height="50px" width="50px" valign="top" align="right">
4662                            <img id="fwOnlineDocCloseButton" class="fwOnlineDocCloseButton" src="'.$this->getBase().'imagens/fwbtnclosered.jpg" border="0" width="28px" height="16px" alt="Fechar" title="Fechar Ajuda" onClick="fwHideOnlineDocumentation()">
4663                        </td>
4664                    </tr>
4665                    <tr id="fwOnlineDocBody_tr">
4666                        <td id="fwOnlineDocBody" class="fwOnlineDocBody" colspan="3">
4667                            <textarea class="fwOnlineDocTextArea"  name="fwOnlineDocTextArea"  id="fwOnlineDocTextArea" wrap="virtual"></textarea>
4668                        </td>
4669                    </tr>
4670                </table>'."\n";
4671              if( $print ) { echo $html; };
4672              return $html;
4673          }
4674      }
4675      
4676      public function processActionGetModulo()
4677      {
4678          $strModule = null;
4679          // encontrar a modulo postado em uma das variáveis: modulo, module
4680          if( isset($_POST[ 'modulo' ]) && $_POST[ 'modulo' ]  )
4681          {
4682              $strModule = $_POST[ 'modulo' ];
4683          }
4684          else if( isset($_GET[ 'modulo' ]) && $_GET[ 'modulo' ]  )
4685          {
4686              $strModule = $_GET[ 'modulo' ];
4687          }
4688          else if( isset($_REQUEST[ 'modulo' ]) && $_REQUEST[ 'modulo' ]  )
4689          {
4690              $strModule = $_REQUEST[ 'modulo' ];
4691          }
4692          if( isset($_POST[ 'module' ]) && $_POST[ 'module' ]  )
4693          {
4694              $strModule = $_POST[ 'module' ];
4695          }
4696          else if( isset($_GET[ 'module' ]) && $_GET[ 'module' ]  )
4697          {
4698              $strModule = $_GET[ 'module' ];
4699          }
4700          else if( isset($_REQUEST[ 'module' ]) && $_REQUEST[ 'module' ]  )
4701          {
4702              $strModule = $_REQUEST[ 'module' ];
4703          }          
4704          return  $strModule;          
4705      }
4706      
4707      public function processActionGetAction($strAction=null)
4708      {
4709          // encontrar a ação postada em uma das variáveis: formDinAcao, acao ou action
4710          if( is_null( $strAction ) )
4711          {
4712              if( isset($_POST[ 'formDinAcao' ]) && $_POST[ 'formDinAcao' ]  )
4713              {
4714                  $strAction = $_POST[ 'formDinAcao' ];
4715              }
4716              else if( isset($_GET[ 'formDinAcao' ]) && $_GET[ 'formDinAcao' ]  )
4717              {
4718                  $strAction = $_GET[ 'formDinAcao' ];
4719              }
4720              else if( isset($_REQUEST[ 'formDinAcao' ]) && $_REQUEST[ 'formDinAcao' ]  )
4721              {
4722                  $strAction = $_REQUEST[ 'formDinAcao' ];
4723              }
4724              if( isset($_POST[ 'acao' ]) && $_POST[ 'acao' ]  )
4725              {
4726                  $strAction = $_POST[ 'acao' ];
4727              }
4728              else if( isset($_GET[ 'acao' ]) && $_GET[ 'acao' ]  )
4729              {
4730                  $strAction = $_GET[ 'acao' ];
4731              }
4732              else if( isset($_REQUEST[ 'acao' ]) && $_REQUEST[ 'acao' ]  )
4733              {
4734                  $strAction = $_REQUEST[ 'action' ];
4735              }
4736              if( isset($_POST[ 'action' ]) && $_POST[ 'action' ]  )
4737              {
4738                  $strAction = $_POST[ 'action' ];
4739              }
4740              else if( isset($_GET[ 'action' ]) && $_GET[ 'action' ]  )
4741              {
4742                  $strAction = $_GET[ 'action' ];
4743              }
4744              else if( isset($_REQUEST[ 'action' ]) && $_REQUEST[ 'action' ]  )
4745              {
4746                  $strAction = $_REQUEST[ 'action' ];
4747              }
4748              
4749              $strAction = $this->removeIllegalChars( $strAction );
4750          }
4751          return $strAction;
4752      }
4753      
4754      /**
4755       * Método para fazer a inclusão do modulo de acordo com a ação solicitada
4756       *
4757       * @param mixed $arrVar
4758       * @param string $strAction
4759       */
4760      public function processAction( $arrVar=null, $strAction=null )
4761      {
4762          $this->setVar( $arrVar );
4763          $strModule = $this->processActionGetModulo();
4764          $strAction = $this->processActionGetAction($strAction);
4765          
4766          if( $strAction && $strModule ) {
4767              $strModule = $this->getRealPath( $strModule, $strAction );
4768              if( !is_null( $strModule ) ){
4769                  include($strModule); // adiciona o arquivo da ação
4770              }
4771          }
4772          $this->showAjaxErrosMessages();
4773      }
4774      
4775      /**
4776       * Este médodo faz uma atualização da página principal
4777       *
4778       */
4779      public function restart($strMessage=null)
4780      {
4781          $this->addJavascript( 'fwApplicationRestart("'.$strMessage.'")');
4782      }
4783      /**
4784       * método para registrar variáveis na instância da classe TForm
4785       * O array de valores deve ser no formato key=>value onde key é o nome
4786       * da variável e value é o seu valor.
4787       *
4788       * Ex: setVar(array('nome','José da Silva'));
4789       *
4790       * @param array $arrObj
4791       */
4792      public function setVar( $arrObj )
4793      {
4794          if( is_array( $arrObj ) )
4795          {
4796              foreach( $arrObj as $k=>$v )
4797              {
4798                  $this->arrVar[ $k ] = $v;
4799              }
4800          }
4801      }
4802      //-----------------------------------------------------------------------------
4803      /**
4804       * Método para recuperar uma variável registrada pelo método setVar()
4805       *
4806       * Ex: $nome = getVar('nome');
4807       *
4808       * @param string $id
4809       * @return mixed
4810       */
4811      public function getVar( $id )
4812      {
4813          return isset( $this->arrVar[ $id ] ) ? $this->arrVar[ $id ] : null;
4814      }
4815      //-----------------------------------------------------------------------------
4816      /**
4817       * Método para encontrar e retornar o caminho correto do módulo dentro do diretório modulos/ da aplicação
4818       *
4819       * @param string $strFileName
4820       */
4821      function getRealPath( $strFileName=null, $strAction=null )
4822      {
4823          
4824          if( file_exists( 'modulos/' ) )
4825          {
4826              $pathModulos = 'modulos/';
4827          }
4828          else
4829          {
4830              if( strpos( $strFileName, 'modulos/' ) === false || strpos( $strFileName, 'modulos/' ) > 0 )
4831              {
4832                  $pathModulos = str_replace( 'base/', 'modulos/', $this->getBase() );
4833              }
4834          }
4835          $aFileParts = pathinfo( $strFileName );
4836          $baseName = $aFileParts[ 'basename' ];
4837          $fileName = $aFileParts[ 'filename' ];
4838          $dirName = $aFileParts[ 'dirname' ];
4839          // extensão padrão é inc
4840          $extName = isset( $aFileParts[ 'extension' ] ) ? $aFileParts[ 'extension' ] : 'inc';
4841          $dirName = ($dirName == '.') ? '' : $dirName;
4842          $dirName = ($dirName == './') ? '' : $dirName;
4843          $dirName .= ( $dirName != '') ? '/' : '';
4844          // se exisiter o diretório, não acrescenter o diretório modulos/
4845          if( $dirName != '' && is_dir( $dirName ) )
4846          {
4847              $pathModulos = '';
4848          }
4849          if( !$fileName )
4850          {
4851              $fileName = basename( $baseName, '.' . $extName );
4852          }
4853          //1º possibilidade: Estrutura de Visão e Controle
4854          $file = $pathModulos . $dirName . $fileName;
4855          if( is_dir( $file ) )
4856          {
4857              $fileOut = $file . '/' . $fileName . '.' . $extName;
4858              if( file_exists( $fileOut ) )
4859              {
4860                  //------------------------------------------------------------------
4861                  if( $strAction )
4862                  {
4863                      $fileOut = $file . '/action/' . $strAction . '.php';
4864                      if( !file_exists( $fileOut ) )
4865                      {
4866                          $fileOut = $file . '/action/' . strtolower( $strAction ) . '.php';
4867                          if( !file_exists( $fileOut ) )
4868                          {
4869                              $fileOut = $file . '/action/' . $strAction . '.inc';
4870                              if( !file_exists( $fileOut ) )
4871                              {
4872                                  $fileOut = $file . '/action/' . strtolower( $strAction ) . '.inc';
4873                                  if( !file_exists( $fileOut ) )
4874                                  {
4875                                      $fileOut = null;
4876                                  }
4877                              }
4878                          }
4879                      }
4880                  }
4881                  //-----------------------------------------------------------------
4882                  //print '<br>tipo 1:'.$fileOut.' Action:'.$strAction;
4883                  return $fileOut;
4884              }
4885              $extName2 = $extName == 'inc' ? 'php' : 'inc';
4886              $fileOut = $file . '/' . $fileName . '.' . $extName2;
4887              if( file_exists( $fileOut ) )
4888              {
4889                  //--------------------------------------------
4890                  if( $strAction )
4891                  {
4892                      $fileOut = $file . '/action/' . $strAction . '.php';
4893                      if( !file_exists( $fileOut ) )
4894                      {
4895                          $fileOut = $file . '/action/' . strtolower( $strAction ) . '.php';
4896                          if( !file_exists( $fileOut ) )
4897                          {
4898                              $fileOut = $file . '/action/' . $strAction . '.inc';
4899                              if( !file_exists( $fileOut ) )
4900                              {
4901                                  $fileOut = $file . '/action/' . strtolower( $strAction ) . '.inc';
4902                                  if( !file_exists( $fileOut ) )
4903                                  {
4904                                      //print 'Ação: <b>'.$fileOut.' nem .php</b> não existe';
4905                                      $fileOut = null;
4906                                  }
4907                              }
4908                          }
4909                          $fileOut = null;
4910                      }
4911                  }
4912                  //--------------------------------------------
4913                  //print '<br>tipo 2:'.$fileOut.' Action:'.$strAction;
4914                  return $fileOut;
4915              }
4916          }
4917          //2º possibilidade modelo normal na pasta modulos
4918          $fileOut = $pathModulos . $dirName . $fileName . '.' . $extName;
4919          if( file_exists( $fileOut ) )
4920          {
4921              //---------------------------------------------------------------------
4922              if( $strAction )
4923              {
4924                  $fileOut = $pathModulos . $dirName . 'action/' . $strAction . '.php';
4925                  if( !file_exists( $fileOut ) )
4926                  {
4927                      $fileOut = $pathModulos . $dirName . 'action/' . $strAction . '.inc';
4928                      if( !file_exists( $fileOut ) )
4929                      {
4930                          $fileOut = $pathModulos . $dirName . 'action/' . strtolower( $strAction ) . '.php';
4931                          if( !file_exists( $fileOut ) )
4932                          {
4933                              $fileOut = $pathModulos . $dirName . 'action/' . strtolower( $strAction ) . '.inc';
4934                              if( !file_exists( $fileOut ) )
4935                              {
4936                                  return null;
4937                              }
4938                          }
4939                      }
4940                  }
4941              }
4942              //----------------------------------------------------------------------
4943              //print '<br>tipo 3:'.$fileOut.' Action:'.$strAction;
4944              return $fileOut;
4945          }
4946          $extName2 = $extName == 'inc' ? 'php' : 'inc';
4947          $fileOut = $pathModulos . $dirName . $fileName . '.' . $extName2;
4948          if( file_exists( $fileOut ) )
4949          {
4950              if( $strAction )
4951              {
4952                  $fileOut = $pathModulos . $dirName . 'action/' . $strAction . '.php';
4953                  if( !file_exists( $fileOut ) )
4954                  {
4955                      $fileOut = $pathModulos . $dirName . 'action/' . strtolower( $strAction ) . '.php';
4956                      if( !file_exists( $fileOut ) )
4957                      {
4958                          $fileOut = $pathModulos . $dirName . 'action/' . $strAction . '.inc';
4959                          if( !file_exists( $fileOut ) )
4960                          {
4961                              $fileOut = $pathModulos . $dirName . 'action/' . strtolower( $strAction ) . '.inc';
4962                              if( !file_exists( $fileOut ) )
4963                              {
4964                                  $fileOut = null;
4965                              }
4966                          }
4967                      }
4968                  }
4969              }
4970              //print '<br>tipo 4:'.$fileOut.' Action:'.$strAction;
4971              return $fileOut;
4972          }
4973          return null;
4974      }
4975      //-----------------------------------------------------------------------------
4976      /**
4977       * Método para procurar e incluir o arquivo css e js que possua o mesmo
4978       * nome do modulo sendo executado
4979       *
4980       */
4981      public function addJsCssModule()
4982      {
4983          if( isset( $_POST[ 'modulo' ] ) && $_POST[ 'modulo' ] )
4984          {
4985              if( $module = $this->getRealPath( $_POST[ 'modulo' ] ) )
4986              {
4987                  $aFileInfo = pathinfo( $module );
4988                  if( file_exists( $viewJs = $aFileInfo[ 'dirname' ] . '/' . $aFileInfo[ 'filename' ] . '.js' ) )
4989                  {
4990                      $this->addCssFile( $viewJs );
4991                  }
4992                  else if( file_exists( $viewJs = $aFileInfo[ 'dirname' ] . '/js/' . $aFileInfo[ 'filename' ] . '.js' ) )
4993                  {
4994                      $this->addCssFile( $viewJs );
4995                  }
4996                  if( file_exists( $viewJs = $aFileInfo[ 'dirname' ] . '/' . $aFileInfo[ 'filename' ] . '.css' ) )
4997                  {
4998                      $this->addCssFile( $viewJs );
4999                  }
5000                  else if( file_exists( $viewJs = $aFileInfo[ 'dirname' ] . '/css/' . $aFileInfo[ 'filename' ] . '.css' ) )
5001                  {
5002                      $this->addCssFile( $viewJs );
5003                  }
5004              }
5005          }
5006      }
5007      /**
5008       * Define o array com as larguras das colunas do layout do formulario
5009       *
5010       * @param array $arrNewColumns
5011       */
5012      public function setColumns( $arrNewColumns ) {
5013          if ( is_string ( $arrNewColumns ) ) {
5014              $this->columns = explode ( ',', $arrNewColumns );
5015          } else if (is_integer ( $arrNewColumns )) {
5016              $this->columns = array ($arrNewColumns );
5017          } else if (is_array ( $arrNewColumns )) {
5018              $this->columns = $arrNewColumns;
5019          }
5020          return $this;
5021      }
5022      /**
5023       * Retorna o array com as larguras das colunas do layout do formulario
5024       *
5025       */
5026      public function getColumns() {
5027          return $this->columns;
5028      }
5029      /**
5030       * Retorna a largura definida ou o array de larguras se o valor da coluna não for informado
5031       *
5032       * @param integer $intColumn
5033       * @return mixed
5034       */
5035      public function getcolumnWidth( $intColumn=null )
5036      {
5037          if( is_null( $intColumn ) )
5038          {
5039              return $this->columns;
5040          }
5041          else
5042          {
5043              
5044              if( isset( $this->columns[ $intColumn ] ) )
5045              {
5046                  return ( int ) $this->columns[ $intColumn ];
5047              }
5048              return 0;
5049          }
5050      }
5051      /**
5052       * Define o metodo de postagem do formulario. (post, get)
5053       *
5054       * @param mixed $strNewMethod
5055       */
5056      public function setMethod( $strNewMethod=null )
5057      {
5058          $this->method = $strNewMethod;
5059      }
5060      //------------------------------------------------------------------------------
5061      /**
5062       * Método interno utilizado para adicionar um campo e um rótulo ao formulário. A classe TDisplaycontrol
5063       * é responsável pela criação do html do rotulo e campo que serão exibidos no formulário.
5064       *
5065       * @param object $newDisplayControl
5066       */
5067      protected function addDisplayControl( $newDisplayControl )
5068      {
5069          // incluir o campo dentro do grupo ou da aba aberta
5070          if( is_array( $this->currentContainer ) && count( $this->currentContainer ) > 0 )
5071          {
5072              // se for pagecontrol, adicionar na ultima aba adicionada
5073              if( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getFieldType() == "pagecontrol" )
5074              {
5075                  // não executar se não tiver nenhuma aba adicionada no page control
5076                  if( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getPages() )
5077                  {
5078                      $aLastPage = array_slice( $this->currentContainer[ count( $this->currentContainer ) - 1 ]->getPages(), -1, 1, true );
5079                      $lastPage = $aLastPage[ key( $aLastPage ) ];
5080                      $lastPage->addDisplayControl( $newDisplayControl );
5081                  }
5082                  else
5083                  {
5084                      if( method_exists( $newDisplayControl->getField(), 'getFieldType' ) )
5085                      {
5086                          if( $newDisplayControl->getField()->getFieldType() <> 'hidden' )
5087                          {
5088                              $this->addMessage( 'Para adicionar campos a uma aba,utilize o metodo $pc->addPage() primeiro.<br>' );
5089                          }
5090                      }
5091                  }
5092              }
5093              else
5094              {
5095                  // o grupo ou a aba será o pai do controle
5096                  $newDisplayControl->getField()->setParentControl( $this->currentContainer[ count( $this->currentContainer ) - 1 ] );
5097                  $this->currentContainer[ count( $this->currentContainer ) - 1 ]->displayControls[ $newDisplayControl->getField()->getName() ] = $newDisplayControl;
5098              }
5099          }
5100          else
5101          {
5102              if( method_exists( $newDisplayControl->getField(), 'setParentControl' ) )
5103              {
5104                  $newDisplayControl->getField()->setParentControl( $this );
5105              }
5106              $this->displayControls[ $newDisplayControl->getField()->getName() ] = $newDisplayControl;
5107          }
5108          // adicionar o valor do rotulo do campo em sua propriedade
5109          if( $newDisplayControl->getLabel() )
5110          {
5111              $newDisplayControl->getField()->setProperty( 'label', $newDisplayControl->getLabel()->getValue() );
5112          }
5113          return $newDisplayControl;
5114      }
5115
5116    /**
5117    * retorna o array de objetos displaycontrol que contem os campos e os labels do
5118    * formulário
5119    *
5120    * @return array
5121    */
5122    public function getDisplayControls()
5123    {
5124       return $this->displayControls;
5125    }
5126       
5127    /**
5128    * Adicionar botão no layout
5129    *
5130    * O parametro mixValue pode ser um array com os nomes dos botões. ex: array('Gravar', 'Limpar').
5131    * Nesta caso os demais parametros não serão considerados exceto o strOnClick que
5132    * pode ser informado o nome de uma função javascript para ser executada ao clicar no botão.
5133    * Esta função receberá o Valor do botão e a variavel this.
5134    *
5135    * Para que o botão fique alinhado na frente de um campo com labelAbove=true, basta
5136    * definir o parametro boolLabelAbove do botão para true tambem.
5137    *
5138    * 
5139    * @param mixed   $mixValue          - 1 :Label do Botão ou array('Gravar', 'Limpar') com nomes
5140    * @param string  $strAction         - 2 :Nome da ação, ignorando $strName $strOnClick. Se ficar null será utilizado o valor de mixValue
5141    * @param string  $strName           - 3 :Nome da ação com submit
5142    * @param string  $strOnClick        - 4 :Nome da função javascript
5143    * @param string  $strConfirmMessage - 5 :Mensagem de confirmação, para utilizar o confirme sem utilizar javaScript explicito.
5144    * @param boolean $boolNewLine       - 6 :Em nova linha. DEFAULT = true
5145    * @param boolean $boolFooter        - 7 :Mostrar o botão no rodapé do form. DEFAULT = true
5146    * @param string  $strImage          - 8 : Imagem no botão. Evite usar no lugar procure usar a propriedade setClass. Busca pasta imagens do base ou no caminho informado
5147    * @param string  $strImageDisabled   - 9 :Imagem no desativado. Evite usar no lugar procure usar a propriedade setClass. Busca pasta imagens do base ou no caminho informado
5148    * @param string  $strHint            -10 : Texto hint para explicar
5149    * @param string  $strVerticalAlign   -11 :
5150    * @param boolean $boolLabelAbove     -12 : Position text label. DEFAULT is false. NULL = false. 
5151    * @param string  $strLabel           -13 : Text label 
5152    * @param string  $strHorizontalAlign -14 : Text Horizontal align. DEFAULT = center. Valeus center, left, right
5153    * @return TButton|string|array
5154    ***/
5155    public function addButton( $mixValue=null
5156                               , $strAction=null
5157                               , $strName=null
5158                               , $strOnClick=null
5159                               , $strConfirmMessage=null
5160                               , $boolNewLine=null
5161                               , $boolFooter=null
5162                               , $strImage=null
5163                               , $strImageDisabled=null
5164                               , $strHint=null
5165                               , $strVerticalAlign=null
5166                               , $boolLabelAbove=null
5167                               , $strLabel=null
5168                               , $strHorizontalAlign=null) {
5169           // botão será criado no rodapé do formulário por padrão
5170           $boolFooter = ($boolFooter === null) ? true : $boolFooter;
5171           $strVerticalAlign = is_null( $strVerticalAlign ) ? 'center' : $strVerticalAlign;
5172           $strHorizontalAlign = is_null( $strHorizontalAlign ) ? 'center' : $strHorizontalAlign;
5173           // a maioria dos botões ficam na frente dos campos
5174           if( $boolNewLine === null )
5175           {
5176               $boolNewLine = false;
5177           }
5178           if( is_string( $mixValue ) && strpos( $mixValue, ',' ) > 0 )
5179           {
5180               $mixValue = explode( ',', $mixValue );
5181           }
5182           if( is_array( $mixValue ) )
5183           {
5184               // passar o objeto e o nome do botão se for informado o nome de uma função para tratamento do click
5185               $onClick = $strOnClick;
5186               if( ( string ) $strOnClick != '' ) {
5187                   // retirar os parenteses do nome da função para poder adicionar os parametros padrão
5188                   if( $posParentese = strpos( $onClick, '(' ) ) {
5189                       $onClick = substr( $onClick, 0, $posParentese );
5190                   }
5191               }
5192               foreach( $mixValue as $k=>$value ) {
5193                   //$strName    = $this->removeIllegalChars($value).'_'.mt_rand(1, 100);
5194                   $strName = strtolower( $this->removeIllegalChars( $value ) );
5195                   $strValue = $value;
5196                   if( !$onClick ) {
5197                       if( $this->getFieldType() != 'form' ) {
5198                           $strAction = $this->getId() . '_' . $value;
5199                       } else {
5200                           $strAction = $value;
5201                       }
5202                   } else {
5203                       $strAction = null;
5204                       $strOnClick = $onClick . '("' . $value . '",this)';
5205                   }
5206                   $btn = new TButton( $strName, $strValue, $strAction, $strOnClick, $strConfirmMessage, $strImage, $strImageDisabled, $strHint );
5207                   if( $boolFooter ) {
5208                       $this->footerButtons[ $btn->getId() ] = $btn;
5209                   } else {
5210                       $this->addDisplayControl( new TDisplayControl( $strLabel, $btn, $boolLabelAbove, $boolNewLine, false, $strVerticalAlign ) );
5211                       //$dc->setCss('text-align',$strHorizontalAlign);
5212                       $btn->setAttribute('align',$strHorizontalAlign);
5213                   }
5214                   $button[ $strName ] = $btn;
5215                   // colocar os botões lado a lado na horizontal
5216                   $boolNewLine = false;
5217               }
5218           }
5219           else if( !is_object( $mixValue ) )
5220           {
5221               if( !isset( $strName ) )
5222               {
5223                   if( isset( $mixValue ) )
5224                   {
5225                       $strName = strtolower( $this->removeIllegalChars( $mixValue ) );
5226                   }
5227               }
5228               $button = new TButton( $strName, $mixValue, $strAction, $strOnClick, $strConfirmMessage, $strImage, $strImageDisabled, $strHint );
5229               if( $boolFooter )
5230               {
5231                   $this->footerButtons[ $button->getId() ] = $button;
5232               }
5233               else
5234               {
5235                   $dc = $this->addDisplayControl( new TDisplayControl( $strLabel, $button, $boolLabelAbove, $boolNewLine, false, $strVerticalAlign ) );
5236                   //$dc->setCss('text-align',$strHorizontalAlign);
5237                   $button->setAttribute('align',$strHorizontalAlign);
5238               }
5239           }
5240           else
5241           {
5242               $strName = $mixValue->getName();
5243               $button = $mixValue;
5244               if( $boolFooter )
5245               {
5246                   $this->footerButtons[ $button->getId() ] = $button;
5247               }
5248               else
5249               {
5250                   $this->addDisplayControl( new TDisplayControl( null, $button, false, $boolNewLine, false, $strVerticalAlign ) );
5251                   //$dc->setCss('text-align',$strHorizontalAlign);
5252                   $button->setAttribute('align',$strHorizontalAlign);
5253                   
5254               }
5255           }
5256           return $button;
5257       }
5258       
5259       /**
5260        * Cria um botão para executar uma chamada ajax utilizando a função fwAjaxRequest
5261        *
5262        *
5263        * @param string $strValue
5264        * @param string $strModule
5265        * @param string $strJsCallback
5266        * @param string $strAction
5267        * @param string $strMsgLoading
5268        * @param string $strDataTypeReturn
5269        * @param boolean $boolAsync
5270        * @param string $strName
5271        * @param string $strConfirmMessage
5272        * @param boolean $boolNewLine
5273        * @param boolean $boolFooter
5274        * @param string $strImage
5275        * @param string $strImageDisabled
5276        * @param string $strHint
5277        * @param string $strVerticalAlign
5278        * @param boolean $boolLabelAbove
5279        * @param string $strLabel
5280        * @param mixed $strHorizontalAlign
5281        * @param mixed $boolBlockScreen
5282        * @return object TButton
5283        */
5284       public function addButtonAjax( $strValue=null, $strModule=null, $strJsBeforeSend=null, $strJsCallback=null, $strAction=null, $strMsgLoading=null, $strDataTypeReturn=null, $boolAsync=null, $strContainerId=null, $strName=null, $strConfirmMessage=null, $boolNewLine=null, $boolFooter=null, $strImage=null, $strImageDisabled=null, $strHint=null, $strVerticalAlign=null, $boolLabelAbove=null, $strLabel=null,$strHorizontalAlign=null,$boolBlockScreen=null )
5285       {
5286           $strOnClick = '';
5287           // botão será criado no rodapé do formulário por padrão
5288           $boolFooter = ($boolFooter === null) ? true : $boolFooter;
5289           $boolAsync = ($boolAsync === true) ? true : false;
5290           $boolBlockScreen = ($boolBlockScreen === true) ? true : false; // mesmo em uma chamada assyncrona pode ser necessário bloquear a tela
5291           $strVerticalAlign = is_null( $strVerticalAlign ) ? 'center' : $strVerticalAlign;
5292           $strHorizontalAlign = is_null( $strHorizontalAlign ) ? 'center' : $strHorizontalAlign;
5293           
5294           // a maioria dos botões ficam na frente dos campos
5295           if( $boolNewLine === null )
5296           {
5297               $boolNewLine = false;
5298           }
5299           if( !isset( $strName ) )
5300           {
5301               if( isset( $strValue ) )
5302               {
5303                   $strName = strtolower( $this->removeIllegalChars( $strValue ) );
5304               }
5305           }
5306           /*if( is_null( $strJsCallback ) )
5307            {
5308            if( !is_null( $strAction ) )
5309            {
5310            $function = 'callback' . ucfirst( $strAction ) . 'Ajax';
5311            }
5312            else
5313            {
5314            $function = 'callback' . ucfirst( $strName ) . 'Ajax';
5315            }
5316            }
5317            else
5318            {
5319            $function = $strJsCallback;
5320            }
5321            
5322            if( is_null( $strJsBeforeSend ) )
5323            {
5324            if( ! is_null( $strAction ) )
5325            {
5326            $functionBeforeSend = 'beforeSend' . ucfirst( $strAction ) . 'Ajax';
5327            }
5328            else
5329            {
5330            $functionBeforeSend = 'beforeSend' . ucfirst( $strName ) . 'Ajax';
5331            }
5332            }
5333            else
5334            {
5335            $functionBeforeSend = $strJsBeforeSend;
5336            }
5337            */
5338           $function = is_null($strJsCallback) ? 'null' : $strJsCallback;
5339           $functionBeforeSend = is_null($strJsBeforeSend) ? 'null':$strJsBeforeSend;
5340           if( is_null( $strAction ) )
5341           {
5342               $strAction = $this->removeIllegalChars( $strValue );
5343           }
5344           if( is_null( $strDataTypeReturn ) )
5345           {
5346               $strDataTypeReturn = 'json'; // json is default
5347               // @todo validar parametro =>  json || text
5348           }
5349           $strOnClick = 'fwAjaxRequest( {"callback": (typeof ' . $function . ' == "function") ? ' . $function . ' : null,"beforeSend":' . ( $functionBeforeSend=='null' ? $functionBeforeSend : '"'.$functionBeforeSend.'"' ) . ',"action":"' . $strAction . '","async":' . ( ( $boolAsync ) ? 'true' : 'false' ) . ',"dataType":"' . $strDataTypeReturn . '","msgLoading":"' . $strMsgLoading . '","containerId":"' . $strContainerId . '","module":"' . $strModule . '","blockScreen":'. ( ( $boolBlockScreen ) ? 'true' : 'false' ).'});';
5350           //$strOnClick = 'fwAjaxRequest( {"callback": (typeof ' . $function . ' == "function") ? ' . $function . ' : null,"beforeSend": (typeof ' . $functionBeforeSend . ' == "function") ? ' . $functionBeforeSend . ' : null,"action":"' . $strAction . '","async":' . ( ( $boolAsync ) ? 'true' : 'false' ) . ',"dataType":"' . $strDataTypeReturn . '","msgLoad":"' . $strMsgLoading . '","containerId":"' . $strContainerId . '","module":"' . $strModule . '"});';
5351           $strAction = null;
5352           $button = new TButton( $strName, $strValue, $strAction, $strOnClick, $strConfirmMessage, $strImage, $strImageDisabled, $strHint );
5353           if( $boolFooter )
5354           {
5355               $this->footerButtons[ $button->getId() ] = $button;
5356           }
5357           else
5358           {
5359               $dc=$this->addDisplayControl( new TDisplayControl( $strLabel, $button, $boolLabelAbove, $boolNewLine, false, $strVerticalAlign ) );
5360               $dc->setCss('text-align',$strHorizontalAlign);
5361               $button->setAttribute('align',$strHorizontalAlign);
5362           }
5363           return $button;
5364       }
5365       /**
5366        * Define os botões do rodapé do formulario. Pode ser passado uma acao ou um array de ações.
5367        * Cada ação será um botão no rodapé do formulário
5368        *
5369        * @param mixed $mixActions
5370        */
5371       public function setAction( $mixActions )
5372       {
5373           $this->actions = $mixActions;
5374       }
5375       /**
5376        * Remove uma ou todas definidas por setAction()
5377        *
5378        * @param string $strAction
5379        */
5380       public function RemoveAction( $strAction=null )
5381       {
5382           if( is_null( $strAction ) )
5383           {
5384               $this->actions = null;
5385           }
5386           if( is_string( $this->actions ) )
5387           {
5388               $aAction = explode( ',', $this->actions );
5389           }
5390           else if( is_array( $this->actions ) )
5391           {
5392               $aAction = $this->actions;
5393           }
5394           if( is_array( $aAction ) )
5395           {
5396               foreach( $aAction as $k=>$action )
5397               {
5398                   if( trim( $action ) == trim( $strAction ) )
5399                   {
5400                       array_splice( $aAction, $k, 1 );
5401                       break;
5402                   }
5403               }
5404               $this->setAction( implode( ',', $aAction ) );
5405           }
5406       }
5407       //-----------------------------------------------------------------------------
5408       /**
5409        * Limpar a fila de codigos javascripts que serão executados no enveno on-load do formulario
5410        *
5411        */
5412       public function clearJavascript()
5413       {
5414           $this->javascript = null;
5415       }
5416       /**
5417        * Método para habilitar a tecla F5 do navegador
5418        *
5419        */
5420       public function enableF5()
5421       {
5422           $this->F5Enabled = true;
5423       }
5424       /**
5425        * Método para desabilitar a tecla F5 do navegador
5426        *
5427        */
5428       public function disableF5()
5429       {
5430           $this->F5Enabled = false;
5431       }
5432       /**
5433        * Método para retornar se a tecla F5 deverá ou não ser habilitada.
5434        *
5435        */
5436       public function getF5Enabled()
5437       {
5438           if( $this->F5Enabled )
5439           {
5440               return 'true';
5441           }
5442           else
5443           {
5444               return 'false';
5445           }
5446       }
5447       //-----------------------------------------------------------------------------
5448       private function processApf()
5449       {
5450           return;
5451           if( $this->getFieldType() == 'form' )
5452           {
5453               if( strpos( __FILE__, 'prototipo' ) > 0 || strpos( __FILE__, 'appbase' ) > 0 )
5454               {
5455                   $this->addButton( 'APF', 'process_apf', '_btnApf' );
5456               }
5457               if( $_POST[ 'formDinAcao' ] == 'process_apf' )
5458               {
5459                   require_once 'Spreadsheet/Excel/Writer.php';
5460                   $fileName = $this->getBase() . 'tmp/' . $this->removeIllegalChars( $_POST[ 'modulo' ] ) . '.xls';
5461                   $workbook = new Spreadsheet_Excel_Writer( $fileName );
5462                   
5463                   $format_title = & $workbook->addFormat();
5464                   $format_title->setBold();
5465                   $format_title->setFgColor( 'silver' );
5466                   $format_title->setBorder( 1 );
5467                   $format_title->setAlign( 'center' );
5468                   
5469                   $format_group = & $workbook->addFormat();
5470                   $format_group->setBold();
5471                   $format_group->setFgColor( 'gray' );
5472                   $format_group->setBorder( 1 );
5473                   $format_group->setAlign( 'center' );
5474                   
5475                   $worksheet = & $workbook->addWorksheet( 'PLANILHA' );
5476                   $worksheet->setColumn( 0, 2, 30 );
5477                   
5478                   $format_cell = & $workbook->addFormat();
5479                   $format_cell->setBorder( 1 );
5480                   // criar o titulo da planilha
5481                   $worksheet->write( 0, 0, $this->getTitle(), $format_title );
5482                   $worksheet->setMerge( 0, 0, 0, 2 );
5483                   $worksheet->write( 1, 0, 'CAMPO', $format_title );
5484                   $worksheet->write( 1, 1, 'TIPO', $format_title );
5485                   $worksheet->write( 1, 2, 'RÓTULO', $format_title );
5486                   $worksheet->line = 2;
5487                   //$workbook->send('base/tmp/apf.xls');
5488                   $aDc = $this->getDisplayControls();
5489                   $this->processarApfFields( $aDc, $worksheet, $format_cell, $format_group );
5490                   $workbook->close();
5491                   $this->addLinkField( 'link_apf', '', 'Visualizar Planilha - APF', null, $fileName, null, null, null, null, 'Pontos de Função - Clique aqui para visualizar a plinilha.' );
5492               }
5493           }
5494       }
5495       protected function processarApfFields( $aDc, $worksheet, $format_cell, $format_group )
5496       {
5497           // não terminada
5498           return;
5499           foreach( $aDc as $k=>$dc )
5500           {
5501               $field = $dc->getField();
5502               $label = $dc->getLabel();
5503               if( $label )
5504               {
5505                   //if($field->getEnabled())
5506                   {
5507                       $worksheet->write( $worksheet->line, 0, $k . '-' . $worksheet->line, $format_cell );
5508                       $worksheet->write( $worksheet->line, 1, $dc->getField()->getFieldType(), $format_cell );
5509                       $worksheet->write( $worksheet->line, 2, $label->getValue(), $format_cell );
5510                       $worksheet->line = $worksheet->line + 1;
5511                   }
5512                   //print 'Campo:'.$k.' Rótulo:'.$label->getValue().'  tipo:'.$dc->getField()->getFieldType().'<br>';
5513               }
5514               else
5515               {
5516                   if( $field->getFieldType() == 'group' )
5517                   {
5518                       $worksheet->write( $worksheet->line, 0, $field->getLegend(), $format_group );
5519                       $worksheet->setMerge( $worksheet->line, 0, $worksheet->line, 2 );
5520                       $worksheet->line = $worksheet->line + 1;
5521                       $field->processarApfFields( $field->getDisplayControls(), $worksheet, $format_cell, $format_group );
5522                   }
5523                   else if( $field->getFieldType() == 'pagecontrol' )
5524                   {
5525                       if( is_array( $field->getPages() ) )
5526                       {
5527                           forEach( $field->getPages() as $name=>$page )
5528                           {
5529                               $worksheet->write( $worksheet->line, 0, $page->getValue(), $format_group );
5530                               $worksheet->line = $worksheet->line + 1;
5531                               $page->processarApfFields( $page->getDisplayControls(), $worksheet, $format_cell, $format_group );
5532                           }
5533                       }
5534                   }
5535               }
5536           }
5537       }
5538       /**
5539        * Método para adicionar texto explicativo a um campo quando o mouse for passado sobre o mesmo.
5540        *
5541        * @param mixed $strFieldName
5542        * @param mixed $strHint
5543        */
5544       public function setHint( $strFieldName=null, $strHint=null )
5545       {
5546           if( is_null( $strFieldName ) )
5547           {
5548               parent::setHint( $strHint );
5549           }
5550           else
5551           {
5552               if( $field = $this->getField( $strFieldName ) )
5553               {
5554                   $field->setHint( $strHint );
5555               }
5556           }
5557       }
5558       //-----------------------------------------------------------------------------
5559       /**
5560        * Habilitar a exibição dos hints no formato de balão
5561        *
5562        */
5563       public function enableCustomHint()
5564       {
5565           $this->setCustomHintEnabled( true );
5566       }
5567       /**
5568        * Desabilitar a exibição dos hints no formato de balão
5569        *
5570        */
5571       public function disableCustomHint()
5572       {
5573           $this->setCustomHintEnabled( false );
5574       }
5575       /**
5576        * Definir ou não a utilização dos hints dentro de um balão
5577        *
5578        * @param mixed $boolNewValue
5579        */
5580       public function setCustomHintEnabled( $boolNewValue=null )
5581       {
5582           $boolNewValue = ($boolNewValue === true ) ? true : false;
5583           $this->customHintEnabled = $boolNewValue;
5584       }
5585       /**
5586        * Retorna verdadeiro ou falso para utilizar os hints de ajuda no formato de balão customizado
5587        *
5588        */
5589       public function getCustomHintEnabled()
5590       {
5591           return $this->customHintEnabled;
5592       }
5593       //-----------------------------------------------------------------------------
5594       public function setColorHighlightBackground( $strNewColor=null )
5595       {
5596           $this->colorHighlightBackground = $strNewColor;
5597       }
5598       //----------------------------------------------------------------------------
5599       public function getColorHighlightBackground()
5600       {
5601           return $this->colorHighlightBackground;
5602       }
5603       /**
5604        * Define se a altura do formulário sera ajustada de acordo com o seu conteudo não
5605        * mostrando a barra vertical de rolagem
5606        *
5607        * @param bool $boolNewValue
5608        */
5609       public function setAutoSize( $boolNewValue=null )
5610       {
5611           $boolNewValue = is_null( $boolNewValue ) ? false : ( bool ) $boolNewValue;
5612           $this->autoSize = $boolNewValue;
5613       }
5614       /**
5615        * Retorna se o formulário está ou não com autosize definido
5616        *
5617        */
5618       public function getAutoSize()
5619       {
5620           return $this->autoSize;
5621       }
5622       //-----------------------------------------------------------------------------
5623       public function get( $strFieldName=null )
5624       {
5625           return $this->getValue( $strFieldName );
5626       }
5627       //-----------------------------------------------------------------------------
5628       public function set( $strFieldName, $strNewValue )
5629       {
5630           return $this->setValue( $strFieldName, $strNewValue );
5631       }
5632       //-----------------------------------------------------------------------------
5633       public function setTooltip( $strFieldName=null, $strTitle=null, $strText=null )
5634       {
5635           if( $field = $this->getField( $strFieldName ) )
5636           {
5637               $field->setTooltip( $strTitle, $strText );
5638               return $field;
5639           }
5640       }
5641       //-----------------------------------------------------------------------------
5642       /**
5643        * Recebe um objeto do tipo VO e seta os valores automaticamente
5644        * @param object $vo
5645        */
5646       public function setVO( $vo )
5647       {
5648           foreach( $this->displayControls as $name=>$dc ) {
5649               if( $dc->getField()->getFieldType() == 'pagecontrol' )
5650               {
5651                   $dc->getField()->setVo( $vo );
5652               }
5653               else if( $dc->getField()->getFieldType() == 'group' )
5654               {
5655                   $dc->getField()->setVo( $vo );
5656               } else {
5657                   $dc = new TDAOCreate();
5658                   if( method_exists( $vo, $method = 'set' . ucfirst( $name ) )
5659                       || method_exists($vo, $method = 'set' . ucfirst( $dc->removeUnderline($name) )) )
5660                   {
5661                       $field = $this->getField( $name );
5662                       if( $field ) {
5663                           if( ! is_array($field->getValue() ) ) {
5664                               if( $field->getFieldType()=='fileasync') {
5665                                   $value = $field->getContent();
5666                               } else {
5667                                   $value = $field->getValue();
5668                               }
5669                           } else {
5670                               $value = $field->getValue();
5671                               //print $name.' = '.print_r($field->getValue(),true).'<br>';
5672                               if( $field->getFieldType()=='check') {
5673                                   if(!isset($value[0])) {
5674                                       $value=null;
5675                                   }elseif ( CountHelper::count($value)==1 ){
5676                                       $value = $value[0];
5677                                   }
5678                               }else{
5679                                   if(isset($value[0])) {
5680                                       $value = $value[0];
5681                                   } else {
5682                                       $value=null;
5683                                   } 
5684                               }                               
5685                           }
5686                           if( !is_array($value) ){
5687                            $method = '$vo->' . $method . '(\'' . addslashes($value) . '\');';
5688                           }else{
5689                               $method = '$vo->' . $method . '( array(';
5690                               $stringArray = null;
5691                               foreach( $value as $key=>$valeuItem ) {
5692                                   $stringItem = '\''.addslashes($key).'\'=>\''.addslashes($valeuItem).'\'';
5693                                   if($key > 0){
5694                                       $stringArray = $stringArray.','.$stringItem;
5695                                   }else{
5696                                       $stringArray = $stringItem;
5697                                   }                                   
5698                               }
5699                               $method = $method.$stringArray.') );';
5700                           }
5701                           eval( $method );
5702                       }
5703                   }
5704               }
5705           }
5706       }
5707       
5708       /**
5709        * Retorna o objeto header (TTableCell) referente a área do titulo do formulário.
5710        *
5711        */
5712       public function getHeaderCell()
5713       {
5714           return $this->header;
5715       }
5716       
5717       /**
5718        * Retorna o objeto TTableCell referente a area do botão fechar da janela
5719        * @deprecated use getHeaderBarButtonArea
5720        */
5721       public function getHeaderButtonCell()
5722       {
5723           return $this->getHeaderBarButtonArea();
5724       }
5725       public function getHeaderBarButtonArea()
5726       {
5727           return $this->headerBarButtonArea;
5728       }
5729       
5730       public function getFooterButtons()
5731       {
5732           return $this->footerButtons;
5733       }
5734       /**
5735        * Retorna o objeto TTableCell referente a area do rodapé da janela
5736        *
5737        */
5738       public function getFooterCell()
5739       {
5740           return $this->footer;
5741       }
5742       /**
5743        * Habilitar/Desabilitar a exibição de mensagens na parte de cima do formulário
5744        *
5745        * @param boolean $boolNewValue
5746        */
5747       public function setShowMessageForm( $boolNewValue = null )
5748       {
5749           $boolNewValue = is_null($boolNewValue) ? true : $boolNewValue;
5750           $this->showMessageAlert = !$boolNewValue;
5751       }
5752       public function getShowMessageForm()
5753       {
5754           return ! $this->showMessageAlert;
5755       }
5756       /**
5757        * Habilitar/Desabilitar a exibição de mensagens com a função alert do javascript
5758        *
5759        * @param boolean $boolNewValue
5760        */
5761       public function setShowMessageAlert( $boolNewValue = null )
5762       {
5763           $this->showMessageAlert = $boolNewValue;
5764       }
5765       public function getShowMessageAlert()
5766       {
5767           return $this->showMessageAlert === true ? 1 : 0;
5768       }
5769       //-----------------------------------------------------------------------------
5770       /**
5771        * Define o alinhamento vertical do formulário na tela
5772        *
5773        * @param string $strNewValue - top,middle,bottom
5774        */
5775       public function setVerticalAlign( $strNewValue=null )
5776       {
5777           $this->vertical_align = $strNewValue;
5778       }
5779       /**
5780        * Recupera o valor definido para o alinhamento vertical do formulário na tela
5781        */
5782       public function getVerticalAlign()
5783       {
5784           return $this->vertical_align;
5785       }
5786       /**
5787        * Define o alinhamento horizontal do formulário na tela
5788        *
5789        * @param string $strNewValue - left,right,center
5790        */
5791       public function setHorizontalAlign( $strNewValue=null )
5792       {
5793           $this->horizontal_align = $strNewValue;
5794       }
5795       /**
5796        * Recupera o valor do alinhamento vertical do formulário na tela
5797        */
5798       public function getHorizontalAlign()
5799       {
5800           return $this->horizontal_align;
5801       }
5802       //-----------------------------------------------------------------------------
5803       public function clearJsFiles()
5804       {
5805           $this->jsFiles = null;
5806       }
5807       public function clearCssFiles()
5808       {
5809           $this->cssFiles = null;
5810       }
5811       //-----------------------------------------------------------------------------
5812       public function addError( $mixError=null, $id=null )
5813       {
5814           static $result=false;
5815           if( is_string($mixError) && trim( $mixError ) !== '' )
5816           {
5817               if( $id )
5818               {
5819                   self::$errors[ $id ] = $mixError;
5820               }
5821               else
5822               {
5823                   self::$errors[] = $mixError;
5824               }
5825               $result = true;
5826           }
5827           elseif ( is_array( $mixError ) )
5828           {
5829               foreach($mixError as $k=>$v)
5830               {
5831                   if( $v )
5832                   {
5833                       $result = $this->addError($v);
5834                   }
5835               }
5836           }
5837           return $result;
5838       }
5839       //-----------------------------------------------------------------------------
5840       public function setError( $strError=null )
5841       {
5842           self::$errors = array( $strError );
5843       }
5844       /**
5845        * Retorna o array de erros de validação gerado pelo método validate()
5846        *
5847        */
5848       public function getErrors()
5849       {
5850           /* if( isset( $_REQUEST['ajax'] ) && isset( $_REQUEST['dataType'] ) && $_REQUEST['dataType']=='text' )
5851            {
5852            return null;
5853            }
5854            */
5855           return ( array ) self::$errors;
5856       }
5857       
5858       //-----------------------------------------------------------------------------
5859       /**
5860        * Remove a área de mensagem criada pela classe no topo do formulário
5861        *
5862        */
5863       public function removeMessageArea()
5864       {
5865           if( $this->message_area )
5866           {
5867               $this->removeField( $this->message_area->getId() );
5868           }
5869       }
5870       //-----------------------------------------------------------------------------
5871       /**
5872        * Define nome da função do usuário, que será chamada a cada linha adicionada ao formulário.
5873        *
5874        * A class passa automaticamente os seguintes parâmetros:
5875        * $dc - Instância da classe TDisplayControl
5876        * $cell - Instância da classe TTableCell
5877        * $RowNum - O número da linha corrente do formulário, aba ou grupo que estiver sendo criado
5878        * $row = Instância do objeto TTableRow
5879        *
5880        * <code>
5881        * function myFormOnDrawRow($ObjDc,$objCell,$intRowNum,$objRow)
5882        * {
5883        *     if( $intRowNum == 2 )
5884        *     {
5885        *         $objCell->setCss('border-bottom','1px dashed blue');
5886        *         $objDc->getField()->setEnabled( false );
5887        *     }
5888        * }
5889        * </code>
5890        *
5891        * @param mixed $strFunctionName
5892        */
5893        public function setOnDrawRow($strFunctionName=null)
5894        {
5895            $this->onDrawRow=$strFunctionName;
5896        }
5897        /**
5898         * Retorna o nome da função do usuario a ser chamada na criação de cada linha do formulário
5899         *
5900         * A class passa automaticamente os seguintes parâmetros:
5901         * $dc - Instância da classe TDisplayControl
5902         * $cell - Instância da classe TTableCell
5903         * $RowNum - O número da linha corrente do formulário, aba ou grupo que estiver sendo criado
5904         * $row = Instância do objeto TTableRow
5905         *
5906         * <code>
5907         * function myFormOnDrawRow($ObjDc,$objCell,$intRowNum,$objRow)
5908         * {
5909         *     if( $intRowNum == 2 )
5910         *     {
5911         *         $objCell->setCss('border-bottom','1px dashed blue');
5912         *         $objDc->getField()->setEnabled( false );
5913         *     }
5914         * }
5915         * </code>
5916         *
5917         * @param mixed $strFunctionName
5918         */
5919         public function getOnDrawRow($strFunctionName=null)
5920         {
5921             return $this->onDrawRow;
5922         }
5923         /**
5924          * Definie o nome da função do usuário, que será chamada na criação de cada campo no formulário
5925          * A class passa automaticamente os seguintes parâmetros:
5926          *
5927          * $dc - Instância da classe TDisplayControl
5928          * $cell - Instância da classe TTableCell
5929          * $RowNum - O número da linha corrente do formulário, aba ou grupo que estiver sendo criado
5930          * $row = Instância do objeto TTableRow
5931          *
5932          * <code>
5933          *    function minhaFuncao($dc,$cell,$rowNum )
5934          *    {
5935          *        if( $dc->getLabel() )
5936          *        {
5937          *            $dc->getLabel()->setCss('color','yellow');
5938          *        }
5939          *     }
5940          * </code>
5941          *
5942          * @param mixed $strFunctionName
5943          */
5944          public function setOnDrawField($strFunctionName=null)
5945          {
5946              $this->onDrawField=$strFunctionName;
5947          }
5948          /**
5949           * Retorna o nome da função do usuário chamada na criação de cada campo no formulário
5950           * A class passa automaticamente os seguintes parâmetros:
5951           *
5952           * $dc - Instância da classe TDisplayControl
5953           * $cell - Instância da classe TTableCell
5954           * $RowNum - O número da linha corrente do formulário, aba ou grupo que estiver sendo criado
5955           * $row = Instância do objeto TTableRow
5956           *
5957           * <code>
5958           *    function minhaFuncao($dc,$cell,$rowNum )
5959           *    {
5960           *        if( $dc->getLabel() )
5961           *        {
5962           *            $dc->getLabel()->setCss('color','yellow');
5963           *        }
5964           *     }
5965           * </code>
5966           *
5967           * @param mixed $strFunctionName
5968           * @return mixed
5969           */
5970           public function getOnDrawField($strFunctionName=null)
5971           {
5972               return $this->onDrawField;
5973           }
5974           //-----------------------------------------------------------------------------
5975           public function setReturnAjaxData($arrData=null)
5976           {
5977               $this->returnAjaxData = $arrData;
5978           }
5979           //-----------------------------------------------------------------------------
5980           public function getReturnAjaxData()
5981           {
5982               if( isset( $this->returnAjaxData ) && !is_array($this->returnAjaxData) )
5983               {
5984                   return array( $this->returnAjaxData );
5985               }
5986               return $this->returnAjaxData;
5987           }
5988           //-----------------------------------------------------------------------------
5989           public function addReturnAjaxData($value=null)
5990           {
5991               if( $value )
5992               {
5993                   if( is_null( $this->returnAjaxData ) )
5994                   {
5995                       $this->returnAjaxData=array();
5996                   }
5997                   $this->returnAjaxData = $value;
5998               }
5999           }
6000           //-----------------------------------------------------------------------------
6001           function setOnlineDocHeight($intNewValue=null)
6002           {
6003               $this->onlineDocHeight = $intNewValue;
6004           }
6005           //-----------------------------------------------------------------------------
6006           function getOnlineDocHeight()
6007           {
6008               return $this->onlineDocHeight;
6009           }
6010           //-----------------------------------------------------------------------------
6011           function setOnlineDocWidth($intNewValue=null)
6012           {
6013               $this->onlineDocWidth = $intNewValue;
6014           }
6015           //-----------------------------------------------------------------------------
6016           function getOnlineDocWidth()
6017           {
6018               return $this->onlineDocWidth;
6019           }
6020           //-----------------------------------------------------------------------------
6021           /**
6022            * Método utilizado para desformatar números decimas adicionando a virgula ou o ponto
6023            * como serparador decimal
6024            *
6025            * @param mixed $number
6026            * @param string $strDecimalSeparator
6027            * @return mixed
6028            */
6029           function unformatNumber($number=null, $strDecimalSeparator=null)
6030           {
6031               if( is_null($number))
6032               {
6033                   return $number;
6034               }
6035               $strDecimalSeparator = ( is_null( $strDecimalSeparator ) ? '.' : $strDecimalSeparator );
6036               if( $strDecimalSeparator != '.' && $strDecimalSeparator!=',')
6037               {
6038                   $strDecimalSeparator = '.';
6039               }
6040               $posComma     = strpos($number,',');
6041               $posDot        = strpos($number,'.');
6042               if($posComma == $posDot)
6043               {
6044                   return $number;
6045               }
6046               // logica para virgula
6047               if( $strDecimalSeparator == ',')
6048               {
6049                   // 1.234,56
6050                   if( $posComma > $posDot )
6051                   {
6052                       $number = preg_replace('/\./','',$number);
6053                   }
6054                   else // 1,234.56
6055                   {
6056                       $number = preg_replace('/\./',',', preg_replace('/,/','',$number ) );
6057                   }
6058               }
6059               else
6060               {
6061                   // 1.234,56
6062                   if( $posComma > $posDot )
6063                   {
6064                       $number = preg_replace('/,/','.',preg_replace('/\./','',$number ) );
6065                   }
6066                   else // 1,234.56
6067                   {
6068                       $number = preg_replace('/,/','',$number );
6069                   }
6070               }
6071               return $number;
6072           }
6073           //-----------------------------------------------------------------------------
6074           public function setOnMaximize($strNewValue=null)
6075           {
6076               $this->onMaximize = $strNewValue;
6077           }
6078           public function getOnMaximize()
6079           {
6080               return $this->onMaximize;
6081           }
6082           //-----------------------------------------------------------------------------
6083           /**
6084            * Define o formulário como sendo parte do gride offline para que o mesmo
6085            * não crie campos de controles duplicados com o form principal
6086            *
6087            * @param mixed $boolNewValue
6088            */
6089           public function setFormGridOffLine($boolNewValue=null)
6090           {
6091               $this->formGridOffLine = $boolNewValue;
6092           }
6093           public function getFormGridOffLine()
6094           {
6095               return $this->formGridOffLine;
6096           }
6097           //-----------------------------------------------------------------------------
6098           /**
6099            * Habilitar/Desabilitar o recurso de maximizar o formulário ao efetuar um duplo-clique
6100            * na barra de título
6101            *
6102            * @param bool $boolNewValue
6103            */
6104           public function setMaximize($boolNewValue = null)
6105           {
6106               $this->maximize = $boolNewValue;
6107           }
6108           /**
6109            * Recuperar o valor da propriedade maximize. Se true o formulário é maximizado
6110            * ao efeturar um duplo-clique no título
6111            *
6112            */
6113           public function getMaximize()
6114           {
6115               return ( $this->maximize === false ? false: true );
6116           }
6117           
6118    //-----------------------------------------------------------------------------
6119    /**
6120    * Define se o formulário será exibido ou não ao receber o post fwSession_expired da
6121    * aplicação
6122    *
6123    * @param boolean $boolNewValue
6124    */
6125    public function setPublicMode($boolNewValue = null)
6126    {
6127       self::$publicMode = $boolNewValue;
6128    }
6129    
6130   /**
6131    * Retorna se o formulário será exibido ou não ao receber o post fwSession_expired da
6132    * aplicação
6133    *
6134    */
6135   public function getPublicMode()
6136   {
6137       self::$publicMode = !empty(self::$publicMode)?strtolower(self::$publicMode):self::$publicMode;
6138       return ( self::$publicMode == 'S' || self::$publicMode == '1' || self::$publicMode == 'true' ) ? true : false;
6139   }
6140           //-----------------------------------------------------------------------------
6141           public function setRequiredFieldText($strNewValue=null)
6142           {
6143               $this->requiredFieldText = $strNewValue;
6144           }
6145           public function getRequiredFieldText()
6146           {
6147               return $this->requiredFieldText;
6148           }
6149           //-----------------------------------------------------------------------------
6150           public function addShortCut($strShortcutKey=null,$objId=null,$boolChangeLabel=null,$strJsFunction=null)
6151           {
6152               $boolChangeLabel = ($boolChangeLabel===false ? 0 : 1);
6153               self::$shortCuts[$strShortcutKey] = (object) array('objectId'=>$objId,'changeLabel'=>$boolChangeLabel,'functionJs'=>$strJsFunction);
6154           }
6155           //-----------------------------------------------------------------------------
6156           public function parseShortcut($obj,$target)
6157           {
6158               
6159               if( !is_object($obj) || ! method_exists($obj,'getValue') ) {
6160                   return;
6161               }
6162               $label = $obj->getValue();
6163               if( FormDinHelper::pregMatch('/\|/',$label) == 1) {
6164                   $char = explode('|',$label);
6165                   if( isset($char[0] ) ) {
6166                       $obj->setProperty('shortcut',$char[0].'|'.$target);
6167                       //$obj->setValue(preg_replace('/&/','',$label) );
6168                       $label = preg_replace('/'.$char[0].'\|/','',$label);
6169                       if( $obj->getFieldType() == 'tabsheet'){
6170                           $obj->setValue(null,$label);
6171                       } else {
6172                           $obj->setValue( $label );
6173                       }
6174                   }
6175               } else if( FormDinHelper::pregMatch('/\&/',$label) == 1) {                   
6176                   $arrSpecialCharFrom = array('&nbsp;','&aacute','&Aacute','&atilde','&Atilde','&acirc','&Acirc','&agrave','&Agrave','&eacute','&Eacute','&ecirc','&Ecirc','&iacute','&Iacute','&oacute','&Oacute','&otilde','&Otilde','&ocirc','&Ocirc','&uacute','&Uacute','&ccedil','&Ccedil;','&amp;','','&circ;','&tilde;','&uml;','&cute;','&cedil;','&quot;','&ldquo;','&rdquo;','&lsquo;','&rsquo;','&sbquo;','&bdquo;','&ordm;','&ordf;','&ndash;','&mdash;','&shy;','&macr;','&lsaquo;','&rsaquo;','&ldquo;','&raquo;','&hellip;','&brvbar;','&bull;','&#8227;','&para;','&sect;','&copy;','&reg;','&trade;','&pound;','&cent;','&#8357;','&euro;','&yen;','&#8354;','&#8355;','&#8356;','&#8367;','&#8358;','&#8359;','&#8360;','&#8361;','&#8362;','&#8363;','&#8365;','&#8366;','&curren;','&sup1;','&#8321;','&sup2;','&#8322;','&sup3;','&#8323;','&#8308;','&#8324;','&#8309;','&#8325;','&#8310;','&#8326;','&#8311;','&#8327;','&#8312;','&#8328;','&#8313;','&#8329;','&#8304;','&#8320;','&#8316;','&#8332;','&#8314;','&#8330;','&#8315;','&#8331;','&#8317;','&#8318;','&#8333;','&#8334;','&#8319;','&#8305;','&frac12;','&#8531;','&frac14;','&#8533;','&#8537;','&#8539;','&#8532;','&#8534;','&frac34;','&#8535;','&#8540;','&#8536;','&#8538;','&#8541;','&#8542;','&ne;','&asymp;','&cong;','&prop;','&equiv;','&gt;','&lt;','&le;','&ge;','&plusmn;','&minus;','&times;','&divide;','&lowast;','&frasl;','&permil;','&int;','&sum;','&prod;','&radic;','&infin;','&ang;','&perp;','&prime;','&Prime;','&deg;','&there4;','&sdot;','&middot;','&part;','&image;','&alefsym;','&real;','&nabla;','&oplus;','&otimes;','&slash;','&Oslash;','&isin;','&notin;','&cap;','&cup;','&sub;','&sup;','&sube;','&supe;','&exist;','&forall;','&empty;','&not;','&and;','&or;','&loz;','&crarr;','&lceil;','&rceil;','&lfloor;','&rfloor;','&#10102;','&#10103;','&#10104;','&#10105;','&#10106;','&#10107;','&#10108;','&#10109;','&#10110;','&#10111;','&#10112;','&#10113;','&#10114;','&#10115;','&#10116;','&#10117;','&#10118;','&#10119;','&#10120;','&#10121;','&#9312;','&#9313;','&#9314;','&#9315;','&#9316;','&#9317;','&#9318;','&#9319;','&#9320;','&#9321;','&#9322;','&#9323;','&#9324;','&#9325;','&#9326;','&#9327;','&#9328;','&#9329;','&#9330;','&#9331;','&#12881;','&#12882;','&#12883;','&#12884;','&#12885;','&#12886;','&#12887;','&#12888;','&#12889;','&#12890;','&#12891;','&#12892;','&#12893;','&#12894;','&#12895;','&#12977;','&#12978;','&#12979;','&#12980;','&#12981;','&#12982;','&#12983;','&#12984;','&#12985;','&#12986;','&#9450;','&#10122;','&#10123;','&#10124;','&#10125;','&#10126;','&#10127;','&#10128;','&#10129;','&#10130;','&#10131;','&#9451;','&#9452;','&#9453;','&#9454;','&#9455;','&#9456;','&#9457;','&#9458;','&#9459;','&#9460;','&#9461;','&#9462;','&#9463;','&#9464;','&#9465;','&#9466;','&#9467;','&#9468;','&#9469;','&#9470;','&#9398;','&#9399;','&#9400;','&#9401;','&#9402;','&#9403;','&#9404;','&#9405;','&#9406;','&#9407;','&#9408;','&#9409;','&#9410;','&#9411;','&#9412;','&#9413;','&#9414;','&#9415;','&#9416;','&#9417;','&#9418;','&#9419;','&#9420;','&#9421;','&#9422;','&#9423;','&#9424;','&#9425;','&#9426;','&#9427;','&#9428;','&#9429;','&#9430;','&#9431;','&#9432;','&#9433;','&#9433;','&#9434;','&#9435;','&#9436;','&#9437;','&#9438;','&#9439;','&#9440;','&#9441;','&#9442;','&#9443;','&#9444;','&#9445;','&#9446;','&#9447;','&#9448;','&#9449;','&ntilde;','&Ntilde;','&iexcl;','&iquest;','&fnof;','&szlig;','&micro;','&auml;','&Auml;','&aring;','&Aring;','&euml;','&Euml;','&grave;','&Egrave;','&iuml;','&Iuml;','&igrave;','&Igrave;','&icirc;','&Icirc;','&ouml;','&Ouml;','&ograve;','&Ograve;','&ugrave;','&Ugrave;','&ucirc;','&Ucirc;','&uuml;','&Uuml;','&yacute;','&Yacute;','&yuml;','&Yuml;','&aelig;','&AElig;','&oelig;','&OElig;','&dagger;','&Dagger;','&scaron;','&Scaron;','&thorn;','&THORN;','&eth;','&ETH;','&alpha;','&Alpha;','&beta;','&Beta;','&gamma;','&Gamma;','&delta;','&Delta;','&epsilon;','&Epsilon;','&zeta;','&Zeta;','&eta;','&Eta;','&theta;','&Theta;','&iota;','&Iota;','&kappa;','&Kappa;','&lambda;','&Lambda;','&mu;','&Mu;','&nu;','&Nu;','&xi;','&Xi;','&omicron;','&Omicron;','&pi;','&Pi;','&rho;','&Rho;','&sigma;','&Sigma;','&sigmaf;','&tau;','&Tau;','&upsilon;','&Upsilon;','&phi;','&Phi;','&chi;','&Chi;','&psi;','&Psi;','&omega;','&Omega;','&thetasym;','&upsih;','&piv;');
6177                   $arrSpecialCharTo   = array('xnbsp;','xaacute','xAacute','xatilde','xAtilde','xacirc','xAcirc','xagrave','xAgrave','xeacute','xEacute','xecirc','xEcirc','xiacute','xIacute','xoacute','xOacute','xotilde','xOtilde','xocirc','xOcirc','xuacute','xUacute','xccedil','xCcedil;','xamp;','','xcirc;','xtilde;','xuml;','xcute;','xcedil;','xquot;','xldquo;','xrdquo;','xlsquo;','xrsquo;','xsbquo;','xbdquo;','xordm;','xordf;','xndash;','xmdash;','xshy;','xmacr;','xlsaquo;','xrsaquo;','xldquo;','xraquo;','xhellip;','xbrvbar;','xbull;','x#8227;','xpara;','xsect;','xcopy;','xreg;','xtrade;','xpound;','xcent;','x#8357;','xeuro;','xyen;','x#8354;','x#8355;','x#8356;','x#8367;','x#8358;','x#8359;','x#8360;','x#8361;','x#8362;','x#8363;','x#8365;','x#8366;','xcurren;','xsup1;','x#8321;','xsup2;','x#8322;','xsup3;','x#8323;','x#8308;','x#8324;','x#8309;','x#8325;','x#8310;','x#8326;','x#8311;','x#8327;','x#8312;','x#8328;','x#8313;','x#8329;','x#8304;','x#8320;','x#8316;','x#8332;','x#8314;','x#8330;','x#8315;','x#8331;','x#8317;','x#8318;','x#8333;','x#8334;','x#8319;','x#8305;','xfrac12;','x#8531;','xfrac14;','x#8533;','x#8537;','x#8539;','x#8532;','x#8534;','xfrac34;','x#8535;','x#8540;','x#8536;','x#8538;','x#8541;','x#8542;','xne;','xasymp;','xcong;','xprop;','xequiv;','xgt;','xlt;','xle;','xge;','xplusmn;','xminus;','xtimes;','xdivide;','xlowast;','xfrasl;','xpermil;','xint;','xsum;','xprod;','xradic;','xinfin;','xang;','xperp;','xprime;','xPrime;','xdeg;','xthere4;','xsdot;','xmiddot;','xpart;','ximage;','xalefsym;','xreal;','xnabla;','xoplus;','xotimes;','xslash;','xOslash;','xisin;','xnotin;','xcap;','xcup;','xsub;','xsup;','xsube;','xsupe;','xexist;','xforall;','xempty;','xnot;','xand;','xor;','xloz;','xcrarr;','xlceil;','xrceil;','xlfloor;','xrfloor;','x#10102;','x#10103;','x#10104;','x#10105;','x#10106;','x#10107;','x#10108;','x#10109;','x#10110;','x#10111;','x#10112;','x#10113;','x#10114;','x#10115;','x#10116;','x#10117;','x#10118;','x#10119;','x#10120;','x#10121;','x#9312;','x#9313;','x#9314;','x#9315;','x#9316;','x#9317;','x#9318;','x#9319;','x#9320;','x#9321;','x#9322;','x#9323;','x#9324;','x#9325;','x#9326;','x#9327;','x#9328;','x#9329;','x#9330;','x#9331;','x#12881;','x#12882;','x#12883;','x#12884;','x#12885;','x#12886;','x#12887;','x#12888;','x#12889;','x#12890;','x#12891;','x#12892;','x#12893;','x#12894;','x#12895;','x#12977;','x#12978;','x#12979;','x#12980;','x#12981;','x#12982;','x#12983;','x#12984;','x#12985;','x#12986;','x#9450;','x#10122;','x#10123;','x#10124;','x#10125;','x#10126;','x#10127;','x#10128;','x#10129;','x#10130;','x#10131;','x#9451;','x#9452;','x#9453;','x#9454;','x#9455;','x#9456;','x#9457;','x#9458;','x#9459;','x#9460;','x#9461;','x#9462;','x#9463;','x#9464;','x#9465;','x#9466;','x#9467;','x#9468;','x#9469;','x#9470;','x#9398;','x#9399;','x#9400;','x#9401;','x#9402;','x#9403;','x#9404;','x#9405;','x#9406;','x#9407;','x#9408;','x#9409;','x#9410;','x#9411;','x#9412;','x#9413;','x#9414;','x#9415;','x#9416;','x#9417;','x#9418;','x#9419;','x#9420;','x#9421;','x#9422;','x#9423;','x#9424;','x#9425;','x#9426;','x#9427;','x#9428;','x#9429;','x#9430;','x#9431;','x#9432;','x#9433;','x#9433;','x#9434;','x#9435;','x#9436;','x#9437;','x#9438;','x#9439;','x#9440;','x#9441;','x#9442;','x#9443;','x#9444;','x#9445;','x#9446;','x#9447;','x#9448;','x#9449;','xntilde;','xNtilde;','xiexcl;','xiquest;','xfnof;','xszlig;','xmicro;','xauml;','xAuml;','xaring;','xAring;','xeuml;','xEuml;','xgrave;','xEgrave;','xiuml;','xIuml;','xigrave;','xIgrave;','xicirc;','xIcirc;','xouml;','xOuml;','xograve;','xOgrave;','xugrave;','xUgrave;','xucirc;','xUcirc;','xuuml;','xUuml;','xyacute;','xYacute;','xyuml;','xYuml;','xaelig;','xAElig;','xoelig;','xOElig;','xdagger;','xDagger;','xscaron;','xScaron;','xthorn;','xTHORN;','xeth;','xETH;','xalpha;','xAlpha;','xbeta;','xBeta;','xgamma;','xGamma;','xdelta;','xDelta;','xepsilon;','xEpsilon;','xzeta;','xZeta;','xeta;','xEta;','xtheta;','xTheta;','xiota;','xIota;','xkappa;','xKappa;','xlambda;','xLambda;','xmu;','xMu;','xnu;','xNu;','xxi;','xXi;','xomicron;','xOmicron;','xpi;','xPi;','xrho;','xRho;','xsigma;','xSigma;','xsigmaf;','xtau;','xTau;','xupsilon;','xUpsilon;','xphi;','xPhi;','xchi;','xChi;','xpsi;','xPsi;','xomega;','xOmega;','xthetasym;','xupsih;','xpiv;');
6178                   //$label = html_entity_decode($label,null,'ISO-8859-1');
6179                   $label = str_replace( $arrSpecialCharFrom,$arrSpecialCharTo,$label);
6180                   if( FormDinHelper::pregMatch('/\&/',$label) == 1) {
6181                       $char = trim( substr($label,strpos($label,'&')+1,1));
6182                       
6183                       if( $char ) {
6184                           $obj->setProperty('shortcut','ALT+'.$char.'|'.$target);
6185                           //$obj->setValue(preg_replace('/&/','',$label) );
6186                           $label = preg_replace('/&/','',$label);
6187                           $label = htmlentities( $label,ENT_COMPAT,ENCODINGS );
6188                           $label = str_replace( $arrSpecialCharTo,$arrSpecialCharFrom,$label);
6189                           if( $obj->getFieldType() == 'tabsheet') {
6190                               $obj->setValue(null,$label);
6191                           } else {
6192                               $obj->setValue( $label );
6193                           }
6194                       }
6195                   }
6196               }
6197           }
6198    //-----------------------------------------------------------------------------
6199    /**
6200    * Define se o form deve redimensionar a area central da aplicação para a sua altura
6201    * evitando a barra de rolagem vertical dentro do iframe central e exibindo
6202    * a barra vertical do browser.
6203    *
6204    * @param boolean $boolNewValue
6205    */
6206    public function setAppFitFormHeight($boolNewValue=null)
6207    {
6208       $this->appFitFormHeight = $boolNewValue;
6209    }
6210    
6211    public function getAppFitFormHeight()
6212    {
6213       return $this->appFitFormHeight;
6214    }
6215    
6216    /**
6217    * Define o alinhamento dos rótulos dos campos.
6218    * Os valores válidos são:center,left ou right.
6219    * O padrão é left
6220    *
6221    * @param string $strNewValue
6222    */
6223    public function setLabelsAlign($strNewValue=null) {
6224       $this->labelsAlign = $strNewValue;
6225       return $this;
6226    }
6227    
6228    //-----------------------------------------------------------------------------
6229    public function getLabelsAlign(){
6230       return $this->labelsAlign;
6231    }
6232    
6233   //-----------------------------------------------------------------------------
6234    /**
6235    * Adiciona um campo oculto ao layout
6236    *
6237    * @param string $strName       - 1: Id do Campo
6238    * @param string $strValue      - 2: Valor inicial
6239    * @param boolean $boolRequired - 3: True = Obrigatório; False (Defalt) = Não Obrigatório  
6240    * @return THidden
6241    */
6242    public function addHiddenField( $strName, $strValue=null, $boolRequired=null )
6243    {
6244       $field = new THidden( $strName, $strValue, $boolRequired );
6245       $this->addDisplayControl( new TDisplayControl( null, $field, false, false ) );
6246       return $field;
6247    }
6248           
6249    /**
6250     * Adicionar campo entrada de dados texto livre
6251     *
6252     * @param string $strName       - 1: id do campo
6253     * @param string $strLabel      - 2: Label do campo
6254     * @param integer $intMaxLength - 3: tamanho máximo de caracteres
6255     * @param boolean $boolRequired - 4: obrigatório ou não
6256     * @param integer $intSize      - 5: quantidade de caracteres visíveis
6257     * @param string $strValue      - 6: texto preenchido
6258     * @param boolean $boolNewLine  - 7: Nova linha
6259     * @param string $strHint
6260     * @param string $strExampleText - 9: Texto de exemplo
6261     * @param boolean $boolLabelAbove - 10: Label sobre
6262     * @param boolean $boolNoWrapLabel
6263     * @return TEdit
6264     */
6265    public function addTextField( string $strName
6266                                , string $strLabel=null
6267                                , $intMaxLength
6268                                , $boolRequired=null
6269                                , $intSize=null
6270                                , $strValue=null
6271                                , $boolNewLine=null
6272                                , $strHint=null
6273                                , $strExampleText=null
6274                                , $boolLabelAbove=null
6275                                , $boolNoWrapLabel=null
6276                                )
6277    {
6278        $field = new TEdit( $strName, $strValue, $intMaxLength, $boolRequired, $intSize );
6279        $field->setHint( $strHint );
6280        $field->setExampleText( $strExampleText );
6281        $tDisplayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel,null,null,null,true);
6282        $this->addDisplayControl( $tDisplayControl );
6283        return $field;
6284    }
6285           
6286    /**
6287     * Adicionar campo de entrada de texto com multiplas linhas ( memo ) equivalente ao html textarea
6288     *
6289     * @param string  $strName         - 1: ID do campo
6290     * @param string  $strLabel        - 2: Label do campo
6291     * @param integer $intMaxLength    - 3: tamanho maximo
6292     * @param boolean $boolRequired    - 4: Obrigatório
6293     * @param integer $intColumns      - 5: qtd colunas
6294     * @param integer $intRows         - 6: qtd linhas
6295     * @param boolean $boolNewLine     - 7: nova linha
6296     * @param boolean $boolLabelAbove  - 8: Label sobre o campo
6297     * @param boolean $boolShowCounter - 9: Contador de caracteres ! Só funciona em campos não RichText
6298     * @param string  $strValue
6299     * @param string $boolNoWrapLabel
6300     * @return TMemo
6301     */
6302    public function addMemoField(string $strName
6303                                  , string $strLabel=null
6304                                  , $intMaxLength
6305                                  , $boolRequired=null
6306                                  , $intColumns=null
6307                                  , $intRows=null
6308                                  , $boolNewLine=null
6309                                  , $boolLabelAbove=null
6310                                  , $boolShowCounter=null
6311                                  , $strValue=null
6312                                  , $boolNoWrapLabel=null )
6313    {
6314        $field = new TMemo( $strName, $strValue, $intMaxLength, $boolRequired, $intColumns, $intRows, $boolShowCounter );
6315        $field->setClass( 'fwMemo' );
6316        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6317        return $field;
6318    }
6319    
6320    /**
6321     * Adicionar campo de entrada de texto com multiplas linhas equivalente ao html textarea
6322     * com editor TinyMCE for free, the most advanced WYSWIYG 
6323     *
6324     * @param string  $strName         - 1: ID do campo
6325     * @param string  $strLabel        - 2: Label do campo
6326     * @param integer $intMaxLength    - 3: tamanho maximo
6327     * @param boolean $boolRequired    - 4: Obrigatório
6328     * @param integer $intColumns      - 5: qtd colunas
6329     * @param integer $intRows         - 6: qtd linhas
6330     * @param boolean $boolNewLine     - 7: nova linha
6331     * @param boolean $boolLabelAbove  - 8: Label sobre o campo
6332     * @param string  $strValue        - 9:
6333     * @param boolean $boolNoWrapLabel - 10:
6334     * @return TRichTextEditor
6335     */
6336    public function addRichTextEditor( string $strName
6337            , string $strLabel=null
6338            , $intMaxLength=null
6339            , $boolRequired=null
6340            , $intColumns=null
6341            , $intRows=null
6342            , $boolNewLine=null
6343            , $boolLabelAbove=null
6344            , $strValue=null
6345            , $boolNoWrapLabel=null )
6346    {
6347        $field = new TRichTextEditor( $strName, $strValue, $intMaxLength, $boolRequired, $intColumns, $intRows );
6348        $field->setClass( 'fwMemo' );
6349        $this->setRichEdit(true);
6350        $this->addJavascript('fwSetHtmlEditor("'.$strName.'","callBackEditor",false)');
6351        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6352        return $field;
6353    }    
6354    
6355    /****
6356     * Adicona um campo data ou mes/ano ou dia/mes de acordo com o parametro strMaxType
6357     * Tipo de máscara: DMY, DM, MY
6358     *  
6359     * @param string  $strName         - 1: Id do Campo
6360     * @param string  $strLabel        - 2: Label do Campo
6361     * @param boolean $boolRequired    - 3: DEFAULT = flase não obrigatório
6362     * @param boolean $boolNewLine     - 4: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6363     * @param string  $strValue        - 5: Valor inicial
6364     * @param string  $strMinValue     - 6: Menor data que o campo aceita
6365     * @param string  $strMaxValue     - 7: Maior data que o campo aceita
6366     * @param string  $strMaskType     - 8: DEFAULT = DMY. Tipo de Mascara DMY (dia/mês/ano), DM (dia/mês), MY (mês/ano) 
6367     * @param boolean $boolButtonVisible - 9: Exibe ou não o botão do calendario.
6368     * @param string  $strExampleText  - 10: Texto de exmplo
6369     * @param boolean $boolLabelAbove  - 11: DEFAULT = flase. Label acima do campo = true
6370     * @param string  $boolNoWrapLabel - 12: 
6371     * @return TDate
6372     */
6373    public function addDateField( $strName
6374            , $strLabel=null
6375            , $boolRequired=null
6376            , $boolNewLine=null
6377            , $strValue=null
6378            , $strMinValue=null
6379            , $strMaxValue=null
6380            , $strMaskType=null
6381            , $boolButtonVisible=null
6382            , $strExampleText=null
6383            , $boolLabelAbove=null
6384            , $boolNoWrapLabel=null )
6385    {
6386        $field = new TDate( $strName, $strValue, $boolRequired, $strMinValue, $strMaxValue, $strMaskType, $boolButtonVisible );
6387        $field->setExampleText( $strExampleText );
6388        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6389        return $field;
6390    }
6391           
6392    /**
6393     * Adiciona campo tipo grupo com legenda na parte superior
6394     * Se o parametro $intHeight for null será auto height
6395     * se o parametro $intWidth for null utilizado a largura do form
6396     *
6397     * <code>
6398     *     // sem quebra nos rotulos quando excederem a largura da coluna definida
6399     *   $frm->addGroupField('gp01','Grupo Teste');
6400     *     // com quebra nos rotulos quando excederem a largura da coluna definida
6401     *   $frm->addGroupField('gp01','Grupo Teste',null,null,null,true);
6402     * </code>
6403     *
6404     * @param string $strName          - 01: Nome Id
6405     * @param string $strLegend        - 02: Label que irá aparecer para o usuario 
6406     * @param integer $intHeight       - 03: Altura do grupo. NULL = auto height
6407     * @param integer $intWidth        - 04: Largura do grupo. NULL = largura do form
6408     * @param boolean $boolNewLine     - 05: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6409     * @param boolean $boolNoWrapLabel - 06:
6410     * @param boolean $boolCloseble    - 07: pode fechar ou não
6411     * @param string  $strAccordionId  - 08:
6412     * @param boolean $boolOpened      - 09: inicia aberto
6413     * @param string $imgOpened        - 10:
6414     * @param string $imgClosed        - 11:
6415     * @param boolean $boolOverflowX   - 12:
6416     * @param boolean $boolOverflowY   - 13:
6417     * @return TGroupBox
6418     */
6419    public function addGroupField( $strName
6420                   , $strLegend=null
6421                , $strHeight=null
6422                , $strWidth=null
6423                , $boolNewLine=null
6424                , $boolNoWrapLabel=null
6425                , $boolCloseble=null
6426                , $strAccordionId=null
6427                , $boolOpened=null
6428                , $imgOpened=null
6429                , $imgClosed=null
6430                , $boolOverflowX=null
6431                , $boolOverflowY=null )
6432    {
6433        //$strWidth = is_null($strWidth) ? $this->getMaxWidth('group') : $strWidth;
6434        $field = new TGroup( $strName, $strLegend, $strHeight, $strWidth,$boolCloseble,$boolOpened,$boolOverflowY,$boolOverflowX );
6435        $field->setAccordionId($strAccordionId);
6436        $this->addDisplayControl( new TDisplayControl( null, $field, false, $boolNewLine ) );
6437        $field->setColumns( $this->getColumns() );
6438        $this->currentContainer[ ] = $field;
6439        if( !is_null($strHeight))
6440        {
6441            $field->setOverFlowY(true);
6442        }
6443        return $field;
6444    }
6445           
6446   /**
6447    * Campo de uso geral para insersão manual de códigos html na página
6448    *
6449    * Se os parametros width ou height não forem informados, serão
6450    * definidos como "auto"
6451    *
6452    * Se o label for null, não será criado o espaço referente a ele no formulário, para criar
6453    * um label invisível defina como "" o seu valor
6454    *
6455    * criado o espaço
6456    * @param string $strName        - 1: Nome do campo            
6457    * @param string $strValue       - 2: Texto HTML que irá aparece dentro
6458    * @param string $strIncludeFile - 3: Arquivo que será incluido
6459    * @param string $strLabel       - 4: label do campo
6460    * @param string $strWidth       - 5:
6461    * @param string $strHeight      - 6: 
6462    * @param boolean $boolNewLine   - 7: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6463    * @param boolean $boolLabelAbove  8:
6464    * @return THtml Field
6465    */
6466   public function addHtmlField( $strName
6467                               , $strValue=null
6468                               , $strIncludeFile=null
6469                               , $strLabel=null
6470                               , $strHeight=null
6471                               , $strWidth=null
6472                               , $boolNewLine=null
6473                               , $boolLabelAbove=null
6474                               , $boolNoWrapLabel=null )
6475   {
6476       //$strWidth = is_null($strWidth) ? $this->getMaxWidth('html') : $strWidth;
6477       $field = new THtml( $strName, $strValue, $strIncludeFile, $strHeight, $strWidth );
6478       $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, null, null, null, false );
6479       $this->addDisplayControl( $displayControl );
6480       return $field;
6481   }
6482   
6483   /**
6484    * Cria um campo html para exibir um gride via ajax no formulário utilizando a classe TGrid
6485    *
6486    * @example $mixFormFields - campos do formulário que serão enviados para o grid na variavel $_POST. 'seq_x,des_x' ou array( 'seq_X'=>10, 'des_x')
6487    * neste caso o valor de des_x será lido do campo do formulário
6488    *
6489    * @param string $strName            - 1: Nome do Campo
6490    * @param string $strGridFile        - 2: Caminho do arquivo
6491    * @param string $strGridId          - 3: Id do Grid
6492    * @param string $strHeight          - 4:
6493    * @param string $strWidth           - 5:
6494    * @param string  $strLoadingMessage - 6:
6495    * @param boolean $boolNewLine       - 7: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6496    * @param mixed $mixFormFields       - 8: Exemplo de uso array( 'seq_documento'=>$frm->get('seq_documento') );
6497    * @return THtml
6498    */
6499   public function addHtmlGride( $strName
6500                               , $strGridFile
6501                               , $strGridId
6502                               , $strHeight=null
6503                               , $strWidth=null
6504                               , $strLoadingMessage=null
6505                               , $boolNewLine=null
6506                               , $mixFormFields=null )
6507   {
6508       //$strWidth = is_null($strWidth) ? $this->getMaxWidth() : $strWidth;
6509       if( $strGridId )
6510       {
6511           $field = new THtml( $strName, null, null, $strHeight, $strWidth );
6512           $field->setGridFile( $strGridFile, $strGridId, $mixFormFields );
6513           $msgDefault = '<center>Carregando...<br><img width=\"190px\" height=\"20px\" src=\"' . $this->getBase() . 'imagens/processando.gif\"><center>';
6514           $strLoadingMessage = is_null( $strLoadingMessage ) ? $msgDefault : $strLoadingMessage;
6515           $field->setLoadingMessage( $strLoadingMessage );
6516           $displayControl = new TDisplayControl( null, $field, false, $boolNewLine );
6517           $this->addDisplayControl( $displayControl );
6518           return $field;
6519       }
6520   }
6521           
6522   //-----------------------------------------------------------------------------
6523   /**
6524    * Adicionar campo CPF
6525    *
6526    * @param string  $strName            -  1: Id do campo
6527    * @param string  $strLabel           -  2: Label do campo
6528    * @param boolean $boolRequired       -  3: Default FALSE = não obrigatori, TRUE = Obrigatório
6529    * @param string  $strValue           -  4: Valor inicial do campo
6530    * @param boolean $boolNewLine        -  5: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6531    * @param boolean $boolLabelAbove
6532    * @param boolean $boolNoWrapLabel
6533    * @param string  $strInvalidMessage
6534    * @param boolean $boolAlwaysValidate
6535    *
6536    * @return TCpf Field
6537    */
6538   public function addCpfField( $strName
6539                              , $strLabel=null
6540                              , $boolRequired=null
6541                              , $strValue=null
6542                              , $boolNewLine=null
6543                              , $boolLabelAbove=null
6544                              , $boolNoWrapLabel=null
6545                              , $strInvalidMessage=null
6546                              , $boolAlwaysValidate=null
6547                              , $strJsCallback=null 
6548                              )
6549   {
6550       $field = new TCpf( $strName, $strValue, $boolRequired );
6551       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6552       $field->setInvalidMessage( $strInvalidMessage );
6553       $field->setAlwaysValidate( $boolAlwaysValidate );
6554       $field->setCallback( $strJsCallback );
6555       return $field;
6556   }
6557   //-----------------------------------------------------------------------------
6558   /**
6559    * Adicionar campo CNPJ
6560    *
6561    * @param string $strName             -  1: Id do campo
6562    * @param string $strLabel            -  2: Label do campo
6563    * @param boolean $boolRequired       -  3: Default FALSE = não obrigatori, TRUE = Obrigatório
6564    * @param string $strValue            -  4: Valor inicial do campo
6565    * @param boolean $boolNewLine        -  5: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6566    * @param boolean $boolLabelAbove
6567    * @return TCnpj Field
6568    */
6569   public function addCnpjField( $strName, $strLabel=null, $boolRequired=null, $strValue=null, $boolNewLine=null, $boolLabelAbove=null, $boolNoWrapLabel=null,$strInvalidMessage=null,$boolAlwaysValidate=null,$strJsCallback=null )
6570   {
6571       $field = new TCnpj( $strName, $strValue, $boolRequired );
6572       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6573       $field->setInvalidMessage( $strInvalidMessage );
6574       $field->setAlwaysValidate( $boolAlwaysValidate );
6575       $field->setCallback( $strJsCallback );
6576       return $field;
6577   }
6578   //-----------------------------------------------------------------------------
6579   /**
6580    * Adicionar campo CPF/CNPJ, fazendo a validação do digito verificador
6581    *
6582    * @param string $strName        -  1: Id do campo
6583    * @param string $strLabel       -  2: Label do campo
6584    * @param boolean $boolRequired  -  3: Default FALSE = não obrigatori, TRUE = Obrigatório
6585    * @param string $strValue       -  4: Valor inicial do campo
6586    * @param boolean $boolNewLine   -  5: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6587    * @param boolean $boolLabelAbove
6588    * @return TCpfCnpj Field
6589    */
6590    public function addCpfCnpjField( $strName, $strLabel=null, $boolRequired=null, $strValue=null, $boolNewLine=null, $boolLabelAbove=null, $boolNoWrapLabel=null,$strInvalidMessage=null,$boolAlwaysValidate=null,$strJsCallback=null )
6591    {
6592        $field = new TCpfCnpj( $strName, $strValue, $boolRequired );
6593        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6594        $field->setInvalidMessage( $strInvalidMessage );
6595        $field->setAlwaysValidate( $boolAlwaysValidate );
6596        $field->setCallback( $strJsCallback );
6597        return $field;
6598    }
6599   //-----------------------------------------------------------------------------
6600   /**
6601    * Adicionar campo para informar o CEP
6602    *
6603    * Para preenchimento automático dos campos do formulário relacionados ao endereço,
6604    * informar o campo do formulário que deverá ser preenchido na lista de parametros.
6605    * Exemplo: para informar o cep e preencher o campo des_endereco do formulário automaticamente, fazer assim:
6606    * 
6607    * <code>
6608    * $frm->addCepField('num_cep','Cep:',true,null,null,'des_endereco');
6609    * </code>
6610    *
6611    * Chama o metodo getCepJquery no arquivo FormDin4Cep.js o parametro cepEngine irá 
6612    * definir qual será o motor de consulta. ViaCep usando Json ou BuscarCep via XML.
6613    * O ViaCep parece que não tem limite de uso, o BuscarCep é um serviço pago que oferece
6614    * algumas busca por dia de forma gratuita.
6615    *
6616    * @param string $strName              -  1: Id do campo
6617    * @param string $strLabel             -  2: Label do campo
6618    * @param boolean $boolRequired        -  3: Default FALSE = não obrigatori, TRUE = Obrigatório
6619    * @param string $strValue             -  4: Valor inicial do campo
6620    * @param boolean $boolNewLine         -  5: Default TRUE = campo em nova linha, FALSE continua na linha anterior
6621    * @param string $strFieldEndereco     -  6: id do campo endereço
6622    * @param string $strFieldBairro       -  7: id do campo bairro
6623    * @param string $strFieldCidade       -  8: id do campo cidade
6624    * @param string $strFieldCodidoUf     -  9: id do campo cod uf ibge
6625    * @param string $strFieldSiglaUf      - 10: id do campo sig uf
6626    * @param string $strFieldLogradouro   - 11: id do campo logradouro
6627    * @param string $strFieldNumero       - 12: id do campo numero
6628    * @param string $strFieldComplemento  - 13: id do complemento
6629    * @param string $strFieldCodigoMunicipio - 14: id do cod municipio. DEVE TERMINAL COM "_temp" SE for no combinar select
6630    * @param boolean $boolLabelAbove      - 15: Label sobre campo 
6631    * @param boolean $boolNoWrapLabel     - 16:
6632    * @param string $jsCallback           - 17: Js Callback
6633    * @param string $jsBeforeSend         - 18: Js Before Send
6634    * @param string $boolClearIncompleteValue - 19: 
6635    * @param string $strIncompleteMessage - 20: Mensagem se for incompleto
6636    * @param integer $cepEngine           - 21: Define o serviço de busca que cep que será usado. Default 1 = ViaCep (https://viacep.com.br/ usando json), 2 = Buscarcep (http://buscarcep.com.br usando xml)
6637    * @return TMask
6638    */
6639   public function addCepField( $strName
6640                              , $strLabel=null
6641                              , $boolRequired=null
6642                              , $strValue=null
6643                              , $boolNewLine=null
6644                              , $strFieldEndereco=null
6645                              , $strFieldBairro=null
6646                              , $strFieldCidade=null
6647                              , $strFieldCodidoUf=null
6648                              , $strFieldSiglaUf=null
6649                              , $strFieldNumero=null
6650                              , $strFieldComplemento=null
6651                              , $strFieldCodigoMunicipio=null
6652                              , $boolLabelAbove=null
6653                              , $boolNoWrapLabel=null
6654                              , $jsCallback=null
6655                              , $jsBeforeSend=null
6656                              , $boolClearIncompleteValue=null
6657                              , $strIncompleteMessage=null
6658                              , $cepEngine=1)
6659   {
6660       $boolClearIncompleteValue = ( $boolClearIncompleteValue === false ? 'false' : 'true' );
6661       $field = new TMask( $strName, $strValue, '99.999-999', $boolRequired );
6662       $field->setFieldType( 'cep' );
6663       $field->addEvent( 'onBlur', 'fwValidarTamanhoCep(this,'.$boolClearIncompleteValue.',"'.$strIncompleteMessage.'")' );
6664       $arrFields = array( );
6665       $arrClearFields = array( );
6666       if( isset( $strFieldEndereco ) )
6667       {
6668           $arrFields[ 'endereco' ] = $strFieldEndereco;
6669           $arrClearFields[ ] = $strFieldEndereco;
6670       }
6671       if( isset( $strFieldBairro ) )
6672       {
6673           $arrFields[ 'bairro' ] = $strFieldBairro;
6674           $arrClearFields[ ] = $strFieldBairro;
6675       }
6676       /*
6677        if( isset($strFieldLogradouro) )
6678        {
6679        $arrFields['logradouro'] = $strFieldLogradouro;
6680        $arrClearFields[]=$strFieldLogradouro;
6681        }
6682        */
6683       if( isset( $strFieldCidade ) )
6684       {
6685           $arrFields[ 'cidade' ] = $strFieldCidade;
6686           $arrClearFields[ ] = $strFieldCidade;
6687       }
6688       if( isset( $strFieldCodidoUf ) )
6689       {
6690           $arrFields[ 'ibge_uf' ] = $strFieldCodidoUf;
6691           $arrClearFields[ ] = $strFieldCodidoUf;
6692       }
6693       if( isset( $strFieldNumero ) )
6694       {
6695           $arrFields[ 'numero' ] = $strFieldNumero;
6696           $arrClearFields[ ] = $strFieldNumero;
6697       }
6698       if( isset( $strFieldSiglaUf ) )
6699       {
6700           $arrFields[ 'uf' ] = $strFieldSiglaUf;
6701           $arrClearFields[ ] = $strFieldSiglaUf;
6702       }
6703       if( isset( $strFieldComplemento ) )
6704       {
6705           $arrFields[ 'complemento' ] = $strFieldComplemento;
6706           $arrClearFields[ ] = $strFieldComplemento;
6707       }
6708       if( isset( $strFieldCodigoMunicipio ) )
6709       {
6710           $arrFields[ 'ibge_municipio_verificador' ] = $strFieldCodigoMunicipio;
6711           $arrClearFields[ ] = $strFieldCodigoMunicipio;
6712       }
6713       $qtd = CountHelper::count($arrFields);
6714       if( $qtd > 0 )
6715       {
6716           $buttonName = $field->getId() . '_btn_consultar';
6717           $getCepJsCallback = ($jsCallback ? $jsCallback : 'null');
6718           $getCepJsBeforeSend = ($jsBeforeSend ? $jsBeforeSend : 'null');
6719           if( $cepEngine == 2){
6720               $buttonOnClick = 'getCepJquery("' . $field->getId() . '",'.json_encode( $arrFields ).','.$getCepJsCallback.','.$getCepJsBeforeSend.')';
6721           } else {
6722               $buttonOnClick = 'getCepJsonViaCep("' . $field->getId() . '",'.json_encode( $arrFields ).','.$getCepJsCallback.','.$getCepJsBeforeSend.')';
6723           }
6724           $button = new TButton( $buttonName , 'Consultar', null, $buttonOnClick, null, null, null, 'Infome o CEP e clique aqui para autocompletar os campos de endereço.' );
6725           $field->addEvent( 'onKeyUp', 'fwFieldCepKeyUp(this,event,"' . implode( ',', $arrClearFields ) . '")' );
6726           $field->add( $button );
6727       }
6728       $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, null, null, null, true );
6729       $this->addDisplayControl( $displayControl );
6730       return $field;
6731   }           
6732   //-----------------------------------------------------------------------------
6733           
6734    /**
6735    * Adicionar campo tipo combobox ou menu select
6736    *
6737    * $mixOptions = array no formato "key=>value", nome do pacote oracle e da função a ser executada, comando sql ou tabela|condicao
6738    * $strKeyColumn = nome da coluna que será utilizada para preencher os valores das opções
6739    * $strDisplayColumn = nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário
6740    * $strDataColumns = informações extras do banco de dados que deverão ser adicionadas na tag option do campo select
6741    *
6742    * <code>
6743    *     // exemplos
6744    *     $frm->addSelectField('tipo','Tipo:',false,'1=Tipo 1,2=Tipo 2');
6745    *     $frm->addSelectField('tipo','Tipo:',false,'tipo');
6746    *     $frm->addSelectField('tipo','Tipo:',false,'select * from tipo order by descricao');
6747    *     $frm->addSelectField('tipo','Tipo:',false,'tipo|descricao like "F%"');
6748    *
6749    *  //Exemplo espcial - Campo Obrigatório e sem senhum elemento pre selecionado.
6750    *  $frm->addSelectField('tipo','Tipo',true,$tiposDocumentos,null,null,null,null,null,null,' ','');
6751    * </code>
6752    *
6753    * @param string  $strName        - 1: ID do campo
6754    * @param string  $strLabel       - 2: Label do campo
6755    * @param boolean $boolRequired   - 3: Default FALSE = não obrigatori, TRUE = Obrigatório
6756    * @param mixed   $mixOptions         - 04: Array dos valores. no formato "id=>value", nome do pacote oracle e da função a ser executada, comando sql ou tabela|condicao
6757    * @param boolean $boolNewLine        - 05: Default TRUE = cria nova linha , FALSE = fica depois do campo anterior
6758    * @param boolean $boolLabelAbove     - 06: Default FALSE = Label mesma linha, TRUE = Label acima
6759    * @param mixed   $mixValue           - 07: Valor DEFAULT, informe o ID do array
6760    * @param boolean $boolMultiSelect    - 08: Default FALSE = SingleSelect, TRUE = MultiSelect
6761    * @param integer $intSize            - 09: Default 1. Num itens que irão aparecer no MultiSelect
6762    * @param integer $intWidth           - 10: Largura em Pixels
6763    * @param string  $strFirstOptionText - 11: First Key in Display. Informe um valor diferente de '' ou null para mostrar um Label.
6764    * @param string  $strFirstOptionValue- 12: Frist Valeu in Display, use value NULL for required. Para o valor DEFAULT informe o ID do $mixOptions e $strFirstOptionText = '' e não pode ser null
6765    * @param string  $strKeyColumn       - 13: Nome da coluna que será utilizada para preencher os valores das opções
6766    * @param string  $strDisplayColumn   - 14: Nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário
6767    * @param string  $boolNoWrapLabel    - 15:
6768    * @param string  $strDataColumns     - 16: Informações extras do banco de dados que deverão ser adicionadas na tag option do campo select
6769    * @return TSelect
6770    */
6771    public function addSelectField( $strName
6772                               , $strLabel=null
6773                               , $boolRequired=null
6774                               , $mixOptions=null
6775                               , $boolNewLine=null
6776                               , $boolLabelAbove=null
6777                               , $mixValue=null
6778                               , $boolMultiSelect=null
6779                               , $intSize=null
6780                               , $intWidth=null
6781                               , $strFirstOptionText=null
6782                               , $strFirstOptionValue=null
6783                               , $strKeyColumn=null
6784                               , $strDisplayColumn=null
6785                               , $boolNoWrapLabel=null
6786                               , $strDataColumns=null ) {
6787           
6788           if( ( substr( $strName, 0, 6 ) == 'cod_uf' || $strName === 'uf') && $mixOptions === null ) {
6789               $mixOptions = $this->getUfs();
6790           } else if( substr( $strName, 0, 4 ) == 'sit_' && $mixOptions === null ) {
6791               $mixOptions = 'N=Não,S=Sim';
6792           }
6793           $field = new TSelect( $strName, $mixOptions, $mixValue, $boolRequired, $boolMultiSelect, $intSize, $intWidth, $strFirstOptionText, $strFirstOptionValue, $strKeyColumn, $strDisplayColumn, $strDataColumns);
6794           $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
6795           $this->addDisplayControl( $displayControl );
6796           return $field;
6797    }
6798    //-----------------------------------------------------------------------------
6799    /**
6800    * Adicicionar campo tipo radiobutton
6801    * 
6802    * 
6803    * @param string $strName        - 1: field ID
6804    * @param string $strLabel       - 2: Label field
6805    * @param boolean $boolRequired  - 3: TRUE = Required, FALSE = not Required
6806    * @param array $arrOptions      - 4: Array Options
6807    * @param boolean $boolNewLine   - 5: TRUE = new line, FALSE = no, DEFAULT ou NULL = FALSE
6808    * @param boolean $boolLabelAbove- 6: TRUE = Titulo em cima das opções, FALSE = titulo lateral
6809    * @param string  $strValue      - 7: Valor DEFUALT, informe do id do array
6810    * @param integer $intQtdColumns - 8: Quantidade de colunas, valor DEFAULT = 1;
6811    * @param integer $intWidth
6812    * @param integer $intHeight
6813    * @param integer $intPaddingItems
6814    * @param boolean $boolNoWrapLabel
6815    * @param boolean $boolNowrapText
6816    * @return TRadio
6817    */
6818    public function addRadioField( $strName
6819                                   , $strLabel=null
6820                                   , $boolRequired=null
6821                                   , $arrOptions=null
6822                                   , $boolNewLine=null
6823                                   , $boolLabelAbove=null
6824                                   , $strValue=null
6825                                   , $intQtdColumns=null
6826                                   , $intWidth=null
6827                                   , $intHeight=null
6828                                   , $intPaddingItems=null
6829                                   , $boolNoWrapLabel=null
6830                                   , $boolNowrapText=null
6831                                   ){
6832       $field = new TRadio( $strName, $arrOptions, $strValue, $boolRequired, $intQtdColumns, $intWidth, $intHeight, $intPaddingItems,$boolNowrapText);
6833       $field->setNoWrapText($boolNowrapText);
6834       $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
6835       $this->addDisplayControl( $displayControl );
6836       $field->addEvent('onDblclick','this.checked=false;fwFieldCheckBoxClick(this);');
6837       return $field;
6838    }
6839    //-----------------------------------------------------------------------------
6840    /***
6841    * Adicicionar campo tipo checkbox
6842    * @param string $strName         - 1: field ID
6843    * @param string $strLabel        - 2: Label field
6844    * @param boolean $boolRequired   - 3: TRUE = Required, FALSE = not Required
6845    * @param array $arrOptions       - 4: array no formato "id=>valeu" para identificar a(s) opção(ões) selecionada(s)
6846    * @param boolean $boolNewLine    - 5: TRUE = new line, FALSE = no, DEFAULT ou NULL = FALSE
6847    * @param boolean $boolLabelAbove - 6: TRUE = Titulo em cima das opções, FALSE = titulo lateral
6848    * @param array $arrValues        - 7: Valor DEFAULT, informe do ID do arrOptions ou UM array no forma "key=>id" para maracar mais de um valor ao mesmo tempo
6849    * @param integer $intQtdColumns  - 8: Quantidade de colunas
6850    * @param integer $intWidth       - 9: Largura
6851    * @param integer $intHeight      -10: Al
6852    * @param integer $intPaddingItems
6853    * @param boolean $boolNoWrapLabel
6854    * @param boolean $boolNowrapText
6855    * @return TCheck
6856    */
6857    public function addCheckField( $strName
6858                               , $strLabel=null
6859                               , $boolRequired=null
6860                               , $arrOptions=null
6861                               , $boolNewLine=null
6862                               , $boolLabelAbove=null
6863                               , $arrValues=null
6864                               , $intQtdColumns=null
6865                               , $intWidth=null
6866                               , $intHeight=null
6867                               , $intPaddingItems=null
6868                               , $boolNoWrapLabel=null 
6869                               , $boolNowrapText=null)
6870    {
6871       $field = new TCheck( $strName, $arrOptions, $arrValues, $boolRequired, $intQtdColumns, $intWidth, $intHeight, $intPaddingItems );
6872       $field->setNoWrapText($boolNowrapText);
6873       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
6874       return $field;
6875    }
6876   //-----------------------------------------------------------------------------
6877    /**
6878    * Adicona controle de paginação através de abas
6879    * Se o parametro $intHeight for null será assumido o height do form, para ser auto, informar "auto";
6880    * se o parametro $intWidth for null utilizado a largura máxima do form
6881    * A função informada no parametro $strOnAfterClick e a função onBeforeClick,
6882    * recebem 3 parametros: a rotulo da aba, o id do page control e o id da aba clicada em caixa baixa.
6883    * Se a função onBeforeClick retornar falso, não ocorrerá a mudança de aba.
6884    *
6885    * @example $pc = $frm->addPageControl('pc',null,null,'pcClick','pcAfterClick');
6886    * @example function pcAfterClick(aba,pageControl,id)
6887    *
6888    * @param mixed $strName           - 01 : id do PageControl
6889    * @param mixed $strHeight         - 02 : Se o parametro $intHeight for null será assumido o height do form, para ser auto, informar "auto";
6890    * @param mixed $strWidth          - 03 : se o parametro $intWidth for null utilizado a largura máxima do form
6891    * @param mixed $strOnBeforeClick  - 04 : 
6892    * @param mixed $strOnAfterClick
6893    * @param mixed $boolShowTabs
6894    * @param bool $boolNewLine
6895    * @return TPageControl
6896    */
6897    public function addPageControl( $strName, $strHeight=null, $strWidth=null, $strOnBeforeClick=null, $strOnAfterClick=null, $boolShowTabs=null, $boolNewLine=null )
6898    {
6899       $boolNewLine = is_null( $strWidth ) ? true : $boolNewLine;
6900       $field = new TPageControl( $strName, $strHeight, $strWidth, $boolShowTabs, $strOnBeforeClick, $strOnAfterClick );
6901       $this->addDisplayControl( new TDisplayControl( null, $field, false, $boolNewLine ) );
6902       $field->setColumns( $this->getColumns() );
6903       
6904       /*
6905        if( $this->getCurrentContainer() )
6906        {
6907        $height = $this->getCurrentContainer()->getHeight();
6908        $field->setColumns( $this->getCurrentContainer()->getColumns() );
6909        if( $this->getCurrentContainer()->getFieldType()=='group')
6910        {
6911        if( !$field->getWidth())
6912        {
6913        $diff = ( $this->getCurrentContainer()->getOverflowY()=='hidden' ? 50 : 64 );
6914        $field->setWidth( ( $this->getCurrentContainer()->getWidth() - $diff ) );
6915        }
6916        if( $field->getHeight() )
6917        {   if( $field->getHeight() > $height)
6918        {
6919        $this->getCurrentContainer()->setHeight( ( $field->getHeight() + 20));
6920        }
6921        }
6922        else
6923        {
6924        if( $this->getCurrentContainer()->getOverflowY()=='hidden')
6925        {
6926        $field->setHeight( ( $this->getCurrentContainer()->getHeight()-47 ) );
6927        }
6928        }
6929        }
6930        else
6931        {
6932        $strHeight = is_null( $strHeight ) ? '250' : $strHeight;
6933        $strWidth = is_null( $strWidth ) ? $this->getCurrentContainer()->getWidth()-20 : $strWidth;
6934        }
6935        }
6936        else
6937        {
6938        if( is_null( $strWidth ) )
6939        {
6940        if( $this->getOverFlowY()=='hidden')
6941        {
6942        $field->setWidth( $this->getWidth()-40 );
6943        }
6944        else
6945        {
6946        $field->setWidth( $this->getWidth()-60 );
6947        }
6948        }
6949        }
6950        */
6951       $this->currentContainer[ ] = $field;
6952       return $field;
6953    }
6954          
6955    /**
6956     * 
6957     * Adiciona campo de entrada de dados numérico
6958     * 
6959     * @param string $strName            - 1: ID do campo
6960     * @param string $strLabel           - 2: Label do campo, que irá aparecer na tela do usuario
6961     * @param integer $intMaxLength      - 3: Quantidade maxima de digitos.
6962     * @param boolean $boolRequired      - 4: Obrigatório
6963     * @param integer $intDecimalPlaces  - 5: Quantidade de casas decimais.
6964     * @param boolean $boolNewLine       - 6: Campo em nova linha. Default = true = inicia em nova linha, false = continua na linha anterior 
6965     * @param string $strValue           - 7: valor inicial do campo
6966     * @param string $strMinValue        - 8: valor minimo permitido. Null = não tem limite.
6967     * @param string $strMaxValue        - 9: valor maxima permitido. Null = não tem limite.
6968     * @param boolean $boolFormatInteger -10: Inteiros com ou sem ponto de separação
6969     * @param string $strDirection
6970     * @param boolean $boolAllowZero
6971     * @param boolean $boolAllowNull
6972     * @param boolean $boolLabelAbove
6973     * @param boolean $boolNoWrapLabel
6974     * @param string $strHint
6975     * @return TNumber
6976     */       
6977    public function addNumberField(string $strName
6978                                   , string $strLabel=null
6979                                   , $intMaxLength
6980                                   , $boolRequired=null
6981                                   , $intDecimalPlaces=null
6982                                   , $boolNewLine=null
6983                                   , $strValue=null
6984                                   , $strMinValue=null
6985                                   , $strMaxValue=null
6986                                   , $boolFormatInteger=null
6987                                   , $strDirection=null
6988                                   , $boolAllowZero=null
6989                                   , $boolAllowNull=null
6990                                   , $boolLabelAbove=null
6991                                   , $boolNoWrapLabel=null
6992                                   , $strHint=null )
6993    {
6994        $field = new TNumber( $strName
6995                            , $strValue
6996                            , $intMaxLength
6997                            , $boolRequired
6998                            , $intDecimalPlaces
6999                            , $strMinValue
7000                            , $strMaxValue
7001                            , $boolFormatInteger
7002                            , $strDirection, $boolAllowZero, $boolAllowNull );
7003        if( $strHint ) {
7004            $field->setHint( $strHint );
7005        }
7006        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7007        return $field;
7008    }
7009    
7010    /**
7011     * Adiciona campo para entrada de endereço eletrônico - e-mail
7012     *
7013     * @param string $strName       - 1: ID do campo
7014     * @param string $strLabel      - 2: Label do campo, que irá aparecer na tela do usuario
7015     * @param integer $intMaxLength - 3: Tamanho maximo de caracteres
7016     * @param boolean $boolRequired - 4: Obrigatório
7017     * @param integer $intSize      - 5: Tamanho do campo na tela
7018     * @param boolean $boolNewLine  - 6: Campo em nova linha
7019     * @param string  $strValue     - 7: valor inicial do campo
7020     * @param boolean $boolLabelAbove-8: Label acima, DEFAULT is FALSE na mesma linha
7021     * @return TEmail
7022     */
7023    public function addEmailField( string $strName, string $strLabel=null, $intMaxLength, $boolRequired=null, $intSize=null, $boolNewLine=null, $strValue=null, $boolLabelAbove=null, $boolNoWrapLabel=null )
7024    {
7025        $field = new TEmail( $strName, $strValue, $intMaxLength, $boolRequired, $intSize );
7026        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7027        return $field;
7028    }
7029    
7030    /**
7031     * Adiciona campo de entrada para telefone e fax
7032     *
7033     * @param string $strName       - 1: ID do campo
7034     * @param string $strLabel      - 2: Label do campo, que irá aparecer na tela do usuario
7035     * @param boolean $boolRequired - 3: Obrigatório
7036     * @param boolean $boolNewLine  - 4: Campo em nova linha
7037     * @param string $strValue      - 5: valor inicial do campo
7038     * @param boolean $boolLabelAbove
7039     * @param boolean $boolNoWrapLabel
7040     * @return TFone
7041     */
7042    public function addFoneField( $strName
7043                                , $strLabel=null
7044                                , $boolRequired=null
7045                                , $boolNewLine=null
7046                                , $strValue=null
7047                                , $boolLabelAbove=null
7048                                , $boolNoWrapLabel=null )
7049    {
7050        $field = new TFone( $strName, $strValue, $boolRequired );
7051        $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
7052        $this->addDisplayControl( $displayControl );
7053        return $field;
7054    }
7055           
7056    /**
7057    * Adicinar campos para entrada de dados de coordenada geográfica no formato GMS ( GRAU, MIN E SEG )
7058    *
7059    * @param mixed $strName
7060    * @param mixed $strLabel
7061    * @param mixed $boolRequired
7062    * @param mixed $boolNewLine
7063    * @param mixed $strLatY
7064    * @param mixed $strLonX
7065    * @param mixed $strFieldNameLat
7066    * @param mixed $strFieldNameLon
7067    * @param string $strLabels - rótulos dos campos separados por virgula: ex: 'Grau:,Min:,Seg:'
7068    * @param string $strSymbols - simbolo para grau, minuto e segundo separado por vígula:. ex: °,',"
7069    * @param mixed $intMapHeight
7070    * @param mixed $intMapWidth
7071    * @param mixed $boolLabelAbove
7072    * @param mixed $boolNoWrapLabel
7073    * @param string $strMapHeaderText
7074    * @param string $strMapHeaderFontColor
7075    * @param string $strMapHeaderFontSize
7076    * @return TCoordGMS
7077    */
7078    public function addCoordGMSField( $strName, $strLabel=null, $boolRequired=null, $boolNewLine=null, $strLatY=null, $strLonX=null, $strFieldNameLat=null, $strFieldNameLon=null, $strLabels=null, $strSymbols=null, $intSymbolsFontSize=null, $intMapHeight=null, $intMapWidth=null, $boolLabelAbove=null, $boolNoWrapLabel=null,$strMapHeaderText=null,$strMapHeaderFontColor=null,$strMapHeaderFontSize=null)
7079    {
7080        $field = new TCoordGMS( $strName, $boolRequired, $strLatY, $strLonX, $strFieldNameLat, $strFieldNameLon, $strLabels, $strSymbols,$intSymbolsFontSize,$intMapHeight, $intMapWidth,$strMapHeaderText,$strMapHeaderFontColor,$strMapHeaderFontSize);
7081        $field->setCustomHintEnabled( $this->getCustomHintEnabled() );
7082        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7083        return $field;
7084    }
7085
7086    /**
7087    * Campo para entrada de senhas
7088    *
7089    * @param string $strName              - 1: ID do campo
7090    * @param string $strLabel             - 2: Label
7091    * @param boolean $boolRequired        - 3: Campo Obrigatório, DEFALUT is FALSE não Obrigatório.
7092    * @param boolean $boolNewLine         - 4: Em nova linha, DEFALUT is TRUE não Obrigatório.
7093    * @param integer $intmaxLength        - 5: Tamanho maximo
7094    * @param string $strValue             - 6: valor inicial do campo
7095    * @param boolean $boolLabelAbove      - 7: Label acima, DEFAULT is FALSE na mesma linha
7096    * @param boolean $boolNoWrapLabel
7097    * @param integer $intSize
7098    * @param boolean $boolUseVirtualKeyboard
7099    * @param boolean $boolShowVirtualKeyboardImage
7100    * @param boolean $boolReadOnly
7101    * @return TPassword
7102    */
7103    public function addPasswordField( $strName
7104                                    , $strLabel=null
7105                                    , $boolRequired=null
7106                                    , $boolNewLine=null
7107                                    , $intmaxLength=null
7108                                    , $strValue=null
7109                                    , $boolLabelAbove=null
7110                                    , $boolNoWrapLabel=null
7111                                    , $intSize=null
7112                                    , $boolUseVirtualKeyboard=null
7113                                    , $boolShowVirtualKeyboardImage=null
7114                                    , $boolReadOnly=null )
7115    {
7116        $field = new TPassword( $strName, $strValue, $intmaxLength, $boolRequired, $intSize, $boolUseVirtualKeyboard, $boolShowVirtualKeyboardImage, $boolReadOnly);
7117        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7118        return $field;
7119    }
7120    
7121    /**
7122    * Campo para entrada de numero de processo do serviço público
7123    *
7124    * @param string $strName         - 1: ID do campo
7125    * @param string $strLabel        - 2: Label
7126    * @param string $boolRequired    - 3: Campo Obrigatório, DEFALUT is FALSE não Obrigatório.
7127    * @param string $boolNewLine     - 4: Em nova linha, DEFALUT is TRUE não Obrigatório.
7128    * @param string $strValue        - 5: valor inicial do campo
7129    * @param string $boolLabelAbove  - 6: Label acima, DEFAULT is FALSE na mesma linha
7130    * @return TProcesso
7131    */
7132    public function addProcessoField( $strName, $strLabel=null, $boolRequired=null, $boolNewLine=null, $strValue=null, $boolLabelAbove=null, $boolNoWrapLabel=null )
7133    {
7134       $field = new TProcesso( $strName, $strValue, $boolRequired );
7135       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7136       return $field;
7137    }
7138
7139    /**
7140    * Campo para entrada de numeros de processos do TJDFT
7141    *
7142    * @param string $strName        - 1: ID do campo
7143    * @param string $strLabel       - 2: Label
7144    * @param string $boolRequired   - 3: Campo Obrigatório, DEFALUT is FALSE não Obrigatório.
7145    * @param string $boolNewLine    - 4: Em nova linha, DEFALUT is TRUE não Obrigatório.
7146    * @param string $strValue       - 5: valor inicial do campo
7147    * @param string $boolLabelAbove - 6: Label acima, DEFAULT is FALSE na mesma linha
7148    * @param boolean $boolAcceptNumeroDistribuicao 
7149    * @param boolean $boolAcceptNumeroUnico 
7150    * @return TNumeroTJDFT
7151    */
7152    public function addNumeroTJDFTField( $strName, $strLabel=null, $boolRequired=null, $boolNewLine=null, $strValue=null, $boolLabelAbove=null, $boolNoWrapLabel=null, $boolAcceptNumeroDistribuicao=true, $boolAcceptNumeroUnico = true )
7153    {
7154       $field = new TNumeroTJDFT( $strName, $strValue, $boolRequired, $boolAcceptNumeroDistribuicao, $boolAcceptNumeroUnico);
7155       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7156       return $field;
7157    }    
7158    
7159    /***
7160    * Campos para anexar arquivo. Pode ser um carregamento sincrono ou assincrono via ajax.
7161    *
7162    * Será incluido no $_POST 4 elementos com os nomes:
7163    * <code>
7164    *   $_POST['strName_temp'] - caminho temporario;
7165    *   $_POST['strName_type'] - mime type;
7166    *   $_POST['strName_size'] - tamanho em kb;
7167    *   $_POST['strName_name'] - nome arquivo;
7168    * </code>
7169    * 
7170     * @param string  $strName         - 1: ID do campo
7171     * @param string  $strLabel        - 2: Rotulo do campo que irá aparece na tela
7172     * @param boolean $boolRequired    - 3: Obrigatório
7173     * @param string  $strAllowedFileTypes - Tipos de arquivos
7174     * @param string  $strMaxFileSize  - Input the max size file with K, M for Megabit (Mb) or G for Gigabit (Gb). Example 2M = 2 Mb = 2048Kb.
7175     * @param integer $intFieldSize
7176     * @param boolean $boolAsync       - 7: Type TFile (POST) ou TFileAsync
7177     * @param boolean $boolNewLine
7178     * @param string  $strJsCallBack
7179     * @param boolean $boolLabelAbove
7180     * @param boolean $boolNoWrapLabel
7181     * @param string  $strMessageInvalidFileType
7182     * @return TFile|TFileAsync
7183     */
7184    public function addFileField( $strName
7185                               , $strLabel=null
7186                               , $boolRequired=null
7187                               , $strAllowedFileTypes=null
7188                               , $strMaxFileSize=null
7189                               , $intFieldSize=null
7190                               , $boolAsync=null
7191                               , $boolNewLine=null
7192                               , $strJsCallBack=null
7193                               , $boolLabelAbove=null
7194                               , $boolNoWrapLabel=null
7195                               , $strMessageInvalidFileType=null ) {
7196           $this->setEncType( 'multipart/form-data' );
7197           if( $boolAsync === false ) {
7198               $field = new TFile( $strName, $intFieldSize, $boolRequired, $strAllowedFileTypes, $strMaxFileSize );
7199           } else {
7200               $field = new TFileAsync( $strName, $intFieldSize, $boolRequired, $strAllowedFileTypes, $strMaxFileSize, null, $strJsCallBack , $strMessageInvalidFileType);
7201           }
7202           $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, null, null, null, true ) );
7203           return $field;
7204    }
7205           
7206    /**
7207    * Classe para criação de campos de entrada de dados com máscara de edição
7208    *
7209    * a - Represents an alpha character (A-Z,a-z)
7210    * 9 - Represents a numeric character (0-9)
7211    * * - Represents an alphanumeric character (A-Z,a-z,0-9)
7212    *
7213    * @link http://digitalbush.com/projects/masked-input-plugin/
7214    *
7215    * @param string $strName         - 1: ID do campo
7216    * @param string $strLabel        - 2: Rotulo do campo que irá aparece na tela
7217    * @param boolean $boolRequired   - 3: Obrigatório
7218    * @param string $strMask
7219    * @param boolean $boolNewLine
7220    * @param string $strValue
7221    * @param boolean $boolLabelAbove
7222    * @return TMask
7223    */
7224    public function addMaskField( $strName, $strLabel=null, $boolRequired=null, $strMask=null, $boolNewLine=null, $strValue=null, $boolLabelAbove=null, $boolNoWrapLabel=null, $strExampleText=null )
7225    {
7226       $field = new TMask( $strName, $strValue, $strMask, $boolRequired );
7227       $field->setExampleText( $strExampleText );
7228       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7229       
7230       return $field;
7231    }
7232    
7233    /**
7234     * Campo para criação de hiperlink no formulário
7235     *
7236     * @param string $strName           - 1: ID do campo
7237     * @param string $strLabel          - 2: Rotulo do campo que irá aparece na tela
7238     * @param string $strValue          - 3: Valor
7239     * @param string $strOnClick        - 4: Nome metodo JavScript
7240     * @param string $strUrl            - 5: Url destinos
7241     * @param string $strTarget
7242     * @param boolean $boolNewLine
7243     * @param boolean $boolLabelAbove
7244     * @param boolean $boolNoWrapLabel
7245     * @param string $strHint
7246     * @return TLink
7247     */
7248    public function addLinkField( $strName, $strLabel=null, $strValue=null, $strOnClick=null, $strUrl=null, $strTarget=null, $boolNewLine=null, $boolLabelAbove=null, $boolNoWrapLabel=null, $strHint=null )
7249    {
7250        $field = new TLink( $strName, $strValue, $strOnClick, $strUrl, $strTarget, $strHint );
7251        $displayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
7252        $this->addDisplayControl( $displayControl );
7253        return $field;
7254    }
7255           
7256    /**
7257     * Método para criar campo de edição de horas
7258     *
7259     * @param string  $strName             - 1: ID do campo
7260     * @param string  $strLabel            - 2: Rotulo do campo que irá aparece na tela
7261     * @param boolean $boolRequired        - 3: True = Obrigatório; False (Defalt) = Não Obrigatório
7262     * @param string  $strMinValue         - 4: Menor Valor
7263     * @param string  $strMaxValue         - 5: Maior valor
7264     * @param string  $strMask             - 6: HM, HMS
7265     * @param boolean $boolNewLine         - 7: Em nova linha. DEFAULT = true
7266     * @param string  $strValue            - 8:
7267     * @param boolean $boolLabelAbove
7268     * @param boolean $boolNoWrapLabel
7269     * @return TTime
7270     */
7271    public function addTimeField( $strName
7272                                , $strLabel=null
7273                            , $boolRequired=null, $strMinValue=null
7274                            , $strMaxValue=null, $strMask=null, $boolNewLine=null
7275                            , $strValue=null, $boolLabelAbove=null
7276                            , $boolNoWrapLabel=null )
7277    {
7278        $field = new TTime( $strName
7279                          , $boolRequired
7280                          , $strValue
7281                          , $strMinValue
7282                          , $strMaxValue
7283                          , $strMask );
7284        $control = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
7285        $this->addDisplayControl( $control );
7286        return $field;
7287    }
7288           
7289    /**
7290    * Adiciona campo para seleção de cor
7291    *
7292    * @param string $strName
7293    * @param string $strLabel
7294    * @param mixed $boolRequired
7295    * @param mixed $boolNewLine
7296    * @param string $strValue
7297    * @param boolean $boolLabelAbove
7298    * @param boolean $boolNoWrapLabel
7299    * @return TColorPicker
7300    */
7301    public function addColorPickerField( $strName, $strLabel=null, $boolRequired=null, $boolNewLine=null, $strValue=null, $boolLabelAbove=null, $boolNoWrapLabel=null )
7302    {
7303       $field = new TColorPicker( $strName, $boolRequired, $strValue );
7304       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7305       return $field;
7306    }
7307    
7308    /**
7309    * Adicionar treeview ao formulário.
7310    *
7311    * @param mixed $strName            - 1: ID do campo
7312    * @param string $strRootLabel      - 2: Label do campo
7313    * @param mixed $arrData            - 3: array de dados
7314    * @param mixed $strParentFieldName - 4: ID do campo chave do pai
7315    * @param mixed $strChildFieldName  - 5: ID do campo chave dos filhos
7316    * @param mixed $strDescFieldName   - 6: Texto da descrição dos nos da arvore
7317    * @param mixed $strInitialParentKey- 7:
7318    * @param mixed $mixUserDataFields  - 8: campos que serão passados quando clicamos no nó da arvore
7319    * @param bool $strHeight           - 9: altura
7320    * @param bool $strWidth            -10: largura
7321    * @param mixed $jsOnClick          -11:
7322    * @param mixed $jsOnCheck          -12:
7323    * @param mixed $jsOnDrag           -13:
7324    * @param mixed $boolEnableCheckBoxes - 14: Habilita campo Checks
7325    * @param mixed $boolEnableRadioButtons - 15:
7326    * @param mixed $boolEnableTreeLines -16:
7327    * @param mixed $strLabel            -17:
7328    * @param mixed $boolLabelAbove      -18:
7329    * @param mixed $boolNewLine         -19: boolNewLine
7330    * @param mixed $boolNoWrapLabel     -20: boolNoWrapLabel
7331    * @param mixed $mixFormSearchFields -21:
7332    * @param mixed $boolShowToolBar     -22:
7333    * @param mixed $startExpanded       -23: Se o TreeView deve iniciar expandido ou não
7334    * @return TTreeView
7335    */
7336    public function addTreeField( $strName
7337                               , $strRootLabel=null
7338                               , $arrData = null
7339                               , $strParentFieldName = null
7340                               , $strChildFieldName = null
7341                               , $strDescFieldName = null
7342                               , $strInitialParentKey=null
7343                               , $mixUserDataFields = null
7344                               , $strHeight = null
7345                               , $strWidth = null
7346                               , $jsOnClick = null
7347                               , $jsOnDblClick = null
7348                               , $jsOnCheck = null
7349                               , $jsOnDrag = null
7350                               , $boolEnableCheckBoxes = null
7351                               , $boolEnableRadioButtons = null
7352                               , $boolEnableTreeLines = null
7353                               , $strLabel = null
7354                               , $boolLabelAbove = null
7355                               , $boolNewLine = null
7356                               , $boolNoWrapLabel = null
7357                               , $mixFormSearchFields=null
7358                               , $boolShowToolBar=null
7359                               , $startExpanded=null
7360        )
7361    {
7362        $this->addJsFile( 'dhtmlx/dhtmlxcommon.js' );
7363        $this->addJsFile( 'dhtmlx/treeview/dhtmlxtree.js' );
7364        $this->addCssFile( 'dhtmlx/treeview/dhtmlxtree.css' );
7365
7366        $tree = new TTreeView( $strName
7367                             , $strRootLabel
7368                             , $arrData
7369                             , $strParentFieldName
7370                             , $strChildFieldName
7371                             , $strDescFieldName
7372                             , $strInitialParentKey
7373                             , $mixUserDataFields
7374                             , $strHeight
7375                             , $strWidth
7376                             , $jsOnClick
7377                             , $jsOnDblClick
7378                             , $jsOnCheck
7379                             , $jsOnDrag
7380                             , $boolEnableCheckBoxes
7381                             , $boolEnableRadioButtons
7382                             , $boolEnableTreeLines
7383                             , $mixFormSearchFields
7384                             , $boolShowToolBar
7385                             , $startExpanded
7386                            );
7387        //$tree->addItem(0,1,'Animal',true,'Animais');
7388        $display = new TDisplayControl( $strLabel, $tree, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
7389        $this->addDisplayControl( $display );
7390        return $tree;
7391    }
7392    
7393    /**
7394     * Permite abrir uma tag html entre os campos do formulário. Utilizado para criar áreas ou grupos de campos
7395     * para que sejam exibidos/escondidos em conjunto ou delimitados por bordas ou cor de fundo diferentes
7396     *
7397     * Exemplo:  $t = $frm->addTag('<div>'); // para abrir
7398     *             $t->setCss('border','1px solid blue');
7399     *             conteudo.......
7400     *             $t = $frm->addTag('</div>'); // para fechar
7401     * @param string $strTagType
7402     * @param string $strId
7403     * @return null
7404     */
7405    public function addTag( $strTagType, $strId = null,$boolNewLine=null )
7406    {
7407        $field = new TTag( $strTagType, $strId );
7408        $boolNewLine = is_null( $boolNewLine ) ? false : $boolNewLine;
7409        $this->addDisplayControl( new TDisplayControl( null, $field, false, $boolNewLine ) );
7410        return null;
7411    }
7412    
7413    /**
7414     * Adiciona campo para exibição de texto ou imagen dentro de um box modal.
7415     * Para incluir ajuda no form utilize setHelpOnLine
7416     *
7417     *
7418     * <code>
7419     * $frm->addBoxField('campo_1','Informe o nome completo',$this->getBase().'imagens/folder.gif',null,null,null,null,null,null,'Ajuda');
7420     * $frm->addBoxField('campo_2',null,$this->getBase().'exemplos/ajuda.html','ajax',null,null,null,null,null,'Ver arquivo de ajuda');
7421     * $frm->addBoxField('campo_3','Este é o texto de ajuda que será exibido quando o usuário clicar na imagem',null,null,null,null,null,null,null,'Exibir ajuda');
7422     * $frm->addBoxField('campo_4',null,$this->getBase()."js/jquery/facebox/stairs.jpg",'jpg','Visualizar Foto:','folder.gif',true,null,null,'Imagem');
7423     * </code>
7424     *
7425     * @param mixed $strId - identificador do campo
7426     * @param mixed $strText - texto para exibição
7427     * @param mixed $strFileName - nome do arquivo que será carregado dentro do box
7428     * @param mixed $strDataType - define o conteudo que será carregado. Ex: image, ajax
7429     * @param mixed $strLabel - rótulo do campo
7430     * @param mixed $strImage - imagem que aparecerá na frente do label
7431     * @param bool $boolNewLine - true ou false se o campo será colocado na frente ou abaixo do último campo adicionado ao formulário
7432     * @param mixed $boolLabelAbove - true ou false para alterar o layout do rótulo para cima ou na frente da imagem
7433     * @param mixed $boolNoWrapLabel - true ou false para quebrar ou não o valor do label se não couber na coluna do formulario
7434     * @param mixed $strHint - texto de ajuda que será exibido ao posicinar o mouse sobre a imagem
7435     */
7436    public function addBoxField( $strId, $strText=null, $strFileName=null, $strDataType=null, $strLabel=null, $strImage=null, $boolNewLine=null, $boolLabelAbove=null, $boolNoWrapLabel=null, $strHint=null )
7437    {
7438        $boolNewLine = is_null( $boolNewLine ) ? false : $boolNewLine; // o padrão é false
7439        $field = new THelpBox( $strId, $strText, $strFileName, $strDataType, $strImage, $strHint );
7440        $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, 'bottom' ) );
7441        return null;
7442    }
7443    
7444    /***
7445     * 
7446     * @param string $strName
7447     * @param string $strLabel
7448     * @param string $hint
7449     * @param integer $intCaracters
7450     * @return NULL|TCaptcha
7451     */
7452    public function addCaptchaField( $strName, $strLabel=null, $hint=null,$intCaracters=null )
7453    {
7454       $field = new TCaptcha( $strName, $hint, $intCaracters );
7455       
7456       $strLabel        = isset($strLabel) ? $strLabel : null;
7457       $field           = isset($field) ? $field : null;
7458       $boolLabelAbove  = isset($boolLabelAbove) ? $boolLabelAbove : null;
7459       $boolNewLine     = isset($boolNewLine) ? $boolNewLine : null;
7460       $boolNoWrapLabel = isset($boolNoWrapLabel) ? $acao : null;
7461       $tDisplay = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, null, null, null, true );
7462       $this->addDisplayControl( $tDisplay );
7463       return $field;
7464    }
7465    
7466    /**
7467    * Adiciona no form uma area para mostrar as mensagens ao usuario identica as mensagens do topo do form
7468    * diferenciando que nesta pode-se definir a mensagem em qualquer lugar do form e será exibida com a mesma formatação da padrão
7469    * <code>
7470    *        $frm->addMessageField('msg_local');
7471    *         <script> fwShowMessage({message:"Mensagem em local especifico<br>Linha2<br>linha3","containerId":"msg_local"});</script>
7472    *    </code>
7473    *
7474    * @param string $strName Nome do campos mensagem
7475    * @return THtml
7476    */
7477    public function addMessageField( $strName=null,$intHeight=null )
7478    {
7479       $field     = $this->addHtmlField( $this->getId().'_'.$strName. '_msg_area','');
7480       $field->setCss( 'visibility', 'visible' );
7481       $field->setCss('width','0px');
7482       $btn     = new TButton( 'btn_close_' .$this->getId() .'_'.$strName.'_msg_area', 'Fechar', null, 'fwHideMsgArea("'.$this->getId() .'_'.$strName.'")', null, 'fwbtnclosered.jpg', null, 'Fechar mensagem' );
7483       $btn->setCss( 'float', 'right' );
7484       $btn->setCss( 'cursor', 'pointer' );
7485       $btn->setCss('visibility','visible');
7486       $field->add( $btn );
7487       $field->add( '<div id="' .$this->getId() .'_'.$strName. '_msg_area_content' . '"></div>' );
7488       return $field;
7489    }
7490    
7491    /**
7492    * Campo para seleção de Diretório ou Pasta
7493    * @param string $strName
7494    * @param string $rootDir
7495    * @param string $strValue
7496    * @param int $intMaxLength
7497    * @param bool $boolRequired
7498    * @param int $intSize
7499    * @param bool $boolLabelAbove
7500    * @param bool $boolNewLine
7501    * @return TOpenDir
7502    */
7503    public function addOpenDirField( $strName, $strLabel=null, $rootDir=null, $strValue=null
7504                                  , $intMaxLength=null, $boolRequired=null, $intSize=null, $strTitle=null, $strJsCallBack=null, $boolLabelAbove=null, $boolNewLine=null)
7505    {
7506       $field = new TOpenDir( $strName, $rootDir, $strValue, $intMaxLength, $boolRequired, $intSize, $strTitle, $strJsCallBack);
7507       $boolNoWrapLabel = isset($boolNoWrapLabel) ? $boolNoWrapLabel : null;
7508       $TDisplayControl = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel, null, null, null, true );
7509       $this->addDisplayControl( $TDisplayControl );
7510       return $field;
7511    }
7512           
7513    /**
7514    * Campo para seleção de fuso horário
7515    *
7516    * @param string $strName
7517    * @param string $strLabel
7518    * @param boolean $boolRequired
7519    * @param boolean $boolNewLine
7520    * @param boolean $boolLabelAbove
7521    * @param mixed $mixValue
7522    * @param integer $intSize
7523    * @param integer $intWidth
7524    * @param string $strFirstOptionText
7525    * @param string $strFirstOptionValue
7526    * @param boolean $boolNoWrapLabel
7527    * @return TTimeZone
7528    */
7529    public function addTimeZoneField( $strName, $strLabel=null, $boolRequired=null,$boolNewLine=null, $boolLabelAbove=null, $mixValue=null, $intSize=null, $intWidth=null, $strFirstOptionText=null, $strFirstOptionValue=null, $boolNoWrapLabel=null )
7530    {
7531       $field = new TTimeZone( $strName, $mixValue, $boolRequired, $intSize, $intWidth, $strFirstOptionText, $strFirstOptionValue);
7532       $this->addDisplayControl( new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel ) );
7533       return $field;
7534    }
7535           
7536    /**
7537    * Adiciona um editor de texto (CKEDITOR)
7538    * @author Daniel Andrade
7539    * @param string $strName
7540    * @param string $strLabel
7541    * @param boolean $boolRequired
7542    * @param boolean $boolNewLine
7543    * @param boolean $boolLabelAbove
7544    * @param string $strValue
7545    * @param boolean $boolNoWrapLabel
7546    * @return TTextEditor
7547    */
7548    public function addTextEditorField( $strName
7549                                     , $strLabel=null
7550                                     , $boolRequired=null
7551                                     , $boolNewLine=null
7552                                     , $strValue=null
7553                                     , $boolLabelAbove=null
7554                                     , $boolNoWrapLabel=true )
7555    {
7556       $field = new TTextEditor( $strName
7557                                  , $strValue
7558                                  , null
7559                                  , $boolRequired, null, null, false );
7560       $field->setClass( 'ckeditor' );
7561       $field->setCss('height','0px');
7562       $this->addJsFile('ckeditor/ckeditor.js');
7563       $boolLabelAbove = is_null($boolLabelAbove) ? true : $boolLabelAbove;
7564       $display = new TDisplayControl( $strLabel, $field, $boolLabelAbove, $boolNewLine, $boolNoWrapLabel );
7565       $this->addDisplayControl( $display );
7566       return $field;
7567    }
7568           
7569   /**
7570    * Criação de campo calendário de eventos tipo agenda
7571    * http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
7572    *
7573    * @param string $strName           - 1: id campo
7574    * @param string $strUrl
7575    * @param string $strHeight         - 3: Tamanho do calendario 
7576    * @param string $strWidth
7577    * @param mixed $defaultView
7578    * @param string $jsOnResize
7579    * @param string $jsOnDrag
7580    * @param string $jsOnDrop
7581    * @param string $jsOnEventClick
7582    * @param string $jsOnSelectDay
7583    * @param string $jsMouseOver
7584    * @return TCalendar
7585    */
7586    public function addCalendarField( $strName
7587                                    , $strUrl=null
7588                                    , $strHeight=null
7589                                    , $strWidth=null
7590                                    , $defaultView=null
7591                                    , $jsOnResize=null
7592                                    , $jsOnDrag=null
7593                                    , $jsOnDrop=null
7594                                    , $jsOnEventClick=null, $jsOnSelectDay=null, $jsMouseOver=null, $jsEventRender=null )
7595    {
7596       if( !DEFINED('INDEX_FILE_NAME') )
7597       {
7598           DEFINE('INDEX_FILE_NAME','index.php');
7599       }
7600       if( ! is_null($strUrl) )
7601       {
7602           $strUrl = INDEX_FILE_NAME.'?ajax=1&modulo='.$strUrl;
7603       }
7604       $field = new TCalendar($strName, $strUrl,  $strHeight, $strWidth, $defaultView, $jsOnResize, $jsOnDrag, $jsOnDrop, $jsOnEventClick, $jsOnSelectDay, $jsMouseOver, $jsEventRender);
7605       $field->setClass( 'fwCalendar',false );
7606       $this->addDisplayControl( new TDisplayControl( null, $field, false,true,true  ) );
7607       return $field;
7608    }      
7609}
7610?>