Lesson 7
Linux / Apache / GT.M / Web Application Lesson 7 - B Corrected for Security.
Tutorial Home: M2Web Tutorials Prev: Lesson 6 Next: Lesson 8
In the following routine we make use of functions and add hypertext links. We also use the special function supplied with GT.M called $ZTRNLNM and use it to examine a environment variable called QUERY_STRING.
Many times when you are surfing the web, you may see a http address followed by a question mark "?", and then a bunch of information. This bunch of information can come from a form that you filled out or that was hidden on the page that you were previously on.
In the UNIX / Linux world the information that is past the question mark "?" is placed in the environment variable QUERY_STRING.
In our mumps routine we use the special function $ZTRNLNM to give us the value that is in the environment variable QUERY_STRING. You will notice in our hyperlinks that we have placed our routine function tags after the question mark "?" for our three methods of displaying the data in our ^ZZLIB3 global.
Depending on which hyperlink you select the environment variable QUERY_STRING will contain "TB1", "TB2", or "TB3".
The $ZTRNLNM function will use this value to set XX equal to "TB1", "TB2", or "TB3".
The I(f) command tests the value of XX. If the test XX="TB1" is true then the rest of the line is executed. If the test XX="TB1" is false execution of this line in discontinued and execution moves to the next line.
If someone tries to run this script/routine with anything other then TB1, TB2, or TB3, nothing happens.
You need to make sure that the HREF file, in my case "library7.cgi" is the cgi file that you have set to call this routine. It is actually designed to recall itself to produce the tables.
IMPORTANT NOTICE: ALL OF THE '{' CHARACTERS HAVE BEEN REPLACED BY '{' CHARACTERS BECAUSE THE WIKI WAS NOT FORMATTING PROPERLY OTHERWISE. LIKEWISE, ALL THE '}' WERE CHANGED TO '}'. Replace these back to the proper '{' and '}' characters when typing into your system.
ZZLIB7 ------------------------------------------------------------------------------- ZZLIB7 ; ROUTINE TO CREATE A WEB PAGE USING THE ^ZZLIB3 GLOBAL. ; ; W "Content-type: text/html",!! W "{html}",! W "{head}",! W "{title}ZZLIB3 GLOBAL LISTS.{/title}",! W "{/head}",! W "{body}",! ; S XX=$ZTRNLNM("QUERY_STRING") ; W "{A HREF=""library7.cgi?TB1""}Sort by Index Number{/A}{BR}" W "{A HREF=""library7.cgi?TB2""}Sort by Last Name{/A}{BR}" W "{A HREF=""library7.cgi?TB3""}Sort by First Name{/A}{BR}" ; I XX="TB1" D TB1 I XX="TB2" D TB2 I XX="TB3" D TB3 ; W "{/body}",! W "{/html}",! ; Q ; TB1 W "{P}",! W "{TABLE BORDER=1}",! W "{TR}",! W "{TH}INDEX{/TH}{TH}FIRST NAME{/TH}{TH}LAST NAME{/TH}",! W "{/TR}",! S ZS1=0 F S ZS1=$O(^ZZLIB3(ZS1)) Q:+ZS1=0 D .S ZD1=^ZZLIB3(ZS1) .W "{TR}",! .W "{TD}",ZS1,"{/TD}","{TD}",$P(ZD1,"^",2),"{/TD}" .W "{TD}",$P(ZD1,"^",1),"{/TD}",! .W "{/TR}",! W "{/TABLE}",! W "{/P}",! Q ; TB2 W "{P}",! W "{TABLE BORDER=1}",! W "{TR}",! W "{TH}INDEX{/TH}{TH}FIRST NAME{/TH}{TH}LAST NAME{/TH}",! W "{/TR}",! S ZS1="B" S ZS2="" F S ZS2=$O(^ZZLIB3(ZS1,ZS2)) Q:ZS2="" D .S ZS3="" .F S ZS3=$O(^ZZLIB3(ZS1,ZS2,ZS3)) Q:ZS3="" D ..S ZS4="" ..F S ZS4=$O(^ZZLIB3(ZS1,ZS2,ZS3,ZS4)) Q:ZS4="" D ...S ZD4=^ZZLIB3(ZS4) ...W "{TR}",! ...W "{TD}",ZS4,"{/TD}","{TD}",$P(ZD4,"^",2),"{/TD}" ...W "{TD}",$P(ZD4,"^",1),"{/TD}",! ...W "{/TR}",! W "{/TABLE}",! W "{/P}",! Q TB3 ; W "{P}",! W "{TABLE BORDER=1}",! W "{TR}",! W "{TH}INDEX{/TH}{TH}FIRST NAME{/TH}{TH}LAST NAME{/TH}",! W "{/TR}",! S ZS1="C" S ZS2="" F S ZS2=$O(^ZZLIB3(ZS1,ZS2)) Q:ZS2="" D .S ZS3="" .F S ZS3=$O(^ZZLIB3(ZS1,ZS2,ZS3)) Q:ZS3="" D ..S ZS4="" ..F S ZS4=$O(^ZZLIB3(ZS1,ZS2,ZS3,ZS4)) Q:ZS4="" D ...S ZD4=^ZZLIB3(ZS4) ...W "{TR}",! ...W "{TD}",ZS4,"{/TD}","{TD}",$P(ZD4,"^",2),"{/TD}" ...W "{TD}",$P(ZD4,"^",1),"{/TD}",! ...W "{/TR}",! W "{/TABLE}",! W "{/P}",! Q
Tutorial Home: M2Web Tutorials Prev: Lesson 6 Next: Lesson 8