<?
/*********************************************************
class DBVariable
Description:
Variables:
History:
2003-11-18 Daniel Önnerby Init version.
*********************************************************/
class DBVariable{
var $iId = 0;
var $sDBTable = "";
var $sDBField = "";
var $sVariable = "";
var $sValue = "";
/**************************************************
function DBVariable
Description:
Constructor.
History:
2003-11-18 Daniel Önnerby Init version.
**************************************************/
function DBVariable( $sDBTable,$sDBField,$sVariable="",$sDefault="" ){
$this->sDBTable = $sDBTable;
$this->sDBField = $sDBField;
if($sVariable!=""){
$this->bGetVariable($sVariable,$sDefault);
}
}
/*****************************************************
function bReset
Description:
Input:
$sMyVar = description.
Returns:
History:
2003-11-25 Daniel Önnerby Init version.
*****************************************************/
function bReset( ){
$this->iId = 0;
$this->sVariable = "";
$this->sValue = "";
}
/*****************************************************
function bGetVariable
Description:
Input:
$sMyVar = description.
Returns:
History:
2003-11-18 Daniel Önnerby Init version.
*****************************************************/
function bGetVariable( $sVariable="",$sDefault="" ){
$this->iId = 0;
$this->sVariable = $sVariable;
$this->sValue = $sDefault;
if($this->bDBDesignTableExists()){
$sSQL="SELECT id,the_variable,the_value FROM dbdesign_variables WHERE
the_table='".addslashes($this->sDBTable)."' AND
the_field='".addslashes($this->sDBField)."' AND
the_variable='".addslashes($sVariable)."'";
//echo $sSQL;
$rsVaraible=mysql_query($sSQL);
if($aVariable=mysql_fetch_array($rsVaraible)){
$this->iId = $aVariable["id"];
$this->sVariable = $aVariable["the_variable"];
$this->sValue = $aVariable["the_value"];
}else{
return false;
}
}else{
return false;
}
}
/*****************************************************
function bDBDesignTableExists
Description:
Input:
$sMyVar = description.
Returns:
History:
2003-11-18 Daniel Önnerby Init version.
*****************************************************/
function bDBDesignTableExists( $bCreate=false ){
global $sDB;
if($GLOBALS["dbtableexists"]==true){
return true;
}else{
if($bCreate){
$sSQL="CREATE TABLE dbdesign_variables (
id int not null auto_increment,
the_table varchar(85) not null default '',
the_field varchar(85) not null default '',
the_variable varchar(85) not null default '',
the_value text default '',
primary key(id),
key(the_table,the_field,the_variable)
);";
mysql_query($sSQL);
$GLOBALS["dbtableexists"]=true;
return true;
}else{
$GLOBALS["dbtableexists"]=false;
$rsTables=mysql_list_tables($sDB);
while( $aTable=mysql_fetch_array($rsTables) ){
if($aTable[0]=="dbdesign_variables"){
$GLOBALS["dbtableexists"]=true;
}
}
return $GLOBALS["dbtableexists"];
}
}
}
/*****************************************************
function bUpdate
Description:
Input:
$sMyVar = description.
Returns:
History:
2003-11-18 Daniel Önnerby Init version.
*****************************************************/
function bUpdate( ){
if($this->bDBDesignTableExists(true)){
if($this->iId==0){
$sSQL="INSERT INTO dbdesign_variables (
the_table,
the_field,
the_variable,
the_value
) VALUES (
'".addslashes($this->sDBTable)."',
'".addslashes($this->sDBField)."',
'".addslashes($this->sVariable)."',
'".addslashes($this->sValue)."'
)";
mysql_query($sSQL);
$this->iId = mysql_insert_id();
}else{
$sSQL="UPDATE dbdesign_variables SET
the_table = '".addslashes($this->sDBTable)."',
the_field = '".addslashes($this->sDBField)."',
the_variable = '".addslashes($this->sVariable)."',
the_value = '".addslashes($this->sValue)."'
WHERE id=".$this->iId;
mysql_query($sSQL);
}
//echo $sSQL;
}
}
/*****************************************************
function bFindXMLVariable
Description:
Input:
$sMyVar = description.
Returns:
History:
2003-11-25 Daniel Önnerby Init version.
*****************************************************/
function bFindXMLVariable( $sVariable,$sXML,$bGet=false ){
if(preg_match("/".$sVariable."=\"(.*)\"/iU",$sXML,$aMatch)){
if($bGet){
$this->bGetVariable($sVariable);
$this->sValue = $aMatch[1];
return true;
}else{
return $aMatch[1];
}
}else{
return false;
}
}
}
?>