Index: trunk/kernel/include/itemdb.php =================================================================== diff -u -N -r3576 -r3907 --- trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 3576) +++ trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 3907) @@ -4,24 +4,44 @@ class clsItemDB { - var $Formatters = Array(); // by Alex - var $m_dirtyFieldsMap = array(); - var $Data = array(); - var $adodbConnection; - var $tablename; - var $BasePermission; - var $id_field; - var $NoResourceId; - var $debuglevel; - - var $SelectSQL = 'SELECT * FROM %s WHERE %s'; + var $Formatters = Array(); // by Alex + var $m_dirtyFieldsMap = array(); + var $Data = array(); + var $adodbConnection; + var $tablename; + var $BasePermission; + var $id_field; + var $NoResourceId; + var $debuglevel; + + var $SelectSQL = 'SELECT * FROM %s WHERE %s'; + /** + * Application object + * + * @var kApplication + */ + var $Application = null; + + /** + * Connection to database + * + * @var kDBConnection + */ + var $Conn = null; + function clsItemDB() { - $this->adodbConnection = &GetADODBConnection(); - $this->tablename=""; - $this->NoResourceId=0; - $this->debuglevel=0; + if (class_exists('kApplication')) { + // just in case when aplication is not found + $this->Application =& kApplication::Instance(); + $this->Conn =& $this->Application->GetADODBConnection(); + } + + $this->adodbConnection = &GetADODBConnection(); + $this->tablename=""; + $this->NoResourceId=0; + $this->debuglevel=0; } // ============================================================================================ @@ -292,6 +312,8 @@ { global $Errors, $objSession; + if( !$this->raiseEvent('OnBeforeItemUpdate') ) return false; + if( count($this->m_dirtyFieldsMap) == 0 ) return true; $this->SetModified($UpdatedBy, $modificationDate); @@ -324,6 +346,9 @@ } if( $objSession->GetVariable('HasChanges') == 2 ) $objSession->SetVariable('HasChanges', 1); + + $this->raiseEvent('OnAfterItemUpdate'); + return true; } @@ -416,7 +441,9 @@ function Create() { global $Errors, $objSession; - + + if( !$this->raiseEvent('OnBeforeItemCreate') ) return false; + if($this->debuglevel) echo "Creating Item: ".get_class($this)."
"; if($this->NoResourceId!=1 && (int)$this->Get("ResourceId")==0) { @@ -443,6 +470,8 @@ $objSession->SetVariable("HasChanges", 1); } */ + $this->raiseEvent('OnAfterItemCreate'); + return true; } @@ -634,7 +663,22 @@ $rs = $db->Execute( sprintf($sql, strtolower($table) ) ); return ($rs->RecordCount() == 1) ? 1 : 0; - } + } + + function raiseEvent($name, $id = null) + { + return true; + + /*if (!getArrayValue($GLOBALS, '_CopyFromEditTable')) { + return true; + } + + if( !isset($id) ) $id = $this->GetID(); + $event = new kEvent( Array('name'=>$name,'prefix'=>$this->Prefix,'special'=>$this->Special) ); + $event->setEventParam('id', $id); + $this->Application->HandleEvent($event); + return $event->status == erSUCCESS ? true : false;*/ + } } ?>