Index: branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php =================================================================== diff -u -r5820 -r5858 --- branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5820) +++ branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5858) @@ -29,7 +29,7 @@ $this->SetDBField('ResourceId', $this->Application->NextResourceId()); $this->SetDBField('Modified', adodb_mktime() ); - if ($this->mode != 't') { + if ($this->mode != 't' && !$this->Application->IsAdmin()) { $this->SetDBField('CreatedById', $this->Application->GetVar('u_id')); } @@ -39,18 +39,15 @@ } $ret = parent::Create(); - if($ret) - { - if ( $this->Application->IsTempTable($this->TableName) ) { - $table = $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems'); - } - else { - $table = TABLE_PREFIX.'CategoryItems'; - } - $cat_id = $this->Application->GetVar('m_cat_id'); - $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat,ItemPrefix,Filename) - VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1,'.$this->Conn->qstr($this->Prefix).','.$this->Conn->qstr($this->GetDBField('Filename')).')'; - $this->Conn->Query($query); + if ($ret) { + $fields_hash = Array( + 'CategoryId' => $this->Application->GetVar('m_cat_id'), + 'ItemResourceId' => $this->GetField('ResourceId'), + 'PrimaryCat' => 1, + 'ItemPrefix' => $this->Prefix, + 'Filename' => $this->GetDBField('Filename'), + ); + $this->Conn->doInsert($fields_hash, $this->CategoryItemsTable()); } return $ret; } @@ -69,15 +66,33 @@ $ret = parent::Update($id, $system_update); if ($ret) { - $table = $this->Application->IsTempTable($this->TableName) ? $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems') : TABLE_PREFIX.'CategoryItems'; $filename = $this->useFilenames ? $this->GetDBField('Filename') : ''; - $this->Conn->Query('UPDATE '.$table.' SET Filename = '.$this->Conn->qstr($filename).' WHERE ItemResourceId = '.$this->GetDBField('ResourceId')); + $sql = 'UPDATE '.$this->CategoryItemsTable().' + SET Filename = '.$this->Conn->qstr($filename).' + WHERE ItemResourceId = '.$this->GetDBField('ResourceId'); + $this->Conn->Query($sql); } unset($this->VirtualFields['ResourceId']); return $ret; } + /** + * Returns CategoryItems table based on current item mode (temp/live) + * + * @return string + */ + function CategoryItemsTable() + { + $table = TABLE_PREFIX.'CategoryItems'; + if ($this->Application->IsTempTable($this->TableName)) { + $table = $this->Application->GetTempName($table); + } + + return $table; + } + + function checkFilename() { if( !$this->GetDBField('AutomaticFilename') ) @@ -147,7 +162,7 @@ } // We need to delete CategoryItems record when deleting product - function Delete($id=null) + function Delete($id = null) { if( isset($id) ) { $this->setID($id); @@ -156,7 +171,8 @@ $ret = parent::Delete(); if ($ret) { - $query = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$this->GetDBField('ResourceId'); + $query = ' DELETE FROM '.$this->CategoryItemsTable().' + WHERE ItemResourceId = '.$this->GetDBField('ResourceId'); $this->Conn->Query($query); }