Difference between revisions of "Lesson 12"

From VistApedia
Jump to: navigation, search
(Added a glossary link to Action~)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Linux / Apache / GT.M / Web Application Lesson 12.
+
Linux / Apache / GT.M / Web [[Application~|Application]] Lesson 12.
  
 
  By Ben Irwin,  
 
  By Ben Irwin,  
Line 22: Line 22:
 
When each button is clicked, you should notice a change in the bottom level of the screen.  Each click of a button returns a different value for the variable SCN.  The number SCN (1, 2, 3, 4, 5, 6) is combined with the letters "SCN" to produce a routine tag to perform (SCN1, SCN2, SCN3, SCN4, SCN5, SCN6).  So that as we continue to develop our routine each press of a button at the top of the page will produce a different form at the bottom of the screen to fill out for the different types of information that we will be collecting.
 
When each button is clicked, you should notice a change in the bottom level of the screen.  Each click of a button returns a different value for the variable SCN.  The number SCN (1, 2, 3, 4, 5, 6) is combined with the letters "SCN" to produce a routine tag to perform (SCN1, SCN2, SCN3, SCN4, SCN5, SCN6).  So that as we continue to develop our routine each press of a button at the top of the page will produce a different form at the bottom of the screen to fill out for the different types of information that we will be collecting.
  
The action variable ACT will be used in a similar manner, combined with the letters "ACT" to create a subroutine tag to perform as required by the context of the routine.  The actions will include adding data to the database, deleting, editing or viewing information in the database.  That is what the dev buttons stand for, delete, edit, view.
+
The [[action~|Action]] variable ACT will be used in a similar manner, combined with the letters "ACT" to create a subroutine tag to perform as required by the context of the routine.  The [[action~|Action]]s will include adding data to the database, deleting, editing or viewing information in the database.  That is what the dev buttons stand for, delete, edit, view.
  
 
This lesson and the previous lessons can be viewed at:
 
This lesson and the previous lessons can be viewed at:
Line 56: Line 56:
 
     D BUTTON
 
     D BUTTON
 
     ;
 
     ;
     ; Perform the requested action step.
+
     ; Perform the requested [[action~|Action]] step.
 
     S ACT="ACT"_$G(ACT)
 
     S ACT="ACT"_$G(ACT)
 
     D @ACT
 
     D @ACT
Line 100: Line 100:
 
     Q RESULT
 
     Q RESULT
 
     ;
 
     ;
  ACT  ; Initial Action.
+
  ACT  ; Initial [[Action~|Action]].
     W "NO ACTION PERFORMED{BR}",!
+
     W "NO [[ACTION~|Action]] PERFORMED{BR}",!
 
     W "{HR}",!
 
     W "{HR}",!
 
     Q
 
     Q
Line 136: Line 136:
 
     ;
 
     ;
 
     W !
 
     W !
     W "{FORM METHOD=""POST"" NAME=""Screen_Form"" ACTION=""ZZLIBM.sh""}",!
+
     W "{FORM METHOD=""POST"" NAME=""Screen_Form"" [[ACTION~|Action]]=""ZZLIBM.sh""}",!
 
     W "  {INPUT TYPE=HIDDEN NAME=SCN}",!
 
     W "  {INPUT TYPE=HIDDEN NAME=SCN}",!
 
     W "{/FORM}",!!
 
     W "{/FORM}",!!

Latest revision as of 18:55, 24 July 2012

Linux / Apache / GT.M / Web Application Lesson 12.

By Ben Irwin, 
Copied from: http://www.doggiedudes.com/fscc/list.htm
Tutorial Home: M Web Tutorials
Prev: Lesson 11

This lesson lists the cgi script that I used to call the main library routine and a listing of the actual main library routine.

The main library mumps routine, so far is just a shell of the routine that we will continue to work on. I am sorry for any terminology confusion.

The routine is made up of a main section at the top that calls subroutines and functions included in the lower portion of the program listing. The nice part about this is that for the process to work in Cache, the main routine is replaced with a csp (Cache Server Page) with calls to the same subroutines and functions. So once the main routine for GT.M and the csp for Cache are distributed, the remainder of the development can be to a single routine common to both systems.

