Wizards Toolkit Documentation

Utils.php

This contain all functions that do not fit into other Wizards Toolkit libraries.

All rights reserved.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Tags
author
Programming Labs
license
All rights reserved
version
2.0

Table of Contents

wzTimeTrack()  : null
Time Track is a debug method
wzShowTimeTracks()  : echoes
Show Time Tracks
wzProtoType()  : null
This takes passed HTML and writes it to /tst/ folder for HTML/CSS debugging
wzAddUserHistory()  : null
This function saves to User History how long it took to generate page.
wzLogError()  : null
Easy error logging
wzInsFailedAttempt()  : null
If there is a failed attack on server it will save information into wzFailedAttempts table
wzErrorHandler()  : null
Custom Error Handling
wzExceptionHandler()  : html
Custom Exception Handling
wzCheckForFatal()  : null
Trap fatal errors
wzSetCookie()  : null
Set Cookie
wzGetCookie()  : string
Get Cookie - returns either the cookie value or a blank '' value
wzDeleteCookie()  : null
Delete Cookie
wzParsCurrencyToNumber()  : number
Changes Currency into simple Number
wzRedirect()  : null
Redirect to passed URL regardless of whether headers have been sent or not
wzRemoveStyle()  : string
This will remove HTML encoding from the value passed in.
wzLoadInclude()  : file
Load and return include file contents
wzReplace()  : string
Similar to str_replace except it replaces values within arrays.
wzGetEnviron()  : string
Get Environ
wzGetParam()  : string
Returns GET if it exists, otherwise returns POSTed value.
wzGetGet()  : string
Get $_GET[] of passed parameter.
wzGetPost()  : string
Get $_POST[]
wzGetServer()  : string
Get $_SERVER[]
wzSetSession()  : null
Set $_SESSION variable.
wzGetSession()  : string
Get $_SESSION value or '' blank if not set.
wzDeleteSession()  : null
unset($_SESSION[$fncSessVariable])
wzFormatPercent()  : value
Format passed number as a percent.
wzFormatCurrency()  : mixed
Format passed number as currency.
wzFormatDateTime()  : formatted
Format passed value for Date and Time
wzHtmlEncode()  : encoded
HTML Encode using htmlentities($fncString, ENT_QUOTES)
wzHtmlDecode()  : decoded
HTML Decode
wzInsertSpaces()  : string
Insert Spaces
wzTruncate()  : string
wzTruncate
wzGetIPaddress()  : mixed
wzGetIPaddress
wzSecondsToDays()  : string
Pass in number of seconds and returns value like: "3 Days 8 Hours 38 Minutes"
wzTimeZoneAdjust()  : string
Checks server's time-zone and if different than passed time-zone, converts time.
wzDeadPage()  : html
Call this function to show a dead-end page.
wzIsWindows()  : bool
Is Windows - determines whether servers is a Windows server
wzIsSSL()  : bool
This detects whether current URL is SSL or not.
wzConvertLinks()  : properly
Based current URL adjusts link to use similar SSL or not SSL link.

Functions

wzTimeTrack()

Time Track is a debug method

wzTimeTrack( string  $fncLocation) : null

This debug method allows displaying debug information and then by changing the $gloTrackTime flag all debug will stop displaying. It also shows exact time for each call so you can check and debug speed issues.

$gloTrackTime = true; // defaults to false; set to true to enable debug mode

wzTimeTrack('just after some code');
Parameters
$fncLocation : string
Tags
global

string $gloTimeTrackCntr

global

array $gloTimeTrackArray

Return values
null

wzShowTimeTracks()

Show Time Tracks

wzShowTimeTracks() : echoes

This shows everything that was sent to wzTimeTrack plus all internal Wizards Toolkit debug logging. It is automatically called at end of each WTK library PHP page but will not show anything unless $gloTrackTime = true. You can also call this earlier for debugging if necessary.

Tags
global

string $gloTimeTrack

global

array $gloTimeTrackArray

Return values
echoes

all time tracks

wzProtoType()

This takes passed HTML and writes it to /tst/ folder for HTML/CSS debugging

wzProtoType( string  $fncHtm) : null

The generated HTML files can be given to UI/HTML/CSS developers so they can work on the UI without needing PHP nor SQL skills. This should be at bottom of your page.

Parameters
$fncHtm : string
Return values
null

