Index: branches/RC/core/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r11721 -r11724 --- branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 11721) +++ branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 11724) @@ -150,10 +150,11 @@ } - if (isset($params['parent']) && $params['parent']) { + if (array_key_exists('parent', $params) && $params['parent']) { do { - $section_data =& $sections_helper->getSectionData($section_data['parent']); - } while (isset($section_data['use_parent_header']) && $section_data['use_parent_header']); + $section = $section_data['parent']; + $section_data =& $sections_helper->getSectionData($section); + } while (array_key_exists('use_parent_header', $section_data) && $section_data['use_parent_header']); } $info = $params['info']; @@ -171,17 +172,27 @@ $res = $this->ModulePath(array('module' => $module)); break; - case 'perm_section': - $res = $sections_helper->getPermSection($section); + case 'perm_section': + $res = $sections_helper->getPermSection($section); break; + case 'label': + $res = $section_data['label']; + if ($section != 'in-portal:root') { + // don't translate label for top section, because it's already translated + $res = $this->Application->Phrase($res); + } + break; + default: $res = $section_data[$info]; + break; } - if ($info == 'label' || isset($params['as_label'])) { + if (array_key_exists('as_label', $params) && $params['as_label']) { $res = $this->Application->Phrase($res); } + return $res; } Index: branches/RC/core/admin_templates/catalog/advanced_view.tpl =================================================================== diff -u -N -r11705 -r11724 --- branches/RC/core/admin_templates/catalog/advanced_view.tpl (.../advanced_view.tpl) (revision 11705) +++ branches/RC/core/admin_templates/catalog/advanced_view.tpl (.../advanced_view.tpl) (revision 11724) @@ -79,8 +79,7 @@ a_toolbar.Render(); - function edit() - { + function edit() { $form_name = $Catalog.queryTabRegistry('prefix', $Catalog.ActivePrefix, 'tab_id') + '_form'; var $kf = document.getElementById($form_name); @@ -95,6 +94,22 @@ } ); } + + function add_item() { + $form_name = $Catalog.queryTabRegistry('prefix', $Catalog.ActivePrefix, 'tab_id') + '_form'; + var $kf = document.getElementById($form_name); + + var $prev_action = $kf.action; + $kf.action = ''; + + set_hidden_field('remove_specials[' + $Catalog.ActivePrefix + ']', 1); + std_precreate_item( + $Catalog.ActivePrefix, $Catalog.queryTabRegistry('prefix', $Catalog.ActivePrefix, 'edit_template'), + function() { + $kf.action = $prev_action; + } + ); + } Index: branches/RC/core/units/general/helpers/category_helper.php =================================================================== diff -u -N -r11640 -r11724 --- branches/RC/core/units/general/helpers/category_helper.php (.../category_helper.php) (revision 11640) +++ branches/RC/core/units/general/helpers/category_helper.php (.../category_helper.php) (revision 11724) @@ -2,6 +2,19 @@ class CategoryHelper extends kHelper { + /** + * Structure tree for ParentId field in category or category items + * + * @var Array + */ + var $_structureTree = null; + + /** + * Prints category path using given blocks. Also supports used defined path elements at the end. + * + * @param Array $params + * @return string + */ function NavigationBar($params) { $main_category_id = isset($params['cat_id']) ? $params['cat_id'] : $this->Application->GetVar('m_cat_id'); @@ -86,6 +99,13 @@ return $ret; } + /** + * Renders path to given category using given blocks. + * + * @param int $main_category_id + * @param Array $params + * @return string + */ function getCategoryPath($main_category_id, $params) { $category_path = $this->getCategoryParentPath($main_category_id); @@ -162,6 +182,13 @@ return $module_info; } + /** + * Renders path to top catalog category + * + * @param Array $params + * @param int $current_category + * @return string + */ function getHomeCategoryPath($params, $current_category) { $block_params['cat_id'] = $this->Application->findModule('Name', 'Core', 'RootCat'); // 0; @@ -173,6 +200,11 @@ return $this->Application->ParseBlock($block_params); } + /** + * Returns root categories from all modules + * + * @return Array + */ function getModuleRootCategories() { static $root_categories = null; @@ -189,6 +221,12 @@ return $root_categories; } + /** + * Returns given category's parent path as array of id=>name elements + * + * @param int $main_category_id + * @return Array + */ function getCategoryParentPath($main_category_id) { static $cached_path = null; @@ -248,6 +286,143 @@ } return false; } + + /** + * Converts multi-dimensional category structure in one-dimensional option array (category_id=>category_name) + * + * @param Array $data + * @param int $parent_category_id + * @param int_type $language_id + * @param int $theme_id + * @param int $level + * @return Array + */ + function _printChildren(&$data, $parent_category_id, $language_id, $theme_id, $level = 0) + { + if ($data['ThemeId'] != $theme_id && $data['ThemeId'] != 0) { + // don't show system templates from different themes + return Array (); + } + + $ret = Array($parent_category_id => str_repeat('-', $level).' '.$data['l'.$language_id.'_Name']); + + if ($data['children']) { + $level++; + foreach ($data['children'] as $category_id => $category_data) { + $ret = array_merge_recursive2($ret, $this->_printChildren($data['children'][$category_id], $category_id, $language_id, $theme_id, $level)); + } + } + + return $ret; + } + + /** + * Returns information about children under parent path (recursive) + * + * @param int $parent_category_id + * @param int $language_count + * @return Array + */ + function _getChildren($parent_category_id, $language_count) + { + $id_field = $this->Application->getUnitOption('c', 'IDField'); + + // get category children + parent category + $sql = 'SELECT * + FROM '.$this->Application->getUnitOption('c', 'TableName').' + WHERE ParentId = '.$parent_category_id.' OR '.$id_field.' = '.$parent_category_id.' + ORDER BY Priority DESC'; + $categories = $this->Conn->Query($sql, $id_field); + + $parent_data = $categories[$parent_category_id]; + unset($categories[$parent_category_id]); + + // no children for this category + $data = Array ('id' => $parent_data[$id_field], 'children' => false, 'ThemeId' => $parent_data['ThemeId']); + for ($i = 1; $i <= $language_count; $i++) { + $data['l'.$i.'_Name'] = $parent_data['l'.$i.'_Name']; + } + + if (!$categories) { + // no children + return $data; + } + + // category has children + foreach ($categories as $category_id => $category_data) { + $data['children'][$category_id] = $this->_getChildren($category_id, $language_count); + } + + return $data; + } + + /** + * Generates OR retrieves from cache structure tree + * + * @return Array + */ + function &_getStructureTree() + { + // get cached version of structure tree + $sql = 'SELECT Data + FROM ' . TABLE_PREFIX . 'Cache + WHERE VarName = "StructureTree"'; + $data = $this->Conn->GetOne($sql); + + if ($data) { + $data = unserialize($data); + + return $data; + } + + // generate structure tree from scratch + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $language_count = $ml_helper->getLanguageCount(); + + $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $data = $this->_getChildren($root_category, $language_count); + + $fields_hash = Array ( + 'VarName' => 'StructureTree', + 'Data' => serialize($data), + 'Cached' => adodb_mktime(), + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'Cache', 'REPLACE'); + + return $data; + } + + /** + * Returns category structure as field option list + * + * @return Array + */ + function getStructureTreeAsOptions() + { + if (defined('IS_INSTALL') && IS_INSTALL) { + // no need to create category structure during install, because it's not used there + return Array (); + } + + if (isset($this->_structureTree)) { + return $this->_structureTree; + } + + $themes_helper =& $this->Application->recallObject('ThemesHelper'); + /* @var $themes_helper kThemesHelper */ + + $data = $this->_getStructureTree(); + + $theme_id = (int)$themes_helper->getCurrentThemeId(); + $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + + $this->_structureTree = $this->_printChildren($data, $root_category, $this->Application->GetVar('m_lang'), $theme_id); + + return $this->_structureTree; + } } Index: branches/RC/core/admin_templates/categories/categories_edit_relations.tpl =================================================================== diff -u -N -r11623 -r11724 --- branches/RC/core/admin_templates/categories/categories_edit_relations.tpl (.../categories_edit_relations.tpl) (revision 11623) +++ branches/RC/core/admin_templates/categories/categories_edit_relations.tpl (.../categories_edit_relations.tpl) (revision 11724) @@ -1,7 +1,7 @@ - + Index: branches/RC/core/admin_templates/no_permission.tpl =================================================================== diff -u -N -r11623 -r11724 --- branches/RC/core/admin_templates/no_permission.tpl (.../no_permission.tpl) (revision 11623) +++ branches/RC/core/admin_templates/no_permission.tpl (.../no_permission.tpl) (revision 11724) @@ -1,29 +1,44 @@ - - + -
- Index: branches/RC/core/admin_templates/incs/form_blocks.tpl =================================================================== diff -u -N -r11711 -r11724 --- branches/RC/core/admin_templates/incs/form_blocks.tpl (.../form_blocks.tpl) (revision 11711) +++ branches/RC/core/admin_templates/incs/form_blocks.tpl (.../form_blocks.tpl) (revision 11724) @@ -1,4 +1,4 @@ - + @@ -13,10 +13,10 @@ - + @@ -27,7 +27,7 @@
-   +  
- + @@ -49,7 +49,7 @@ Index: branches/RC/core/admin_templates/incs/sections_list.css =================================================================== diff -u -N -r11004 -r11724 --- branches/RC/core/admin_templates/incs/sections_list.css (.../sections_list.css) (revision 11004) +++ branches/RC/core/admin_templates/incs/sections_list.css (.../sections_list.css) (revision 11724) @@ -117,4 +117,13 @@ .rTD { +} + +.dLink, .dLink:hover { + color: #2C73CB; + display: block; + font-family: Verdana; + font-size: 13px; + font-weight: bold; + margin-bottom: 5px; } \ No newline at end of file Index: branches/RC/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r11693 -r11724 --- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 11693) +++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 11724) @@ -13,13 +13,13 @@ { parent::mapPermissions(); $permissions = Array( - 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), - 'OnResetSettings' => Array('self' => 'add|edit|advanced:import'), - 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'), + 'OnSaveSettings' => Array ('self' => 'add|edit|advanced:import'), + 'OnResetSettings' => Array ('self' => 'add|edit|advanced:import'), + 'OnBeforeDeleteOriginal' => Array ('self' => 'edit|advanced:approve'), - 'OnDownloadFile' => Array('self' => 'view'), - 'OnCancelAction' => Array('self' => true), - 'OnItemBuild' => Array('self' => true), + 'OnDownloadFile' => Array ('self' => 'view'), + 'OnCancelAction' => Array ('self' => true), + 'OnItemBuild' => Array ('self' => true), 'OnMakeVote' => Array ('self' => true), ); @@ -68,43 +68,40 @@ $this->Application->LinkVar('m_cat_id'); } - $check_events = Array ('OnEdit', 'OnSave', 'OnMassDelete'); + $check_events = Array ( + 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove', + 'OnMassDecline', 'OnMassMoveUp', 'OnMassMoveDown' + ); if (in_array($event->Name, $check_events)) { - // check each id from selected individually and only if all are allowed proceed next - if ($event->Name == 'OnSave') { - $selected_ids = implode(',', $this->getSelectedIDs($event, true)); - if (!$selected_ids) { - $selected_ids = 0; // when saving newly created item (OnPreCreate -> OnPreSave -> OnSave) - } - } - else { - $selected_ids = implode(',', $this->StoreSelectedIDs($event)); - } + $items = $this->_getPermissionCheckInfo($event); - $perm_value = true; - if (strlen($selected_ids)) { - $perm_helper =& $this->Application->recallObject('PermissionsHelper'); - /* @var $perm_helper kPermissionsHelper */ + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ - $items = $perm_helper->GetCategoryItemData($event->Prefix, $selected_ids); + if (($event->Name == 'OnSave') && array_key_exists(0, $items)) { + // adding new item (ID = 0) + $perm_value = $perm_helper->AddCheckPermission($items[0]['CategoryId'], $event->Prefix) > 0; + } + else { + // leave only items, that can be edited + $ids = Array (); $check_method = ($event->Name == 'OnMassDelete') ? 'DeleteCheckPermission' : 'ModifyCheckPermission'; foreach ($items as $item_id => $item_data) { - if ($perm_helper->$check_method($item_data['CreatedById'], $item_data['CategoryId'], $event->Prefix) == 0) { - // one of items selected has no permission - $perm_value = false; - break; + if ($perm_helper->$check_method($item_data['CreatedById'], $item_data['CategoryId'], $event->Prefix) > 0) { + $ids[] = $item_id; } } - if (!$perm_value) { - $event->status = erPERM_FAIL; + if (!$ids) { + // no items left for editing -> no permission + return $perm_helper->finalizePermissionCheck($event, false); } + + $perm_value = true; + $event->setEventParam('ids', $ids); // will be used later by "kDBEventHandler::StoreSelectedIDs" method } - else { - trigger_error('IDs not passed to '.$event->getPrefixSpecial().':CheckPermission', E_USER_WARNING); - } - return $perm_value; + return $perm_helper->finalizePermissionCheck($event, $perm_value); } $export_events = Array ('OnSaveSettings', 'OnResetSettings', 'OnExportBegin'); @@ -124,6 +121,64 @@ } /** + * Returns category item IDs, that require permission checking + * + * @param kEvent $event + * @return string + */ + function _getPermissionCheckIDs(&$event) + { + if ($event->Name == 'OnSave') { + $selected_ids = implode(',', $this->getSelectedIDs($event, true)); + if (!$selected_ids) { + $selected_ids = 0; // when saving newly created item (OnPreCreate -> OnPreSave -> OnSave) + } + } + else { + // OnEdit, OnMassDelete events, when items are checked in grid + $selected_ids = implode(',', $this->StoreSelectedIDs($event)); + } + + return $selected_ids; + } + + /** + * Returns information used in permission checking + * + * @param kEvent $event + * @return Array + */ + function _getPermissionCheckInfo(&$event) + { + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + + // when saving data from temp table to live table check by data from temp table + $item_ids = $this->_getPermissionCheckIDs($event); + $items = $perm_helper->GetCategoryItemData($event->Prefix, $item_ids, $event->Name == 'OnSave'); + + if (!$items) { + // when item not present in temp table, then permission is not checked, because there are no data in db to check + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + list ($id, $fields_hash) = each($items_info); + + if (array_key_exists('CategoryId', $fields_hash)) { + $item_category = $fields_hash['CategoryId']; + } + else { + $item_category = $this->Application->GetVar('m_cat_id'); + } + + $items[$id] = Array ( + 'CreatedById' => $this->Application->RecallVar('use_id'), + 'CategoryId' => $item_category, + ); + } + + return $items; + } + + /** * Add selected items to clipboard with mode = COPY (CLONE) * * @param kEvent $event @@ -676,8 +731,7 @@ $object->addCalculatedField('CachedNavbar', 'l'.$this->Application->GetVar('m_lang').'_CachedNavbar'); - if ($event->Special == 'export' || $event->Special == 'import') - { + if ($event->Special == 'export' || $event->Special == 'import') { $export_helper =& $this->Application->recallObject('CatItemExportHelper'); $export_helper->prepareExportColumns($event); } @@ -750,26 +804,36 @@ } /** - * Enter description here... + * Moves item to preferred category, updates item hits * * @param kEvent $event */ function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + + // update hits field $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - if (!$property_map) { - return; + if ($property_map) { + $click_field = $property_map['ClickField']; + + $object =& $event->getObject(); + /* @var $object kCatDBItem */ + + if( $this->Application->IsAdmin() && ($this->Application->GetVar($click_field.'_original') !== false) && + floor($this->Application->GetVar($click_field.'_original')) != $object->GetDBField($click_field) ) + { + $sql = 'SELECT MAX('.$click_field.') FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + WHERE FLOOR('.$click_field.') = '.$object->GetDBField($click_field); + $hits = ( $res = $this->Conn->GetOne($sql) ) ? $res + 0.000001 : $object->GetDBField($click_field); + $object->SetDBField($click_field, $hits); + } } - $click_field = $property_map['ClickField']; - $object =& $event->getObject(); - if( $this->Application->IsAdmin() && ($this->Application->GetVar($click_field.'_original') !== false) && - floor($this->Application->GetVar($click_field.'_original')) != $object->GetDBField($click_field) ) - { - $sql = 'SELECT MAX('.$click_field.') FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - WHERE FLOOR('.$click_field.') = '.$object->GetDBField($click_field); - $hits = ( $res = $this->Conn->GetOne($sql) ) ? $res + 0.000001 : $object->GetDBField($click_field); - $object->SetDBField($click_field, $hits); + // change category + $target_category = $object->GetDBField('CategoryId'); + if ($object->GetOriginalField('CategoryId') != $target_category) { + $object->MoveToCat($target_category); } } @@ -2425,14 +2489,16 @@ { parent::OnAfterConfigRead($event); - if ($event->Prefix != 'cms') { - $file_helper =& $this->Application->recallObject('FileHelper'); - /* @var $file_helper FileHelper */ - - $file_helper->createItemFiles($event->Prefix, true); // create image fields - $file_helper->createItemFiles($event->Prefix, false); // create file fields + if (defined('IS_INSTALL') && IS_INSTALL) { + return ; } + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ + + $file_helper->createItemFiles($event->Prefix, true); // create image fields + $file_helper->createItemFiles($event->Prefix, false); // create file fields + // add EditorsPick to ForcedSorting if needed $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); if (array_key_exists('ForceEditorPick', $config_mapping) && $this->Application->ConfigValue($config_mapping['ForceEditorPick'])) { @@ -2459,6 +2525,17 @@ $grids[$process_grid . 'ShowAll'] = $grid_data; } $this->Application->setUnitOption($this->Prefix, 'Grids', $grids); + + // add options for CategoryId field (quick way to select item's primary category) + $category_helper =& $this->Application->recallObject('CategoryHelper'); + /* @var $category_helper CategoryHelper */ + + $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); + + $virtual_fields['CategoryId']['default'] = (int)$this->Application->GetVar('m_cat_id'); + $virtual_fields['CategoryId']['options'] = $category_helper->getStructureTreeAsOptions(); + + $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); } /** Index: branches/RC/core/admin_templates/catalog/catalog.tpl =================================================================== diff -u -N -r11711 -r11724 --- branches/RC/core/admin_templates/catalog/catalog.tpl (.../catalog.tpl) (revision 11711) +++ branches/RC/core/admin_templates/catalog/catalog.tpl (.../catalog.tpl) (revision 11724) @@ -266,6 +266,12 @@ $form_name = $Catalog.queryTabRegistry('prefix', $current_prefix, 'tab_id') + '_form'; std_edit_item($current_prefix, $Catalog.queryTabRegistry('prefix', $current_prefix, 'edit_template')); } + + function add_item() { + var $current_prefix = $Catalog.getCurrentPrefix(); + $form_name = $Catalog.queryTabRegistry('prefix', $current_prefix, 'tab_id') + '_form'; + std_precreate_item($current_prefix, $Catalog.queryTabRegistry('prefix', $current_prefix, 'edit_template')); + } Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r11693 -r11724 --- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11693) +++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11724) @@ -62,49 +62,40 @@ } } - if ($event->Name == 'OnEdit' || $event->Name == 'OnSave') { - // check each id from selected individually and only if all are allowed proceed next - if ($event->Name == 'OnEdit') { - $selected_ids = implode(',', $this->StoreSelectedIDs($event)); - } - else { - $selected_ids = implode(',', $this->getSelectedIDs($event, true)); - } + $check_events = Array ( + 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove', + 'OnMassDecline', 'OnMassMoveUp', 'OnMassMoveDown' + ); + if (in_array($event->Name, $check_events)) { + $items = $this->_getPermissionCheckInfo($event); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ - if (strlen($selected_ids) > 0) { - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $sql = 'SELECT '.$id_field.', CreatedById - FROM '.$table_name.' item_table - WHERE '.$id_field.' IN ('.$selected_ids.')'; - $items = $this->Conn->Query($sql, $id_field); + if (($event->Name == 'OnSave') && array_key_exists(0, $items)) { + // adding new item (ID = 0) + $perm_value = $perm_helper->AddCheckPermission($items[0]['ParentId'], $event->Prefix) > 0; } else { - // when creating new category, then no IDs are stored in session - $parent_cat = $this->Application->RecallVar('m_cat_id'); - $items[$parent_cat] = Array ( - $id_field => $parent_cat, - 'CreatedById' => $this->Application->RecallVar('user_id'), - ); - } - $perm_value = true; - $perm_helper =& $this->Application->recallObject('PermissionsHelper'); - /* @var $perm_helper kPermissionsHelper */ + // leave only items, that can be edited + $ids = Array (); + $check_method = ($event->Name == 'OnMassDelete') ? 'DeleteCheckPermission' : 'ModifyCheckPermission'; + foreach ($items as $item_id => $item_data) { + if ($perm_helper->$check_method($item_data['CreatedById'], $item_data['ParentId'], $event->Prefix) > 0) { + $ids[] = $item_id; + } + } - foreach ($items as $item_id => $item_data) { - if ($perm_helper->ModifyCheckPermission($item_data['CreatedById'], $item_data[$id_field], $event->Prefix) == 0) { - // one of items selected has no permission - $perm_value = false; - break; + if (!$ids) { + // no items left for editing -> no permission + return $perm_helper->finalizePermissionCheck($event, false); } - } - if (!$perm_value) { - $event->status = erPERM_FAIL; + $perm_value = true; + $event->setEventParam('ids', $ids); // will be used later by "kDBEventHandler::StoreSelectedIDs" method } - return $perm_value; + return $perm_helper->finalizePermissionCheck($event, $perm_value); } if ($event->Name == 'OnPasteClipboard') { @@ -117,6 +108,70 @@ } /** + * Returns category item IDs, that require permission checking + * + * @param kEvent $event + * @return string + */ + function _getPermissionCheckIDs(&$event) + { + if ($event->Name == 'OnSave') { + $selected_ids = implode(',', $this->getSelectedIDs($event, true)); + if (!$selected_ids) { + $selected_ids = 0; // when saving newly created item (OnPreCreate -> OnPreSave -> OnSave) + } + } + else { + // OnEdit, OnMassDelete events, when items are checked in grid + $selected_ids = implode(',', $this->StoreSelectedIDs($event)); + } + + return $selected_ids; + } + + /** + * Returns information used in permission checking + * + * @param kEvent $event + * @return Array + */ + function _getPermissionCheckInfo(&$event) + { + // when saving data from temp table to live table check by data from temp table + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + if ($event->Name == 'OnSave') { + $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $event->Prefix); + } + + $sql = 'SELECT ' . $id_field . ', CreatedById, ParentId + FROM ' . $table_name . ' + WHERE ' . $id_field . ' IN (' . $this->_getPermissionCheckIDs($event) . ')'; + $items = $this->Conn->Query($sql, $id_field); + + if (!$items) { + // when creating new category, then no IDs are stored in session + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + list ($id, $fields_hash) = each($items_info); + + if (array_key_exists('ParentId', $fields_hash)) { + $item_category = $fields_hash['ParentId']; + } + else { + $item_category = $this->Application->RecallVar('m_cat_id'); // saved in c:OnPreCreate event permission checking + } + + $items[$id] = Array ( + 'CreatedById' => $this->Application->RecallVar('user_id'), + 'ParentId' => $item_category, + ); + } + + return $items; + } + + /** * Set's mark, that root category is edited * * @param kEvent $event @@ -1536,30 +1591,13 @@ $this->Application->setUnitOption($event->Prefix, 'SectionAdjustments', $section_ajustments); // prepare structure dropdown - $sql = 'SELECT Data - FROM ' . TABLE_PREFIX . 'Cache - WHERE VarName = "StructureTree"'; - $data = $this->Conn->GetOne($sql); - if ($data) { - $data = unserialize($data); - } - else { - $data = $this->_getChildren($event, $root_category); + $category_helper =& $this->Application->recallObject('CategoryHelper'); + /* @var $category_helper CategoryHelper */ - $fields_hash = Array ( - 'VarName' => 'StructureTree', - 'Data' => serialize($data), - 'Cached' => adodb_mktime(), - ); - - $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'Cache', 'REPLACE'); - } - - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); - $theme_id = $this->_getCurrentThemeId(); + $fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id'); - $fields['ParentId']['options'] = $this->_printChildren($data, $root_category, $this->Application->GetVar('m_lang'), $theme_id); + $fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions(); // limit design list by theme $design_folders = Array ('tf.FilePath = "/designs"', 'tf.FilePath = "/platform/designs"'); @@ -1568,6 +1606,7 @@ } $design_folders = array_unique($design_folders); + $theme_id = $this->_getCurrentThemeId(); $design_sql = $fields['Template']['options_sql']; $design_sql = str_replace('(tf.FilePath = "/designs")', '(' . implode(' OR ', $design_folders) . ')' . ' AND (t.ThemeId = ' . $theme_id . ')', $design_sql); $fields['Template']['options_sql'] = $design_sql; @@ -1601,74 +1640,7 @@ $this->Application->setUnitOption($this->Prefix, 'Grids', $grids); } - function _printChildren(&$data, $parent_category_id, $language_id, $theme_id, $level = 0) - { - if ($data['ThemeId'] != $theme_id && $data['ThemeId'] != 0) { - // don't show system templates from different themes - return Array (); - } - - $ret = Array($parent_category_id => str_repeat('-', $level).' '.$data['l'.$language_id.'_Name']); - - if ($data['children']) { - $level++; - foreach ($data['children'] as $category_id => $category_data) { - $ret = array_merge_recursive2($ret, $this->_printChildren($data['children'][$category_id], $category_id, $language_id, $theme_id, $level)); - } - } - - return $ret; - } - /** - * Returns information about children under parent path (recursive) - * - * @param kEvent $event - * @param int $parent_category_id - * @param int $language_count - */ - function _getChildren(&$event, $parent_category_id) - { - static $language_count = null; - if (!isset($language_count)) { - $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); - /* @var $ml_helper kMultiLanguageHelper */ - - $language_count = $ml_helper->getLanguageCount(); - } - - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - - // get category children + parent category - $sql = 'SELECT * - FROM '.$table_name.' - WHERE ParentId = '.$parent_category_id.' OR '.$id_field.' = '.$parent_category_id.' - ORDER BY Priority DESC'; - $categories = $this->Conn->Query($sql, $id_field); - - $parent_data = $categories[$parent_category_id]; - unset($categories[$parent_category_id]); - - // no children for this category - $data = Array ('id' => $parent_data[$id_field], 'children' => false, 'ThemeId' => $parent_data['ThemeId']); - for ($i = 1; $i <= $language_count; $i++) { - $data['l'.$i.'_Name'] = $parent_data['l'.$i.'_Name']; - } - - if (!$categories) { - // no children - return $data; - } - - // category has children - foreach ($categories as $category_id => $category_data) { - $data['children'][$category_id] = $this->_getChildren($event, $category_id); - } - return $data; - } - - /** * Removes this item and it's children (recursive) from structure dropdown * * @param kEvent $event @@ -1742,6 +1714,9 @@ return ; } + set_time_limit(0); + ini_set('memory_limit', -1); + $dummy =& $this->Application->recallObject($event->Prefix . '.-dummy', null, Array ('skip_autoload' => true)); /* @var $dummy kDBItem */ Index: branches/RC/core/admin_templates/categories/relations_edit.tpl =================================================================== diff -u -N -r11623 -r11724 --- branches/RC/core/admin_templates/categories/relations_edit.tpl (.../relations_edit.tpl) (revision 11623) +++ branches/RC/core/admin_templates/categories/relations_edit.tpl (.../relations_edit.tpl) (revision 11724) @@ -1,5 +1,5 @@ - +
- + @@ -74,40 +74,6 @@ - - DEPRICATED. PLEASE USE "COMBINED_HEADER" - - - - - - - - - -
- - - - - - - - - -
- - -
-
Index: branches/RC/core/admin_templates/categories/related_searches_edit.tpl =================================================================== diff -u -N -r11623 -r11724 --- branches/RC/core/admin_templates/categories/related_searches_edit.tpl (.../related_searches_edit.tpl) (revision 11623) +++ branches/RC/core/admin_templates/categories/related_searches_edit.tpl (.../related_searches_edit.tpl) (revision 11724) @@ -1,5 +1,5 @@ - +
Index: branches/RC/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r11711 -r11724 --- branches/RC/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 11711) +++ branches/RC/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 11724) @@ -2388,7 +2388,7 @@ */ function VisibleToolbarButtons($params) { - $preset_name = $params['title_preset']; + $preset_name = replaceModuleSection($params['title_preset']); $title_presets = $this->Application->getUnitOption($this->Prefix, 'TitlePresets'); if (!array_key_exists($preset_name, $title_presets)) {