WIKINDX uses sessions extensively for storage of default configuration, authorization, user preferences and for temporary storage of user input strings and the session class has a variety of methods for manipulating sessions.
All session variables in WIKINDX have a prefix which groups all variables of a certain type together. For example, all session variables to do with authorization and default configuration have the prefix 'setup' and it is a simple matter to access and manipulate this group of variables using the session methods:
getArray('setup') writeArray($assocArray, 'setup') clearArray('setup')Currently used prefixes:
'config' (temporary storage of admin configuration variables used when updating the WIKINDX configuration) 'convert' (temporary storage of database conversion variables used when converting v1 database resources to v2) 'exportRtf' (temporary storage for RTF export parameters) 'exportHtml' (temporary storage for HTML export parameters) 'import' (temporary storage of bibliography import parameters) 'list' (all resource listing options) 'mywikindx' (user bibliographies etc.) 'news' (for news items) 'preferences' (temporary storage of configuration variables used when updating WIKINDX user preferences) 'resource' (temporary storage user resource input when creating or editing resources) 'setup' (all authorization and configuration variables setup on script initialization) 'sql' (SQL statements used when exporting the last resource select or list operation to RTF or BibTeX) 'style' (temporary storage of variables used when creating/editing bibliographic styles) 'cite' (temporary storage of variables used when creating/editing citation styles) 'list' (temporary storage of variables used when listing bibliographies) 'custom' (temporary storage of variables used when creating custom database fields) 'bookmarks' (user bookmarks)
'wp' (temporary storage of word processor variables) 'exportPaper' (temporary storage for paper (SUWP) export parameters) 'select' (temporary storage of resource select parameters) 'search' (temporary storage of resource quick search parameters) 'powerSearch' (temporary storage of resource power search parameters) 'selectMeta' (temporary storage of metadata select parameters) 'searchMeta' (temporary storage of metadata search parameters) 'preview' (temporary storage of bibliographic style preview data) 'basket' (temporary storage of a basket of resources) 'emailFriend' (temporary storage of email message when sending resource link to a friend)
Of the above, the following are set at system initialisation:
setup_language: the user's preferred localisation matching the folder name in languages/ setup_style: the user's preferred bibliographic style setup_default: the user's preferred template/theme setup_paging: the user's preferred number of resources to display per page setup_pagingMaxLinks: the user's preferred number of paging links setup_stringLimit: the user's preferred maximum string length within form select boxes setup_notify: is email notification allowed when resources are added or edited? 0|1 for FALSE|TRUE (or not set) setup_title: the WIKINDX title (displayed on each page) setup_fileDeleteSeconds: number of seconds before exported files are scheduled for deletion setup_bibliographies: are there populated user bibliographies for viewing? 0|1 for FALSE|TRUE (or not set) setup_multiUser: is the WIKINDX in multi user mode? 0|1 for FALSE|TRUE (or not set) setup_readOnly: read only access? 0|1 for FALSE|TRUE setup_fileAttach: allow file attachments? 0|1 for FALSE|TRUE setup_fileViewLoggedOnOnly: allow only logged on users to view file attachments? 0|1 for FALSE|TRUE setup_news: are there news items available for viewing? 0|1 for FALSE|TRUE The following are set if setup_readOnly is not set (or is FALSE): setup_superadmin: is the user the admin? 0|1 for FALSE|TRUE setup_userId: the user's ID number as found in the database table WKX_users setup_write: does this user have write/edit privileges? 0|1 for FALSE|TRUE
The following may also be of interest:
sql_stmt: the complete SQL statement last used when displaying bibliographic lists (list by, select by, search or power search). This can be fed direct to the database once you have stripped slashes from it. sql_lastMulti: the type of the last bibliographic list display (list|select|search|powerSearch) sql_lastSolo: the resource ID (as in WKX_resource) of the last single resource view mywikindx_bibliography_use: the id of the bibliography (as in WKX_user_bibliography) that the user has chosen to browse. This is not set (or is FALSE) if the master bibliography has been chosen for browsing instead. sql_lastMultiMeta: the last type of view for metadata (select|search).
Note that SESSION::getVar(STRING: session variable) will return FALSE if the session variable is FALSE (or 0) OR the session variable is not set.
When displaying a form or processing user input, it is good practice to grab any needed/preset values from the database or from user form input and immediately write them all to the session with an appropriate prefix. Then, create the HTML code for the form elements grabbing appropriate values from the session if needed.
If the user makes an error on form input, this method makes it very easy to send the user back to the form with his/her pre-filled values grabbed from the session.
i.e. Make it standard practice that preset values for form elements come only from the session (which may get its values from user form input or from the database) and never directly from user form input or the database.
An example of this can be found in CONFIG:
When displaying the form for the first time, the program flow may be summarized thus:A: 'config' prefixed variables in session? yes: store session 'config_xxxx' variables in $array no: grab values from db table and place in $array and write 'config_xxxx' variables to session using $array display form elements with values from $arrayand when accepting user input from the form:
B: write user input to session with 'config' prefix user input correctly validated? no: return to A yes: insert/update database