Databases
|
|
|
|
<?php
/*
------------------------------------------------------------------------------------------
waf_log class
version 1.0Beta
------------------------------------------------------------------------------------------
waf means Web Application Framework. It is a larger system designed to provide
overall easy access to tools that you need when developing any dynamic website.
the dbdriver class is the corner-stone of the system.
The log class intends to provide a class-based log system to record specifics that the
developer might not want to have to dig into the web server's log for. It works based
on a dbdriver class and is designed to find all necessary files within the
doc_root/system folder.
The constructor will require database connection information to interface the dbdriver
object.
IMPORTANT NOTE: The first row of the waf_log table MUST remain intact at all times!
This system will upgrade itself as necessary. ALSO, the combination of values 0 in
both context_id and application_id is reserved to update the version information of the
system.
License Information
-------------------
Copyright (C) 2003 Fabien Papleux, fpa Technology Consulting
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation,
version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program;
if not, you can get a copy at http://www.gnu.org/licenses/gpl.txt
Contact Information
-------------------
Should you have any questions / remarks / suggestions, please don't hesitate to
contact me at dev_support@fpatech.com
Synopsis
--------
Constants: Constants are defined outside the scope of the class and are global.
WAF_LOG = 1 : Indicates that the WAF_LOG Module is loaded
WAF_LOG_VERSION = "1.0Beta" : Indicates the version of log system. This
system is used so that it can upgrade itself
automatically.
Properties:
$db : database connection
$db_name : name of the database to use
$connected : holds whether we are connected to the right database or not.
Methods:
log($message, [$context_ID], [$application]);
waf_log($server, $user, $pwd, $dbname);
classprint()
create_system();
get_version();
check_version();
upgrade(); -- Empty in Version 100Beta. Will be used to upgrade from
any version to any version in the future
Known Bugs
----------
Version History
---------------
Future Development
------------------
1. Reporting Tools
------------------------------------------------------------------------------------------
*/
// LOADING DEPENDENCIES
// ------------------------------------------------------------------------------------------
$waf_dbdriverfile = $_SERVER["DOCUMENT_ROOT"] . "/system/dummy.php";
if (! defined("DBDRIVER")) {
$waf_dbdriverfile = $_SERVER["DOCUMENT_ROOT"] . "/system/dbdriver.cls.php";
}
include($waf_dbdriverfile);
// CONSTANTS DEFINITIONS
// ------------------------------------------------------------------------------------------
define("WAF_LOG", 1);
define("WAF_LOG_VERSION", "1.0Beta");
class waf_log {
// PROPERTIES DECLARATION
// ------------------------------------------------------------------------------------------
var $db;
var $db_name;
var $connected;
// CONSTRUCTOR
// The constructor will initialize the properties and attempt to connect to the server.
// ------------------------------------------------------------------------------------------
function waf_log($server, $user, $pwd, $dbname) {
$this->db = new dbdriver($server, $user, $pwd);
$this->db_name = $dbname;
$this->connected = $this->db->db_select($dbname);
return $this->db->link_id;
}
// LOG
// Log is the principal method of this class. It receives the mandatory parameter $message
// and optional Context_ID and Application_ID that help classify the log entry.
// Context_ID is numerical and Application_ID is alphanumeric.
// ------------------------------------------------------------------------------------------
function log($message, $context_id = 0, $application_id = "") {
$result = 0;
if ($this->connected) {
$sql = "INSERT INTO WAF_LOG (MSG";
if ($context_id) $sql = $sql . ", CONTEXT_ID";
if ($application_id) $sql = $sql . ", APP_ID";
$sql = $sql . ") VALUES ('{$message}'";
if ($context_id) $sql = $sql . ", $context_id";
if ($application_id) $sql = $sql . ", '{$application_id}'";
$sql = $sql . ")";
$result = $this->db->query($sql);
}
return $result;
}
// CLASSPRINT
// Prints information about the current object
// ------------------------------------------------------------------------------------------
function classprint() {
echo "Object of waf_log class version " . WAF_LOG_VERSION . "<br>";
echo "Using DBDriver version " . DBDRIVER_VERSION . "<br><br>";
echo "Database Name: $this->db_name<br><br>";
echo "DBDriver information:<br>";
$this->db->classprint();
}
// CREATE_SYSTEM
// Creates the log system into designated server/database.
// ------------------------------------------------------------------------------------------
function create_system() {
$result = 0;
if ($this->connected) {
$sql = "CREATE TABLE WAF_LOG (ID BIGINT PRIMARY KEY AUTO_INCREMENT,
CONTEXT_ID INT NULL, APP_ID CHAR(10) NULL, MSG CHAR(255))";
echo $sql . "<br><br>";
$result = $this->db->query($sql);
echo "result of the creation query: $result<br>";
echo $this->db->error() . "<br><br>";
if ($result) {
$sql = "INSERT INTO WAF_LOG (CONTEXT_ID, APP_ID, MSG) VALUES
(0, 0, '1.00Beta')";
$result = $this->db->query($sql);
}
}
return $result;
}
// GET_VERSION
// Returns version of the current log system
// ------------------------------------------------------------------------------------------
function get_version() {
$result = "";
if ($this->connected && $this->db->table_exists("waf_log")) {
$sql = "SELECT MSG FROM WAF_LOG WHERE (CONTEXT_ID = 0) AND (APP_ID = 0)";
$this->db->query($sql);
if ($this->db->result_id && ($this->db->num_rows() > 0)) {
$system_version_array = $this->db->fetch_row();
$result = $system_version_array[0];
}
}
return $result;
}
// CHECK_VERSION
// Checks the version of current system and returns True if version is current.
// ------------------------------------------------------------------------------------------
function check_version() {
$result = 0;
echo "connected: $this->connected<br>";
echo "Table exists? " . $this->db->table_exists("waf_log") . "<br>";
if ($this->connected && (! $this->db->table_exists("waf_log"))) {
echo "sending to create_system<br>";
$this->create_system();
}
if (strtoupper(WAF_LOG_VERSION) == strtoupper($this->get_version()))
$result = 1;
return $result;
}
// UPGRADE
// Will upgrade the log system from anything to anything
// ------------------------------------------------------------------------------------------
function upgrade() {
return 1;
}
}
|
|
|
Usage Example
|
$log = new waf_log("localhost", "manager", "jskhd", "system");
$log->log("That's it, I've had it", 0, "redirect");
header("location: http://www.gotohl.org");
|
|
|
Rate This Script
|
|
|
|