Index: branches/5.0.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -r12466 -r12472 --- branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12466) +++ branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12472) @@ -1,6 +1,6 @@ Application->getUnitOption($event->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); if ($clipboard_data['cut']) { $sql = 'SELECT ParentId - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + FROM ' . $table_name . ' WHERE ' . $id_field . ' = ' . $clipboard_data['cut'][0]; $source_category_id = $this->Conn->GetOne($sql); } @@ -1077,7 +1078,18 @@ } if ($clipboard_data['copy']) { - foreach ($clipboard_data['copy'] as $id) { + // don't allow to copy/paste system OR theme-linked virtual pages + + $sql = 'SELECT ' . $id_field . ' + FROM ' . $table_name . ' + WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (IsSystem = 0) AND (ThemeId = 0)'; + $allowed_ids = $this->Conn->GetCol($sql); + + if (!$allowed_ids) { + return ; + } + + foreach ($allowed_ids as $id) { $recursive_helper->PasteCategory($id, $event->Prefix); } } @@ -1191,11 +1203,13 @@ $object->SetDBField('Status', $new_status); - /* - if (!$this->Application->IsAdmin()) { + // don't forget to set Priority for suggested from Front-End categories + $min_priority = $this->_getNextPriority($object->GetDBField('ParentId'), $object->TableName); + $object->SetDBField('Priority', $min_priority); + + /*if (!$this->Application->IsAdmin()) { $object->SetDBField('IsMenu', 0); // add all suggested categories as non-menu - } - */ + }*/ } else { $event->status = erPERM_FAIL; @@ -1204,6 +1218,21 @@ } /** + * Returns next available priority for given category from given table + * + * @param int $category_id + * @param string $table_name + * @return int + */ + function _getNextPriority($category_id, $table_name) + { + $sql = 'SELECT MIN(Priority) + FROM ' . $table_name . ' + WHERE ParentId = ' . $category_id; + return (int)$this->Conn->GetOne($sql) - 1; + } + + /** * Sets correct status for new categories created on front-end * * @param kEvent $event @@ -1562,30 +1591,17 @@ $design_template = $this->_getDefaultDesign(); // leading "/" added ! } - // put all templates to then end of list (in their category) - $sql = 'SELECT MIN(Priority) - FROM ' . $object->TableName . ' - WHERE ParentId = ' . $page_category; - $min_priority = (int)$this->Conn->GetOne($sql); - $object->Clear(); $object->SetDBField('ParentId', $page_category); $object->SetDBField('IsSystem', $system); + $object->SetDBField('IsMenu', 0); + $object->SetDBField('ThemeId', $theme_id); // $system ? $theme_id : 0 - // system templates don't build their NamedParentPath based on their location because they are all added under - // "Content" when theme file structure is rebuilded and for ex. file "in-edit/designs/general" will have filename - // (after stripDisallowed) like "in_edit_designs_general" witch is less readable like "in-edit/designs/general" - // as for now. + // put all templates to then end of list (in their category) + $min_priority = $this->_getNextPriority($page_category, $object->TableName); + $object->SetDBField('Priority', $min_priority); - // TODO: 1. make system template NamedParentPath dependent on their location in structure. - // 2. load cms-page not only by NamedParentPath, but also by 'OR (Template = "$template" AND IsSystem = 1)' - // This way we can store CMS-blocks based on system template name on HDD no matter where it's location is - // and we can address him from template using his system path OR structure path (CMS-blocks should work too). - - $object->SetDBField('IsMenu', 0); - $object->SetDBField('ThemeId', $system ? $theme_id : 0); - $object->SetDBField('Priority', $min_priority - 1); $object->SetDBField('Template', $design_template); $object->SetDBField('CachedTemplate', $design_template);