init($dbconn);
}
/**
* initialize the standard variables
*
* @param Object a database connection
*/
function init(&$dbconn) {
global $current_user,$tutos;
$this->id = -1;
$this->dbconn = &$dbconn;
$this->creator = $current_user;
$this->creation = new DateTime();
$this->acl = array();
$this->modified = array();
$this->history = array();
$this->neighbours = array();
$this->tablename = "UNKNOWN";
$this->tablename_hash = "objectids";
if (isset($current_user->id)) {
$this->acl[$current_user->id] = $tutos[modok];
}
#
# initialize custom database fields
#
$this->init_custom($this->gettype());
}
/**
* initialize custom database fields
*/
function init_custom ($sector) {
global $table;
if (!isset($table[$sector])) {
return;
}
foreach($table[$sector] as $i => $x) {
if (!is_array($x)) continue;
if (!isset($x['custom'])) continue;
if (!$x['custom']) continue;
$fld = "_fld_".$i;
if ($x[type] == "float") {
$this->$fld = 0.0;
} else if ($x[type] == "TS_TYPE") {
$this->$fld = new DateTime();
} else {
$this->$fld = "";
}
}
}
/**
* read the data of the specified object
*
* @param int $id the object id
*/
function read ($id,&$obj) {
global $g_hash,$tutos;
//print("GS --> base read id=".$id." t=".$tablename);
if ( empty($id) ) return -1;
if ( -1 == $id ) return -1;
//if ( ! is_numeric($id) ) return -1;
if ( $obj->tablename == "UNKNOWN" ) return -1;
/* commented by srini
if ( !isset($tutos['nohash']) && isset($g_hash[$id]) ) {
# Hashed
#$this = $g_hash[$id];
# if ($this->id != $id) {
# PHP 5
#die ("CACHE failed for ".$id ."(". $g_hash[$id]->getFullName() .") got ". $obj->id ." ". $obj->gettype() ."
\n");
# PHP_ERROR("8888",$_SERVER["REQUEST_URI"] ." > CACHE failed for ".$id ."(". $g_hash[$id]->getFullName() .") got ". $obj->id ." ". $obj->gettype() .":\n",3,$tutos[errlog],"see","backtrace");
# echo $id ." ". $g_hash[$id]->getFullName() ." ###
";
# } else {
$g_hash['hits']++;
$obj = &$g_hash[$id];
return $obj;
# }
}
if (!isset($obj->dbconn)) {
return -1;
}
*/
$q = "SELECT * from ". $obj->tablename ." WHERE id = '". $id . "'";
//print("GS --> base q=".$q);
/*$r = $obj->dbconn->Exec($q);
$n = $r->numrows();*/
$r = $obj->db->query($q);
$n = $obj->db->getRowCount($r);
//print("GS --> base n=".$n);
if ( 1 != $n) {
return -1;
}
$val_array = mysql_fetch_assoc($r);
$obj->read_result($val_array);
//$r->free();
return $obj;
}
/**
* read the custom fields of a resultset
*/
function read_custom_result (&$r,$pos,$sector ) {
global $table;
if (!isset($table[$sector])) {
return;
}
foreach($table[$sector] as $i => $x) {
if (!is_array($x)) continue;
if (!isset($x['custom'])) continue;
if (!$x['custom']) continue;
$fld = "_fld_".$i;
if ($x[type] == "TS_TYPE") {
$this->$fld = $r->getDateTime($pos, $i);
} else {
$this->$fld = @$r->get($pos,$i);
}
if (!isset($this->$fld)) $this->$fld ="";
}
}
/**
* read a resultset
*/
/*function read_result (&$r, $pos ) {
global $g_hash;
#$this->id = $r->get($pos, "id");
#$this->creation = $r->getDateTime($pos, "creation");
#
# read custom database fields
#
#$this->read_custom_result($r,$pos,$this->gettype());
# we have a real object so we reset the acl
$this->acl = array();
#acl_read($this);
$g_hash[$this->id] = &$this;
return;
}*/
// srini
function read_result($val_array, $pos=-1)
{
if($pos!=-1) return;
global $g_hash;
$this->id = $val_array["id"];
$this->creation = new DateTime($val_array["date_entered"]);
#
# read custom database fields
#
#$this->read_custom_result($r,$pos,$this->gettype());
# we have a real object so we reset the acl
$this->acl = array();
#acl_read($this);
$g_hash[$this->id] = &$this;
return;
}
/**
* Return Info about history of this object
*/
function readHistory($adr_id,$sort,$dir,$start) {
if ( count($this->history) > 0 ) {
return;
}
readHistory($this,$adr_id,$sort,$dir,$start);
return;
}
/**
* Return Info about connected tasks of this object
*/
function readTasks() {
if ( ! class_exists ("task") ) {
require_once 'task.pinc';
}
task::obj_read($this);
return;
}
/**
* Return Info about the total time spent for this object
*/
function readTimetrackSum() {
if ( ! class_exists ("timetrack") ) {
require_once 'timetrack.pinc';
}
readTimetrackSum($this);
return;
}
/**
* Return Info about time spent for this object
*/
function readTimetrack() {
if ( ! class_exists ("timetrack") ) {
require_once 'timetrack.pinc';
}
timetrack::obj_read($this);
return;
}
/**
* parse XML import
*/
function parseXML ($fld,$data,$attrs) {
global $tutos;
if ( $fld == "systemid" ) {
$this->force_insert = ($data != $this->dbconn->db->systemid);
}
if ($fld == "id") {
if ($this->force_insert) {
$this->id = -1;
} else {
$tutos['nohash'] =1 ;
$xx = $this->read($data,$this);
unset($tutos['nohash']);
# echo "X:".$xx->id." ".$this->id." ". $data ."\n";
if ( ($this->id != $data) ) {
if ($tutos[debug] != 0) {
Fatal_Error($this->gettype() ." with id ". $data. " does not exist");
}
die ($this->gettype() ." with id ". $data. " does not exist");
}
}
}
if ($fld == "creation") {
$this->creation->setDateTime($data);
}
return;
}
/**
* Head of XML export
*/
function exportXML_head () {
global $tutos;
$r = "\n";
$r .= "\n";
$r .= "\n";
return $r;
}
/**
* Start of XML export
*/
function exportXML_start () {
return "<". $this->gettype() .">\n";
}
/**
* End of XML export
*/
function exportXML_end () {
return "". $this->gettype() .">\n";
}
/**
* Data of XML export
*/
function exportXML_body () {
global $current_user;
if (!$this->see_ok()) {
return;
}
$r = "
\n";
}
if ( $this->$fld != $value ) {
$this->modified[] = array ( "field" => $histfield , "old" => $this->$fld , "new" => $value );
$this->$fld = $value;
return true;
}
return false;
}
/**
* set a field for this object and maintain the change history
*
* @param String $fld the fieldname to change
* @param int $value the new value for $fld
* @param String $histfield the label of the field in the history table
*/
function setIntField ($fld,$value,$histfield) {
if ( $this->$fld != $value ) {
$this->modified[] = array ( "field" => $histfield , "old" => $this->$fld , "new" => $value );
$this->$fld = (int)$value;
return true;
}
return false;
}
/**
* set a field for this object and maintain the change history
*
* @param String $fld the fieldname to change
* @param float $value the new value for $fld
* @param String $histfield the label of the field in the history table
*/
function setFloatField ($fld,$value,$histfield) {
if ( $this->$fld != $value ) {
$this->modified[] = array ( "field" => $histfield , "old" => $this->$fld , "new" => $value );
$this->$fld = (float)$value;
return true;
}
return false;
}
/**
* set a Date field for this object and maintain the change history
*
* @param String $fld the fieldname to change
* @param Object $value the new value for $fld
* @param String $histfield the label of the field in the history table
*/
function setDateField ($fld,&$value,$histfield) {
if ( isset($this->$fld) ) {
$a = $this->$fld->getYYYYMMDD();
} else {
$a = "";
}
$b = $value->getYYYYMMDD();
if ( $a != $b ) {
$this->modified[] = array ( "field" => $histfield , "old" => $a , "new" => $b );
$this->$fld = $value;
return true;
}
return false;
}
/**
* set a DateTime field for this object and maintain the change history
*
* @param String $fld the fieldname to change
* @param Object $value the new value for $fld
* @param String $histfield the label of the field in the history table
*/
function setDateTimeField ($fld,&$value,$histfield) {
if ( isset($this->$fld) ) {
$a = $this->$fld->getYYYYMMDDHHMM();
} else {
$a = "";
}
$b = $value->getYYYYMMDDHHMM();
if ( $a != $b ) {
$this->modified[] = array ( "field" => $histfield , "old" => $a , "new" => $b );
$this->$fld = $value;
return true;
}
return false;
}
/**
* fill mailing list with address/team objects or mail addresses
*/
function fill_maillist(&$ml) {
return;
}
/**
* get a usefull human readable name
*/
function getFullName () {
return $this->getType()." (". $this->id .")";
}
function getShortName () {
return $this->getFullName();
}
/**
* get the info as text
*/
function getAsText (&$lang) {
# defaults to fullname
$r = "";
$r .= $this->getFullName() ."\n";
return $r;
}
/**
* get a url to this object
*/
function getURL () {
return "mytutos.php";
}
/**
* get a url to the modify page of this object
*/
function getModURL () {
return "mytutos.php";
}
/**
* get a url to the delete script of this object
*/
function getDelURL () {
return "mytutos.php";
}
/**
* get a link to this object
*/
function getLink ($text = "") {
if ( empty($text) ) {
$text = $this->getFullname();
}
return makelink($this->getURL(),myentities($text),sprintf("%s",$this->getFullname()));
}
/**
* get a ulink to the objects history
*/
function getHistoryLink ($cols) {
global $current_user,$lang;
$ret = "";
if ( $current_user->feature_ok(usehistory,PERM_SEE) ) {
$ret .= "