Index: branches/5.3.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r16519 -r16600 --- branches/5.3.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 16519) +++ branches/5.3.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 16600) @@ -1,6 +1,6 @@ Application->GetVar('admin') ) { + // User can't edit anything. + kUtil::safeDefine('EDITING_MODE', ''); + + return; + } + + /** @var Session $admin_session */ + $admin_session = $this->Application->recallObject('Session.admin'); + + // Store Admin Console User's ID to Front-End's session for cross-session permission checks. + $this->Application->StoreVar('admin_user_id', (int)$admin_session->RecallVar('user_id')); + + $base_category = $this->Application->getBaseCategory(); + + if ( $this->Application->CheckAdminPermission('CATEGORY.MODIFY', 0, $base_category) ) { + // User can edit cms blocks (when viewing front-end through admin's frame). + $editing_mode = $this->Application->GetVar('editing_mode'); + define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_BROWSE); + } + + // User can't edit anything. + kUtil::safeDefine('EDITING_MODE', ''); + } + + /** * Set's mark, that root category is edited * * @param kEvent $event @@ -1350,6 +1384,41 @@ } /** + * Validates category data. + * + * @param kEvent $event Event. + * + * @return void + */ + protected function OnBeforeItemValidate(kEvent $event) + { + parent::OnBeforeItemValidate($event); + + /** @var kDBItem $object */ + $object = $event->getObject(); + + $friendly_url = $object->GetDBField('FriendlyURL'); + + if ( strlen($friendly_url) && $friendly_url != $object->GetOriginalField('FriendlyURL') ) { + $sql = 'SELECT CategoryId + FROM %s + WHERE NamedParentPath = ' . $this->Conn->qstr('Content/' . $friendly_url); + $duplicate_id = $this->Conn->GetOne(sprintf($sql, $object->TableName)); + + if ( $duplicate_id === false && $object->IsTempTable() ) { + $duplicate_id = $this->Conn->GetOne(sprintf( + $sql, + $this->Application->GetLiveName($object->TableName) + )); + } + + if ( $duplicate_id !== false ) { + $object->SetError('FriendlyURL', 'unique'); + } + } + } + + /** * Sets correct status for new categories created on front-end * * @param kEvent $event @@ -1863,8 +1932,20 @@ $object->setRequired('PageCacheKey', $object->GetDBField('OverridePageCacheKey')); $object->SetDBField('Template', $this->_stripTemplateExtension( $object->GetDBField('Template') )); - if ($object->GetDBField('Type') == PAGE_TYPE_TEMPLATE) { - if (!$this->_templateFound($object->GetDBField('Template'), $object->GetDBField('ThemeId'))) { + $category_type = $object->GetDBField('Type'); + + // Changing category type would associate/disassociate it to theme. + if ( $category_type != $object->GetOriginalField('Type') ) { + if ( $category_type == PAGE_TYPE_TEMPLATE ) { + $object->SetDBField('ThemeId', $this->_getCurrentThemeId()); + } + else { + $object->SetDBField('ThemeId', 0); + } + } + + if ( $category_type == PAGE_TYPE_TEMPLATE ) { + if ( !$this->_templateFound($object->GetDBField('Template'), $object->GetDBField('ThemeId')) ) { $object->SetError('Template', 'template_file_missing', 'la_error_TemplateFileMissing'); } }