| 911 |
*/ |
*/ |
| 912 |
|
|
| 913 |
class mosDBTableEntry { |
class mosDBTableEntry { |
|
/** @var int ID for file record in database */ |
|
|
var $id = 0; |
|
|
var $database = ''; |
|
| 914 |
|
|
| 915 |
function mosDBTableEntry () { |
function mosDBTableEntry () { |
| 916 |
die ('Cannot instantiate mosDBTableEntry'); |
die ('Cannot instantiate mosDBTableEntry'); |
| 917 |
} |
} |
| 918 |
|
|
|
function getDatabase () { |
|
|
if (!is_object($this->database)) $this->database =& mamboDatabase::getInstance(); |
|
|
return $this->database; |
|
|
} |
|
|
|
|
| 919 |
/* Stores all POST data where the name matches an object variable name */ |
/* Stores all POST data where the name matches an object variable name */ |
| 920 |
function addPostData () { |
function addPostData () { |
| 921 |
foreach (get_class_vars(get_class($this)) as $field=>$value) { |
foreach (get_class_vars(get_class($this)) as $field=>$value) { |
| 935 |
/* Updates an existing DB entry with the object's current values */ |
/* Updates an existing DB entry with the object's current values */ |
| 936 |
function updateObjectDB () { |
function updateObjectDB () { |
| 937 |
$this->prepareValues(); |
$this->prepareValues(); |
| 938 |
$database = $this->getDatabase(); |
$database = mamboDatabase::getInstance(); |
| 939 |
$database->doSQL($this->updateSQL()); |
$database->doSQL($this->updateSQL()); |
| 940 |
} |
} |
| 941 |
|
|
| 943 |
function delete () { |
function delete () { |
| 944 |
$table = $this->tableName(); |
$table = $this->tableName(); |
| 945 |
$sql = "DELETE FROM $table WHERE id=$this->id"; |
$sql = "DELETE FROM $table WHERE id=$this->id"; |
| 946 |
$database = $this->getDatabase(); |
$database = mamboDatabase::getInstance(); |
| 947 |
$database->doSQL($sql); |
$database->doSQL($sql); |
| 948 |
} |
} |
| 949 |
|
|
| 999 |
|
|
| 1000 |
/* Ensures values can safely be written to DB; assumes magic quotes forced off */ |
/* Ensures values can safely be written to DB; assumes magic quotes forced off */ |
| 1001 |
function prepareValues () { |
function prepareValues () { |
| 1002 |
$database = $this->getDatabase(); |
$database = mamboDatabase::getInstance(); |
| 1003 |
foreach (get_class_vars(get_class($this)) as $field=>$value) { |
foreach (get_class_vars(get_class($this)) as $field=>$value) { |
| 1004 |
if (!is_numeric($this->$field)) $this->$field = $database->getEscaped($this->$field); |
if (!is_numeric($this->$field) AND is_string($this->$field)) $this->$field = $database->getEscaped($this->$field); |
| 1005 |
} |
} |
| 1006 |
} |
} |
| 1007 |
|
|
| 1008 |
/* Takes some arbitrary SELECT type SQL and places the first or only result into the current object */ |
/* Takes some arbitrary SELECT type SQL and places the first or only result into the current object */ |
| 1009 |
function readDataBase($sql) { |
function readDataBase($sql) { |
| 1010 |
$database = $this->getDatabase(); |
$database = mamboDatabase::getInstance(); |
| 1011 |
$database->setQuery( $sql ); |
$database->setQuery( $sql ); |
| 1012 |
if (!$database->loadObject($this)) $this->id = 0; |
if (!$database->loadObject($this)) $this->id = 0; |
| 1013 |
} |
} |