-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl7page.PRG
More file actions
2179 lines (2014 loc) · 86.9 KB
/
l7page.PRG
File metadata and controls
2179 lines (2014 loc) · 86.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* L7Page.PRG
#INCLUDE L7.H
#DEFINE THIS_DEBUG_OBJECTS .F.
#IF .F.
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is "Level 7 Framework for Web Connection" and
"Level 7 Toolkit" (collectively referred to as "L7").
The Initial Developer of the Original Code is Randy Pearson of
Cycla Corporation.
Portions created by the Initial Developer are Copyright (C) 2004 by
the Initial Developer. All Rights Reserved.
***** END LICENSE BLOCK *****
#ENDIF
* L7 RESERVED QueryString Parameters
* one-character variables:
* A : async ID (for automatic async request handling)
* C : cookie sent with previous response flag {1}
* E : edit mode switch (read-only toggle) {0,1}
* G : RESERVED for GUID use
* L : logout requested {0,1,2}
* M : minimum indetification method (force authentication) {3,5}
* P : printable version request {1}
* R : auto-refresh time constant (seconds)
* S : session ID (replaces LP)
* U : RESERVED for User specification/emulation (potential bootstrapping)
* W-Z : RESERVED (for company-specific framework needs)
* ? : any other 1-letter variable name not listed is RESERVED for L7 future use!
* other variables:
* LP : license plate [DEPRECATED]
* MSGBOX : Message Box answer.
*** ========================================================= ***
DEFINE CLASS L7Page AS CUSTOM
* Keep out of debugInfo:
PROTECTED Parent, ParentClass, WhatsThisHelpId, Top, Left, Height, Width, Picture, Tag, Comment
cNextID = 0 && for generating unique IDs attributes across all elements in a page -- see access method
* Reference to "parent" generating application object:
oApp = NULL
* Values used in <head> section of response:
cTitle = NULL && NULL means inherit from app
cSubTitle = ""
cGenerator = "L7 Framework for VFP"
cAuthor = ""
cCopyright = ""
cKeywords = ""
cDescription = ""
cTemplateExpanderClass = "L7ExpandTemplate" && bridge pattern
* HTTP header and response construction properties:
lIncludeHttpHeader = .T.
oHttpHeader = NULL
cHTTPHeaderClass = "L7HTTPHeader"
oHead = NULL
cHeadElementClass = "L7HeadElement"
cPageLanguage = "en" && leads to: <html lang="en"> (see L7ResponseManager)
* Frame/frameset properties:
lFrameSet = .F. && FRAMESET pages need different handling
cFrameSetAttributes = "" && attributes for <frameset>
lFrame = .F. && flag for page being a FRAME in a set
* Body element options:
oBody = NULL
cDocType = L7_DOCTYPE_LOOSE
lNoBodyTag = .F. && turn on to suppress addition of <body>..</body>
cBackground = "" && image
cBgColor = "" && DEPRECATED (CSS)
cOnLoad = "" && JavaScript instruction
cBaseFont = "" && DEPRECATED (CSS) [Ex: face="Arial" size=2]
cBodyElementClass = "L7PageElement"
cBodyAttributes = "" && merge-able <body> tag attributes (also see ExpandTemplate)
cBodyCssClass = ""
* Error handling properties:
lError = .F.
lErrorMsg = .F.
cErrorMessage = "" && show to user
cErrorTitle = "Error on Page" && show to user
** cErrorInfo = "" && email to admin
nErrorPageInfo = L7_NONE && in addition to App-level settings
nErrorEmailInfo = L7_NONE && (see L7.H for values)
lPrintable = .T. && printable version of page allowed?
lPrint = .F. && printable version of page requested?
nMinimumRefresh = -1 && minimum auto-refresh time in seconds (-1 = not allowed)
nRefresh = 0 && requested refresh time in seconds (0 = none)
*!* * Color scheme properties:
*!* oColorScheme = NULL && created in INIT
*!* cColorSchemeClass = "L7ColorScheme"
*!* cColorSchemeName = "American"
cCssFile = "http://www.cycla.com/software/l7/l7.css" && eg, "thisapp.css"
cJsFile = "http://www.cycla.com/software/l7/l7Core.js"
cOutputFile = ""
oCurrent = NULL
lCancelled = .F.
lRedirected = .F.
lAuthRequired = .F. && Does page require authentication?
lAuthenticate = .F. && Have we initiated authentication?
lRendered = .F. && have we rendered yet?
cResult = "" && pre-render container
tNow = NULL && Synchronized timestamp value. Set on each hit.
nStartSeconds = NULL
nElapsedSeconds = NULL && see ACCESS method
lDoNotLog = .F. && allows disabling logging for minor things like Pings
oBrowser = NULL
*!* cBrowserClass = "L7Browser"
*!* cBrowserName = "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
****** Properties that had been in L7WCPage ******
** Total URL Management (TUM) properties:
DIMENSION aBaseUrlParameters[1,3] && populated by AddBaseUrlParameter method
nBaseUrlParameters = 0
cBaseURL = "" && base from which to add/modify parameters
cBaseQueryString = "" && see access method (also see GetBaseHiddenFormVars method)
* Managed URLs (for developer convenience, see ReadQueryString() method):
cUrlA = "" && minimal QS parameters -- used for menus and navigation
cUrlB = "" && most like "current" URL -- for navigation within context of current page
cUrlC = "" && (rarely used) for special intra-page handling like sort orders (see MessageBox, for example)
* DEPRECATED names: cUpUrl, cUrl, cDownUrl (handled with _access methods for right now)
* Options for groking Home and Cancel "places" to send user when bad things happen:
cTopPage = "Home" && Override if your's is different.
cTopUrl = ""
cCancelPage = ""
cCancelUrl = ""
* HTTP artifact paths:
cStylePath = "/L7/styles/" && .CSS files
cScriptPath = "/L7/scripts/" && .JS files
cImagePath = "/L7/images/" && .GIF files
lWcPowerImage = .F. && "Powered by Web Connection GIF" && DEPRECATED
*[[ Need L7 Image that is used by default in shareware mode.
* Session-oriented properties:
oSession = NULL
** cSessionClass = "L7Session" && bridge pattern
nSessionTimeout = NULL && Override of app-level setting.
* Async processing properties:
cAsyncID = "" && see CheckAsyncID()
cAsyncClass = "L7Async" && bridge pattern
* User Identification properties:
*
* These 4 flags control which types of user identification
* schemes are used/supported by your application. In general,
* you set these once for the application and don't change them
* in individual pages. If a specific page has different requirements,
* be it looser or stricter, you can use other properties, such as
* "nMinIdentificationMethod" and "nMinLoginLevel" to alter behavior.
*
lUsesAuthentication = .T. && App uses Win authentication as #1 priority to identify users.
lUsesPersistentCookies = .F. && App uses Persistent Cookies as #2 priority to identify users.
lUsesTemporaryCookies = .T. && App uses Temporary Cookies as #3 priority to identify users.
lUsesLicensePlates = .T. && App uses License Plates as a last resort.
* NOTE: You can use any combination of the above flags.
cUserIdentificationClass = "L7UserIdentifier" && bridge to strategy class
nMinIdentificationMethod = L7_IDENTIFICATION_LICENSE_PLATE
nIdentificationActual = L7_NONE
nMinLoginLevel = L7_NONE && L7_LOGIN_LOGGED_IN or L7_NONE
lAutoAcceptNetworkUsers = .F. && Any network user is welcome and gets a user record.
cLicensePlate = "" && Actual license plate value for user.
lCookieSatisfiesLogin = .F. && Does existence of cookie == being logged in?
lSingleLogin = .T. && Does authentication == being logged in?
lShowLogin = .F. && Did we decide a login form should be displayed?
lLoginFailure = .F. && set to TRUE by others when current login attempt failed
cLoginFailureMessage = "User ID not found and/or incorrect password! (Note: Passwords are case-sensitive.)"
* [See L7.H] Identification Methods are:
* 1 = License Plate (URL)
* 2 = Temporary Cookie
* 3 = Persistent Cookie
* 4 = [RESERVED]
* 5 = NT Authentication (usage discouraged)
oUser = NULL
oTempUser = NULL && for emulation
* [[ This should be an app-level property:
cUserClass = "L7User" && override this with your own class, if needed
cUserId = "" && Application-specific User ID.
cAuthenticatedUser = "" && NT User ID, if applicable.
lLogoutRequested = .F. && was a logout requested on this hit?
lLoginRequested = .F. && was a new login specifically requested on this hit?
*!* cUserName = "" && See access method cUserName_ACCESS()
cTemporaryCookieName = "L7TEMPID" && [[ was L7ID also ]]
cPersistentCookieName = "L7ID"
cTemporaryCookieValue = ""
cPersistentCookieValue = ""
lCookieAttempted = .F. && URL indicates cookie delivered on previous hit
lProcessPage = .T. && flag for continuing with page [PROTECTED?]
* Specialized usage flags for developer convenience:
lReadOnly = .F. && read-only user flag
lEditMode = .T.
lAdding = .F. && flag for adding a new record (vs editing an existing one)
PROTECTED nMessageBoxAnswer
nMessageBoxAnswer = -1 && see CheckMessageBox() and MessageBox() methods
* Properties for saving/restoring environment:
oEnvironment = NULL
lAutoCloseTables = .F. && flag determines whether push/pop is performed
* Menu properties:
oMenu = NULL
cMenuClass = [L7Menu] && bridge
cCurrentMenuContext = []
lRenderParentMenus = .T.
cMenuPath = [main]
* Auto-parsing:
lParseContent = .F.
lOutputDelivered = .F.
* Error-handling augmentation:
lReturnHttpServerError = .T.
PROTECTED cErrorMsgReturnMethod
cErrorMsgReturnMethod = ""
cSystemMessageClass = "L7SystemMessage" && bridge pattern for custom display of error messages
* Special FW flag to enforce calls up the hierarchy:
HIDDEN lBeforeProcessRequest_FW
lBeforeProcessRequest_FW = .F.
* JSON response properties
oJsonContents = NULL
* File handling properties (used by GetFileContents() method):
cFileContents = "" && set either this or next 2 for templates, etc.
cFilePath = ""
cFileName = ""
lFileDownload = .F. && use octet-stream binary download response
lFileTransmit = .F.
cDLLName = "wc.dll" && in case you rename wc.dll (may be DEPRECATED)
#IF .F.
** further DEPRECATED properties -- new developers please ignore!:
cApplication = "XXXX" && Set below from App object!
cAppClass = "L7App" && can override
cAppTitle = ""
cPageExtension = "wcs" && used in SetupBaseURL
cSaveConfirmationMessage = "Saving changes to database..." && DEPRECATED
#ENDIF
oArtifacts = NULL
cArtifactsClass = "Collection" && bridge
oUrls = NULL
cUrlsClass = "L7UrlCollection" && bridge
#IF .T. && DEPRECATED names (to-be-deleted)
cUpURL = "" && variation for up/out navigation (to higher places)
cURL = "" && current URL, adjusted for framework requirements
cDownURL = "" && variation for downward navigation (drilling, etc.)
FUNCTION cUpUrl_ACCESS
RETURN THIS.cUrlA
ENDFUNC
FUNCTION cUrl_ACCESS
RETURN THIS.cUrlB
ENDFUNC
FUNCTION cDownUrl_ACCESS
RETURN THIS.cUrlC
ENDFUNC
#ENDIF
* --------------------------------------------------------- *
function tNow_ACCESS
if vartype(m.Environ) = "O"
return Environ.item("appManager.startTime")
endif
if isnull(this.tNow)
this.tNow = datetime() && not preferred--we're moving to stateless page processing
endif
return this.tNow
endfunc
* --------------------------------------------------------- *
FUNCTION cNextID_ACCESS && auto-incrementing property on each use
* For general use anywhere. Just ask for Page.cNextID.
THIS.cNextID = THIS.cNextID + 1
RETURN "L7Page_" + TRANSFORM(THIS.cNextID)
ENDFUNC
* --------------------------------------------------------- *
FUNCTION cTopUrl_ACCESS
* ACCESS method for cCancelUrl property!
DO CASE
CASE NOT EMPTY( THIS.cTopUrl)
* Explicit URL has been dictated.
RETURN THIS.cTopUrl
OTHERWISE
* Nothing explicitly set, so return them to Top Page.
RETURN StuffURL( THIS.cUrlA, 1, THIS.oApp.cActivePageExtension, ;
2, THIS.cTopPage)
ENDCASE
ENDFUNC && cTopUrl_ACCESS
* --------------------------------------------------------- *
FUNCTION cCancelUrl_ACCESS
* ACCESS method for cCancelUrl property!
DO CASE
CASE NOT EMPTY( THIS.cCancelUrl)
* Explicit URL has been dictated.
RETURN THIS.cCancelUrl
CASE NOT EMPTY( THIS.cCancelPage)
* Specific cancel page has been set as a property.
RETURN StuffURL( THIS.cUrlA, 1, THIS.oApp.cActivePageExtension, ;
2, THIS.cCancelPage)
OTHERWISE
* Nothing explicitly set, so return them to Top Page.
RETURN StuffURL( THIS.cUrlA, 1, THIS.oApp.cActivePageExtension, ;
2, THIS.cTopPage)
ENDCASE
ENDFUNC && cCancelUrl_ACCESS
* --------------------------------------------------------- *
FUNCTION lProcessPage_ACCESS
RETURN THIS.lProcessPage AND NOT THIS.lError AND ;
NOT (VARTYPE(THIS.oApp) = "O" AND THIS.oApp.lError) AND ;
NOT THIS.lErrorMsg AND NOT THIS.lRedirected
ENDFUNC
* --------------------------------------------------------- *
*!* FUNCTION cUserName_ACCESS && what was point of this??
*!* * Access Method for cUserName property.
*!* IF VARTYPE( THIS.oUser) = "O"
*!* RETURN THIS.oUser.GetUserName()
*!* ELSE
*!* RETURN ""
*!* ENDIF
*!* ENDFUNC && cUserName_ACCESS
*!* * --------------------------------------------------------- *
FUNCTION nElapsedSeconds_ACCESS
RETURN MOD( SECONDS() - THIS.nStartSeconds, 86400 )
ENDFUNC && nElapsedSeconds_ACCESS
* --------------------------------------------------------- *
FUNCTION INIT(loApp)
** THIS.tNow = DATETIME() && deprecated--see access method to cover old code
THIS.nStartSeconds = SECONDS()
IF VARTYPE( m.loApp ) = "O"
THIS.oApp = m.loApp
ENDIF
THIS.oArtifacts = CREATEOBJECT(THIS.cArtifactsClass)
THIS.oUrls = CREATEOBJECT(THIS.cUrlsClass)
THIS.oHttpHeader = CREATEOBJECT(THIS.cHttpHeaderClass) && bridge
* HTTP header is created by default. Set property lIncludeHttpHeader
* to false to kill off the output from this.
THIS.oHead = CREATEOBJECT(THIS.cHeadElementClass) && bridge
*!* THIS.oColorScheme = CREATEOBJECT(THIS.cColorSchemeClass, THIS.cColorSchemeName )
THIS.AfterINIT()
THIS.SetupBrowserObject()
#IF THIS_DEBUG_OBJECTS
DEBUGOUT THIS.Name + " created."
#ENDIF
ENDFUNC && INIT
* --------------------------------------------------------- *
FUNCTION AfterINIT
DO StandardVfpSettings && In L7Utils.PRG
SET SAFETY OFF && In case not standard!
THIS.oEnvironment = CREATEOBJECT("L7Environment")
WITH THIS.oEnvironment
.lAutoCloseTables = THIS.lAutoCloseTables
* Stores state of open tables and databases for closeout.
.SaveState() && RestoreState called on Destroy().
ENDWITH
ENDFUNC && AfterINIT
* --------------------------------------------------------- *
FUNCTION DESTROY
THIS.GarbageCollect()
ENDFUNC && DESTROY
* --------------------------------------------------------- *
FUNCTION GarbageCollect
* Garbage collection, etc. Called by DESTROY().
* NOTE: If you override this, be sure to DODEFAULT()!!
* This is just an object reference:
THIS.oCurrent = NULL
* Release any child Page Element objects:
IF VARTYPE( THIS.oHttpHeader ) = "O"
THIS.oHttpHeader.GarbageCollect()
THIS.oHttpHeader = NULL
ENDIF
IF VARTYPE( THIS.oHead ) = "O"
THIS.oHead.GarbageCollect()
THIS.oHead = NULL
ENDIF
IF VARTYPE( THIS.oBody ) = "O"
THIS.oBody.GarbageCollect()
THIS.oBody = NULL
ENDIF
* Clear back link reference:
THIS.oApp = NULL
THIS.oUser = .F.
THIS.oTempUser = .F.
THIS.oSession = .F.
THIS.oMenu = .F.
THIS.oArtifacts = NULL
THIS.oUrls = NULL
* This should always come last, in case any other objects
* above affect the current environment while releasing:
IF VARTYPE(THIS.oEnvironment) = "O"
THIS.oEnvironment.RestoreState()
THIS.oEnvironment = NULL
ENDIF
#IF THIS_DEBUG_OBJECTS
DEBUGOUT THIS.Name + " destroyed."
#ENDIF
ENDFUNC && GarbageCollect
* ------------------------------------------------------------------- *
PROCEDURE RELEASE
THIS.GarbageCollect()
RELEASE THIS
ENDFUNC && RELEASE
* --------------------------------------------------------- *
FUNCTION SetError(lcMessage, lcTitle, loException)
THIS.lError = .T.
THIS.cErrorMessage = THIS.cErrorMessage + m.lcMessage
IF VARTYPE(lcTitle) = "C" AND NOT EMPTY(m.lcTitle)
THIS.cErrorTitle = m.lcTitle
ENDIF
THIS.oApp.SetError(THIS.cErrorMessage, THIS.cErrorTitle, m.loException)
ENDFUNC && SetError
* --------------------------------------------------------- *
*!* * You can disable error handling by setting L7_PAGE_DEBUG to
*!* * .T. in L7_OVERRIDE.H (recompile required). Be careful not
*!* * to put apps in production that way, however!
*!* #IF L7_PAGE_DEBUG = .F.
*!* FUNCTION Error(lnError, lcMethod, lnLine)
*!* IF THIS.lError = .T.
*!* * If there has already been an error, we're in big trouble.
*!* * Most likely, our error handling code has generated an
*!* * error of its own. At this point, it isn't safe to try
*!* * returning anything but a server-level error.
*!* ELSE
*!* THIS.lError = .T.
*!* LOCAL loException AS Exception, lcMessage AS String
*!* TRY
*!* loException = L7ErrorToException(m.lnError, m.lcMethod, m.lnLine)
*!* CATCH TO loExc
*!* loException = m.loExc
*!* loException.Comment = "Exception occurred trying to convert page error to exception object."
*!* ENDTRY
*!* lcMessage = [Error: ] + MESSAGES() + [. ] + L7BR
*!* THIS.SetError(m.lcMessage, "Page Error", m.loException)
*!* ENDIF
*!* * Bail out of any buffered changes:
*!* RevertTables() && function in L7Utils.PRG
*!* * Try to find a safe point for exiting:
*!* IF NOT EMPTY( THIS.cErrorMsgReturnMethod)
*!* LOCAL lcAltReturn
*!* lcAltReturn = THIS.cErrorMsgReturnMethod
*!* RETURN TO &lcAltReturn
*!* ELSE && ???
*!* RETURN TO ProcessPage && in L7App
*!* ENDIF
*!* ENDFUNC && Error
*!* #ENDIF
* --------------------------------------------------------- *
FUNCTION GetFileContents()
WITH THIS
DO CASE
CASE NOT EMPTY(.cFileContents)
RETURN .cFileContents
CASE NOT EMPTY(.cFileName)
LOCAL lcFile
lcFile = IIF(EMPTY(.cFilePath), "", ADDBS(.cFilePath)) + .cFileName
IF FILE(m.lcFile)
RETURN FILETOSTR(m.lcFile)
ELSE
ERROR [File "] + m.lcFile + [" not found.]
RETURN
ENDIF
OTHERWISE
ERROR "No return file contents specified."
RETURN
ENDCASE
ENDWITH
ENDFUNC
* --------------------------------------------------------- *
FUNCTION SetupBodyElement
IF NOT THIS.lFrameSet
THIS.oBody = THIS.CreateBodyElement()
THIS.oCurrent = THIS.oBody.CurrentOutputObject
ELSE && <FRAMESET>
* For framesets we want to insert frame info only,
* and make sure menus, content, etc., are not used:
THIS.oBody = CREATEOBJECT("L7PageElement")
THIS.oCurrent = THIS.oBody
ENDIF
ENDFUNC && SetupBodyElement
* --------------------------------------------------------- *
FUNCTION CreateBodyElement
* Factory that implements a Bridge pattern.
* Note: If you have a single class that requires different
* body element classes depending on URL (or other request)
* parameters, such that this simple bridge doesn't handle
* your situation, you can also override *this* method and
* do something further. Just make sure you return an object
* that complies with L7BodyElement interface.
LOCAL loObj
loObj = CREATEOBJECT(THIS.cBodyElementClass)
RETURN m.loObj
ENDFUNC && CreateBodyElement
* --------------------------------------------------------- *
FUNCTION SetupBrowserObject
LOCAL loObj
if vartype(this.oApp) = "O"
loObj = THIS.oApp.GetBrowserObject()
else
loObj = createobject("L7Browser") && no app--perhaps a test
endif
THIS.oBrowser = m.loObj
RETURN
*!* THIS.oBrowser = CREATEOBJECT( THIS.cBrowserClass)
*!* IF NOT EMPTY(THIS.cBrowserName)
*!* * In an ISAPI subclass, set this property to empty, and then
*!* * call SetBrowser() later after the string is read.
*!* THIS.oBrowser.SetBrowser( THIS.cBrowserName)
*!* ENDIF
*!* * Note: You can call this method again to change browsers.
ENDFUNC && SetupBrowserObject
* --------------------------------------------------------- *
FUNCTION SetExpires(lvExpires, llReplace)
* Can be called from response object or directly, thus allowing
* support for ASP syntax Response.Expires.
THIS.oHttpHeader.SetExpires(m.lvExpires, m.llReplace)
* NOTE: To force a reload, another possibility is a META
* tag for HTTP-EQUIV="pragma" CONTENT="no-cache".
ENDFUNC
* --------------------------------------------------------- *
FUNCTION ForceReload
THIS.oHead.AddMetaHttpEquiv( "pragma", "no-cache" )
THIS.oHttpHeader.AddHeader("Cache-Control", "no-cache") && added 12/16/2004
ENDFUNC
* --------------------------------------------------------- *
FUNCTION ForceNoFrames
THIS.oHead.AddMetaHttpEquiv( "Window-target", "_top" )
ENDFUNC
* --------------------------------------------------------- *
FUNCTION RenderBodyTag
LOCAL lcBodyTag
lcBodyTag = [<body] + IIF(EMPTY(THIS.cBodyAttributes), [], ;
[ ] + THIS.cBodyAttributes)
IF NOT EMPTY(THIS.cBodyCssClass)
lcBodyTag = m.lcBodyTag + [ class="] + THIS.cBodyCssClass + ["]
ENDIF
IF NOT EMPTY(THIS.cBackground) AND ATC(" background=", m.lcBodyTag) = 0
lcBodyTag = m.lcBodyTag + [ background="] + THIS.cBackground + ["]
ENDIF
IF NOT EMPTY(THIS.cBGColor) AND ATC(" bgcolor=", m.lcBodyTag) = 0
lcBodyTag = m.lcBodyTag + [ bgcolor="] + THIS.cBGColor + ["]
ENDIF
IF NOT EMPTY(THIS.cOnLoad) AND ATC(" onload=", m.lcBodyTag) = 0
lcBodyTag = m.lcBodyTag + [ onLoad="] + THIS.cOnLoad + ["]
ENDIF
lcBodyTag = m.lcBodyTag + [>] + CR
IF NOT EMPTY( THIS.cBaseFont)
lcBodyTag = m.lcBodyTag + [<basefont ] + THIS.cBaseFont + [>] + CR
ENDIF
#IF L7_SHAREWARE
lcBodyTag = m.lcBodyTag + ;
[<p style="margin: 0; border: 1px; background-color: orange; color: #333333; text-align: center; font-size: 11px; font-style: italic; font-weight: medium; font-family: Cursive;">] + ;
[This page was produced by an unlicensed evaluation copy of The L7 Framework for Web Connection!] + ;
[<br>Licensed copies can be attained from Cycla Corporation ] + ;
[(<a href="mailto:L7@cycla.com">mailto:L7@cycla.com</a>).] + ;
[</p>] + CR
*[[TO DO: Revise this so all response assemblers will deal with shareware situation.
#ENDIF
RETURN m.lcBodyTag
ENDFUNC
* --------------------------------------------------------- *
FUNCTION SSLCheck
IF THIS.lSSLRequired
IF THIS.SSLAvailable()
IF NOT Request.IsLinkSecure()
RETURN .F.
ENDIF
ENDIF
ENDIF
RETURN
ENDFUNC
* --------------------------------------------------------- *
FUNCTION SSLAvailable
RETURN goL7AppManager.oConnector.nSslPort > 0 && SSL available (INI setting)
ENDFUNC
* --------------------------------------------------------- *
FUNCTION ForceSSL
LOCAL lcHeading, lcBody, lcUrl
lcHeading = "Secure Protocol Required"
TEXT TO lcBody NOSHOW PRETEXT 3
<p>For privacy or security reasons, this page requires the
HTTPS secure protocol. Follow the link below. </p>
ENDTEXT
lcUrl = Request.GetRelativeSecureLink(THIS.cUrlB) && was THIS.cUrl
THIS.StandardPage(m.lcHeading, m.lcBody, , , m.lcUrl)
RETURN
ENDFUNC
* --------------------------------------------------------- *
* [[ Can the next 6 functions move up to L7App?
* [[ Shouldn't most/all of the next 6 methods inject App_Log messages of their own?
* --------------------------------------------------------- *
FUNCTION NotFound(lcMsg) && 404 Responses
WITH THIS
* .lError = .T.
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse" && "StandardResponse"
.oHTTPHeader.cStatus = "404 Not Found"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '404 Not Found')
.cFileContents = m.lcMsg && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Not Found (404) response: " + m.lcMsg)
* HTML was not needed or always appropriate
*!* .oHTTPHeader.cStatus = "404 Not Found"
*!* .oHead = NULL && release what we have so far
*!* .oHead = CREATEOBJECT("L7HeadElement")
*!* .oHead.cTitle = '404 Not Found'
*!* .oBody = NULL && release what we have so far
*!* .oBody = CREATEOBJECT("L7PageElement")
*!* lcMsg = EVL(m.lcMsg, '404 Not Found')
*!* IF m.lcMsg <> '<'
*!* lcMsg = '<h1>' + m.lcMsg + '</h1>' + CRLF
*!* ENDIF
*!* WITH .oBody
*!* .cTag = 'body'
*!* .Write(m.lcMsg)
*!* ENDWITH
ENDWITH
RETURN
ENDFUNC && NotFound
* --------------------------------------------------------- *
FUNCTION Conflict(lcMsg) && 409 Responses
WITH THIS
* .lError = .T.
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cStatus = "409 Conflict"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '409 Conflict')
.cFileContents = m.lcMsg && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Conflict (409) response: " + m.lcMsg)
ENDWITH
RETURN
ENDFUNC && Conflict
* --------------------------------------------------------- *
FUNCTION BadRequest(lcMsg) && 400 Responses
WITH THIS
* .lError = .T.
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cStatus = "400 Bad Request"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '400 Bad Request')
.cFileContents = m.lcMsg && avoids need for disk presence
* This one suggests a warning. The remainder could be planned by app circumstances,
* so app should trigger any flag-raising log messages.
.App_Log(L7_SEVERITY_WARNING, "Bad Request (400) response: " + m.lcMsg)
ENDWITH
RETURN
ENDFUNC && BadRequest
* --------------------------------------------------------- *
FUNCTION Forbidden(lcMsg) && 403 Responses
WITH THIS
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cStatus = "403 Forbidden"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '403 Forbidden')
.cFileContents = m.lcMsg && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Forbidden (403) response: " + m.lcMsg)
ENDWITH
RETURN
ENDFUNC && Gone
* --------------------------------------------------------- *
FUNCTION Gone(lcMsg) && 410 Responses
WITH THIS
* .lError = .T.
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cStatus = "410 Gone"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '410 Gone')
.cFileContents = m.lcMsg && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Gone (410) response: " + m.lcMsg)
ENDWITH
RETURN
ENDFUNC && Gone
* --------------------------------------------------------- *
FUNCTION OK(lcMsg) && 200 OK - direct plain/text Responses
WITH THIS
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cStatus = "200 OK"
.oHTTPHeader.cContentType = "text/plain"
lcMsg = EVL(m.lcMsg, '200 OK')
.cFileContents = m.lcMsg && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "OK (200) direct response: " + m.lcMsg)
ENDWITH
RETURN
ENDFUNC && OK
* --------------------------------------------------------- *
FUNCTION Moved(lcUrl) && 301 Moved Permanently
with this
.lRedirected = .T.
.lProcessPage = .F.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cRedirectUrl = m.lcUrl
.oHTTPHeader.cStatus = "301 Moved Permanently"
.oHTTPHeader.cContentType = "text/plain"
.cFileContents = '301 Moved Permanently: ' + m.lcUrl && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Moved (301) response: " + m.lcUrl)
endwith
return
* --------------------------------------------------------- *
* [[ long-term, switch this to 303 See Other
FUNCTION Redirect(lcUrl) && 302 Moved Temporarily (comp w/ Moved())
with this
.lRedirected = .T.
.lProcessPage = .F. && added 3/25/2010, like Forbidden(), etc.
.oApp.cActiveResponse = "FileResponse"
.oHTTPHeader.cRedirectUrl = m.lcUrl
.oHTTPHeader.cStatus = "302 Moved"
.oHTTPHeader.cContentType = "text/plain"
.cFileContents = '302 Moved: ' + m.lcUrl && avoids need for disk presence
.App_Log(L7_SEVERITY_INFO, "Moved (302) response: " + m.lcUrl)
endwith
return
* old L7Page code, should not be needed
*!* IF VARTYPE(THIS.oHead) = "O"
*!* THIS.oHead.lCancelled = .T.
*!* ENDIF
*!* IF VARTYPE(THIS.oBody) = "O"
*!* THIS.oBody.lCancelled = .T.
*!* ENDIF
endfunc && Redirect
* --------------------------------------------------------- *
* [[ should this act more like the above 6 methods:
function Authenticate(lcRealm)
*[[TO DO: Revise this so all response assemblers will know how to handle!
with this
.lProcessPage = .F. && added 3/25/2010, like Forbidden(), etc.
.lAuthenticate = .T.
.oHTTPHeader.lAuthenticate = .T.
if NOT EMPTY( m.lcRealm)
.oHTTPHeader.cAuthRealm = m.lcRealm
endif
.App_Log(L7_SEVERITY_INFO, "Authentication response indicated" )
if vartype(.oHead) = "O"
.oHead.lCancelled = .T.
endif
if vartype(.oBody) = "O"
.oBody.lCancelled = .T.
endif
endwith
return
endfunc && Authenticate
* --------------------------------------------------------- *
FUNCTION ExpandTemplate(lcFileName, llIsString, loHeadStrategy)
* Framework-based expansion, intended to merge template aspects,
* such as <head> section details and <body> tag attributes with
* those of the framework and application. (See also the L7PageElement
* method ExpandTemplateSnippet() for a different option.)
* Delegate to another class that can be subclassed. (Keeps current class
* simpler, and allows developers to modify how things like the <head>
* section merging is done, because some HTML authoring tools could
* present unique challenges there.
LOCAL loExpander
loExpander = CREATEOBJECT(THIS.cTemplateExpanderClass) && bridge pattern
WITH loExpander
.lSafeTextmerge = .T. && avoid recursion if nested elements use textmerge
IF m.llIsString
.cScript = m.lcFileName
ELSE && it's a file name
.cFileName = m.lcFileName
ENDIF
*!* .nHeadOptions = m.lnHeadOptions
IF VARTYPE(m.loHeadStrategy) = "O"
.oHeadStrategy = m.loHeadStrategy
ENDIF
*!* .nBodyTagOptions = m.lnBodyTagOptions
.Expand()
ENDWITH
ENDFUNC && ExpandTemplate
* --------------------------------------------------------- *
PROTECTED FUNCTION ValidateRequest
* hook to block lProcessPage if request looks like a hack
local lcQS, lcBadChars, llBad, lnSet, lcSet, lcParm, lcVal
lcBadChars = "<>"
lcQS = Request.QueryString()
for lnSet = 1 to getwordcount(m.lcQS, '&')
lcSet = getwordnum(m.lcQS, m.lnSet, '&')
lcParm = getwordnum(m.lcSet, 1, "=")
if !empty(chrtran(m.lcParm, L7_WORD_CHARACTERS, ''))
this.forbidden("Illegal QS parameter name")
llBad = .t.
exit
endif
lcVal = urldecode(getwordnum(m.lcSet, 2, "="))
if !chrtran(m.lcVal, m.lcBadChars, '') == m.lcVal
this.forbidden("Illegal QS value")
llBad = .t.
endif
next
return !m.llBad
endfunc && ValidateRequest
* --------------------------------------------------------- *
FUNCTION ExecuteRequest
* Main function called by L7 "application" object.
* Sets up environment and calls application wrapper function
* DoProcessRequest(), which in turn calls page-specific ProcessRequest()
* function to produce the output.
*
* This hierarchy allows for creation of a consistent, yet
* simple environment from the standpoint of the user's individual
* page creation code/script. Object references are available either
* through PRIVATE variables (referencable at all containership levels)
* or Page object properties. These include:
*
* Request : uniform reference to incoming (ISAPI/CGI) web request
* Response : reference to current Element of output (HTML) page
* Page : THIS object
* Page.oApp : L7 application object
* Browser : browser object (properties of user's agent)
* Config : same as Page.oApp.oConfig
* Artifacts : Page.Artifacts object (collection of ad-hoc items)
LOCAL lcStr
** PRIVATE Response, Page, Config, Browser, Content, Session, Artifacts, URLs
PRIVATE Response, Page, Config, Content, Session, Artifacts, URLs
Page = THIS
** Browser = THIS.oBrowser
Artifacts = THIS.oArtifacts
URLs = THIS.oUrls
Config = THIS.oApp.oConfig
Session = NULL
*[[ TRY
* Setup TUM. We need this established early so that ErrorMsg()
* functions have a base URL to build from if we abort page processing:
if !this.validateRequest()
this.lProcessPage = .f.
else
THIS.SetupBaseURL()
THIS.SynchronizeManagedUrls()
endif
IF THIS.lProcessPage
* Setup Menu object (done early so other hooks can add items):
THIS.CreateMenu()
* Setup the browser object:
** THIS.cBrowserName = Request.cBrowser (handled in App now)
** THIS.oBrowser.SetBrowser( THIS.cBrowserName )
THIS.AfterDetermineBrowser() && Hook to allow CSS settings, etc.
* Determine User Identity via call to IdentifyUser():
THIS.oSession = THIS.GetSessionObject() && was: CREATEOBJECT( THIS.cSessionClass, THIS )
Session = THIS.oSession
THIS.oSession.cClientCRC = THIS.oApp.getClientCRC() && Request.cClientCRC
THIS.oSession.cIpAddress = Request.cIpAddress
if !vartype(m.CurrentUser) = 'O'
* allows App to create instead...
CurrentUser = this.InstantiateUser() && 06/22/2010
TrueUser = CurrentUser
* Note: Your app can achieve emulation by pointing CurrentUser at a different object
endif
*!* THIS.InstantiateUser() && sets up THIS.oUser object
*!* * default is CREATEOBJECT( THIS.cUserClass, THIS ), but override is allowed
* Check URL to see if a logout was requested:
lcStr = THIS.StripUrl("L") && "L" for logout
IF EMPTY(m.lcStr) && no logout requested
* = .F.
ELSE
DO CASE
CASE m.lcStr == "0"
THIS.lLogoutRequested = .T.
CASE m.lcStr == "1"
THIS.lLoginRequested = .T.
CASE m.lcStr == "2"
THIS.lLogoutRequested = .T.
THIS.lLoginRequested = .T.
ENDCASE
ENDIF
* Check URL to see if a cookie was sent with previous page:
lcStr = THIS.StripUrl("C") && "C" for cookie
IF m.lcStr = "1"
THIS.lCookieAttempted = .T. && flag this, so we can revert to LP's if user rejected cookie
ENDIF
* See if the URL is forcing an authentication level:
lcStr = THIS.StripURL("M")
IF NOT EMPTY( m.lcStr )
lcStr = VAL( m.lcStr)
IF INLIST( m.lcStr, L7_IDENTIFICATION_Persistent_COOKIE, L7_IDENTIFICATION_AUTHENTICATION)
THIS.nMinIdentificationMethod = m.lcStr
ENDIF
ENDIF
* User identity and login checks:
IF THIS.BeforeIdentifyUser() && hook for setting up anything needed before login
THIS.lProcessPage = THIS.lProcessPage AND THIS.IdentifyUser() && major routine that implements user identification settings
ENDIF
IF THIS.lShowLogin && we decided in IdentifyUser that we need to present the login form
THIS.OnShowLogin() && hook to do stuff like turning off the menu, etc.
ENDIF
IF THIS.lProcessPage
*!* PRIVATE CurrentUser, TrueUser && these PRIVATE's now created in App--really??
*|* CurrentUser = THIS.oUser
*|* TrueUser = THIS.oUser
* Note: Your app can achieve emulation by pointing CurrentUser
* to a different user object. [Need KB topic on this.]
IF NOT THIS.AfterIdentifyUser() && hook for security call, etc.
THIS.lProcessPage = .F.
ENDIF
ENDIF
ENDIF
IF THIS.lProcessPage
** Response = THIS.oCurrent