wzAddUserHistory()

This function saves to User History how long it took to generate page.

wzAddUserHistory( [ string  $fncPageTitle = '' ] ) : null

Data is saved to wzUserHistory table. This is called via wzBuildDataBrowse, wzFormWriteUpdField and wzMergePage. If it is called more than once it only updates the SecondsTaken instead of making a new data row.

Parameters
$fncPageTitle : string = ''

optionally pass Page Title

Return values
null

wzLogError()

Easy error logging

wzLogError( string  $fncErrType , string  $fncErrMsg [, string  $fncLineNum = 'NULL' ]) : null

Pass in Error Type and Error Message and this inserts that plus additional information into the wzErrorLog table. This includes logged-in user, Current Page, and Referer Page in addition to the Type and Message passed. Several functions in Wizards Toolkit use this so check your wzErrorLog table any time you have problems.

Parameters
$fncErrType : string
$fncErrMsg : string
$fncLineNum : string = 'NULL'

defaults to NULL

Tags
global

string $gloUserUID

Return values
null

wzInsFailedAttempt()

If there is a failed attack on server it will save information into wzFailedAttempts table

wzInsFailedAttempt( string  $fncFailCode [, string  $fncFailNote = '' ] ) : null

Pass in 4-character code that we want to log this failed attempt for. This includes logged-in user, IP Address, Browser Type, Current Page, and Referer Page in addition to the Message passed.

Parameters
$fncFailCode : string

4-character code so you can easily count types of failures

$fncFailNote : string = ''

optionally mention what caused failure

Tags
global

string $gloConnected

global

string $gloUserUID

global

string $gloCurrentPage

global

string $gloWebBaseURL useful if you have multiple domains saving to same database

Return values
null

wzErrorHandler()

Custom Error Handling

wzErrorHandler ( string  $fncNum , mixed  $fncStr , mixed  $fncFile , mixed  $fncLine [, mixed  $fncContext = null ] ) : null

This is called from wzCheckForFatal. This calls wzExceptionHandler to show the error using the client's GUI templates.

Parameters
$fncNum : string
$fncStr : mixed
$fncFile : mixed
$fncLine : mixed
$fncContext : mixed = null
Return values
null

wzExceptionHandler()

Custom Exception Handling

wzExceptionHandler(mixed $fncErr) : html

Uncaught exception handler set using set_exception_handler. This shows the error using the client's GUI templates after saving the error to the wzErrorLog table.

Parameters
$fncErr : mixed
Return values
html

with error information; if user's SecurityLevel is > 94 then shows additional error->getMessage()

wzCheckForFatal()

Trap fatal errors

wzCheckForFatal() : null

This captures fatal errors and calls wzExceptionHandler to display. This prevents White Screens with no error messaging. This uses $fncError = error_get_last() then if 'type' >= 256 then calls wzErrorHandler and wzExceptionHandler.

Checks for a fatal error, work around for set_error_handler not working on fatal errors. This is set using register_shutdown_function.

Return values
null

wzSetCookie()

Set Cookie

wzSetCookie( string  $fncCookieName , string  $fncValue , string  $fncExpires [, string  $fncPath = '/' ] ) : null

For the 'Expires' parameter you can pass in any of these: 1day, 1week, 1month, 1year. If you pass nothing the cookie expires at end of session.

Parameters
$fncCookieName : string
$fncValue : string
$fncExpires : string

Defaults to "0". Switch cases: "1day, 1week, 1month, 1year". If numeric value is passed it is added to time() for when to expire.

$fncPath : string = '/'

Defaults to "/"

Return values
null

wzGetCookie()

Get Cookie - returns either the cookie value or a blank '' value

wzGetCookie( string  $fncCookieName ) : string
Parameters
$fncCookieName : string
Return values
string

wzDeleteCookie()

Delete Cookie

wzDeleteCookie( string  $fncCookieName ) : null
Parameters
$fncCookieName : string
Return values
null

wzParsCurrencyToNumber()

Changes Currency into simple Number

wzParsCurrencyToNumber( [ string  $fncVal = '$0' ]) : number

For example will change '$12,345.67' into 12345.67

Parameters
$fncVal : string = '$0'
Return values
number

from passed currency value

wzRedirect()

Redirect to passed URL regardless of whether headers have been sent or not

