libname SAMPDAT '!SASROOT\intrnet\sample'; data SAMPDAT.LIB_INVENTORY; length type $10 desc $80; input refno 1-5 type 7-16 desc 17-80; datalines4; 17834 BOOKSAS/GRAPH Software: Reference 32345 BOOKSAS/GRAPH Software: User's Guide 52323 BOOK SAS Procedures Guide 54337 BOOK SAS Host Companion for UNIX Environments 35424 BOOK SAS Host Companion forz/OS Environment 93313 AUDIO The Zen of SAS 34222 VIDEO Getting Started with SAS 34223 VIDEO Introduction to AppDev Studio 34224 VIDEO Building Web Applications withSAS/IntrNet Software 70001 HARDWARE Cellphone - Model 5153 70002 HARDWARE Video Project - Model 79F15 ;;;;
/* LIB_LOGIN.SAS - Welcome to the Online Library */ /* Print a welcome page that is static except for the Application Dispatcher variables _URL, _SERVICE, and _PGMLIB. */ data _null_; file _webout; put '<HEAD>'; put '<TITLE>Welcome to the Online Library</TITLE>'; put '</HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put "<H1 ALIGN=CENTER>Welcome to the Online Library</H1>"; put '<HR>'; put "<P>This is a demonstration ofSAS/IntrNet Application Dispatcher sessions.</P>"; put '<P>Before you can start, you must log in. Enter your login ID below: </P>'; put '<FORM ACTION="' "&_url" '">'; put '<INPUT TYPE="HIDDEN" NAME="_service" VALUE="' "&_service" '">'; put '<INPUT TYPE="HIDDEN" NAME="_program" VALUE="' "&_pgmlib" '.lib_main.sas">'; put 'Login ID: <INPUT SIZE=12 NAME="loginid"><P>'; put 'Password: <INPUT SIZE=12 TYPE="password" NAME="password"><P>'; put '<INPUT TYPE="SUBMIT" VALUE="Login">'; put '<INPUT TYPE="RESET" VALUE="Reset">'; put '</FORM>'; put '</BODY>'; put '</HTML>'; run;
/* LIB_MAIN.SAS - Main Aisle of the Online Library */ /* Use a macro here in order to use conditional logic. */ %macro lib_main; /* Check to see if you are already in a session; if so, you don't need to validate login info. */ %if %sysfunc(libref(SAVE)) %then %do; /* SAVE libref doesn't exist, so you have not successfully logged in. */ /* Insert logic here in order to validate the login ID and password. For the purposes of this sample, assume that any non-blank password is valid. This is not usually a good idea; a real application can be expected to insert some real validation logic here. */ %if &password ne %then %let IDCHECK=PASSED; %else %let IDCHECK=FAILED; %if &IDCHECK ne PASSED %then %do; /* Validation failed - print a failure page. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Invalid Login</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Invalid Login</H1>'; put; put '<P>The login ID and password that you supplied are invalid.'; put 'Please return to the <A HREF="' @; put "&_URL?_SERVICE=&_service" '&_program=' "&_pgmlib" @; put '.lib_login.sas">login page</a> and re-enter a valid'; put 'login ID and password.</P>'; put; put '<P>If you are unable to log in, please contact the'; put 'Library Help at extension 14325.</P>'; put '</BODY></HTML>'; run; %end; %else %do; /* Validation successful - create session and save login ID. */ %let rc=%sysfunc(appsrv_session(create)); /* SAVE_* variables must be global. */ %global SAVE_LOGINID; /* Save the login ID in the session. */ %let SAVE_LOGINID=&loginid; %end; %end; /* Assume valid login if session already exists. */ %else %let IDCHECK=PASSED; %if &IDCHECK eq PASSED %then %do; /* Print the Main Aisle page. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Online Library Main Aisle</TITLE></HEAD>'; put; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Online Library Main Aisle</H1>'; put; put 'Select one of the following areas of the library:'; put '<UL>'; length hrefroot $400; hrefroot = "%superq(_THISSESSION)" || '&_PROGRAM=' || "&_PGMLIB"; put '<LI><A HREF="' hrefroot +(-1) '.lib_aisle.sas&type=Book">Book Aisle</A></LI>'; put '<LI><A HREF="' hrefroot +(-1) '.lib_aisle.sas&type=Video">Video Aisle</A></LI>'; put '<LI><A HREF="' hrefroot +(-1) '.lib_aisle.sas&type=Audio">Audio Aisle</A></LI>'; put '<LI><A HREF="' hrefroot +(-1) '.lib_aisle.sas&type=Hardware">Hardware Aisle</A></LI>'; put '<LI><A HREF="' hrefroot +(-1) '.lib_cart.sas">View my shopping cart</A></LI>'; put '<LI><A HREF="' hrefroot +(-1) '.lib_logout.sas">Logout</A></LI>'; put '</UL>'; put '</BODY>'; put '</HTML>'; run; %end; %mend; %lib_main;
/* LIB_AISLE.SAS - List items in a specified aisle. The aisle is specified by the TYPE variable. */ %macro lib_aisle; /* Check for a valid session - verifies that the user has logged in. */ %if %sysfunc(libref(SAVE)) %then %do; /* SAVE libref doesn't exist - redirect to login page. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Missing Login</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Missing Login</H1>'; put; put '<P>You must log in before you can use this application.'; put 'Please return to the <A HREF="' @; put "&_URL?_SERVICE=&_service" '&_program=' "&_pgmlib" @; put '.lib_login.sas">login page</a> and enter a valid login ID'; put 'and password.</P>'; put; put '<P>If you are unable to log in, please contact the'; put 'Library Help at extension 14325.</P>'; put '</BODY></HTML>'; run; %end; %else %do; /* Build a temporary data set that contains the selected type, and add links for selecting and adding items to the shopping cart. */ data templist; set SAMPDAT.LIB_INVENTORY; where type="%UPCASE(&type)"; length select $200; select = '<A HREF="' || "%superq(_THISSESSION)" || '&_program=' || "&_PGMLIB" || '.LIB_ADDITEM.SAS&REFNO=' || trim(left(refno)) || '&TYPE=' || "&TYPE" || '">Add to cart</A>'; run; ods html body=_webout(nobot) rs=none; title Welcome to the &type Aisle; proc print data=templist noobs label; var refno desc select; label refno='RefNo' desc='Description' select='Select'; run; ods html close; data _null_; file _webout; put '<P>'; put 'Return to <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_MAIN.SAS">main aisle</A><BR>'; put 'View my <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_CART.SAS">shopping cart</A><BR>'; put '</BODY>'; put '</HTML>'; run; %end; %mend; %lib_aisle;
/* LIB_ADDITEM.SAS - Add a selected item to the shopping cart. This program uses REFNO and TYPE input variables to identify the item. */ /* Perform REFNO and TYPE verification here. */ /* Append the selected item. */ proc append base=SAVE.CART data=SAMPDAT.LIB_INVENTORY; where refno=&refno; run; /* Print the page. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Selected Item Added to Shopping Cart</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put "<H1>Item &refno Added</H1>"; put 'Return to <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_AISLE.SAS&TYPE=' "&TYPE" '">' "&TYPE aisle</A><BR>"; put 'Return to <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_MAIN.SAS">main aisle</A><BR>'; put 'View my <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_CART.SAS">shopping cart</A><BR>'; put '</BODY>'; put '</HTML>'; run;
/* LIB_CART.SAS - Display contents of the shopping cart (SAVE.CART data set). */ %macro lib_cart; %let CART=%sysfunc(exist(SAVE.CART)); %if &CART %then %do; /* This program could use the same technique as the LIB_AISLE program in order to add a link to each line of the table that removes items from the shopping cart. */ /* Print the CART contents. */ ods html body=_webout(nobot) rs=none; title Your Selected Items; proc print data=SAVE.CART noobs label; var refno desc; label refno='RefNo' desc='Description'; run; ods html close; %end; %else %do; /* No items in the cart. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>No items selected</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>No Items Selected</H1>'; put; run; %end; /* Print navigation links. */ data _null_; file _webout; put '<P>'; if &CART then do; put '<FORM ACTION="' "&_url" '">'; put '<INPUT TYPE="HIDDEN" NAME="_service" VALUE="' "&_service" '">'; put '<INPUT TYPE="HIDDEN" NAME="_program" VALUE="' "&_pgmlib" '.LIB_LOGOUT.SAS">'; put '<INPUT TYPE="HIDDEN" NAME="_server" VALUE="' "&_server" '">'; put '<INPUT TYPE="HIDDEN" NAME="_port" VALUE="' "&_port" '">'; put '<INPUT TYPE="HIDDEN" NAME="_sessionid" VALUE="' "&_sessionid" '">'; put '<INPUT TYPE="HIDDEN" NAME="CHECKOUT" VALUE="YES">'; put '<INPUT TYPE="SUBMIT" VALUE="Request these items">'; put '</FORM><P>'; end; put 'Return to <A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_MAIN.SAS">main aisle</A><BR>'; put '<A HREF="' "%SUPERQ(_THISSESSION)" '&_PROGRAM=' "&_PGMLIB" '.LIB_LOGOUT.SAS&CHECKOUT=NO">Logout</A><BR>'; put '</BODY>'; put '</HTML>'; run; %mend; %lib_cart;
/* LIB_LOGOUT.SAS - logout of Online Library application. Send e-mail to the library@abc.com account with requested item if CHECKOUT=YES is specified. */ %macro lib_logout; /* Define CHECKOUT in case it was not input. */ %global CHECKOUT; %if %UPCASE(&CHECKOUT) eq YES %then %do; /* Checkout - send an e-mail request to the library. E-mail options must be specified in order for the Application Server to use the e-mail access method. */ filename RQST EMAIL 'library@mybiz.xyz' SUBJECT="Online Library Request for &SAVE_LOGINID"; ods listing body=RQST; title Request for &SAVE_LOGINID; proc print data=SAVE.CART label; var refno type desc; label refno='RefNo' type='Type' desc='Description'; run; ods listing close; data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Library Checkout</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Library Checkout</H1>'; put; put 'The items in your shopping cart have been requested.'; put '<P>Requested items will normally arrive via interoffice'; put 'mail by the following day. Thank you for using the Online Library.'; put '<P><A HREF="' "&_URL?_SERVICE=&_SERVICE" '&_PROGRAM=' "&_PGMLIB" '.LIB_LOGIN.SAS">Click here</A> to re-enter the'; put 'application.'; put '</BODY>'; put '</HTML>'; run; %end; %else %do; /* Logout without requesting anything. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Logout</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Library Logout</H1>'; put; put '<P>Thank you for using the Online Library.'; put '<P><A HREF="' "&_URL?_SERVICE=&_SERVICE" '&_PROGRAM=' "&_PGMLIB" '.LIB_LOGIN.SAS">Click here</A> to re-enter the'; put 'application.'; put '</BODY>'; put '</HTML>'; run; %end; %mend; %lib_logout; /* User is finished - delete the session. */ %let rc=%sysfunc(appsrv_session(delete));
/* LIB_INVSESS.SAS - Display useful message for expired or invalid sessions. */ %macro lib_invsess; %if %upcase(%substr(%scan(&_USERPROGRAM,2,.),1,4)) eq LIB_ and %upcase(%scan(&_USERPROGRAM,3,.)) eq SAS %then %do; /* If the program name (second part of three part name) starts with LIB_ and the program type (third part) is SAS, then this is the On-Line Library application and you can print an application-specific message. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Session Expired</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Session Expired</H1>'; put; put 'Your connection to the Online Library has expired. You must'; put 'log in again.'; put '<P>'; put '<A HREF="' "&_URL;?_SERVICE=&_SERVICE" '&_PROGRAM=' "%scan(&_USERPROGRAM,1,.).LIB_LOGIN.SAS" '">Click here</A> to log in.'; put '</BODY>'; put '</HTML>'; run; %end; %else %do; /* Otherwise, this is an unknown application; print a generic error page. */ data _null_; file _webout; put '<HTML>'; put '<HEAD><TITLE>Invalid or Expired Session</TITLE></HEAD>'; put '<BODY vlink="#004488" link="#0066AA" bgcolor="#E0E0E0">'; put '<H1>Invalid or Expired Session</H1>'; put; put 'Your application session has expired. In order to continue,'; put 'you must restart this application.'; put '</BODY>'; put '</HTML>'; run; %end; %mend; %lib_invsess;