This programming technique user four different languages to produce one little web application.

1. CGI Scripting used to interface between the Apache Web Server and MUMPS.
2. MUMPS as the main control language used to write html and JavaScript to the web page.
3. HTML to produce the web page look and feel.
4. JavaScript to make the buttons and form submission a little more user friendly.

When each button is clicked, you should notice a change in the bottom level of the screen. Each click of a button returns a different value for the variable SCN. The number SCN (1, 2, 3, 4, 5, 6) is combined with the letters "SCN" to produce a routine tag to perform (SCN1, SCN2, SCN3, SCN4, SCN5, SCN6). So that as we continue to develop our routine each press of a button at the top of the page will produce a different form at the bottom of the screen to fill out for the different types of information that we will be collecting.

The Action variable ACT will be used in a similar manner, combined with the letters "ACT" to create a subroutine tag to perform as required by the context of the routine. The Actions will include adding data to the database, deleting, editing or viewing information in the database. That is what the dev buttons stand for, delete, edit, view.

This lesson and the previous lessons can be viewed at:

http://www.doggiedudes.com/fscc/Library.htm
ZZLIBM.sh
-------------------------------------------------------------#!/bin/sh
read XXXX
export XXXX
cd /usr/local/gtm/VISTA
export gtm_dist=/usr/local/gtm
export gtmroutines="$gtm_dist/VISTA/uo($gtm_dist/VISTA/ur) $gtm_dist"
export gtmgbldir=/usr/local/gtm/VISTA/mumps.gld
export PATH=$PATH:$gtm_dist
mumps -run ZZLIBM
-------------------------------------------------------------


ZZLIBM - Main Library Routine.
-------------------------------------------------------------
ZZLIBM    ; VISTA LIBRARY SYSTEM.
    ;
    ; Call the routine to print the page header information.
    D HEAD
    ;
    ; Set incoming variables using the WEBIN function.
    S CHK=$$WEBIN($ZTRNLNM("XXXX"),"ACT|SCN|DATA1|DATA2|DATA3|DATA4")
    I CHK=0 W "SORRY, PAGE ERROR" G FOOT
    ;
    ; Write button portion of the page.
    D BUTTON
    ;
    ; Perform the requested Action step.
    S ACT="ACT"_$G(ACT)
    D @ACT
    ;
    ; Perform the requested screen step
    S SCN="SCN"_$G(SCN)
    D @SCN
    ;
    ; Call the routine to print the page footer information.
    D FOOT
    ;
    Q
    ;
HEAD; HTML Main header information.
    W "Content-type: text/html",!!
    W "{html}",!
    W "{head}",!
    W "{title}Main Library System{/title}",!
    W "{/head}",!
    W "{BODY BGCOLOR=#AAFFFF}",!
    W "{CENTER}{P}{FONT SIZE=+2}VISTA LIBRARY SYSTEM{/FONT}{/P}{/CENTER}",!
    Q
    ;
BUTTON   ; Subroutine to draw the buttons.
    W "{CENTER}",!
    W "{TABLE}",!
    W "{TR}",!
    W $$BUTTON1(1,2,"Book"),!
    W $$BUTTON1(3,4,"Author"),!
    W $$BUTTON1(5,6,"Publisher"),!
    W "{/TR}",!
    W "{/TABLE}",!
    W "{HR}",!
    Q
    ;
BUTTON1(S1,S2,DESC)  ; Function to produce buttons and labels.
    N RESULT
    S RESULT="{TD valign=top Align=center WIDTH=100}"
    S RESULT=RESULT_"{INPUT TYPE=BUTTON VALUE=""Add"" onClick=""SCREENB1('"_S1_"')""}{BR}"
    S RESULT=RESULT_"{INPUT TYPE=BUTTON VALUE=""Dev"" onClick=""SCREENB1('"_S2_"')""}{BR}"
    S RESULT=RESULT_DESC
    S RESULT=RESULT_"{/TD}"
    Q RESULT
    ;
ACT  ; Initial Action.
    W "NO Action PERFORMED{BR}",!
    W "{HR}",!
    Q
    ;
