<?php
//
// +———————————————————————-+
// | whxbb 基类 |
// +———————————————————————-+
// | copyright (c) 2001 netfish software |
// | |
// | author: whxbb(whxbb@21cn.com) |
// +———————————————————————-+
//
// $id: whxbb.class.php,v 0.1 2001/8/4 12:53:33 yf exp $
//
// 禁止直接访问该页面
if (basename($http_server_vars[php_self]) == "whxbb.class.php") {
header("http/1.0 404 not found");
}
// 调试标志,为1时,系统运行在调试状态
define(whxbb_debug_flag, 0);
// 出错代码的预定义
// 忽略错误
define(whxbb_error_ignore, 1);
// 在页面显示错误
define(whxbb_error_echo , 2);
// 弹出错误警告并显示错误
define(whxbb_error_alert , 4);
// 停止程序的运行
define(whxbb_error_die , 8);
// 返回上页
define(whxbb_error_return, 16);
// 跳到指定页
define(whxbb_error_goto, 32);
/**
* purpose
* 基类, 在该类中封装了一些常用的方法
*
* @author : whxbb(whxbb@21cn.com)
* @version : 0.1
* @date : 2001/12/4
*/
class whxbb
{
/**
* 调试标志
* @access protected
*/
var $_debug;
/**
* 数据库连接标志
* @access protect
*/
var $_conn;
function whxbb()
{
// 数据库连接标志
global $_conn;
if (!is_resource($conn))
die("数据库连接错误");
$this->_conn = $conn;
$this->_debug = whxbb_debug_flag;
}
/**
* 处理字符串
* @param $str 要处理的字符串
* @param $act in 将替换成\’out 把\’替换成
* @access public
*/
function operatestring(&$str, $act)
{
if($act == in)
$str = str_replace("", "\\’", $str);
if($act == out)
$str = str_replace("\\’", "", $str);
}
/**
* 判断一个变量是否为错误对象
*
* @param $data 要判断的变量
* @access public
* @return bool 是 true 不是 false
*/
function iserror($data) {
return (bool)(is_object($data) &&
(get_class($data) == "whxbb_error" ||
is_subclass_of($data, "whxbb_error")));
}
/**
* 判断一个变量是否为分页对象
*
* @param $data the value to test
* @access public
* @return bool true if $data is an pager
*/
function ispager($data) {
return (bool)(is_object($data) &&
(get_class($data) == "pager" ||
is_subclass_of($data, "pager")));
}
}
/**
* 调试类
*
* purpose
*
* 程序调试用
*
* @author : wxhbb(whxbb@21cn.com)
* @version : 0.1
* @date : 2001/8/4
*/
class whxbb_debug extends whxbb
{
function whxbb_debug($msg)
{
$this->whxbb();
if($this->_debug == 1)
{
echo "\n<br>whxbb debug >>> $msg<br>\n";
}
}
}
/**
* purpose
* 错误处理(触发错误,显示错误)
*
* @author : whxbb(whxbb@21cn.com)
* @version : 0.1
* @date : 2001/8/4
*/
class whxbb_error extends whxbb
{
/**
* 错误信息
* @access protected
*/
var $_errno;
/**
* 错误代码
* @access protected
*/
var $_errmsg;
/** 报错方式 参见"出错代码的预定义" */
var $_reportmethod;
/**
* 构造一个错误对象
* @param $errmsg 错误信息, 错误的字符描述
* @param $errno 错误代码, 错误的代码
* @param $reportmethod 报错方式,参见"出错代码的预定义"
* @param $param1 参数一,如跳转到指定页面时页面的url
* @param $param2 参数二 保留
* @access public
*/
function whxbb_error($errmsg, $errno, $reportmethod = whxbb_error_ignore, $param1 = , $param2 = )
{
$this->whxbb();
$this->_errmsg = $errmsg;
$this->_errno = $errno;
$this->_reportmethod = $reportmethod;
switch($reportmethod)
{
case whxbb_error_ignore:
break;
case whxbb_error_echo:
echo $errmsg;
break;
case whxbb_error_alert:
js::alert($errmsg);
break;
case whxbb_error_die:
$this->close();
exit;
break;
case whxbb_error_die + whxbb_error_alert:
js::alert($errmsg);
$this->close();
exit;
break;
case whxbb_error_die + whxbb_error_echo:
echo $errmsg;
$this->close();
exit;
break;
case whxbb_error_alert + whxbb_error_return:
js::alert($errmsg);
js::back();
break;
case whxbb_error_return:
js::back();
break;
case whxbb_error_goto:
js::goto($param1);
break;
case whxbb_error_goto + whxbb_error_alert:
js::alert($errmsg);
js::goto($param1);
break;
}
new whxbb_debug($errno.":".$errmsg);
}
/**
* 得到错误对象的错误信息
*/
function getmsg()
{
return $this->_errmsg;
}
/**
* 得到错误对象的错误代买
*/
function getno()
{
return $this->_errno;
}
}
?>
