// Use WebSessionVariables.nui // Web session variables for ASP pages //> pkgdoc.begin //> Whenever a web application needs to keep track of session variables this //> package provides the means of doing so. Since the WebApp'lication itself //> offers no persistance the variables cannot be kept in here between requests. //> They have to be stored in the IIS that was designed for keeping track of //> sessions. //> //> Traditionally a number of variables are therefore declared in the ASP files //> and these are then stored in session vaiables (session("User_Id), for //> example). //> //> Usually you want access to these variables from within the WebApp so you //> therefore need to pass these variables back and forth between the APS layer //> and the WebApp all the time (on a need-to-know basis). In a reasonable //> complex application this constitutes a lot of house keeping. //> //> This package lets you define your session variables in the VDF code and then //> defines two methods that should be made public to the ASP layer via some //> .wo object. //> //> One function packs all your variables into one string, that the ASP file //> can store in one variable. The other method is a procedure that receives //> such a string from the ASP file and unpacks it into all your variables. //> //> Your session variables are stored inside arrays of the cWebSessionVariables //> class. To assign names to these variables you should use enumeration lists //> like this one: //> //> //> enumeration_list // Standard Web Session Variables //> DEFINE WSV_LANGUAGE // For use in systems with dynamic choice of language //> DEFINE WSV_USER_ID // An identification of the current user //> DEFINE WSV_USER_NAME // The name of the current user //> end_enumeration_list //> //> //> This enables you to get and set the values of the array in a way that //> indicates the purpose of each variable. //> //> Two rules should be observed when assigning values to session variables. //> //> 1. The '|' character (alt+124) may NOT be part of the value. //> 2. The value 0 (or blank) should always be taken to mean 'un-initialised'. //> pkgdoc.end use base.nui class WebFormCookieValues is a cArray procedure construct_object forward send construct_object //> This one identifies the cookie on the client property string psIdent public "" end_procedure item_property_list item_property string psName.i item_property string psValue.i item_property date pdTimeOut end_item_property_list WebFormCookieValues function iFindRow string lsName returns integer integer liRow liMax get row_count to liMax decrement liMax for liRow from 0 to liMax if (lsName=psName.i(self,liRow)) function_return liRow loop function_return -1 end_function function cookie_value string lsName returns string integer liRow get iFindRow lsName to liRow if (liRow<>-1) function_return (psValue.i(self,liRow)) end_function procedure set cookie_value string lsName string lsValue integer liRow get iFindRow lsName to liRow if (liRow=-1) get row_count to liRow set value item liRow to lsValue end_procedure procedure remove_cookie integer lsName integer liRow get iFindRow lsName to liRow if (liRow<>-1) send delete_row liRow end_procedure end_class class WebSessionVariables is a cArray procedure construct_object forward send construct_object //> This one identifies the set of session variables. Needs to be unique. property string psIdent public "" end_procedure function sEncode returns string integer liMax liItem string lsValue lsItem move "" to lsValue get item_count to liMax decrement liMax for liItem from 0 to liMax get value liItem to lsItem move (replaces("|",lsItem,"?")) to lsItem move (lsValue+lsItem+"|") to lsValue loop function_return lsValue end_function procedure ShowLn integer liMax liItem string lsValue showln ("---Session variables ("+psIdent(self)+")---") get item_count to liMax decrement liMax for liItem from 0 to liMax showln (string(liItem)+": "+value(self,liItem)) loop end_procedure procedure end_construct_object integer lhSelf forward send end_construct_object move self to lhSelf // Superstition send WebSessionVariables_Register lhSelf end_procedure end_class // WebSessionVariables object oWebSessionVariablesList is a cArray item_property_list item_property string psIdent.i item_property integer phWebSessionVariables.i end_item_property_list function iFindObject.s string lsIdent returns integer integer liRow liMax get row_count to liMax decrement liMax for liRow from 0 to liMax if (lsIdent=psIdent.i(self,liRow)) function_return liRow loop function_return -1 end_function procedure register_object integer lhObj integer liRow string lsIdent get psIdent of lhObj to lsIdent if (lsIdent="") error 231 "Missing ident of WebSessionVariables object" else begin get iFindObject.s lsIdent to liRow if (liRow<>-1) error 232 "WebSessionVariables object already defined" else begin get row_count to liRow set psIdent.i liRow to lsIdent set phWebSessionVariables.i liRow to lhObj end end end_procedure function sEncode returns string integer liMax liRow liItemCount lhObj string lsIdent lsValue lsRval move "" to lsRval get row_count to liMax decrement liMax for liRow from 0 to liMax get phWebSessionVariables.i liRow to lhObj get item_count of lhObj to liItemCount if liItemCount begin // If there's anything in it get sEncode of lhObj to lsValue get psIdent.i liRow to lsIdent move (lsIdent+"|"+string(liItemCount)+"|"+lsValue) to lsValue // Ident|Number|Values move (lsRval+lsValue) to lsRval end loop function_return lsRval end_function procedure DoResetValues integer liMax liRow lhObj get row_count to liMax decrement liMax for liRow from 0 to liMax get phWebSessionVariables.i liRow to lhObj send delete_data of lhObj loop end_procedure procedure Decode string lsValue integer liItem liPos liLen liItemCount lhObj liRow integer lbReadWhat // 0=Ident, 1=ItemCount, 2=Value string lsItem lsChar lsIdent send DoResetValues // Let nothing survive from previous request move 0 to liPos move 0 to lbReadWhat move (length(lsValue)) to liLen for liPos from 1 to liLen move (mid(lsValue,1,liPos)) to lsChar if (lsChar="|") begin if (lbReadWhat=0) begin // Ident move lsItem to lsIdent move 1 to lbReadWhat // Next read item count end else if (lbReadWhat=1) begin // ItemCount move lsItem to liItemCount if liItemCount begin get iFindObject.s lsIdent to liRow if (liRow=-1) error 233 "cSessionVariablesObject could not be found" get phWebSessionVariables.i liRow to lhObj move 0 to liItem move 2 to lbReadWhat // Read item values end else move 0 to lbReadWhat // If no items, read next ident end else begin // Item Value set value of lhObj item liItem to lsItem increment liItem decrement liItemCount ifnot liItemCount move 0 to lbReadWhat // We're done. Next read Ident end move "" to lsItem end else move (lsItem+lsChar) to lsItem loop if (lsItem<>"") set value item liItem to lsItem end_procedure end_object // oWebSessionVariablesList procedure WebSessionVariables_Register global integer lhWebSessionVariables send register_object of oWebSessionVariablesList lhWebSessionVariables end_procedure // Takes an encoded string containing all variables and dispatches them out // to their respective WebSessionVariables objects. procedure WebSessionVariables_Decode global string lsValue send Decode of oWebSessionVariablesList lsValue end_procedure // Returns the values of all session variables in the application in one big string. function WebSessionVariables_Encode global returns string string lsValue get sEncode of oWebSessionVariablesList to lsValue function_return lsValue end_function object oBaseSessionVariables is a WebSessionVariables set psIdent to "base" end_object enumeration_list // Standard Web Session Variables DEFINE WSV_SESSION_ACTIVE // If a session is active this is 1, otherwise blank. DEFINE WSV_LANGUAGE // For use in systems with dynamic choice of language (integer) DEFINE WSV_USER_ID // An identification of the current user DEFINE WSV_USER_NAME // The name of the current user DEFINE WSV_MODULE_NAME // Name of the module currently being accessed DEFINE WSV_PAGE_NAME // Name of the page within the module currently being accessed DEFINE WSV_COMMENTS_ON // TRUE if site commenting feature has been switched on DEFINE WSV_CURRENT_URL // The URL most currently requested DEFINE WSV_CURRENT_QRYSTR // The query string that came with the most currently requested URL DEFINE WSV_PREV_QRYSTR // The query string that came with the previously requested URL end_enumeration_list