wzRedirect( string  $fncURL) : null

To prevent redirection errors this will change go-to link to use https: or http: based on what current web page user is on.

Parameters
$fncURL : string
Return values
null

wzRemoveStyle()

This will remove HTML encoding from the value passed in.

wzRemoveStyle( string  $fncThisValue) : string
Parameters
$fncThisValue : string
Return values
string

wzLoadInclude()

Load and return include file contents

wzLoadInclude( string  $fncIncludeFile) : file
Parameters
$fncIncludeFile : string
Return values
file

contents

wzReplace()

Similar to str_replace except it replaces values within arrays.

wzReplace( string  $fncSubject , string  $fncSearchFor , string  $fncReplaceWith) : string

Case sensitive search and replace. It does not affect the passed-in value to be searched. The parameters are in a more intuitive order. It returns the result after replacing all matches even in recursive arrays. For arrays it replaces values, not keys. If array is passed in, array is returned. If a string is passed in, a string is returned.

Example: $pgNewStr = wzReplace($Subject, $SearchFor, $ReplaceWith);

Parameters
$fncSubject : string
$fncSearchFor : string
$fncReplaceWith : string
Return values
string

or array depending on what was passed in

wzGetEnviron()

Get Environ

wzGetEnviron( string  $fncEnvVariable) : string
Parameters
$fncEnvVariable : string
Return values
string

Returns a variable from ENV or '' if no value

wzGetParam()

Returns GET if it exists, otherwise returns POSTed value.

wzGetParam( string  $fncParameter [, string  $fncDefault = '' ] ) : string

wzGetParam returns default if otherwise would return ''.

Parameters
$fncParameter : string
$fncDefault : string = ''

which defaults to '' blank

Return values
string

wzGetGet()

Get $_GET[] of passed parameter.

wzGetGet( string  $fncParameter [, string  $fncDefault = '' ] ) : string

If not blank, returns stripslashes(urldecode($_GET[$fncParameter])). If result is blank, then returns $fncDefault.

Parameters
$fncParameter : string
$fncDefault : string = ''

which defaults to '' blank

Return values
string

wzGetPost()

Get $_POST[]

wzGetPost( string  $fncParameter [, string  $fncDefault = '' ] ) : string

If result is blank, then returns $fncDefault.

Parameters
$fncParameter : string
$fncDefault : string = ''

which defaults to '' blank

Return values
string

wzGetServer()

Get $_SERVER[]

wzGetServer( mixed $fncParameter) : string
Parameters
$fncParameter : mixed
Return values
string

returns a variable from SERVER or '' if no value

wzSetSession()

Set $_SESSION variable.

wzSetSession( string  $fncSessVariable , string  $fncValue) : null

If setting 'UserLevel' then to prevent other sites on same server from sharing UserLevel it prepends $gloAuthStatus

Parameters
$fncSessVariable : string
$fncValue : string
Tags
global

string $gloAuthStatus

Return values
null

wzGetSession()

Get $_SESSION value or '' blank if not set.

wzGetSession( string  $fncSessVariable) : string

If retrieving 'UserLevel' then to prevent other sites on same server from sharing UserLevel it prepends $gloAuthStatus

Parameters
$fncSessVariable : string
Tags
global

string $gloAuthStatus

Return values
string

returns a variable from session or '' if no value

wzDeleteSession()

unset($_SESSION[$fncSessVariable])

wzDeleteSession( string  $fncSessVariable ) : null

If retrieving 'UserLevel' then to prevent other sites on same server from sharing UserLevel it prepends $gloAuthStatus

Parameters
$fncSessVariable : string
Tags
global

string $gloAuthStatus

Return values
null

wzFormatPercent()

Format passed number as a percent.

wzFormatPercent ( string  $fncValue [, numeric  $fncRoundDigits = 2 ] [, string  $fncGroupSep = '' ] [, string  $fncDecimalSep = '.' ] [, string  $fncPercentChar = 'after' ] ) : value

This assumes number needs to be multiplied by 100. Only first parameter of number is required.

Parameters
$fncValue : string
$fncRoundDigits : numeric = 2

Defaults to '2'

$fncGroupSep : string = ''

Defaults to '' blank

$fncDecimalSep : string = '.'

Defaults to '.'

$fncPercentChar : string = 'after'

