operations array to track all database operations 2003/04/09 added: function debug() shows get_error_message() and get_error_number() 2003/03/20 added: function get_affected_rows() returns the number of rows affected by the previous insert, delete, update statement 2003/02/26 sub disconnect() added: $this->connection = ""; to reset the connection identifier 2003/02/24 added: mysql_free_result() in query() method and update() method to free result memory 2003/02/10 added: $this->host = 'localhost'; 2003/01/29 added: edited all set routines: added ability to call any CLASS set method with no value this will return the current set value NOTE: performing this operation will still not set a MODULE ERROR level warning 2003/01/28 added: function return_array() function return_hash() function return_associative_array() returns database results in: return_array: [0][1][2] return_hash: ['id']['text'['status'] return_associative_array: (same as hash) $DB -> return_array(1); #default 0 $DB -> return_hash(1); #default 1 $DB -> return_associative_array(1); #default 1 2002/11/22 function query function update function get_tables function disconnect etc. added: if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } 2002/11/13 function query added query key capabilities 2002/10/31 added MODULE INFO to the debug mode 2002/10/02 function Database_Handler() changed to: if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']) || isset($GLOBALS['REQUEST_METHOD'])) { 2002/09/16 added: function reconnect_tries() function timeout() function reconnect() CALL: require_once('./Database_Handler.inc.php'); $Database = new Database_Handler; METHODS TESTING MODULE ERRORS $Database -> driver(); $Database -> host(); $Database -> username(); $Database -> password(); $Database -> database(); $Database -> query_key(); $Database -> set_query_raw(); # SET ERROR LEVEL 1: ONLY DISPLAY ERROR $Error -> error_level(1); # SET ERROR LEVEL 2: WRITE LOG $Error -> error_level(2); # SET ERROR LEVEL 3: SEND ADMIN EMAIL $Error -> error_level(3); # SET ERROR LEVEL 3: SEND ADMIN EMAIL AND WRITE LOG $Error -> error_level(4); # SET ERROR LEVEL 99: DEBUG MODE (same as $Error -> debug()) $Error -> error_level(99); $Error -> admin_email('mike@nextopia.com'); #optional (default: webmasters email) $Error -> error_level(99); #optional (default: 99 - debug) $Error -> template('templates/error_template.html'); #optional (default: templates/error_template.html) $Error -> title('Error'); #optional (default: Error $Error -> log_path('./logs/); #optional (default: ./logs/) $Error -> log_file('error.dat'); #optional (default: default_error_log.dat) $Error -> message('Error'); #optional (default: Error: $!) $Error -> log_message('Log Error'); #optional (default: Error: $!) $Error -> date(date("Y-m-d")); #optional (default: yyyy-mm-dd) $Error -> timestamp(date("H:i:s")); #optional (default: hh:nn:ss) $Error -> return_page('javascript:history.back()'); #optional (default: javascript:history.back()) DISPLAY ERROR METHOD NOTE: the DISPLAY method will NOT maintain all values within the object the values only exist within the DISPLAY method if values are not passed, the object will attempt to use previously set values $Error -> display('ERROR MESSAGE','LOG MESSAGE',99,'template','title','log file', 'return page'); OR $Error -> display('ERROR MESSAGE','LOG MESSAGE'); ################################################# returns the most recent error produced within the module NOTE: not necessarily a fatal error many module errors will not cause the module to fail $module_error = $Database -> get_module_error(); ################################################# debug the error handler $Database -> debug(); # exit $Database -> debug(1); # do not exit */ var $connection; var $host; var $port; var $username; var $password; var $database; var $table; var $sql_query; var $last_query; var $query_raw; var $query_key; var $insert_id; var $fields; var $fields_array; /* * void Database_Handler() * class constructor */ function Database_Handler() { global $HTTP_SERVER_VARS, $GLOBALS; $this->INFO_ARRAY = array( 'PACKAGE' => 'DATABASE HANDLER', 'VERSION' => '2.4', 'CREATED' => '2002/07/13', 'MODIFIED' => '2003/09/09', 'WRITTEN BY' => 'Michael McInally (mike@nextopia.com)' ); $this->operations = array(); $this->return_array = 0; $this->return_associative_array = 1; $this->timeout = 10; $this->reconnect_tries = 10; $this->connection = ""; $this->driver = 'mysql'; $this->host = 'localhost'; $this->port = 3306; $this->username = ""; $this->password = ""; $this->database = ""; $this->table = ""; $this->sql_query = ""; $this->last_query = ""; $this->query_raw = 0; $this->query_key = ""; $this->insert_id = ""; $this->module_errors = 0; $this->module_error = array (); $this->type = 1; $this->cr = "
"; if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']) || isset($GLOBALS['REQUEST_METHOD'])) { $this->type = 1; $this->cr = "
"; } else { $this->type = 0; $this->cr = "\n"; } } /* * debug() * DEBUG THE CLASS * show all variables set within the class */ function debug() { $arg_array = func_get_args(); $arg_num = func_num_args(); $exit = 0; if (!(empty($arg_array[0]))) {$exit = $arg_array[0];} ### default debugging mode if ($this->type) { echo "

"; echo "PACKAGE: ".$this->INFO_ARRAY['PACKAGE']."$this->cr"; echo "VERSION: ".$this->INFO_ARRAY['VERSION']."$this->cr"; echo "CREATED: ".$this->INFO_ARRAY['CREATED']."$this->cr"; echo "MODIFIED: ".$this->INFO_ARRAY['MODIFIED']."$this->cr"; echo "WRITTEN BY: ".$this->INFO_ARRAY['WRITTEN BY']."$this->cr$this->cr"; echo "

"; echo "

"; echo "Debugging Mode:$this->cr"; echo "line: ".__LINE__." in ".__FILE__."$this->cr$this->cr"; echo "

"; echo "Connection ID: $this->connection$this->cr$this->cr"; echo "Error Number: ".$this->get_error_number()."$this->cr$this->cr"; echo "Error Message: ".$this->get_error_message()."$this->cr$this->cr"; echo "Database Reconnect Tries: $this->reconnect_tries$this->cr$this->cr"; echo "Database Timeout: $this->timeout$this->cr$this->cr"; echo "Database Handle: $this->dbh$this->cr$this->cr"; echo "Database Driver: $this->driver$this->cr$this->cr"; echo "Database Name: $this->database$this->cr$this->cr"; echo "Database Host: $this->host$this->cr$this->cr"; echo "Database Port: $this->port$this->cr$this->cr"; echo "Database Username: $this->username$this->cr$this->cr"; echo "Database Password: $this->password$this->cr$this->cr"; echo "Database Query Key: $this->query_key$this->cr$this->cr"; echo "Database Query Raw: $this->query_raw$this->cr$this->cr"; echo "Database Set Query: $this->sql_query$this->cr$this->cr"; echo "Database Last Query: $this->last_query$this->cr$this->cr"; echo "Database Insert ID: $this->insert_id$this->cr$this->cr"; echo "Database Array: $this->return_array$this->cr$this->cr"; echo "Database Associative Array: $this->return_associative_array$this->cr$this->cr"; echo "Database Results: $this->results$this->cr$this->cr"; while (list ($key, $value) = each ($this->module_error)) { echo ("Module Error $key: $value$this->cr$this->cr"); } echo "Database Operations:$this->cr$this->cr"; while (list ($key, $value) = each ($this->operations)) { echo ("$key: $value$this->cr"); } } else { echo "PACKAGE: ".$this->INFO_ARRAY['PACKAGE']."$this->cr"; echo "VERSION: ".$this->INFO_ARRAY['VERSION']."$this->cr"; echo "CREATED: ".$this->INFO_ARRAY['CREATED']."$this->cr"; echo "MODIFIED: ".$this->INFO_ARRAY['MODIFIED']."$this->cr"; echo "WRITTEN BY: ".$this->INFO_ARRAY['WRITTEN BY']."$this->cr$this->cr"; echo "Debugging Mode:$this->cr"; echo "line: ".__LINE__." in ".__FILE__."$this->cr$this->cr"; echo "Connection ID: $this->connection$this->cr$this->cr"; echo "Error Number: ".$this->get_error_number()."$this->cr$this->cr"; echo "Error Message: ".$this->get_error_message()."$this->cr$this->cr"; echo "Database Reconnect Tries: $this->reconnect_tries$this->cr$this->cr"; echo "Database Timeout: $this->timeout$this->cr$this->cr"; echo "Database Handle: $this->dbh$this->cr$this->cr"; echo "Database Driver: $this->driver$this->cr$this->cr"; echo "Database Name: $this->database$this->cr$this->cr"; echo "Database Host: $this->host$this->cr$this->cr"; echo "Database Port: $this->port$this->cr$this->cr"; echo "Database Username: $this->username$this->cr$this->cr"; echo "Database Password: $this->password$this->cr$this->cr"; echo "Database Query Key: $this->query_key$this->cr$this->cr"; echo "Database Query Raw: $this->query_raw$this->cr$this->cr"; echo "Database Set Query: $this->sql_query$this->cr$this->cr"; echo "Database Last Query: $this->last_query$this->cr$this->cr"; echo "Database Insert ID: $this->insert_id$this->cr$this->cr"; echo "Database Array: $this->return_array$this->cr$this->cr"; echo "Database Associative Array: $this->return_associative_array$this->cr$this->cr"; echo "Database Results: $this->results$this->cr$this->cr"; while (list ($key, $value) = each ($this->module_error)) { echo ("Module Error $key: $value$this->cr$this->cr"); } } if (!$exit) { exit; } } /* * reset() * reset all class variables */ function reset() { global $HTTP_SERVER_VARS, $GLOBALS; $this->return_array = 0; $this->return_associative_array = 1; $this->timeout = 10; $this->reconnect_tries = 10; $this->connection = ""; $this->driver = 'mysql'; $this->host = 'localhost'; $this->port = 3306; $this->username = ""; $this->password = ""; $this->database = ""; $this->table = ""; $this->sql_query = ""; $this->last_query = ""; $this->query_raw = 0; $this->query_key = ""; $this->insert_id = ""; $this->module_errors = 0; $this->module_error = array (); $this->type = 1; $this->cr = "
"; if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']) || isset($GLOBALS['REQUEST_METHOD'])) { $this->type = 1; $this->cr = "
"; } else { $this->type = 0; $this->cr = "\n"; } } /* * driver() * set the driver value */ function driver() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->driver == "") { $this->module_error("No driver provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->driver != "") { return ($this->driver); } else { return (0); } return (0); } else { $this->driver = $arg_array[0]; return (1); } } /* * host() * set the host value */ function host() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->host == "") { $this->module_error("No host provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->host != "") { return ($this->host); } else { return (0); } } else { $this->host = $arg_array[0]; return (1); } } /* * port() * set the port value */ function port() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->port == "") { $this->module_error("No port provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->port != "") { return ($this->port); } else { return (0); } } else { $this->port = $arg_array[0]; return (1); } } /* * username() * set the username value */ function username() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->username == "") { $this->module_error("No username provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->username != "") { return ($this->username); } else { return (0); } } else { $this->username = $arg_array[0]; return (1); } } /* * password() * set the password value */ function password() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->password == "") { $this->module_error("No password provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->password != "") { return ($this->password); } else { return (0); } } else { $this->password = $arg_array[0]; return (1); } } /* * database() * set the database value */ function database() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->database == "") { $this->module_error("No database provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->database != "") { return ($this->database); } else { return (0); } } else { $this->database = $arg_array[0]; return (1); } } /* * table() * set the table value */ function table() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->table == "") { $this->module_error("No table provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->table != "") { return ($this->table); } else { return (0); } } else { $this->table = $arg_array[0]; return (1); } } /* * return_array() * set the return type of SQL statements * return_array(0) default * return_array(1) */ function return_array() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= -1 || $arg_array[0] >= 2) { $this->module_error("SQL return type: array value must be 0 or 1. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->return_array <= -1 || $this->return_array >= 2) { $this->module_error("No SQL return type: array value provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->return_array == 0 || $this->return_array == 1) { return ($this->return_array); } else { return (0); } } else { $this->return_array = $arg_array[0]; return (1); } } /* * return_associative_array() * set the return type of SQL statements * return_associative_array(1) default * return_associative_array(0) */ function return_associative_array() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= -1 || $arg_array[0] >= 2) { $this->module_error("SQL return type: associative array value must be 0 or 1. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->return_associative_array <= -1 || $this->return_associative_array >= 2) { $this->module_error("No SQL return type: associative array value provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->return_associative_array == 0 || $this->return_associative_array == 1) { return ($this->return_associative_array); } else { return (0); } } else { $this->return_associative_array = $arg_array[0]; return (1); } } /* * return_hash() * set the return type of SQL statements * return_hash(1) default * return_hash(0) */ function return_hash() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= -1 || $arg_array[0] >= 2) { $this->module_error("SQL return type: hash value must be 0 or 1. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->return_associative_array <= -1 || $this->return_associative_array >= 2) { $this->module_error("No SQL return type: hash value provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->return_associative_array == 0 || $this->return_associative_array == 1) { return ($this->return_associative_array); } else { return (0); } } else { $this->return_associative_array = $arg_array[0]; return (1); } } /* * sql_query() * set the sql_query value */ function sql_query() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] == "") { if ($this->sql_query == "") { $this->module_error("No sql_query provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->sql_query != "") { return ($this->sql_query); } else { return (0); } } else { $this->sql_query = $arg_array[0]; return (1); } } /* * query_raw() * set the query_raw value */ function query_raw() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= -1 || $arg_array[0] >= 2) { $this->module_error("query_raw must be 0 or 1. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->query_raw <= -1 || $this->query_raw >= 2) { $this->module_error("No query_raw provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->query_raw == 0 || $this->query_raw == 1) { return ($this->query_raw); } else { return (0); } } else { $this->query_raw = $arg_array[0]; return (1); } } /* * query_key() * set the query_key value */ function query_key() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->query_key == "") { $this->module_error("No query_key provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->query_key != "") { return ($this->query_key); } else { return (0); } } else { $this->query_key = $arg_array[0]; return (1); } } /* * reconnect_tries() * assigns database reconnect tries */ function reconnect_tries() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= 0 || $arg_array[0] == "") { $this->module_error("reconnect_tries must be > 0. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->reconnect_tries <= 0 || $this->reconnect_tries == "") { $this->module_error("No reconnect_tries provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->reconnect_tries > 0) { return ($this->reconnect_tries); } else { return (0); } } else { $this->reconnect_tries = $arg_array[0]; return (1); } } /* * timeout() * assigns database reconnect timeout */ function timeout() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] <= 0 || $arg_array[0] == "") { $this->module_error("timeout must be > 0. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); if ($this->timeout <= 0 || $this->timeout == "") { $this->module_error("No timeout provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->timeout > 0) { return ($this->timeout); } else { return (0); } } else { $this->timeout = $arg_array[0]; return (1); } } /* * get_error_number() * returns the error number */ function get_error_number() { return (@mysql_errno($this->connection)); } /* * get_error_message() * returns the error message */ function get_error_message() { return (@mysql_error($this->connection)); } /* * connect() * open() * connects the database connection */ function open() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->connect($arg_array[0],$arg_array[1],$arg_array[2],$arg_array[3],$arg_array[4],$arg_array[5]))) { return (0); } else { return (1); } } /* * reconnect() * tries to reconnect the database connection */ function reconnect() { $arg_array = func_get_args(); $arg_num = func_num_args(); $reconnect_tries = ""; $timeout = ""; if ($arg_array[0] != "") {$reconnect_tries = $arg_array[0];} if ($arg_array[1] != "") {$timeout = $arg_array[1];} if ($this->reconnect_tries == "") { $this->reconnect_tries = $reconnect_tries; } if ($this->timeout == "") { $this->timeout = $timeout; } if ($reconnect_tries == "") { $reconnect_tries = $this->reconnect_tries; } if ($timeout == "") { $timeout = $this->timeout; } for ($i = 0;$i < $reconnect_tries;$i++) { if ($this -> connect()) { return (1); } sleep($timeout); } return (0); } function connect() { $arg_array = func_get_args(); $arg_num = func_num_args(); $driver = ""; $host = ""; $username = ""; $password = ""; $port = ""; if ($arg_array[0] != "") {$driver = $arg_array[0];} if ($arg_array[1] != "") {$host = $arg_array[1];} if ($arg_array[2] != "") {$username = $arg_array[2];} if ($arg_array[3] != "") {$password = $arg_array[3];} if ($arg_array[4] != "") {$port = $arg_array[4];} if ($this->driver == "") { $this->driver = $driver; } if ($this->host == "") { $this->host = $host; } if ($this->username == "") { $this->username = $username; } if ($this->password == "") { $this->password = $password; } if ($this->port == "") { $this->port = $port; } if ($driver == "") { $driver = $this->driver; } if ($host == "") { $host = $this->host; } if ($username == "") { $username = $this->username; } if ($password == "") { $password = $this->password; } if ($port == "") { $port = $this->port; } if ($driver == "") { $this->module_error("No driver provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_connect']++; return (0); } if ($host == "") { $this->module_error("No host provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_connect']++; return (0); } if ($username == "") { $this->module_error("No username provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_connect']++; return (0); } /* if ($password == "") { $this->module_error("No password provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } */ if ($port != "") { $host = $host . ':' . $port; } if (!($this->connection = @mysql_connect($host, $username, $password))) { $this->module_error("Failed to connect. Host: $host Username: $username Password: $password. Error #: ".mysql_errno()." Error: ".mysql_error()." MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_connect']++; return(0); } else { $this->operations['connect']++; return (1); } } /* * disconnect() * close() * disconnect the database connection */ function close() { if (!($this->disconnect())) { return(0); } else { return(1); } } function disconnect() { if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_disconnect']++; return (0); } if (!(@mysql_close($this->connection))) { $this->module_error("Failed to disconnect. Connection: $this->connection. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_disconnect']++; return(0); } else { $this->connection = ""; $this->operations['disconnect']++; return(1); } } /* * get_fields() * retrieves a field listing for the requested table name */ function get_fields() { $arg_array = func_get_args(); $arg_num = func_num_args(); $table = ""; $database = ""; if ($arg_array[0] != "") {$table = $arg_array[0];} if ($arg_array[1] != "") {$database = $arg_array[1];} if ($this->table == "") { $this->table = $table; } if ($this->database == "") { $this->database = $database; } if ($table == "") { $table = $this->table; } if ($database == "") { $database = $this->database; } if ($table == "") { $this->module_error("No table provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if ($database == "") { $this->module_error("No database provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if (!($fields = @mysql_list_fields($database, $table, $this->connection))) { $this->module_error("Failed to list fields. Database: $database Table: $table. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if (!($columns = @mysql_num_fields($fields))) { $this->module_error("Failed to retrieve num fields. Fields: $fields. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } $fields_array = array (); for ($i = 0; $i < $columns; $i++) { $fields_array[$i]['field_name'] = @mysql_field_name($fields, $i); $fields_array[$i]['field_flags'] = @mysql_field_flags($fields, $i); $fields_array[$i]['field_len'] = @mysql_field_len($fields, $i); $fields_array[$i]['field_type'] = @mysql_field_type($fields, $i); } return ($fields_array); } /* * query() * queries the database */ function query () { $arg_array = func_get_args(); $arg_num = func_num_args(); $sql_query = ""; $database = ""; $query_key = ""; $query_raw = ""; $return_array = ""; $return_associative_array = ""; if ($arg_array[0] != "") {$sql_query = $arg_array[0];} if ($arg_array[1] != "") {$database = $arg_array[1];} if ($arg_array[2] != "") {$query_key = $arg_array[2];} if ($arg_array[3] != "") {$query_raw = $arg_array[3];} if ($arg_array[4] != "") {$return_array = $arg_array[4];} if ($arg_array[5] != "") {$return_associative_array = $arg_array[5];} if ($this->sql_query == "") { $this->sql_query = $sql_query; } if ($this->database == "") { $this->database = $database; } if ($this->query_raw == "" && $this->query_raw != 0) { $this->query_raw = $query_raw; } if ($this->query_key == "") { $this->query_key = $query_key; } if ($this->return_array == "" && $this->return_array != 0) { $this->return_array = $return_array; } if ($this->return_associative_array == "" && $this->return_associative_array != 0) { $this->return_associative_array = $return_associative_array; } if ($sql_query == "") { $sql_query = $this->sql_query; } if ($database == "") { $database = $this->database; } if ($query_raw == "" && $query_raw != 0) { $query_raw = $this->query_raw; } if ($query_key == "") { $query_key = $this->query_key; } if ($return_array == "" && $return_array != 0) { $return_array = $this->return_array; } if ($return_associative_array == "" && $return_associative_array != 0) { $return_associative_array = $this->return_associative_array; } if ($sql_query == "") { $this->module_error("No sql_query provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_query']++; return (0); } if ($database == "") { $this->module_error("No database provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_query']++; return (0); } if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_query']++; return (0); } if (!($results = @mysql_db_query($database,$sql_query, $this->connection))) { $this->operations['failed_query']++; $this->module_error("Failed to query: $sql_query database: $database. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } else { $this->last_query = $sql_query; // if raw cursor requested // return the raw cursor results if ($query_raw) { return ($results); } else { $results_array = array (); for ($i = 0; $i < @mysql_num_rows($results); $i++) { if ($query_key == "") { if ($return_array == 1 && $return_associative_array == 1) { $results_array[$i] = @mysql_fetch_array ($results); } else if ($return_array == 1) { $results_array[$i] = @mysql_fetch_row($results); } else { $results_array[$i] = @mysql_fetch_assoc($results); } ($results); } else { if ($return_array == 1 && $return_associative_array == 1) { $temp_array = @mysql_fetch_array($results); } else if ($return_array == 1) { $temp_array = @mysql_fetch_row($results); } else { $temp_array = @mysql_fetch_assoc($results); } //$temp_array = @mysql_fetch_array ($results); $results_array[$temp_array[$query_key]] = $temp_array; } } $this->operations['query']++; @mysql_free_result($results); return ($results_array); } } return (0); } /* * get_insert_id() * gets the last insert ID from this object */ function get_insert_id () { return ($this->insert_id); } /* * get_affected_rows() * returns the number of rows affected by the * the last insert, delete, update statement */ function get_affected_rows() { if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } $affected_rows = mysql_affected_rows($this->connection); return ($affected_rows); } /* * update() * update_query() * insert() * insert_query() * send an update query to the database */ function update_query () { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->update($arg_array[0],$arg_array[1]))) { return (0); } else { return (1); } } function insert () { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->update($arg_array[0],$arg_array[1]))) { return (0); } else { return (1); } } function insert_query () { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->update($arg_array[0],$arg_array[1]))) { return (0); } else { return (1); } } function update () { $arg_array = func_get_args(); $arg_num = func_num_args(); $sql_query = ""; $database = ""; if ($arg_array[0] != "") {$sql_query = $arg_array[0];} if ($arg_array[1] != "") {$database = $arg_array[1];} if ($this->sql_query == "") { $this->sql_query = $sql_query; } if ($this->database == "") { $this->database = $database; } if ($sql_query == "") { $sql_query = $this->sql_query; } if ($database == "") { $database = $this->database; } if ($sql_query == "") { $this->module_error("No sql_query provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_update']++; return (0); } if ($database == "") { $this->module_error("No database provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_update']++; return (0); } if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_update']++; return (0); } if (!(@mysql_db_query($database,$sql_query, $this->connection))) { $this->module_error("Failed to query: $sql_query database: $database. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->operations['failed_update']++; return (0); } else { // sets the insert ID of the insert command $this->insert_id = @mysql_insert_id($this->connection); $this->operations['update']++; return (1); } } /* * get_tables() * lists available tables in the database */ function get_tables () { $arg_array = func_get_args(); $arg_num = func_num_args(); $database = ""; if ($arg_array[0] != "") {$database = $arg_array[0];} if ($this->database == "") { $this->database = $database; } if ($database == "") { $database = $this->database; } if ($database == "") { $this->module_error("No database provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if ($this->connection == "") { $this->module_error("Database not connected. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } if (!($tables = @mysql_list_tables($database,$this->connection))) { $this->module_error("Failed to list tables. Database: $database. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } else { for ($i = 0; $i < @mysql_num_rows($tables); $i++) { if (!($tables_array[$i] = @mysql_tablename($tables, $i))) { return (0); } } if (count ($tables_array) > 0) { return ($tables_array); } else { return (0); } } } /* * get_module_error() * retrieve the most recent module error */ function get_module_error() { return ($this->module_error[$this->module_errors]); } /* * module_error() * set the module error */ function get_database() { return ($this->database); } function module_error() { $arg_array = func_get_args(); $arg_num = func_num_args(); $this->module_errors++; $this->module_error[$this->module_errors] = "$arg_array[0]"; for ($i = 0;$i < ($this->module_errors - 10);$i++) { if (isset($this->module_error[$i])) { unset($this->module_error[$i]); } } return (1); } }; // end of class ?> error_level(); $Error -> template(); $Error -> return_page(); $Error -> log_path(); $Error -> log_file(); $Error -> date(); $Error -> timestamp(); $Error -> admin_email(); # SET ERROR LEVEL 1: ONLY DISPLAY ERROR $Error -> error_level(1); # SET ERROR LEVEL 2: WRITE LOG $Error -> error_level(2); # SET ERROR LEVEL 3: SEND ADMIN EMAIL $Error -> error_level(3); # SET ERROR LEVEL 3: SEND ADMIN EMAIL AND WRITE LOG $Error -> error_level(4); # SET ERROR LEVEL 99: DEBUG MODE (same as $Error -> debug()) $Error -> error_level(99); $Error -> admin_email('mike@nextopia.com'); #optional (default: webmasters email) $Error -> error_level(99); #optional (default: 99 - debug) $Error -> template("http://theory.nextopia.com/dev/mike/php/include/error.php"); #optional (default: templates/error_template.html) $Error -> template('templates/error_template.html'); #optional (default: templates/error_template.html) $Error -> title('Error'); #optional (default: Error $Error -> log_path('./logs/); #optional (default: ./logs/) $Error -> log_file('error.dat'); #optional (default: default_error_log.dat) $Error -> message('Error'); #optional (default: Error: $!) $Error -> log_message('Log Error'); #optional (default: Error: $!) $Error -> date(date("Y-m-d")); #optional (default: yyyy-mm-dd) $Error -> timestamp(date("H:i:s")); #optional (default: hh:nn:ss) $Error -> return_page('javascript:history.back()'); #optional (default: javascript:history.back()) DISPLAY ERROR METHOD NOTE: the DISPLAY method will NOT maintain all values within the object the values only exist within the DISPLAY method if values are not passed, the object will attempt to use previously set values $Error -> display('ERROR MESSAGE','LOG MESSAGE',99,'template','title','log file', 'return page'); OR $Error -> display('ERROR MESSAGE','LOG MESSAGE'); ################################################# returns the most recent error produced within the module NOTE: not necessarily a fatal error many module errors will not cause the module to fail $module_error = $Error -> get_module_error(); ################################################# debug the error handler $Error -> debug(); # exit $Error -> debug(1); # do not exit */ var $message; var $log_message; var $error_level; var $template; var $log_path; var $log_file; var $date; var $timestamp; var $title; var $return_page; var $admin_email; /* * void Error_Handler() * class constructor */ function Error_Handler() { global $HTTP_SERVER_VARS, $GLOBALS; $this->INFO_ARRAY = array( 'PACKAGE' => 'ERROR HANDLER', 'VERSION' => '1.6', 'CREATED' => '2002/07/31', 'MODIFIED' => '2003/02/06', 'WRITTEN BY' => 'Michael McInally (mike@nextopia.com)' ); $this->error_levels = array( 1 => 'ONLY DISPLAY' , 2 => 'SEND ADMIN EMAIL' , 3 => 'WRITE LOG FILE' , 4 => 'SEND ADMIN EMAIL AND WRITE LOG FILE' , 99 => 'DEBUGGING MODE' ); $this->message = ""; $this->log_message = ""; // set default error level to 1 (no logging) $this->error_level = "1"; $this->template = "error_template.html"; if (!(file_exists($this->template))) { $this->template = "./templates/error_template.html"; } $this->log_path = './logs/' . date("Y-m-d") . '/'; $this->log_file = date("Y-m-d") . ".error.dat"; $this->title = "Server Error"; $this->return_page = "javascript:history.back()"; $this->date = date("Y-m-d"); $this->timestamp = date("H:i:s"); // set default values for these settings $this->admin_email = $HTTP_SERVER_VARS['SERVER_ADMIN']; $this->script_name = $HTTP_SERVER_VARS['SCRIPT_FILENAME']; $this->request_method = $HTTP_SERVER_VARS['REQUEST_METHOD']; $this->query_string = $HTTP_SERVER_VARS['QUERY_STRING']; $this->browser = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; $this->ip_address = $HTTP_SERVER_VARS['REMOTE_ADDR']; $this->host_name = $HTTP_SERVER_VARS['REMOTE_HOST']; if (empty($this->admin_email)) { $this->admin_email = $GLOBALS['SERVER_ADMIN']; } if (empty($this->script_name)) { $this->script_name = $GLOBALS['SCRIPT_FILENAME']; } if (empty($this->request_method)) { $this->request_method = $GLOBALS['REQUEST_METHOD']; } if (empty($this->query_string)) { $this->query_string = $GLOBALS['QUERY_STRING']; } if (empty($this->browser)) { $this->browser = $GLOBALS['HTTP_USER_AGENT']; } if (empty($this->ip_address)) { $this->ip_address = $GLOBALS['REMOTE_ADDR']; } if (empty($this->host_name)) { $this->host_name = $GLOBALS['REMOTE_HOST']; } $this->module_errors = 0; $this->module_error = array (); $this->type = 1; $this->cr = "
"; if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']) || isset($GLOBALS['REQUEST_METHOD'])) { $this->type = 1; $this->cr = "
"; } else { $this->type = 0; $this->cr = "\n"; } } /* * debug() * DEBUG THE CLASS * show all variables set within the class */ function debug() { $arg_array = func_get_args(); $arg_num = func_num_args(); $exit = 0; $message = ""; $log_message = ""; if ($arg_array[0] != "") {$exit = $arg_array[0];} if ($message == "") {$message = $this->message;} if ($log_message == "") {$log_message = $this->log_message;} ### default debugging mode if ($this->type) { echo "

"; echo "PACKAGE: ".$this->INFO_ARRAY['PACKAGE']."$this->cr"; echo "VERSION: ".$this->INFO_ARRAY['VERSION']."$this->cr"; echo "CREATED: ".$this->INFO_ARRAY['CREATED']."$this->cr"; echo "MODIFIED: ".$this->INFO_ARRAY['MODIFIED']."$this->cr"; echo "WRITTEN BY: ".$this->INFO_ARRAY['WRITTEN BY']."$this->cr$this->cr"; echo "

"; echo "

"; echo "Debugging Mode:$this->cr"; echo "line: ".__LINE__." in ".__FILE__."$this->cr$this->cr"; echo "

"; echo "Template: $this->template$this->cr$this->cr"; echo "Title: $this->title$this->cr$this->cr"; echo "Error Message: $message$this->cr$this->cr"; echo "Log Message: $log_message$this->cr$this->cr"; echo "Log Path: $this->log_path$this->cr$this->cr"; echo "Log File: $this->log_file$this->cr$this->cr"; echo "Log File Date: $this->date$this->cr$this->cr"; echo "Log File Timestamp: $this->timestamp$this->cr$this->cr"; echo "Return Page URL: $this->return_page$this->cr$this->cr"; echo "Error Level: $this->error_level: ".$this->error_levels[$this->error_level]." $this->cr$this->cr"; echo "Admin Email: $this->admin_email$this->cr$this->cr"; echo "$this->cr"; while (list ($key, $value) = each ($this->module_error)) { echo ("Module Error $key: $value$this->cr$this->cr
"); } /* foreach my $key (sort sortnum keys %{$this->module_error}) { echo "Module Error $key: $this->module_error{$key}$this->cr$this->cr"; } */ echo "$this->cr"; } else { echo "PACKAGE: ".$this->INFO_ARRAY['PACKAGE']."$this->cr"; echo "VERSION: ".$this->INFO_ARRAY['VERSION']."$this->cr"; echo "CREATED: ".$this->INFO_ARRAY['CREATED']."$this->cr"; echo "MODIFIED: ".$this->INFO_ARRAY['MODIFIED']."$this->cr"; echo "WRITTEN BY: ".$this->INFO_ARRAY['WRITTEN BY']."$this->cr$this->cr"; echo "Debugging Mode:$this->cr"; echo "line: ".__LINE__." in ".__FILE__."$this->cr$this->cr"; echo "Template: $this->template$this->cr$this->cr"; echo "Title: $this->title$this->cr$this->cr"; echo "Error Message: $message$this->cr$this->cr"; echo "Log Message: $log_message$this->cr$this->cr"; echo "Log Path: $this->log_path$this->cr$this->cr"; echo "Log File: $this->log_file$this->cr$this->cr"; echo "Log File Date: $this->date$this->cr$this->cr"; echo "Log File Timestamp: $this->timestamp$this->cr$this->cr"; echo "Return Page URL: $this->return_page$this->cr$this->cr"; echo "Error Level: $this->error_level: ".$this->error_levels[$this->error_level]." $this->cr$this->cr"; echo "Admin Email: $this->admin_email$this->cr$this->cr"; echo "$this->cr"; while (list ($key, $value) = each ($this->module_error)) { echo ("Module Error $key: $value$this->cr$this->cr
"); } /* foreach my $key (sort sortnum keys %{$this->module_error}) { echo "Module Error $key: $this->module_error{$key}$this->cr$this->cr"; } */ echo "$this->cr"; } if (!$exit) { exit; } } /* * message() * set the error handler message value */ function message() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->message == "") { $this->module_error("No message provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->message != "") { return ($this->message); } else { return (0); } } else { $this->message = $arg_array[0]; return (1); } } /* * log_message() * set the error handler log message value */ function log_message() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->log_message == "") { $this->module_error("No log_message provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->log_message != "") { return ($this->log_message); } else { return (0); } } else { $this->log_message = $arg_array[0]; } } /* * error_level() * set the error level value */ function error_level() { $arg_array = func_get_args(); $arg_num = func_num_args(); if ($arg_array[0] < 1 || $arg_array[0] > 99) { if ($this->error_level < 1 || $this->error_level > 99) { $this->module_error("No error_level provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->error_level >= 1 && $this->error_level <= 99) { return ($this->error_level); } else { return (0); } } else { $this->error_level = $arg_array[0]; } } /* * template() * set the error handler template file value */ function template() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->template == "") { $this->module_error("No template provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->template != "") { return ($this->template); } else { return (0); } } else { $this->template = $arg_array[0]; } } /* * template_file() * set the error handler template file value */ function template_file() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->template($arg_array[0]))) { return (0); } else { return (1); } } /* * title() * set the error handler title value */ function title() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->title == "") { $this->module_error("No title provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->title != "") { return ($this->title); } else { return (0); } } else { $this->title = $arg_array[0]; } } /* * log_path() * set the error handler log path value */ function log_path() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->log_path == "") { $this->module_error("No log_path provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->log_path != "") { return ($this->log_path); } else { return (0); } } else { $this->log_path = $arg_array[0]; } } /* * log_file() * set the error handler log file value */ function log_file() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->log_file == "") { $this->module_error("No log_file provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->log_file != "") { return ($this->log_file); } else { return (0); } } else { $this->log_file = $arg_array[0]; } } /* * date() * set the error handler log date value */ function date() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->date == "") { $this->module_error("No date provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->date != "") { return ($this->date); } else { return (0); } } else { $this->date = $arg_array[0]; } } /* * log_date() * set the error handler log date value */ function log_date() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->date($arg_array[0]))) { return (0); } else { return (1); } } /* * timestamp() * set the error handler log time value */ function timestamp() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->timestamp == "") { $this->module_error("No timestamp provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->timestamp != "") { return ($this->timestamp); } else { return (0); } } else { $this->timestamp = $arg_array[0]; } } /* * log_time() * set the error handler log date value */ function log_time() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->timestamp($arg_array[0]))) { return (0); } else { return (1); } } /* * return_page() * set the error handler return page value */ function return_page() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->return_page == "") { $this->module_error("No return_page provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->return_page != "") { return ($this->return_page); } else { return (0); } } else { $this->return_page = $arg_array[0]; } } /* * admin_email() * set the error handler administrator email value */ function admin_email() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!(isset($arg_array[0]))) { if ($this->admin_email == "") { $this->module_error("No admin_email provided. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); } if ($this->admin_email != "") { return ($this->admin_email); } else { return (0); } } else { $this->admin_email = $arg_array[0]; } } /* * display_error() * display() -> synonym for display_error * displays the error_handler error to the user * checks error level of error and: * 1: no error logging * 2: emails the admin * 3: logs error to a log file * 4: emails the admin and logs the error to a log file */ function display() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->display_error($arg_array[0],$arg_array[1],$arg_array[2],$arg_array[3],$arg_array[4],$arg_array[5],$arg_array[6],$arg_array[7],$arg_array[8]))) { return (0); } } function display_error() { $arg_array = func_get_args(); $arg_num = func_num_args(); $message = ""; $log_message = ""; $error_level = ""; $template = ""; $title = ""; $log_path = ""; $log_file = ""; $return_page = ""; $admin_email = ""; if ($arg_array[0] != "") {$message = $arg_array[0];} if ($arg_array[1] != "") {$log_message = $arg_array[1];} if ($arg_array[2] != "") {$error_level = $arg_array[2];} if ($arg_array[3] != "") {$template = $arg_array[3];} if ($arg_array[4] != "") {$title = $arg_array[4];} if ($arg_array[5] != "") {$log_path = $arg_array[5];} if ($arg_array[6] != "") {$log_file = $arg_array[6];} if ($arg_array[7] != "") {$return_page = $arg_array[7];} if ($arg_array[8] != "") {$admin_email = $arg_array[8];} if ($log_message == "") { $log_message = $message; } if ($this->message == "") { $this->message = $message; } if ($this->log_message == "") { $this->log_message = $log_message; } if ($this->error_level != "99") { if ($this->error_level < 1 || $this->error_level > 99) { $this->error_level = $error_level; } } if ($this->template == "") { $this->template = $template; } if ($this->title == "") { $this->title = $title; } if ($this->log_path == "") { $this->log_path = $log_path; } if ($this->log_file == "") { $this->log_file = $log_file; } if ($this->return_page == "") { $this->return_page = $return_page; } if ($this->admin_email == "") { $this->admin_email = $admin_email; } if ($message == "") { $message = $this->message; } if ($log_message == "") { $log_message = $this->log_message; } if ($this->error_level == "99") { $error_level = "99"; } else { if ($error_level < 1 || $error_level > 99) { $error_level = $this->error_level; } } if ($template == "") { $template = $this->template; } if ($title == "") { $title = $this->title; } if ($log_path == "") { $log_path = $this->log_path; } if ($log_file == "") { $log_file = $this->log_file; } if ($return_page == "") { $return_page = $this->return_page; } if ($admin_email == "") { $admin_email = $this->admin_email; } if ($message == "") { $message = "Unknown error has occured."; } if ($this->error_level == "99") { $error_level = "99"; } if ($error_level == "") { $error_level = 1; } if ($error_level == "99") { $this->debug(); exit; } // log the error message if needed if (!($this->log_error($log_message,$error_level,$template,$title,$log_path,$log_file,$return_page,$admin_email))) { //$this->debug(); //exit; } if (preg_match("/http/i", $template)) { if (!(headers_sent())) { header("Location:".$template."?message=".urlencode($message)."&return_page=".urlencode($return_page)); } else { ?> Redirect

Page failed to redirect

Please click on the link below to be properly redirected.

Click Here!

module_error("Failed to open: $template. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); $this->message($message); $this->log_message($log_message); $this->debug(); } $html = preg_replace("/\[title\]/i", $title, $html); $html = preg_replace("/\[message\]/i", $message, $html); //$html = preg_replace("/\[log_file\]/i", $log_file, $html); $html = preg_replace("/\[log_message\]/i", $log_message, $html); $html = preg_replace("/\[return_page\]/i", "Return", $html); echo($html); exit; } } /* * log_error() * log() -> synonym for log_error() * checks error level of error and: * 1: no error logging * 2: emails the admin * 3: logs error to a log file * 4: emails the admin and logs the error to a log file */ function log() { $arg_array = func_get_args(); $arg_num = func_num_args(); if (!($this->log_error($arg_array[0],$arg_array[1],$arg_array[2],$arg_array[3],$arg_array[4],$arg_array[5],$arg_array[6],$arg_array[7],$arg_array[8]))) { return (0); } } function log_error() { $arg_array = func_get_args(); $arg_num = func_num_args(); $log_message = ""; $error_level = ""; $template = ""; $title = ""; $log_path = ""; $log_file = ""; $return_page = ""; $admin_email = ""; if ($arg_array[0] != "") {$log_message = $arg_array[0];} if ($arg_array[1] >= 0 && $arg_array[2] <= 99) {$error_level = $arg_array[1];} if ($arg_array[2] != "") {$template = $arg_array[2];} if ($arg_array[3] != "") {$title = $arg_array[3];} if ($arg_array[4] != "") {$log_path = $arg_array[4];} if ($arg_array[5] != "") {$log_file = $arg_array[5];} if ($arg_array[6] != "") {$return_page = $arg_array[6];} if ($arg_array[7] != "") {$admin_email = $arg_array[7];} if ($this->log_message == "") { $this->log_message = $log_message; } if ($this->error_level == "" && $this->error_level != 0) { $this->error_level = $error_level; } if ($this->template == "") { $this->template = $template; } if ($this->title == "") { $this->title = $title; } if ($this->log_path == "") { $this->log_path = $log_path; } if ($this->log_file == "") { $this->log_file = $log_file; } if ($this->return_page == "") { $this->return_page = $return_page; } if ($this->admin_email == "") { $this->admin_email = $admin_email; } if ($log_message == "") { $log_message = $this->log_message; } if ($error_level == "" && $error_level != 0) { $error_level = $this->error_level; } if ($template == "") { $template = $this->template; } if ($title == "") { $title = $this->title; } if ($log_path == "") { $log_path = $this->log_path; } if ($log_file == "") { $log_file = $this->log_file; } if ($return_page == "") { $return_page = $this->return_page; } if ($admin_email == "") { $admin_email = $this->admin_email; } if ($log_message == "") { $log_message = "Unknown error has occured."; } if ($error_level == "" || $error_level == 0) { $error_level = 1; } switch($error_level) { case 1: break; case 2: $new_log_message = $this->date . "\n"; $new_log_message .= $this->timestamp . "\n"; $new_log_message .= $log_message . "\n"; $new_log_message .= $this->script_name . "\n"; $new_log_message .= $this->request_method . "\n"; $new_log_message .= $this->query_string . "\n"; $new_log_message .= $this->browser . "\n"; $new_log_message .= $this->ip_address . "\n"; $new_log_message .= $this->host_name . "\n"; //$status = @error_log($new_log_message, 1, $admin_email, "Script: $this->script_name"); if (!($status = @error_log($new_log_message, 1, $admin_email, "Script: $this->script_name"))) { $this->module_error("Failed send mail to: $admin_email. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } break; case 3: $new_log_message = $this->date . "\t"; $new_log_message .= $this->timestamp . "\t"; $new_log_message .= $log_message . "\t"; $new_log_message .= $this->script_name . "\t"; $new_log_message .= $this->request_method . "\t"; $new_log_message .= $this->query_string . "\t"; $new_log_message .= $this->browser . "\t"; $new_log_message .= $this->ip_address . "\t"; $new_log_message .= $this->host_name . "\n"; if (!(@file_exists($log_path))) { if (!(@mkdir($log_path, 0777))) { $this->module_error("Failed create directory: |$log_path|. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } } //$status = @error_log($new_log_message, 3, $log_path.$log_file); if (!($status = @error_log($new_log_message, 3, $log_path.$log_file))) { $this->module_error("Failed write error log: $log_path.$log_file. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } break; case 4: $new_log_message = $this->date . "\n"; $new_log_message .= $this->timestamp . "\n"; $new_log_message .= $log_message . "\n"; $new_log_message .= $this->script_name . "\n"; $new_log_message .= $this->request_method . "\n"; $new_log_message .= $this->query_string . "\n"; $new_log_message .= $this->browser . "\n"; $new_log_message .= $this->ip_address . "\n"; $new_log_message .= $this->host_name . "\n"; if (!(file_exists($log_path))) { if (!(mkdir($log_path, 0777))) { $this->module_error("Failed create directory: $log_path. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } } //$status = @error_log($new_log_message, 1, $admin_email, "Script: $this->script_name"); if (!($status = @error_log($new_log_message, 1, $admin_email, "Script: $this->script_name"))) { $this->module_error("Failed send mail to: $admin_email. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } $new_log_message = $this->date . "\t"; $new_log_message .= $this->timestamp . "\t"; $new_log_message .= $log_message . "\t"; $new_log_message .= $this->script_name . "\t"; $new_log_message .= $this->request_method . "\t"; $new_log_message .= $this->query_string . "\t"; $new_log_message .= $this->browser . "\t"; $new_log_message .= $this->ip_address . "\t"; $new_log_message .= $this->host_name . "\n"; //$status = @error_log($new_log_message, 3, $log_path.$log_file); if (!($status = @error_log($new_log_message, 3, $log_path.$log_file))) { $this->module_error("Failed write error log: $log_path.$log_file. MODULE ERROR AT LINE: ".__LINE__." in ".__FILE__."."); return (0); } break; default: break; } return (1); } /* * get_module_error() * retrieve the most recent module error */ function get_module_error() { return ($this->module_error[$this->module_errors]); } /* * module_error() * set the module error */ function module_error() { $arg_array = func_get_args(); $arg_num = func_num_args(); $this->module_errors++; $this->module_error[$this->module_errors] = "$arg_array[0]"; for ($i = 0;$i < ($this->module_errors - 10);$i++) { if (isset($this->module_error[$i])) { unset($this->module_error[$i]); } } return (1); } }; // end of class ?> error_level(1); #$Error -> template(''); #$Error -> log_path (LOG_PATH); $DB -> host(hostName); $DB -> username(hostUser); $DB -> password(hostPassword); $DB -> database(databasename); $DB -> connect() OR $Error -> display_error(); #$DB -> connect() OR $DB ->debug(); ?> Environmental Medicine Consortium

Qualified individuals can become a part of the EMC experience by participating in special field events.

Welcome to the EMC Volunteer Network. This is where EMC field responses, projects, and activities are scheduled and coordinated. If you are already registered, log on below to proceed. If you are interested in becoming a member of the EMC Volunteer Network please register to begin processing your registration.

Login

Please enter your username and password
Username:
Password
 

Environmental Medicine Consortium
NC State University College of Veterinary Medicine
All material on this site is ©Environmental Medicine Consortium. All Rights Reserved.