Lesson 7

Linux / Apache / GT.M / Web Application~ Lesson 7 - B Corrected for Security. By Ben Irwin, Copied from: http://www.doggiedudes.com/fscc/list.htm

Tutorial Home: M Web 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 the HTML entity CHARACTERS ie: & lt ; BECAUSE THE WIKI WAS NOT FORMATTING PROPERLY OTHERWISE. LIKEWISE, ALL THE '>' characters WERE CHANGED TO & rt ;. You can cut and paste from the rendered page, but you will have to Replace these back to the proper '<' and '>' characters when cutting and pasting from the edit-page.

ZZLIB7 --- ZZLIB7   ; ROUTINE TO CREATE A WEB PAGE USING THE ^ZZLIB3 GLOBAL. ;    ;     W "Content-type: text/html",!! W "&lt;html&gt;",! W "&lt;head&gt;",! W "&lt;title&gt;ZZLIB3 GLOBAL LISTS.&lt;/title&gt;",! W "&lt;/head&gt;",! W "&lt;body&gt;",! ;    S XX=$ZTRNLNM("QUERY_STRING") ;    W "&lt;A HREF=""library7.cgi?TB1""&gt;Sort by Index Number&lt;/A&gt;&lt;BR&gt;" W "&lt;A HREF=""library7.cgi?TB2""&gt;Sort by Last Name&lt;/A&gt;&lt;BR&gt;" W "&lt;A HREF=""library7.cgi?TB3""&gt;Sort by First Name&lt;/A&gt;&lt;BR&gt;" ;            I XX="TB1" D TB1 I XX="TB2" D TB2 I XX="TB3" D TB3 ;    W "&lt;/body&gt;",! W "&lt;/html&gt;",! ;    Q     ; TB1 W "&lt;P&gt;",! W "&lt;TABLE BORDER=1&gt;",! W "&lt;TR&gt;",! W "&lt;TH&gt;INDEX&lt;/TH&gt;&lt;TH&gt;FIRST NAME&lt;/TH&gt;&lt;TH&gt;LAST NAME&lt;/TH&gt;",! W "&lt;/TR&gt;",! S ZS1=0 F S ZS1=$O(^ZZLIB3(ZS1)) Q:+ZS1=0  D     .S ZD1=^ZZLIB3(ZS1) .W "&lt;TR&gt;",! .W "&lt;TD&gt;",ZS1,"&lt;/TD&gt;","&lt;TD&gt;",$P(ZD1,"^",2),"&lt;/TD&gt;" .W "&lt;TD&gt;",$P(ZD1,"^",1),"&lt;/TD&gt;",! .W "&lt;/TR&gt;",! W "&lt;/TABLE&gt;",! W "&lt;/P&gt;",! Q    ; TB2 W "&lt;P&gt;",! W "&lt;TABLE BORDER=1&gt;",! W "&lt;TR&gt;",! W "&lt;TH&gt;INDEX&lt;/TH&gt;&lt;TH&gt;FIRST NAME&lt;/TH&gt;&lt;TH&gt;LAST NAME&lt;/TH&gt;",! W "&lt;/TR&gt;",! 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 "&lt;TR&gt;",! ...W "&lt;TD&gt;",ZS4,"&lt;/TD&gt;","&lt;TD&gt;",$P(ZD4,"^",2),"&lt;/TD&gt;" ...W "&lt;TD&gt;",$P(ZD4,"^",1),"&lt;/TD&gt;",! ...W "&lt;/TR&gt;",! W "&lt;/TABLE&gt;",! W "&lt;/P&gt;",! Q TB3 ; W "&lt;P&gt;",! W "&lt;TABLE BORDER=1&gt;",! W "&lt;TR&gt;",! W "&lt;TH&gt;INDEX&lt;/TH&gt;&lt;TH&gt;FIRST NAME&lt;/TH&gt;&lt;TH&gt;LAST NAME&lt;/TH&gt;",! W "&lt;/TR&gt;",! 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 "&lt;TR&gt;",! ...W "&lt;TD&gt;",ZS4,"&lt;/TD&gt;","&lt;TD&gt;",$P(ZD4,"^",2),"&lt;/TD&gt;" ...W "&lt;TD&gt;",$P(ZD4,"^",1),"&lt;/TD&gt;",! ...W "&lt;/TR&gt;",! W "&lt;/TABLE&gt;",! W "&lt;/P&gt;",! Q

Tutorial Home: M Web Tutorials Prev: Lesson 6 Next: Lesson 8