Defaults to 'after' to determine whether % should be before or after value

Return values
value

with percentage using above passed parameters

wzFormatCurrency()

Format passed number as currency.

wzFormatCurrency( string  $fncValue [, numeric  $fncRoundDigits = 2 ] [, string  $fncMoneyChar = '$' ] [, string  $fncGroupSep = ',' ] [, mixed  $fncDecimalSep = '.' ] ) : mixed

This assumes number needs to be multiplied by 100. Only first parameter of number is required.

Parameters
$fncValue : string
$fncRoundDigits : numeric = 2

Defaults to '2'

$fncMoneyChar : string = '$'

Defaults to '$'

$fncGroupSep : string = ','

Defaults to blank

$fncDecimalSep : mixed = '.'
Return values
mixed

wzFormatDateTime()

Format passed value for Date and Time

wzFormatDateTime( string  $fncFormat [, numeric  $fncVal = '' ]) : formatted

Returns '' if either parameter is null, blank, '0000-00-00', or '00/00/0000' otherwise sets date format via: date($fncFormat, strtotime($fncVal))

Parameters
$fncFormat : string
$fncVal : numeric = ''

Defaults to blank

Return values
formatted

date or ''

wzHtmlEncode()

HTML Encode using htmlentities($fncString, ENT_QUOTES)

wzHtmlEncode( string  $fncString) : encoded
Parameters
$fncString : string
Return values
encoded

HTML

wzHtmlDecode()

HTML Decode

wzHtmlDecode( string  $fncString) : decoded
Parameters
$fncString : string
Return values
decoded

HTML

wzInsertSpaces()

Insert Spaces

wzInsertSpaces( string  $fncFieldName ) : string

This converts under_scored_fields into Under Scored Fields and it also converts WordCappedSentences into 'Word Capped Sentences'

Parameters
$fncFieldName : string
Return values
string

with spaces before every capital letter

wzTruncate()

wzTruncate

wzTruncate( string  $fncStr [, numeric  $fncSize = 80 ] ) : string

This is called by BrowsePDO function to truncate text and add ellipsis. It makes certain to truncate at last space so it doesn't break in middle of word.

Here is an example: $fncThisValue = wzTruncate($fncThisValue, 80);

Parameters
$fncStr : string

string passed in to possibly truncate

$fncSize : numeric = 80

defaults to 80; if fncStr is greater than this it will be truncated and an ellipsis appended

Return values
string

original value unless too long in which case truncated and ellipsis added

wzGetIPaddress()

wzGetIPaddress

wzGetIPaddress() : mixed

get IP address of web surfer

Tags
returns

IP Address or 'no-IP' if no IP address

Return values
mixed

wzSecondsToDays()

Pass in number of seconds and returns value like: "3 Days 8 Hours 38 Minutes"

wzSecondsToDays( string  $fncSeconds) : string
Parameters
$fncSeconds : string
Return values
string

like 3 Days 8 Hours 38 Minutes

wzTimeZoneAdjust()

Checks server's time-zone and if different than passed time-zone, converts time.

wzTimeZoneAdjust( string  $fncDateTime , string  $fncTimeZone [, string  $fncDateFormat = '' ] ) : string

Pass in Date-Time and desired TimeZone to receive adjusted Date-Time in preferred format. Uses date_default_timezone_get to determine server's time-zone.

Parameters
$fncDateTime : string
$fncTimeZone : string
$fncDateFormat : string = ''
  • optionally send your preferred PHP date format
Return values
string

wzDeadPage()

Call this function to show a dead-end page.

wzDeadPage() : html

If the IP Address is known it is shown with a message about "Nefarious Action Detected". This is used internally when user does something that looks like they are trying to hack the web server.

Return values
html

page telling hackers they cannot continue

wzIsWindows()

Is Windows - determines whether servers is a Windows server

wzIsWindows() : bool
Return values
bool

eturns true if Windows, otherwise returns false

wzIsSSL()

This detects whether current URL is SSL or not.

wzIsSSL() : bool
Return values
bool

true if SSL, else false

Based current URL adjusts link to use similar SSL or not SSL link.

wzConvertLinks( string  $fncLinks) : properly

This is used by wzRedirect to determine whether http:// or https:// should be used when redirecting.

Parameters
$fncLinks : string
Return values
properly

formed link

Search results