Index: trunk/core/units/categories/categories_item.php =================================================================== diff -u -r6093 -r7391 --- trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 6093) +++ trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 7391) @@ -4,17 +4,19 @@ { function Create($force_id=false, $system_create=false) { + $this->checkFilename(); + $this->generateFilename(); + if (!$this->Validate()) return false; - + $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') ); + $this->SetDBField('CreatedById', $this->Application->RecallVar('user_id') ); $this->SetDBField('CreatedOn_date', adodb_mktime() ); $this->SetDBField('CreatedOn_time', adodb_mktime() ); - - $this->checkFilename(); - $this->generateFilename(); - $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') ); + $parent_category = $this->GetDBField('ParentId') > 0 ? $this->GetDBField('ParentId') : $this->Application->GetVar('m_cat_id'); + $this->SetDBField('ParentId', $parent_category); + $ret = parent::Create($force_id, $system_create); if ($ret) { $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s'; @@ -31,15 +33,15 @@ { $this->checkFilename(); $this->generateFilename(); - + $ret = parent::Update($id, $system_update); return $ret; } - + function buildParentPath() { $parent_id = $this->GetDBField('ParentId'); - + if ($parent_id == 0) { $parent_path = '|'; } @@ -48,7 +50,7 @@ $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s'; $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) ); } - + return $parent_path.$this->GetID().'|'; } @@ -138,7 +140,7 @@ if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name); } - + /** * Allows to detect if root category being edited * @@ -147,26 +149,26 @@ function IsRoot() { $category_id = $this->Application->GetVar($this->getPrefixSpecial().'_id'); - if (is_numeric($category_id) && $category_id == 0) { + if (is_numeric($category_id) && $category_id == 0 && !$this->Application->GetVar($this->getPrefixSpecial().'_PreCreate')) { $sql = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$category_id; if ($this->Conn->GetOne($sql) === false) { return true; } } - + return false; } - + /** * Sets correct name to Home category while editing it * * @return bool */ function IsNewItem() { - if ($this->IsRoot()) { + if ($this->IsRoot() && $this->Prefix == 'c') { $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField'); $category_name = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') ); $this->SetDBField($title_field, $category_name);