Authentication, form elements display, data handling routines
Package: eiseIntra
Version: 2.0beta
eiseIntra is the core class that encapsulates routines for authenication, form elements display, data handling, redirection and debug.
This class extends eiseIntraData as base class.
Constructor receives eiseSQL object with database connection as input parameter and performs object initialization with configuration options supplied in $conf array.
Category: Authentication Initialization
Parameters:
ltrim(dirname($_SERVER['PHP_SELF']), '/')
(isset($eiseIntraCookiePath) ? $eiseIntraCookiePath : '/')
Function decodes authstring login:password using current encoding algorithm (now base64).
Category: Authentication
Parameters:
Returns: array [string $login, string $password]
Function encodes authstring login:password using current encoding algorithm (now base64).
Category: Authentication
Parameters:
Returns: string Encoded authentication string.
Function that checks authentication with credentials database using selected $method. Now it supports the following methods:
LDAP method was successfully tested with Active Directory on Windows 2000, 2003, 2008, 2008R2 servers.
Category: Authentication
Parameters:
Returns: boolean authentication result: true on success, otherwise false.
This function intialize session with session cookes placed at path set by $this->conf[‘cookiePath’] configuration variable.
Category: Authentication
This function quits user session.
Category: Authentication
This function checks current user’s permissions on currently open script.
Also it checks session expiration time, and condition when user is blocked or not in the database.
Script name is obtained from $_SERVER['SCRIPT_NAME']
global variable.
Permission information is collected from stbl_page_role table and calculated according to user role membership defined at stbl_role_user table.
Permissions are calulated in the following way:
If user has no permissions to ‘Read’ the script, function throws header Location: login.php
and stops the script.
When ‘Read’ permissions are confirmed for the user, function updates $intra->arrUsrData property. Click on this link to see full description.
NOTE: Role membership information is collected from stbl_role_user table basing on rluInsertDate timestamp, it should not be in the future. It is useful when some actions should be temporarily delegated to the other user in case of vacations, illness etc.
Page permissions can be set with eiseAdmin’s GUI at < database >/Pages menu.
Role membership can be set by system’s GUI at system’s Setting/Access Control menu or
Category: Authentication Authorization
Returns: array $intra->arrUsrData
This method returns content of top-level “jumper” menu as drop-down list. “Jumper” menu content goes with an associative array passed as parameter to this function.
Category: Navigation
This method returns system menu <ul>
HTML for menu structure.
Category: Navigation
Parameters:
<a href="...">
inside menuReturns: string HTML with menu structure
This method returns HTML for “action menu” - the menu that displayed above the functional part of the screen. Menu content is set by $arrActions parameter, the set of associative arrays with menu items. Menu item definition array consists of the following properties: array[] - menu item set. No nested menu items, no dropdowns in this version.
Category: Navigation
Parameters:
Returns: string HTML for “action menu”.
This method includes specified $components into your PHP code by calling corresponding include() PHP functions and filling out $arrJS and $arrCSS arrays.
Category: Initialization
Parameters:
This method adds HTTP header “Location” that redirects user to URL/URI specified in $strLocation, with text message to be shown on this page, specified in $strMessage parameter.
Message will be shown on eiseIntra enabled page, using $('body').eiseIntra('showMessage')
function that will fire right after $('window').load()
event.
Message will be saved for display using cookies. By default cookie path is the path part of $strLocation URL. If $intra->conf[‘flagSetGlobalCookieOnRedirect’] is TRUE, cookie path will be set by global constant $this->conf[‘cookiePath’].
This property can be overriden for this function with the $arrConfig[] parameter member ‘flagSetGlobalCookieOnRedirect’ = TRUE/FALSE. It can be useful when you need to redirect user from project subdirectory to the script placed at the root one, for example:
$intra->redirect('Operation successfull', '/myproject/item_form.php?itemID=12345');
// normal redirect within the project
$intra->redirect('Bye-bye, see you later', '/byebye.php', array('flagSetGlobalCookieOnRedirect'=>true));
// when $this->conf['cookiePath']='/' and you redirect user to the root dir of your web server.
Category: Navigation
Parameters:
Returns: nothing, script execution terminates.
This method returns proper ‘Back’ reference for this button in Action Menu. If $_SERVER[‘HTTP_REFERER’] doesn’t contain current URI, it set a cookie with referring page.
Otherwise, it use this cookie value, and if it’s absent, it returns $urlIfNoReferer parameter.
It works like this: when user arrives to given form via hyperlink in list or other form, or whatever that leaves HTTP_REFERER header, it returns this value and saves a cookie with that URL, with this form path. When user saves data on this form it appears back without this HTTP header and ‘Back’ button needs proper value. It takes it from cookie (if it exists) or from specified parameter.
$arrActions[] = array('title'=>'Back', 'action'=>$intra->backref('myitems_list.php'));
// it will return user to the item list by default
Category: Navigation
Parameters:
Returns: string URL
Function outputs JSON-encoded response basing on intra specification and terminates the script.
Category: Data output
Parameters:
This function outputs necessary stuff to start batch data operation script.
Category: Output Batch run
This function outputs data at batch data operation script, adds htmlspecialchars() and flushes output buffer.
Category: Data output Batch run
This function retrieves user message from the cookie and deletes the cookie itself.
Returns: string with user message
This method returns array of role users by role ID
Category: Authentication Authorization
Parameters:
This function initialize what language to use: local or global
Category: Initialization i18n
An analog of industrial standard __() function, $intra->translate() translates simple words/phrases to local language according to the system dictionary oridinarily located in < sys dir >/common/lang.php and included at auth.php. Now it supports sprintf() formatting, so it can translate phrases with format strings like “Item #%s is updated.”
Category: i18n
This is service method that turns on translation key collection for further dictionary fill in (lang.php)
Category: i18n
This function reads stbl_setup
table into $intra->conf[]
array.
Category: Initialization
This function returns HTML for single field If parameter $title is specified, it returns full HTML with container, label and input/text If parameter $name is specified it returns HTML for input/text according to $value parameter else it returns HTML specified in $value parameter.
Category: Forms
This function returns HTML for single fieldset
Category: Forms
Parameters:
<legend>
tagThis function returns HTML for the form.
Category: Forms
Parameters:
This function returns HTML for the text box <input type="text">
.
Category: Forms
This function returns HTML for the <textarea>
.
Category: Forms
showButton() method returns <input type="submit">
or <button>
HTML. Input type should be specified in $arrConfig['type']
member.
Category: Forms
Parameters:
<input type="submit" class="eiseIntraActionSubmit">
will be returned<button class="eiseIntraDelete">
<button>
element will be returned
Returns: HTML stringThis method returns HTML for <select>
form control.
Element id and name are set with $strName parameter. Selected element will be chosen accorging to $strValue. Option values and this variable will be converted being casted to strings.
Empty element (with empty value) will be added if $confOptions[‘defaultText’] option is set.
$arrOptions array can have nested arrays. In this case <optgroup> tag will be added. Option group title can be set via $confOptions[‘optgroups’] option array. See below.
$confOptions is configuration array, it can have the following options:
<select>
element will be shown. Otherwise, it will be <div>
with chosen option text and hidden <input>
with existing value.<select class="{...}">
attribute. Specified classes will be added to the end of class list.<select>
element attributes string, e.g. ` data-xx=”YY” aria-role=”nav” class=”my-gorgeous-class”`. Classes will be merged with ‘class’ option content.<option>
with empty value will be added to the beginning of dropdown list, option text will be taken from this conf option value. If ‘auto_translate’ $intra option is TRUE, this value will be translated.<option class="deleted">
<optgroup>
titles. If $arrOption array member is array, it will search for <optgroup>
tag title in this conf option array by the same key.<a href="{...}">
Category: Forms
Parameters:
<option value="">
and array element value is option text<select>
element. See above.Returns: string HTML
This function returns HTML for the < input type=”checkbox” >.
Category: Forms
This function returns HTML for the < input type=”radio” >.
Category: Forms
This function returns HTML for the < input type=”radio” >, basing on arrays
Category: Forms
This function returns HTML for the AJAX-based autocomplete inputs. They download data from the server while user inputs the text.
Category: Forms
This method returns True if user permissions allow to edit the data. It is possible either if FlagWrite is positive at current page or FlagCreate or FlagUpdate are too. Perissions may be forced to allow editing or deny it by setting $flagToForce parameter to True or Flase correspondingly. If it’s not set or null it meaningless.
Category: Forms
Parameters:
Returns: bool
Function that loads JavaScript files basing on GLOBAL $arrJS
Category: Initialization
Function that loads CSS files basing on GLOBAL $arrCSS
Category: Initialization
Data handling hook function. If $_GET or $_POST [‘DataAction’] array member fits contents of $dataAction parameter that can be array or string, user function $function_name will be called and contents of $_POST or $_GET will be passed as parameters.
Category: Navigation Data handling
Parameters:
Returns: variant value that return user function.
Data read hook function. If $query[‘DataAction’] array member fits contents of $dataReadValues parameter that can be array or string, user function $function_name will be called and contents of $query parameter will be passed. If $query parameter is omitted, function will take $_GET global array.
Category: Navigation Data output
Parameters:
Returns: variant value that return user function.
Static functions that returns first occurence of configuration array $conf key variations passed as $variations parameter (array). Made for backward compatibility.
Category: Utilities
Parameters:
Returns: $conf array value of first occurence of supplied key variations. NULL if key not found
This function returns external reference to the script inside <iframe>
. This href will load all iframe surrounding, including menu and $iframeHREF will be inside this <iframe>
Parameters:
<iframe>
function to obtain keyboard layout variations when user searches something but miss keyboard layout switch
It takes multibyte UTF-8-encoded string as the parameter, then it searches variations in static property self::$arrKeyboard and returns it as associative array.
Category: i18n Useful stuff
Parameters:
Returns: array Associative array of possible string variations, like array('EN'=>'qwe', 'RU'=>'йцу')
This function rebuilds style.css for selected theme using style.less located in the same folder as style.css. REMEMBER TO chmod a+w to this folder!
Category: Utilities
This function dumps $to_echo variable using var_export() or simply echoes it, with stack trace ahead
Category: Debug
Parameters:
This function returns cookie path for given location. In case when flagSetGlobalCookieOnRedirect it returns $this->conf[‘cookiePath’] constant. Otherwise it returns path part of location URL.
Category: Initialization
Parameters:
Returns: string A cookie path.
Array with data of currently logged user:
['Managers', 'Users']
['MNG', 'USR']
(*) - type is ‘string’ because of PHP function mysql_fetch_assoc()’s nature. It fetches anything like strings despite actual data type in the database.
For more details on how and when this data is obtained, please proceed to eiseIntra::checkPermissions().
Category: Authentication
ID of current user.
Category: Authentication
eiseIntraData is the class that encapsulates data handling routines
Data types definition and conversion SQL <-> PHP output data conversions SQL query result conversion to JSON or Array (result2JSON()) Reference table routines (getDataFromCommonViews()) Archive/Restore routines etc
Package: eiseIntra
Version: 2.0beta
This function formats data for user-friendly output according to user data type provided in $type parameter.
Category: Data formatting
Parameters:
Returns: string
This function formats data to SQL-query friendly value, not escaped, without quotes.
Category: Data formatting
Parameters:
Returns: string - The value formatted.
This function returns SQL result as JSON string or array, in format that can be understood by eiseIntra’s JavaScript fill() methods. Output format is a bit more complex than just list of rows as dictionaries. It also contains some features that scipt interpret for data display:
Category: Data read
Parameters:
$arrConf['arrPermittedFields'] == ['c']
and $arrConf['flagAllowDeny'] == 'allow'
‘c’ field will be prenected in the following way: {c: {v: ‘d’, rw: ‘r’}}.$arrConf['fields']['c']['href'] == '/page.php?a=[a]' and $arrConf['fields']['c']['target'] == '_blank'
it will return {c: {v: d, h: '/page.php?a=b', tr: '_blank'}}
Returns: array (default) or string when $arrConf[‘flagEncode’]==True
This function unquotes SQL value previously prepared to be added into SQL code by functions like $oSQL->e(). Same exists in eiseSQL class.
Category: Data formatting
Parameters:
Returns: string $sqlReadyValue without quotes, or NULL if source string is ‘NULL’ (case-insensitive)
This function converts decimal value from user input locale into SQL-friendly value. If $val is empty string it returns $valueIfNull string or ‘NULL’ string.
Category: Data formatting
Parameters:
Returns: variant - double value converted from original one or $valueIfNull if it’s set or ‘NULL’ string otherwise.
This function converts data fetched from SQL query to string, according to $intra locale settings.
Category: Data formatting
Parameters:
Returns: string decimal value.
This function converts date value as it’s been fetched from SQL (‘YYYY-MM-DD’ or any strtotime()-parseable format) into string accoring to $intra locale settings ($intra->conf[‘dateFormat’] and $intra->conf[‘timeFormat’]). If $precision is not ‘date’ (e.g. ‘time’ or ‘datetime’) it will also adds a time component.
Category: Data formatting
Parameters:
Returns: string - converted date or date/time value
This function converts date value as it’s been fetched from SQL (‘YYYY-MM-DD’ or any strtotime()-parseable format) into string accoring to $intra locale settings ($intra->conf[‘dateFormat’] and $intra->conf[‘timeFormat’]).
Category: Data formatting
Parameters:
Returns: string - converted date/time value
This function converts date value received from user input into SQL-friendly value, quoted with single quotes. If origin value is empty string it returns $valueIfEmpty parameter or ‘NULL’ if it’s not set. Origin value is checked for compliance to date format using regular expression $intra->conf[‘prgDate’]. Also $dtVar format accepts output formatted as ‘YYYY-MM-DD’ string. If $dtVar format is wrong it returns $valueIfEmpty or ‘NULL’ string.
Category: Data formatting
Parameters:
Returns: string - Converted value ready to be added to SQL query string.
This function converts date/time value received from user input into SQL-friendly string, quoted with single quotes. If origin value is empty string it returns $valueIfEmpty parameter or ‘NULL’ if it’s not set. Origin value is checked for compliance to date format using regular expression $intra->conf[‘prgDate’] and $intra->conf[‘prgTime’]. Time part is optional. Function also accepts ‘YYYY-MM-DD[ HH:MM:SS]’ string. If $dtVar format is wrong it returns $valueIfEmpty or ‘NULL’ string.
Category: Data formatting
Parameters:
Returns: string - Converted value ready to be added to SQL query string.
getTableInfo() funiction retrieves useful MySQL table information: in addition to MySQL’s ‘SHOW FULL COLUMNS …’ and ‘SHOW KEYS FROM …’ it also returns some PHP code that could be added to URL string, SQL queries or evaluated. See description below. Currently it uses eiseSQL::getTableInfo() function.
Parameters:
Returns: array - see more in eiseSQL::getTableInfo() function documentation
getSQLValue() function returns ready-to-eval PHP code to be used in SQL queries. Currently kept for backward compatibility.
Category: Data formatting
Parameters:
Returns: string PHP code that could be evaluated in SQL query.
This tiny function composes WHERE SQL condition for multiple column primary key. It’s assumed that column values are delimited with double-hash (‘##’).
Category: Database routines
Parameters:
This function reads data from SQL views or tables that’s used as foreign key references. This function is widely used in eiseIntra as the data source for
Category: Data read
Parameters:
LIKE %..%
, e.g. for AJAX autocomplete list.$extra (string) - some extra criteria, pipe(‘ | ’)-delimited string. Table/view should contain fields named like ‘extra’, ‘extra1’, ‘extra2’… |
Returns: resource with data obtained from the database
This function returns basic data type for provided $type variable. It can be as any MySQL data type as input type used in eiseIntra.
Parameters:
Returns: string - basic type from keys of eiseIntraData::$arrBasicTypes. If basic type’s not found it returns ‘text’.
This function returns Intra type from key set of $arrIntraDataTypes array above. It takes $type and $field name as parameters, and it can be as Intra types as SQL data types returned by fetch_fields() or getTableInfo() functions.
eiseIntra::getDecimalPlaces() gets actual number of digits beyond decimal separator. It reads original float or string value with “.” (period symbol) as delimiter and returns actual number of decimal places skipping end zeros.
Category: Data formatting
Parameters:
Returns: int - number of decimals. If $val is not numberic (i.e. it doesn’t fit is_numeric() PHP function) it returns NULL.
$arrIntraDataTypes defines basic type set that is used for conversion of data obtained from the database into user-specific locale.
eiseSQL is the class for object wrapper for database access functions. Currently it extends PHP’s built-in mysqli class but also it adds some useful shortcuts for most popular functions. Also in contains built-in profiler and some functions to profile your SQL query sequence.
Package: eiseIntra
Version: 2.0beta
Performs connect to the database with parent constructor.
WARNING! method connect() only make some adjustments
Throws: eiseSQLException object when connect fails
Category: Database routines
Parameters:
Dummy. Needed for some backward compatibility. Do not use.
Another backward-compatibility function Do not use.
Method e() escapes source string for SQL query using mysql_escape_string() and put escaped string into single quotes. Please used it to prevent from SQL injections.
Category: Database routines Data formatting
Parameters:
echo $oSQL->('qq', 'search')
=>LIKE '%qq%'
This function strips single quotes from both ends of the string. If string is word ‘NULL’, it returns NULL.
Parameters:
Returns: string
This function first quotes the string using eiseSQL::e() function, then it strips quotes with eiseSQL::unq(). So it secures the string from any SQL injection.
Category: Database routines Data formatting
Parameters:
Returns: string
This method executes SQL query and returns MySQL resource. Also it collects all necessary data for query profile:
Category: Database routines Useful stuff
Returns: MySQL resource
This method returns number of rows obtained within MySQL result object. Actually it returns $mysqli_result->num_rows property.
Category: Database routines
Parameters:
Returns: int
This method fetches a row from MySQL result or SQL query passed as a parameter. If you’d like to reduce amount of code and you need to obtain only one record - just pass SQL query directly to this method. So it is a little bit more than wrapper around MySQL result::fetch_assoc()
Category: Database routines Useful stuff
Parameters:
Returns: associative array with field names as keys, like MySQL result::fetch_assoc()
This method fetches a row from MySQL result as an enumerated array. So it is just a wrapper around MySQL result::fetch_array()
Category: Database routines
Parameters:
Returns: enumerated array, like MySQL result::fetch_array()
This method fetches field information from MySQL result as MySQL result::fetch_fields(). It is actually a wrapper around it.
Category: Database routines
Parameters:
Returns: array, like MySQL result::fetch_fields()
This method returns autoincremental ID value after last INSERT ...
query in current connection. It is a wrapper over MySQLi::insert_id property.
Category: Database routines
Returns: int - last insert id.
This method returns number of rows affected by last INSERT ...
, UPDATE ...
or DELETE ...
query in current connection. It is a wrapper over MySQLi::affected_rows property.
Category: Database routines
Returns: int - number of records affected.
This method fetches first value of first row from MySQL result or SQL query passed as a parameter. If you’d like to reduce amount of code and you need to obtain only one record - just pass SQL query directly to this method. So it is a little bit more than wrapper around MySQL result::fetch_assoc()
Category: Database routines Useful stuff
Parameters:
Returns: associative array with field names as keys, like MySQL result::fetch_assoc()
Use this method to start or reset profiling process in your MySQL script. It drops all counters and set $oSQL->flagProfiling=true
Category: Debug
This function outputs profile info to current standard output. Use it for brief investigation of what’s going on within your SQL query sequence.
Category: Debug
This function returns profiling as the list of associative arrays for each query.
Category: Debug
Returns: enumerable array of associative arrays:
getTableInfo() funiction retrieves useful MySQL table information: in addition to MySQL’s ‘SHOW FULL COLUMNS …’ and ‘SHOW KEYS FROM …’ it also returns some PHP code that could be added to URL string, SQL queries or evaluated. See description below.
Category: Data read Database routines Useful stuff
Parameters:
Returns: array:
'SHOW FULL COLUMNS ...'
:
'SHOW KEYS FROM ...'
'$bltID = (isset($_POST[\'bltID\']) ? $_POST[\'bltID\'] : $_GET[\'bltID\'] );
'
bltID = ".(int)($bltID)."'
'bltID=".urlencode($bltID)."'
,This array maps intra data types into MySQL data types
This array maps intra data types into MySQL binary data types constants