<?
require_once( "IBClass.php" );
// Classes for inserting and uppdating data in interbase 6.0
// hide@address.com
// version 0.6
// For the latest version visit: http://www.phpclasses.org/browse.html/package/1002.html
//
// Please write to me and tell me what you think of my class.
//
// 2003-03-09 11:00 First release on the internet
// 2003-03-16 18:30 Added ParamBLOBFromFile
// 2003-03-19 08:00 Change so that TIBFiledhandler no longer makes a copy of the TIBCon object
/*
$dbp = new TIBFieldHandler( $ibq );
$dbp->SetTableName( "Answer" );
if( $_POST["Action"]=="Save" )
{
$dbp->ParamInt ("Q_ID", $_POST["Q_ID"]);
$dbp->ParamText ("T_Title", $_POST["T_Title"],100);
$dbp->ParamBlob ("T_Note", $_POST["T_Note"]);
$dbp->ParamTimeStamp("T_Start", $_POST["T_Start"]);
$dbp->ParamTimeStamp("T_End", $_POST["T_End"]);
$dbp->ParamText ("T_AdminPassword", $_POST["T_AdminPassword"],20);
if($_POST["T_ID"]==0)
{
$dbp->ParamRaw( "T_ID", "GEN_ID(GEN_T_ID,1)" ) // Do not pass value as parameter.
$dbp->DoInsert();
}
else
$dbp->DoUpdate( "T_ID=" . $_POST["T_ID"] );
}
else if( $_POST["Action"]=="Delete" )
$dbp->DoDelete( "T_ID=" . $_POST["T_ID"] );
*/
class TIBFieldHandler
{
var $IBQuery;
var $TableName;
var $InsParNames;
var $InsParValues;
var $UpdateParams;
var $ParamArr;
//----------------------------------------------------
function TIBFieldhandler( &$ibq, $sTableName=NULL )
{
$this->IBQuery = &$ibq;
$this->TableName = $sTableName;
$this->Where = "";
$this->Clear();
}
//----------------------------------------------------
function Clear()
{
$this->InsParNames = "";
$this->InsParValues = "";
$this->UpdateParams = "";
$this->ParamArr = array();
}
//----------------------------------------------------
function SetWhere( $sWhere )
{
$this->Where = $sWhere;
}
//----------------------------------------------------
function SetTableName( $sTableName )
{
$this->TableName = $sTableName;
}
//----------------------------------------------------
function DoUpdate( $Where=NULL )
{
if( !is_null( $Where ) )
$this->Where = $Where;
if( ! is_a ( $this->IBQuery, "TIBQuery" ) )
trigger_error ("IBQuery variable not set or is not of the right type.", E_USER_ERROR);
if( $this->TableName=="" )
trigger_error ("TableName empty!", E_USER_ERROR);
if( $this->Where=="" )
trigger_error ("Update without a where clause is NOT ok!", E_USER_ERROR);
if( $this->UpdateParams!="" )
$retur = $this->IBQuery->Execute( "update ".$this->TableName." set ".$this->UpdateParams." where ".$this->Where, $this->ParamArr );
else
$retur = true;
$this->Clear();
return $retur;
}
//----------------------------------------------------
function DoDelete( $Where=NULL )
{
if( !is_null( $Where ) )
$this->Where = $Where;
if( ! is_a ( $this->IBQuery, "TIBQuery" ) )
trigger_error ("IBQuery variable not set or is not of the right type.", E_USER_ERROR);
if( $this->TableName=="" )
trigger_error ("TableName empty!", E_USER_ERROR);
if( $this->Where=="" )
trigger_error ("Delete without a where clause is NOT ok!", E_USER_ERROR);
$retur = $this->IBQuery->Execute( "delete from ".$this->TableName." where ".$this->Where);
$this->Clear();
return $retur;
}
//----------------------------------------------------
function DoInsert()
{
if( ! is_a ( $this->IBQuery, "TIBQuery" ) )
trigger_error ("IBQuery variable not set or is not of the right type.", E_USER_ERROR);
if( $this->TableName=="" )
trigger_error ("TableName empty!", E_USER_ERROR);
if( $this->InsParNames != "" )
$retur = $this->IBQuery->Execute( "insert into ".$this->TableName." (".$this->InsParNames.") values (".$this->InsParValues.")", $this->ParamArr );
else
$retur = true;
$this->Clear();
return $retur;
}
//----------------------------------------------------
function AddToParamLists( $ParName, $Value, $Raw=FALSE )
{
if( $this->InsParNames<>"" )
{
$this->InsParNames .= ", ";
$this->InsParValues .= ", ";
$this->UpdateParams .= ", ";
}
if( $Raw ) // Do not go through params array. used for inserting GENID(asdf,1)
{
$this->InsParNames .= $ParName;
$this->InsParValues .= $Value;
$this->UpdateParams .= "$ParName=$Value";
}
else
{
$this->InsParNames .= $ParName;
$this->InsParValues .= "?";
$this->UpdateParams .= "$ParName=?";
$this->ParamArr[] = $Value;
}
}
//----------------------------------------------------
function ParamRaw( $ParName, $Value ) // Do not pass value as parameter. used for GENID()
{
$this->AddToParamLists( $ParName, $Value, TRUE );
}
//----------------------------------------------------
function ParamText( $ParName, $Value, $Length=0 )
{
if( $Length!=0 )
$Value = substr( $Value, 0, $Length );
if( is_null($Value) || Trim($Value) == "" )
$this->AddToParamLists( $ParName, NULL );
else
$this->AddToParamLists( $ParName, $Value );
}
//----------------------------------------------------
function ParamInt( $ParName, $Value )
{
if( ! is_numeric($Value) )
$this->AddToParamLists( $ParName, NULL );
else
$this->AddToParamLists( $ParName, $Value );
}
//----------------------------------------------------
function ParamDate( $ParName, $Value )
{
if( is_null($Value) || Trim($Value) == "" )
$this->AddToParamLists( $ParName, NULL );
else
{
if( strtoupper( $Value ) == "[NOW]")
$datetime = time();
elseif( is_integer($Value) )
$datetime = $Value;
else
$datetime = strtotime ($Value);
$this->AddToParamLists( $ParName, date ("Y-m-d", $datetime ) );
}
}
//----------------------------------------------------
function ParamTime( $ParName, $Value )
{
if( is_null($Value) || Trim($Value) == "" )
$this->AddToParamLists( $ParName, NULL );
else
{
if( strtoupper( $Value ) == "[NOW]")
$datetime = time();
elseif( is_integer($Value) )
$datetime = $Value;
else
$datetime = strtotime ($Value);
$this->AddToParamLists( $ParName, date ("H:i:s", $datetime ) );
}
}
//----------------------------------------------------
function ParamTimeStamp( $ParName, $Value )
{
if( is_null($Value) || Trim($Value) == "" )
$this->AddToParamLists( $ParName, NULL );
else
{
if( strtoupper( $Value ) == "[NOW]")
$datetime = time();
elseif( is_integer($Value) )
$datetime = $Value;
else
$datetime = strtotime ($Value);
$this->AddToParamLists( $ParName, date ("Y-m-d H:i:s", $datetime ) );
}
}
//----------------------------------------------------
function ParamBool( $ParName, $Value )
{
if( $Value === True || $Value === False )
$this->AddToParamLists( $ParName, $Value );
else
{
$Value = strtoupper( $Value );
if( strpos( "|1|JA|YES|TRUE|SANT|", "|$Value|" ) !== False )
$this->AddToParamLists( $ParName, TRUE );
else
if( strpos( "|0|NEJ|NO|FALSE|FALSKT|", "|$Value|" ) !== False )
$this->AddToParamLists( $ParName, FALSE );
else
$this->AddToParamLists( $ParName, NULL );
}
}
//----------------------------------------------------
function ParamBLOB( $ParName, $Value )
{
if( ! is_a ( $this->IBQuery, "TIBQuery" ) )
trigger_error ("IBQuery variable not set or is not of the right type.", E_USER_ERROR);
if( is_null($Value) || Trim($Value)=="" )
$this->AddToParamLists( $ParName, NULL );
else
$this->AddToParamLists( $ParName, $this->IBQuery->BlobFromString( $Value ) );
}
//----------------------------------------------------
function ParamBLOBFromFile( $ParName, $Value )
{
if( ! is_a ( $this->IBQuery, "TIBQuery" ) )
trigger_error ("IBQuery variable not set or is not of the right type.", E_USER_ERROR);
if( is_null($Value) || Trim($Value)=="" )
$this->AddToParamLists( $ParName, NULL );
else
$this->AddToParamLists( $ParName, $this->IBQuery->BlobFromFile( $Value ) );
}
}
?>