158 lines
4.4 KiB
PHP
Executable File
158 lines
4.4 KiB
PHP
Executable File
<?php
|
|
#########################################################
|
|
# #
|
|
# Error handling functions #
|
|
# written by benjamin ramey #
|
|
# bsr@rameydesign.net #
|
|
# #
|
|
# best viewed with: #
|
|
# resolution = 1280x960 #
|
|
# tab = 4 spaces #
|
|
# indent = 8 spaces #
|
|
# #
|
|
# #
|
|
###################################################################################################### takes an error message for later display
|
|
# returns: nothing
|
|
# parameters: 1) specific error mesg; 3) error level of specific error
|
|
function errors_collect($message,$level)
|
|
{
|
|
if(kDEBUG) { print 'Entering errors_collect.<br />'; }
|
|
|
|
global $_SCRIPT_ERRORS;
|
|
|
|
if(empty($level)) { $level = 'HIGH'; }
|
|
|
|
$_SCRIPT_ERRORS[] = array('text'=>$message,'level'=>$level); // put error in errors array
|
|
|
|
if(kDEBUG) { print 'Leaving errors_collect.<br />'; }
|
|
}
|
|
|
|
###################################################################################################### displays all errors according to error display level passed to function
|
|
# returns: nothing
|
|
# parameters: none
|
|
function errors_display()
|
|
{
|
|
if(kDEBUG) { print 'Entering errors_display.<br />'; }
|
|
|
|
global $_SCRIPT_ERRORS;
|
|
$err_num = 1;
|
|
|
|
if(empty($_SCRIPT_ERRORS)) { // if there are no errors in the errors array,
|
|
if(kDEBUG) { print 'Leaving errors_display, exiting early.<br />'; }
|
|
return;
|
|
} // don't try to display any
|
|
|
|
?>
|
|
<div id="errors">
|
|
<?php
|
|
|
|
if(kERROR_LEVEL == 'ALL') { // if level is all, simply step through errors array
|
|
foreach($_SCRIPT_ERRORS as $error) { // and print all of the errors
|
|
print $err_num.') '.$error['text']."<br />\n";
|
|
$err_num++;
|
|
}
|
|
}
|
|
|
|
?>
|
|
</div>
|
|
<br />
|
|
<?php
|
|
if(kDEBUG) { print 'Leaving errors_display, exiting late.<br />'; }
|
|
}
|
|
|
|
#################################################################################
|
|
# #
|
|
# written by benjamin ramey #
|
|
# bsr@rameydesign.net #
|
|
# #
|
|
# This file contains: #
|
|
# Functions that handle errors throughout the script #
|
|
# #
|
|
#################################################################################
|
|
# style: all caps, underscores
|
|
# prefix: E_
|
|
####################################################################### GLOBALS #
|
|
# errors that will be displayed to the user (public)
|
|
$E_PUB_ERR = array();
|
|
# errors that will be logged, but not shown to the user (private)
|
|
$E_PRIV_ERR = array();
|
|
|
|
############################################################ FUNCTION: err_make #
|
|
function err_make($mesg,$type)
|
|
{
|
|
global $E_PUB_ERR,$E_PRIV_ERR;
|
|
|
|
# if we received a public error message...
|
|
if($type == 'pub')
|
|
{
|
|
$E_PUB_ERR[] = $mesg;
|
|
}
|
|
# or, if we received a private error message...
|
|
else if($type == 'priv')
|
|
{
|
|
$E_PRIV_ERR[] = $mesg;
|
|
}
|
|
}
|
|
|
|
######################################################## FUNCTION: err_log_priv #
|
|
function err_log_priv()
|
|
{
|
|
global $E_PRIV_ERR,$_CONFIG,$_LB;
|
|
|
|
# a nice timestamp to prepend to the error mesg
|
|
# timestamp example: [Sun, August 23, 2003 18:23:34 EST]
|
|
$err_time = '['.date("D, M d, Y G:i:s T").'] ';
|
|
|
|
# open the private error file, append the debugging msg to it, and
|
|
# then close it
|
|
$fh = fopen($_CONFIG['priv_err_file'], 'a');
|
|
|
|
foreach($E_PRIV_ERR as $error)
|
|
{
|
|
fwrite($fh,$err_time.$error.$_LB);
|
|
}
|
|
|
|
fclose($fh);
|
|
}
|
|
|
|
######################################################### FUNCTION: err_log_pub #
|
|
function err_log_pub()
|
|
{
|
|
global $E_PUB_ERR,$_CONFIG,$_LB;
|
|
|
|
# a nice timestamp to prepend to the error mesg
|
|
# timestamp example: [Sun, August 23, 2003 18:23:34 EST]
|
|
$err_time = '['.date("D, M d, Y G:i:s T").'] ';
|
|
|
|
# open the private error file, append the debugging msg to it, and
|
|
# then close it
|
|
$fh = fopen($_CONFIG['pub_err_file'], 'a');
|
|
|
|
foreach($E_PUB_ERR as $error)
|
|
{
|
|
fwrite($fh,$err_time.$error.$_LB);
|
|
}
|
|
|
|
fclose($fh);
|
|
}
|
|
|
|
########################################################### FUNCTION: err_exist #
|
|
function err_exist()
|
|
{
|
|
global $E_PUB_ERR, $E_PRIV_ERR;
|
|
|
|
# if both error arrays are empty, then
|
|
# no errors exists. otherwise, they do exist
|
|
if(empty($E_PUB_ERR) and empty($E_PRIV_ERR))
|
|
{
|
|
return(false);
|
|
}
|
|
else
|
|
{
|
|
return(true);
|
|
}
|
|
|
|
return(false);
|
|
}
|
|
|
|
?>
|