SCN  ; Initial Screen.
    W "NO SCREEN PERFORMED{BR}",!
    Q
    ;
SCN1 ; Screen 1.
    W "SCREEN SELECTION 1",!
    Q
    ;
SCN2 ; Screen 2.
    W "SCREEN SELECTION 2",!
    Q
    ;
SCN3 ; Screen 3.
    W "SCREEN SELECTION 3",!
    Q
    ;
SCN4 ; Screen 4.
    W "SCREEN SELECTION 4",!
    Q
    ;
SCN5 ; Screen 5.
    W "SCREEN SELECTION 5",!
    Q
    ;
SCN6 ; Screen 6.
    W "SCREEN SELECTION 6",!
    Q
    ;
FOOT ; TAG USED TO QUIT ON INPUT ERROR
    ;
    W !
    W "{FORM METHOD=""POST"" NAME=""Screen_Form"" Action=""ZZLIBM.sh""}",!
    W "   {INPUT TYPE=HIDDEN NAME=SCN}",!
    W "{/FORM}",!!
    W "{SCRIPT LANGUAGE=""JavaScript""}",!
    W "function SCREENB1(SCN)",!
    W "     {",!
    W "     document.Screen_Form.SCN.value=SCN",!
    W "     document.Screen_Form.submit()",!
    W "     }",!
    W "{/SCRIPT}",!!
    W "{/body}",!
    W "{/html}",!
    ;
    Q
    ;
WEBIN(WEBIN,VARS) ; Routine to Split the Input Line from a Web Form.
    ;
    ; Input: WEBIN - Web QUERY_STRING, POST, or GET variable.
    ;        VARS  - String of variables to set.  Can not include
    ;                XX, ERR, VAR, VARS, VARSA, VAL, WEBIN.
    ;
    ; Output: Web Form Variables
    ;         Function Value: 0 - Error
    ;                         1 - Successful
    ;
    N XX,VAR,VAL,VARSA,ERR
    ;
    ; Check for missing input variables.
    Q:$L(WEBIN)=0 1
    Q:$L(WEBIN,"=")<2 1
    Q:$L(VARS)=0 0
    ;
    ; Disable setting global variables and routine values.
    Q:$L(WEBIN,"^")>1 0
    Q:$L(WEBIN,"%5E")>1 0
    ;
    ; Set up acceptable output variables array.
    F XX=1:1:$L(VARS,"|") S:$P(VARS,"|",XX)'="" VARSA($P(VARS,"|",XX))=""
    ;
    ; Protect function variables.
    Q:$D(VARSA("XX"))=1 0
    Q:$D(VARSA("ERR"))=1 0
    Q:$D(VARSA("VAR"))=1 0
    Q:$D(VARSA("VARS"))=1 0
    Q:$D(VARSA("VARSA"))=1 0
    Q:$D(VARSA("VAL"))=1 0
    Q:$D(VARSA("WEBIN"))=1 0
    ;
    ; Translate the "+" to spaces.
    S WEBIN=$TR(WEBIN,"+"," ")
    ;
    ; Move through each Variable=Value pair.
    F XX=1:1:$L(WEBIN,"&") D
    .S VAR=$P($P(WEBIN,"&",XX),"=",1)
    .S VAL=$$PARSE($P($P(WEBIN,"&",XX),"=",2))
    .S:$D(VARSA(VAR))=1 @VAR=VAL
    ;
    Q 1
    ;
PARSE(PIN); Parse Input Line.  Assigning charicators to the ascii values.
    ;
    N YY,POUT,PIECE
    I $L(PIN,"%")<2 Q PIN
    S POUT=$P(PIN,"%",1)
    F YY=2:1:$L(PIN,"%") D
    .S PIECE=$P(PIN,"%",YY)
    .S POUT=POUT_$C($$FUNC^%HD($E(PIECE,1,2)))
    .S POUT=POUT_$E(PIECE,3,$L(PIECE))
    ;
    Q POUT
-------------------------------------------------------------
Tutorial Home: M Web Tutorials
Prev: Lesson 11