Index: trunk/kernel/units/categories/categories_config.php
===================================================================
diff -u -N
--- trunk/kernel/units/categories/categories_config.php (revision 6669)
+++ trunk/kernel/units/categories/categories_config.php (revision 0)
@@ -1,298 +0,0 @@
- 'c',
- 'ItemClass' => Array('class'=>'CategoriesItem','file'=>'categories_item.php','build_event'=>'OnItemBuild'),
- 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
- 'EventHandlerClass' => Array('class'=>'CategoriesEventHandler','file'=>'categories_event_handler.php','build_event'=>'OnBuild'),
- 'TagProcessorClass' => Array('class'=>'CategoriesTagProcessor','file'=>'categories_tag_processor.php','build_event'=>'OnBuild'),
-
- 'RegisterClasses' => Array(
- Array('pseudo' => 'kPermCacheUpdater','class' => 'kPermCacheUpdater', 'file' => 'cache_updater.php','build_event'=>''),
- ),
-
- 'AutoLoad' => true,
- 'CatalogItem' => true,
- 'AdminTemplatePath' => 'categories',
- 'AdminTemplatePrefix' => 'categories_',
-
- 'QueryString' => Array(
- 1 => 'id',
- 2 => 'page',
- 3 => 'event',
- 4 => 'mode',
- ),
- 'AggregateTags' => Array(
- Array(
- 'AggregateTo' => 'm',
- 'AggregatedTagName' => 'CategoryLink',
- 'LocalTagName' => 'CategoryLink',
- ),
- ),
- 'IDField' => 'CategoryId',
-
- 'StatusField' => Array('Status'),
-
- 'TitleField' => 'Name', // field, used in bluebar when editing existing item
- 'TitlePhrase' => 'la_Text_Category',
- 'ItemType' => 1, // used for custom fields only
-
- 'StatisticsInfo' => Array(
- 'pending' => Array(
- 'icon' => 'icon16_cat_pending.gif',
- 'label' => 'la_tab_Categories',
- 'js_url' => '#url#',
- 'url' => Array('t' => 'advanced_view', 'SetTab' => 'c', 'pass' => 'm,c.showall', 'c.showall_event' => 'OnSetFilterPattern', 'c.showall_filters' => 'show_active=0,show_pending=1,show_disabled=0,show_new=1,show_pick=1'),
- 'status' => STATUS_PENDING,
- ),
- ),
-
- 'TableName' => TABLE_PREFIX.'Category',
-
- 'ViewMenuPhrase' => 'la_text_Categories',
-
- 'TitlePresets' => Array(
- 'default' => Array( 'new_status_labels' => Array('c' => '!la_title_Adding_Category!'),
- 'edit_status_labels' => Array('c' => '!la_title_Editing_Category!'),
- 'new_titlefield' => Array('c' => '!la_title_New_Category!'),
- ),
- 'category_list' => Array('prefixes' => Array('c_List'), 'format' => "!la_title_Categories! (#c_recordcount#)"),
-
- 'catalog' => Array('prefixes' => Array('c_List'), 'format' => "!la_title_Categories! (#c_recordcount#)"),
-
- 'advanced_view' => Array('prefixes' => Array('c_List'), 'format' => "!la_title_AdvancedView!"),
-
- 'categories_edit' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_General!"),
- 'categories_properties' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Properties!"),
- 'categories_relations' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Relations!"),
- 'categories_images' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Images!"),
- 'categories_permissions'=> Array('prefixes' => Array('c', 'g_List'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Permissions!"),
- 'categories_custom' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Custom!"),
-
- 'categories_update' => Array('prefixes' => Array(), 'format' => "!la_title_UpdatingCategories!"),
-
- 'images_edit' => Array( 'prefixes' => Array('c', 'c-img'),
- 'new_status_labels' => Array('c-img'=>'!la_title_Adding_Image!'),
- 'edit_status_labels' => Array('c-img'=>'!la_title_Editing_Image!'),
- 'new_titlefield' => Array('c-img'=>'!la_title_New_Image!'),
- 'format' => "#c_status# '#c_titlefield#' - #c-img_status# '#c-img_titlefield#'",
- ),
-
- 'relations_edit' => Array( 'prefixes' => Array('c', 'c-rel'),
- 'new_status_labels' => Array('c-rel'=>"!la_title_Adding_Relationship! '!la_title_New_Relationship!'"),
- 'edit_status_labels' => Array('c-rel'=>'!la_title_Editing_Relationship!'),
- 'format' => "#c_status# '#c_titlefield#' - #c-rel_status#",
- ),
-
- 'tree_site' => Array('format' => '!la_selecting_categories!'),
- ),
-
- 'PermItemPrefix' => 'CATEGORY',
-
- 'PermSection' => Array('main' => 'CATEGORY:in-portal:categories', /*'search' => 'in-portal:configuration_search',*/ 'email' => 'in-portal:configuration_email', 'custom' => 'in-portal:configuration_custom'),
-
-
- 'Sections' => Array(
- // "Structure & Data" section
- 'in-portal:site' => Array(
- 'parent' => 'in-portal:root',
- 'icon' => 'struct',
- 'label' => 'la_tab_Site_Structure',
- 'url' => Array('t' => 'sections_list', 'pass_section' => true, 'pass' => 'm'),
- 'permissions' => Array('view'),
- 'priority' => 1,
- 'type' => stTREE,
- ),
-
- 'in-portal:browse' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'catalog',
- 'label' => 'la_tab_Browse',
- 'url' => Array('t' => 'in-portal/catalog', 'pass' => 'm'),
- 'late_load' => Array('t' => 'in-portal/xml/tree_categories', 'pass' => 'm', 'm_cat_id' => 0),
- 'onclick' => 'checkCatalog(0)',
- 'permissions' => Array('view'),
- 'priority' => 0.1,
- 'type' => stTREE,
- ),
- 'in-portal:advanced_view' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'advanced_view',
- 'label' => 'la_tab_AdvancedView',
- 'url' => Array('t' => 'in-portal/advanced_view', 'pass' => 'm'),
- 'permissions' => Array('view'),
- 'priority' => 0.2,
- 'type' => stTREE,
- ),
-
- /*'in-portal:browse' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'catalog',
- 'label' => 'la_tab_Browse',
- 'url' => Array('index_file' => 'browse.php', 'pass' => 'm'),
- 'permissions' => Array('view'),
- 'priority' => 1,
- 'type' => stTREE,
- ),
-
- 'in-portal:advanced_view' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'advanced_view',
- 'label' => 'la_tab_AdvancedView',
- 'url' => Array('index_file' => 'advanced_view.php', 'pass' => 'm'),
- 'permissions' => Array('view'),
- 'priority' => 2,
- 'type' => stTREE,
- ),*/
-
- 'in-portal:reviews' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'reviews',
- 'label' => 'la_tab_Reviews',
- 'url' => Array('index_file' => 'reviews.php', 'pass' => 'm'),
- 'permissions' => Array('view'),
- 'priority' => 3,
- 'type' => stTREE,
- ),
-
- 'in-portal:configure_categories' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'cat_settings',
- 'label' => 'la_tab_Settings',
- 'url' => Array('t' => 'config/config_universal', 'pass_section' => true, 'pass' => 'm'),
- 'permissions' => Array('view', 'edit'),
- 'priority' => 4,
- 'type' => stTREE,
- ),
-
- 'in-portal:configuration_search' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'settings_search',
- 'label' => 'la_tab_ConfigSearch',
- 'url' => Array('t' => 'in-portal/config/config_search', 'module_key' => 'category', 'pass_section' => true, 'pass' => 'm'),
- 'permissions' => Array('view', 'edit'),
- 'priority' => 5,
- 'type' => stTREE,
- ),
-
- 'in-portal:configuration_email' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'settings_email',
- 'label' => 'la_tab_ConfigE-mail',
- 'url' => Array('t' => 'in-portal/config/config_email', 'module' => 'In-Portal:Category', 'pass_section' => true, 'pass' => 'm'),
- 'permissions' => Array('view', 'edit'),
- 'priority' => 6,
- 'type' => stTREE,
- ),
-
- 'in-portal:configuration_custom' => Array(
- 'parent' => 'in-portal:site',
- 'icon' => 'settings_custom',
- 'label' => 'la_tab_ConfigCustom',
- 'url' => Array('t' => 'in-portal/custom_fields/custom_fields_list', 'cf_type' => 1, 'pass_section' => true, 'pass' => 'm,cf'),
- 'permissions' => Array('view', 'add', 'edit', 'delete'),
- 'priority' => 7,
- 'type' => stTREE,
- ),
-
- ),
-
- 'FilterMenu' => Array(
- 'Groups' => Array(
- Array('mode' => 'AND', 'filters' => Array('show_active','show_pending','show_disabled'), 'type' => WHERE_FILTER),
- Array('mode' => 'AND', 'filters' => Array('show_new'), 'type' => HAVING_FILTER),
- Array('mode' => 'AND', 'filters' => Array('show_pick'), 'type' => WHERE_FILTER),
- ),
- 'Filters' => Array(
- 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => 'Status != 1' ),
- 'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => 'Status != 2' ),
- 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => 'Status != 0' ),
- 's1' => Array(),
- 'show_new' => Array('label' => 'la_Text_New', 'on_sql' => '', 'off_sql' => '`IsNew` != 1' ),
- 'show_pick' => Array('label' => 'la_prompt_EditorsPick', 'on_sql' => '', 'off_sql' => '`EditorsPick` != 1' ),
- )
- ),
-
- 'ListSQLs' => Array( ''=> ' SELECT %1$s.* %2$s
- FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId
- LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'),
-
- 'ItemSQLs' => Array( ''=> ' SELECT %1$s.* %2$s
- FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId
- LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'),
-
- 'SubItems' => Array('c-rel', 'c-img', 'c-cdata', 'c-perm'),
-
- 'ListSortings' => Array(
- '' => Array(
- 'ForcedSorting' => Array("CurrentSort" => 'asc', 'Priority' => 'desc', 'Name' => 'asc'),
- 'Sorting' => Array('Name' => 'asc'),
- )
- ),
-
- 'CalculatedFields' => Array(
- '' => Array(
- 'CurrentSort' => "REPLACE(ParentPath, CONCAT('|', ".'%1$s'.".CategoryId, '|'), '')",
- )
- ),
-
- 'Fields' => Array
- (
- 'CategoryId' => Array('type' => 'int','not_null' => 1,'default' => ''),
- 'Type' => Array('type' => 'int','not_null' => 1,'default' => 0),
- 'ParentId' => Array('type' => 'int','not_null' => 1,'default' => 0),
- 'Name' => Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'not_null' => 1, 'required' => 1, 'default' => ''),
- 'Filename' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
- 'AutomaticFilename' => Array('type' => 'int', 'not_null' => 1, 'default' => 1),
- 'Description' => Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'not_null' => 1, 'required' => 1, 'default' => ''),
- 'CreatedOn' => Array('formatter' => 'kDateFormatter', 'default'=>'#NOW#', 'required' => 1, 'not_null' => 1),
- 'EditorsPick' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'Status' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Active', 2 => 'la_Pending', 0 => 'la_Disabled' ), 'use_phrases' => 1, 'not_null' => 1,'default' => 2),
- 'Pop' => Array('type' => 'int', 'default' => ''),
- 'Priority' => Array('type' => 'int', 'not_null' => 1, 'default' => ''),
- 'MetaKeywords' => Array('type' => 'string', 'default' => ''),
- 'CachedDescendantCatsQty' => Array('type' => 'int', 'default' => ''),
- 'CachedNavbar' => Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'not_null' => 1, 'default' => ''),
- 'CreatedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(-1 => 'root', -2 => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Login', 'not_null' => 1,'default' => '0'),
- 'ResourceId' => Array('type' => 'int', 'default' => ''),
- 'ParentPath' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
- 'NamedParentPath' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
- 'MetaDescription' => Array('type' => 'string', 'default' => ''),
- 'HotItem' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2),
- 'NewItem' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2),
- 'PopItem' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2),
- 'Modified' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1,'default' => '#NOW#'),
- 'ModifiedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(-1 => 'root', -2 => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Login', 'not_null' => 1,'default' => '0'),
- 'CategoryTemplate' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
- 'CachedCategoryTemplate' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
- ),
-
- 'VirtualFields' => Array(
- 'CurrentSort' => Array('type' => 'string', 'default' => ''),
- 'IsNew' => Array('type' => 'int', 'default' => 0),
- ),
-
- 'Grids' => Array(
- 'Default' => Array(
- 'Icons' => Array('default'=>'icon16_cat.gif'),
- 'Fields' => Array(
- 'Name' => Array('title' => 'la_col_Name', 'data_block' => 'category_td'),
- 'Description' => Array('title' => 'la_col_Description'),
- 'CreatedOn_formatted' => Array('title' => 'la_col_CreatedOn', 'sort_field' => 'CreatedOn'),
- ),
-
- ),
- ),
-
- 'ConfigMapping' => Array(
- 'PerPage' => 'Perpage_Category',
- 'DefaultSorting1Field' => 'Category_Sortfield',
- 'DefaultSorting2Field' => 'Category_Sortfield2',
- 'DefaultSorting1Dir' => 'Category_Sortorder',
- 'DefaultSorting2Dir' => 'Category_Sortorder2',
- ),
- );
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/categories/categories_event_handler.php
===================================================================
diff -u -N
--- trunk/kernel/units/categories/categories_event_handler.php (revision 6625)
+++ trunk/kernel/units/categories/categories_event_handler.php (revision 0)
@@ -1,504 +0,0 @@
- Array('self' => 'add|edit'),
-// 'OnSave' => Array('self' => 'add|edit')
- );
- $this->permMapping = array_merge($this->permMapping, $permissions);
- }
-
- /**
- * Checks permissions of user
- *
- * @param kEvent $event
- */
- function CheckPermission(&$event)
- {
- if (!$this->Application->IsAdmin()) {
- if ($event->Name == 'OnSetSortingDirect') {
- // allow sorting on front event without view permission
- return true;
- }
- }
-
- 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 = $this->Application->RecallVar($event->getPrefixSpecial().'_selected_ids');
- }
-
- $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
- $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);
-
- $perm_value = true;
- $perm_helper =& $this->Application->recallObject('PermissionsHelper');
- 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 (!$perm_value) {
- $event->status = erPERM_FAIL;
- }
-
- return $perm_value;
- }
-
- return parent::CheckPermission($event);
- }
-
- /**
- * Apply system filter to categories list
- *
- * @param kEvent $event
- */
- function SetCustomQuery(&$event)
- {
- parent::SetCustomQuery($event);
-
- $types=$event->getEventParam('types');
- $except_types=$event->getEventParam('except');
- $object =& $event->getObject();
- $type_clauses = Array();
-
- $object =& $event->getObject();
-
- if ( $event->getEventParam('parent_cat_id') ) {
- $parent_cat_id = $event->getEventParam('parent_cat_id');
-
- if ($parent_cat_id == 'Root') {
- $module_name = $event->getEventParam('module') ? $event->getEventParam('module') : 'In-Commerce';
- $module =& $this->Application->recallObject('mod.'.$module_name);
- $parent_cat_id = $module->GetDBField('RootCat');
- }
-
- }
- else {
- $parent_cat_id = $this->Application->GetVar('c_id');
- if (!$parent_cat_id) {
- $parent_cat_id = $this->Application->GetVar('m_cat_id');
- }
- if (!$parent_cat_id) {
- $parent_cat_id = 0;
- }
- }
-
- if ("$parent_cat_id" != 'any') {
- if ($event->getEventParam('recursive')) {
- $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id);
- $subcats = $this->Conn->GetCol('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ParentPath LIKE "'.$current_path.'%" ');
- $object->addFilter('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')');
- }
- else {
- $object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
- }
- }
-
- $object->addFilter('perm_filter', 'PermId = 1'); // check for CATEGORY.VIEW permission
- if ($this->Application->GetVar('u_id') != -1) {
- // apply permission filters to all users except "root"
- $groups = explode(',',$this->Application->RecallVar('UserGroups'));
- foreach ($groups as $group) {
- $view_filters[] = 'FIND_IN_SET('.$group.', acl)';
- }
- $view_filter = implode(' OR ', $view_filters);
- $object->addFilter('perm_filter2', $view_filter);
- }
-
- if (!$this->Application->IsAdmin()) {
- // apply status filter only on front
- $object->addFilter('status_filter', $object->TableName.'.Status = 1');
- }
-
- if(strpos($types, 'category_related') !== false)
- {
- $object->removeFilter('parent_filter');
- $resource_id = $this->Conn->GetOne('
- SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
- WHERE CategoryId = '.$parent_cat_id
- );
-
- $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
- WHERE SourceId = '.$resource_id.' AND SourceType = 1';
- $related_cats = $this->Conn->GetCol($sql);
- $related_cats = is_array($related_cats) ? $related_cats : Array();
- $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
- WHERE TargetId = '.$resource_id.' AND TargetType = 1 AND Type = 1';
- $related_cats2 = $this->Conn->GetCol($sql);
- $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
- $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
-
- if($related_cats)
- {
- $type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
- $type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
- }
- else
- {
- $type_clauses['category_related']['include'] = '0';
- $type_clauses['category_related']['except'] = '1';
- }
- $type_clauses['category_related']['having_filter'] = false;
- }
-
- if(strpos($types, 'product_related') !== false)
- {
- $object->removeFilter('parent_filter');
-
- $product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id');
- $resource_id = $this->Conn->GetOne('
- SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
- WHERE ProductId = '.$product_id
- );
-
- $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
- WHERE SourceId = '.$resource_id.' AND TargetType = 1';
- $related_cats = $this->Conn->GetCol($sql);
- $related_cats = is_array($related_cats) ? $related_cats : Array();
- $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
- WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1';
- $related_cats2 = $this->Conn->GetCol($sql);
- $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
- $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
-
- if($related_cats)
- {
- $type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
- $type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
- }
- else
- {
- $type_clauses['product_related']['include'] = '0';
- $type_clauses['product_related']['except'] = '1';
- }
- $type_clauses['product_related']['having_filter'] = false;
- }
-
- /********************************************/
-
- $includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
- $includes_or_filter->setType(FLT_TYPE_OR);
-
- $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
- $excepts_and_filter->setType(FLT_TYPE_AND);
-
- $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
- $includes_or_filter_h->setType(FLT_TYPE_OR);
-
- $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
- $excepts_and_filter_h->setType(FLT_TYPE_AND);
-
- $except_types_array=explode(',', $types);
-
- if ($types){
- $types_array=explode(',', $types);
- for ($i=0; $iremoveFilter('filter_'.$type);
- $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
- }else{
- $includes_or_filter->removeFilter('filter_'.$type);
- $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
- }
- }
- }
- }
-
- if ($except_types){
- $except_types_array=explode(',', $except_types);
- for ($i=0; $iremoveFilter('filter_'.$type);
- $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
- }else{
- $excepts_and_filter->removeFilter('filter_'.$type);
- $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
- }
- }
- }
- }
-
- $object->addFilter('includes_filter', $includes_or_filter);
- $object->addFilter('excepts_filter', $excepts_and_filter);
-
- $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
- $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
- }
-
- function GetPassedId(&$event)
- {
- if ( $this->Application->IsAdmin() ) {
- return parent::getPassedID($event);
- }
-
- return $this->Application->GetVar('m_cat_id');
- }
-
- /**
- * Adds calculates fields for item statuses
- *
- * @param kCatDBItem $object
- * @param kEvent $event
- */
- function prepareObject(&$object, &$event)
- {
- $object =& $event->getObject( Array('skip_autoload' => true) );
-
- $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2,
- IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '.
- $this->Application->ConfigValue('Category_DaysNew').
- '*3600*24), 1, 0),
- %1$s.NewItem
- )');
- }
-
- /**
- * Set correct parent path for newly created categories
- *
- * @param kEvent $event
- */
- function OnAfterCopyToLive(&$event)
- {
- if ($event->getEventParam('temp_id') == 0) {
- $object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true));
- $object->Load($event->getEventParam('id'));
- if ($object->isLoaded()) {
- // update path only for real categories (not including "Home" root category)
- $fields_hash = Array('ParentPath' => $object->buildParentPath());
- $this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = '.$object->GetID());
- }
- }
- }
-
- /**
- * Set cache modification mark if needed
- *
- * @param kEvent $event
- */
- function OnBeforeDeleteFromLive(&$event)
- {
- $id = $event->getEventParam('id');
-
- // loding anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event
- $temp_object =& $event->getObject( Array('skip_autoload' => true) );
- $temp_object->Load($id);
-
- if ($id == 0) {
- if ($temp_object->isLoaded()) {
- // new category -> update chache (not loaded when "Home" category)
- $this->Application->StoreVar('PermCache_UpdateRequired', 1);
- }
- return ;
- }
-
- // existing category was edited, check if in-cache fields are modified
- $live_object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('live_table' => true, 'skip_autoload' => true));
- $live_object->Load($id);
-
- $cached_fields = Array('Name', 'Filename', 'CategoryTemplate');
-
- foreach ($cached_fields as $cached_field) {
- if ($live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field)) {
- // use session instead of REQUEST because of permission editing in category can contain
- // multiple submits, that changes data before OnSave event occurs
- $this->Application->StoreVar('PermCache_UpdateRequired', 1);
- break;
- }
- }
- }
-
- /**
- * Checks cache update mark and redirect to cache if needed
- *
- * @param kEvent $event
- */
- function OnSave(&$event)
- {
- $object =& $event->getObject();
- if ($object->IsRoot()) {
- $event->setEventParam('master_ids', Array(0));
- }
-
- parent::OnSave($event);
- if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) {
- // "catalog" should be in opener stack by now
- $opener_stack = unserialize($this->Application->RecallVar('opener_stack'));
- $opener_stack[0] = str_replace('catalog', 'categories/cache_updater', $opener_stack[0]);
- $this->Application->StoreVar('opener_stack', serialize($opener_stack));
- $this->Application->RemoveVar('PermCache_UpdateRequired');
- }
- }
-
- /**
- * Deletes all selected items.
- * Automatically recurse into sub-items using temp handler, and deletes sub-items
- * by calling its Delete method if sub-item has AutoDelete set to true in its config file
- *
- * @param kEvent $event
- */
- function OnMassDelete(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
- return;
- }
-
-// $event->status = erSUCCESS;
-
- $ids = $this->StoreSelectedIDs($event);
- if ($ids) {
- $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
- foreach ($ids as $id) {
- $recursive_helper->DeleteCategory($id);
- }
- }
- $this->clearSelectedIDs($event);
- }
-
- /**
- * Add selected items to clipboard with mode = COPY (CLONE)
- *
- * @param kEvent $event
- */
- function OnCopy(&$event)
- {
- $this->Application->RemoveVar('clipboard');
- $clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
- $clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event));
- }
-
- /**
- * Add selected items to clipboard with mode = CUT
- *
- * @param kEvent $event
- */
- function OnCut(&$event)
- {
- $this->Application->RemoveVar('clipboard');
- $clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
- $clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event));
- }
-
- /**
- * Controls all item paste operations. Can occur only with filled clipbord.
- *
- * @param kEvent $event
- */
- function OnPasteClipboard(&$event)
- {
- $clipboard = unserialize( $this->Application->RecallVar('clipboard') );
- foreach ($clipboard as $prefix => $clipboard_data) {
- $paste_event = new kEvent($prefix.':OnPaste', Array('clipboard_data' => $clipboard_data));
- $this->Application->HandleEvent($paste_event);
-
- $event->redirect = $paste_event->redirect;
- $event->redirect_params = $paste_event->redirect_params;
- $event->status = $paste_event->status;
- }
- }
-
- /**
- * Paste categories with subitems from clipboard
- *
- * @param kEvent $event
- */
- function OnPaste(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
- return;
- }
-
- $clipboard_data = $event->getEventParam('clipboard_data');
-
- if (!$clipboard_data['cut'] && !$clipboard_data['copy']) {
- return false;
- }
-
- $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
- if ($clipboard_data['cut']) {
- $recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id'));
- }
-
- if ($clipboard_data['copy']) {
- foreach ($clipboard_data['copy'] as $id) {
- $recursive_helper->PasteCategory($id);
- }
- }
-
- if ($clipboard_data['cut'] || $clipboard_data['copy']) {
- $event->redirect = 'categories/cache_updater';
- }
- }
-
- /**
- * Occurs when pasting category
- *
- * @param kEvent $event
- */
- /*function OnCatPaste(&$event)
- {
- $inp_clipboard = $this->Application->RecallVar('ClipBoard');
- $inp_clipboard = explode('-', $inp_clipboard, 2);
-
- if($inp_clipboard[0] == 'COPY')
- {
- $saved_cat_id = $this->Application->GetVar('m_cat_id');
- $cat_ids = $event->getEventParam('cat_ids');
-
- $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
- $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
- $ids_sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE ResourceId IN (%s)';
- $resource_ids_sql = 'SELECT ItemResourceId FROM '.TABLE_PREFIX.'CategoryItems WHERE CategoryId = %s AND PrimaryCat = 1';
-
- $object =& $this->Application->recallObject($event->Prefix.'.item', $event->Prefix, Array('skip_autoload' => true));
-
- foreach($cat_ids as $source_cat => $dest_cat)
- {
- $item_resource_ids = $this->Conn->GetCol( sprintf($resource_ids_sql, $source_cat) );
- if(!$item_resource_ids) continue;
-
- $this->Application->SetVar('m_cat_id', $dest_cat);
- $item_ids = $this->Conn->GetCol( sprintf($ids_sql, implode(',', $item_resource_ids) ) );
-
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
- if($item_ids) $temp->CloneItems($event->Prefix, $event->Special, $item_ids);
- }
-
- $this->Application->SetVar('m_cat_id', $saved_cat_id);
- }
- }*/
-
- /**
- * Cleares clipboard content
- *
- * @param kEvent $event
- */
- function OnClearClipboard(&$event)
- {
- $this->Application->RemoveVar('clipboard');
- }
-}
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/categories/categories_tag_processor.php
===================================================================
diff -u -N
--- trunk/kernel/units/categories/categories_tag_processor.php (revision 6583)
+++ trunk/kernel/units/categories/categories_tag_processor.php (revision 0)
@@ -1,493 +0,0 @@
-Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
- $sql = ' SELECT COUNT(*) - 1
- FROM '.$cat_object->TableName.'
- WHERE ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"';
- if (isset($params['today'])) {
- $sql .= ' AND CreatedOn > '.(adodb_mktime()-86400);
- }
- return $this->Conn->GetOne($sql);
- }
-
- function IsNew($params)
- {
- $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
- $ret = $object->GetDBField('IsNew') ? 1 : 0;
- return $ret;
- }
-
- function IsPick($params)
- {
- $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
- $ret = $object->GetDBField('EditorsPick') ? 1 : 0;
- return $ret;
- }
-
- function ItemIcon($params)
- {
- $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
- $status = $object->GetDBField('Status');
- if($status == 1)
- {
- $ret = $object->GetDBField('IsNew') ? 'icon16_cat_new.gif' : 'icon16_cat.gif';
- }
- else
- {
- $ret = $status ? 'icon16_cat_pending.gif' : 'icon16_cat_disabled.gif';
- }
- return $ret;
- }
-
- function ItemCount($params)
- {
- $cat_object =& $this->getObject($params);
- $ci_table = $this->Application->getUnitOption('l-ci', 'TableName');
-
- $sql = ' SELECT COUNT(*)
- FROM '.$cat_object->TableName.' c
- LEFT JOIN '.$ci_table.' ci
- ON c.CategoryId=ci.CategoryId
- WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"
- AND NOT (ci.CategoryId IS NULL)';
- return $this->Conn->GetOne($sql);
- }
-
- function ListCategories($params)
- {
- return $this->PrintList2($params);
- }
-
- function RootCategoryName($params)
- {
- return $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params);
- }
-
- function CheckModuleRoot($params)
- {
- $module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
- $module =& $this->Application->recallObject('mod.'.$module_name);
- $module_root_cat = $module->GetDBField('RootCat');
-
- $additional_cats = $this->SelectParam($params, 'add_cats');
- if ($additional_cats) {
- $additional_cats = explode(',', $additional_cats);
- }
- else {
- $additional_cats = array();
- }
-
- if ($this->Application->GetVar('m_cat_id') == $module_root_cat || in_array($this->Application->GetVar('m_cat_id'), $additional_cats)) {
- $home_template = getArrayValue($params, 'home_template');
- if (!$home_template) return;
- $this->Application->Redirect($home_template, Array('pass'=>'all'));
- };
- }
-
- function CategoryPath($params)
- {
- $module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
- $module_category_id = $this->Application->findModule('Name', $module_name, 'RootCat');
- $module_item_id = $this->Application->GetVar($this->Application->findModule('Name', $module_name, 'Var').'_id');
-
- $block_params['separator'] = $params['separator'];
-
- if (!isset($params['cat_id'])) {
- $params['cat_id'] = getArrayValue($params, 'cat_id') ? $params['cat_id'] : $this->Application->GetVar('m_cat_id');
- }
-
- if ($params['cat_id'] == 0) {
- $block_params['current'] = 1;
- $block_params['cat_id'] = 0;
- $block_params['cat_name'] = $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params);
- $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock,render_as');
- return $this->Application->ParseBlock($block_params);
- }
- else {
- $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- $navbar_field = $ml_formatter->LangFieldName('CachedNavBar');
-
- $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
- $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');
- $sql = 'SELECT '.$navbar_field.', ParentPath
- FROM '.$table_name.'
- WHERE '.$id_field.' = '.$params['cat_id'];
- $category_data = $this->Conn->GetRow($sql);
- $ret = '';
- if ($category_data) {
- $category_names = explode('&|&', $category_data[$navbar_field]);
- $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1));
-
- // add "Home" category at beginning of path
- array_unshift($category_names, $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params));
- array_unshift($category_ids, 0);
-
- foreach ($category_ids as $category_pos => $category_id) {
- $block_params['cat_id'] = $category_id;
- $block_params['cat_name'] = $category_names[$category_pos];
- $block_params['current'] = ($params['cat_id'] == $category_id) && !$module_item_id ? 1 : 0;
- $block_params['is_module_root'] = $category_id == $module_category_id ? 1 : 0;
- $block_params['name'] = $this->SelectParam($params, 'render_as,block');
-
- // which block to parse as current ?
- if ($category_id == 0) {
- $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock,render_as,block');
- }
-
- if ($block_params['is_module_root'] == 1) { // module root
- $block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock,render_as,block');
- }
-
- if ($block_params['current'] == 1) { // current cat (label)
- $block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock,render_as,block');
- }
-
- $this->Application->SetVar($this->Prefix.'_id', $category_id);
- $ret .= $this->Application->ParseBlock($block_params, 1);
- }
- }
-
- return $ret;
- }
- }
-
- function CurrentCategoryName($params)
- {
- $cat_object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix.'_List');
- $sql = 'SELECT '.$this->getTitleField().'
- FROM '.$cat_object->TableName.'
- WHERE CategoryId = '.$this->Application->GetVar('m_cat_id');
- return $this->Conn->GetOne($sql);
- }
-
- function getTitleField()
- {
- $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- return $ml_formatter->LangFieldName('Name');
- }
-
- function CategoryLink($params)
- {
- // 'p_id'=>'0', ??
- $params = array_merge(array('pass'=>'m'), $params);
- $cat_id = getArrayValue($params,'cat_id');
- if ($cat_id === false) {
-// $cat_id = $this->Application->Parser->GetParam('cat_id');
- $cat_id = $this->Application->GetVar($this->getPrefixSpecial().'_id');
- }
- if($cat_id == 'Root')
- {
- $object =& $this->Application->recallObject('mod.'.$params['module']);
- $params['m_cat_id'] = $object->GetDBField('RootCat');
- unset($params['module']);
- }
- else{
- $params['m_cat_id'] = $cat_id;
- }
- unset($params['cat_id']);
-
- $params['pass_category'] = 1;
-
- $main_processor =& $this->Application->recallObject('m_TagProcessor');
- return $main_processor->T($params);
- }
-
- function CategoryList($params)
- {
- //$object =& $this->Application->recallObject( $this->getPrefixSpecial() , $this->Prefix.'_List', $params );
- $object =& $this->GetList($params);
-
-
- if ($object->RecordsCount == 0)
- {
- if (isset($params['block_no_cats'])) {
- $params['name'] = $params['block_no_cats'];
- return $this->Application->ParseBlock($params);
- }
- else {
- return '';
- }
- }
-
- if (isset($params['block'])) {
- return $this->PrintList($params);
- }
- else {
- $params['block'] = $params['block_main'];
- if (isset($params['block_row_start'])) {
- $params['row_start_block'] = $params['block_row_start'];
- }
-
- if (isset($params['block_row_end'])) {
- $params['row_end_block'] = $params['block_row_end'];
- }
- return $this->PrintList2($params);
- }
- }
-
- function Meta($params)
- {
- $name = getArrayValue($params, 'name');
- $object =& $this->Application->recallObject($this->Prefix.'.-item');
-
- $field = $object->GetField('Meta'.$name);
- if ($field) return $field;
-
- switch ($name) {
- case 'Description':
- $conf = 'Category_MetaDesc';
- break;
- case 'Keywords':
- $conf = 'Category_MetaKey';
- break;
- }
-
- return $this->Application->ConfigValue($conf);
- }
-
- function BuildListSpecial($params)
- {
- if ( isset($params['parent_cat_id']) ) {
- $parent_cat_id = $params['parent_cat_id'];
- }
- else {
- $parent_cat_id = $this->Application->GetVar($this->Prefix.'_id');
- if (!$parent_cat_id) {
- $parent_cat_id = $this->Application->GetVar('m_cat_id');
- }
- if (!$parent_cat_id) {
- $parent_cat_id = 0;
- }
- }
-
- $types = $this->SelectParam($params, 'types');
- $except = $this->SelectParam($params, 'except');
-
- $no_special = isset($params['no_special']) && $params['no_special'];
- if ($no_special) return $this->Special;
-
- if ($types.$except.$parent_cat_id == '') {
- return parent::BuildListSpecial($params);
- }
-
- $special = crc32($types.$except.$parent_cat_id);
- return $special;
- }
-
- function IsCurrent($params)
- {
- $object =& $this->getObject($params);
- if ($object->GetID() == $this->Application->GetVar('m_cat_id')) {
- return true;
- }
- else {
- return false;
- }
- }
-
- /**
- * Substitutes category in last template base on current category
- *
- * @param Array $params
- */
- function UpdateLastTemplate($params)
- {
- $category_id = $this->Application->GetVar('m_cat_id');
-
- list($index_file, $env) = explode('|', $this->Application->RecallVar('last_template'), 2);
- $this->Application->SetVar(ENV_VAR_NAME, str_replace('%5C', '\\', $env));
- $this->Application->HttpQuery->processQueryString();
-
- // update required fields
- $this->Application->SetVar('m_cat_id', $category_id);
- $this->Application->Session->SaveLastTemplate($params['template']);
- }
-
- function GetParentCategory($params)
- {
- $parent_id = 0;
- $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
- $table = $this->Application->getUnitOption($this->Prefix,'TableName');
- $cat_id = $this->Application->GetVar('m_cat_id');
- if ($cat_id > 0) {
- $sql = 'SELECT ParentId
- FROM '.$table.'
- WHERE '.$id_field.' = '.$cat_id;
- $parent_id = $this->Conn->GetOne($sql);
- }
- return $parent_id;
- }
-
- function InitCacheUpdater($params)
- {
- safeDefine('CACHE_PERM_CHUNK_SIZE', 30);
-
- $continue = $this->Application->GetVar('continue');
- $total_cats = (int) $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category');
-
- if ($continue === false && $total_cats > CACHE_PERM_CHUNK_SIZE) {
- // first step, if category count > CACHE_PERM_CHUNK_SIZE, then ask for cache update
- return true;
- }
-
- if ($continue === false) {
- // if we don't have to ask, then assume user selected "Yes" in permcache update dialog
- $continue = 1;
- }
-
- $updater =& $this->Application->recallObject('kPermCacheUpdater', null, Array('continue' => $continue));
- if ($continue === '0') { // No in dialog
- $updater->clearData();
- $this->Application->Redirect($params['destination_template']);
- }
-
- $ret = false; // don't ask for update
- if ($continue == 1) { // Initial run
- $updater->setData();
- }
- if ($continue == 2) { // Continuing
- // called from AJAX request => returns percent
- $needs_more = true;
- while ($needs_more && $updater->iteration <= CACHE_PERM_CHUNK_SIZE) {
- // until proceeeded in this step category count exceeds category per step limit
- $needs_more = $updater->DoTheJob();
- }
-
- if ($needs_more) {
- // still some categories are left for next step
- $updater->setData();
- }
- else {
- // all done -> redirect
- $updater->clearData();
- $this->Application->RemoveVar('PermCache_UpdateRequired');
- $this->Application->Redirect($params['destination_template']);
- }
-
- $ret = $updater->getDonePercent();
- }
- return $ret;
- }
-
- function SaveWarning($params)
- {
- $main_prefix = getArrayValue($params, 'main_prefix');
- if ($main_prefix && $main_prefix != '$main_prefix') {
- $top_prefix = $main_prefix;
- }
- else {
- $top_prefix = $this->Application->GetTopmostPrefix($this->Prefix);
- }
-
- $temp_tables = $this->Application->GetVar($top_prefix.'_mode') == 't';
- $modified = $this->Application->RecallVar($top_prefix.'_modified');
-
- if (!$temp_tables) {
- $this->Application->RemoveVar($top_prefix.'_modified');
- return '';
- }
-
- $block_name = $this->SelectParam($params, 'render_as,name');
- if ($block_name) {
- $block_params = $this->prepareTagParams($params);
- $block_params['name'] = $block_name;
- $block_params['edit_mode'] = $temp_tables ? 1 : 0;
- $block_params['display'] = $temp_tables && $modified ? 1 : 0;
- return $this->Application->ParseBlock($block_params);
- }
- else {
- return $temp_tables && $modified ? 1 : 0;
- }
- return ;
- }
-
- /**
- * Allows to detect if this prefix has something in clipboard
- *
- * @param Array $params
- * @return bool
- */
- function HasClipboard($params)
- {
- $clipboard = $this->Application->RecallVar('clipboard');
- if ($clipboard) {
- $clipboard = unserialize($clipboard);
- foreach ($clipboard as $prefix => $clipboard_data) {
- foreach ($clipboard_data as $mode => $ids) {
- if (count($ids)) return 1;
- }
- }
- }
- return 0;
- }
-
- /**
- * Allows to detect if root category being edited
- *
- * @param Array $params
- */
- function IsRootCategory($params)
- {
- $object =& $this->getObject($params);
- return $object->IsRoot();
- }
-
- function CatalogItemCount($params)
- {
- $object =& $this->GetList($params);
- if (!$object->Counted) {
- $object->CountRecs();
- }
- return $object->NoFilterCount != $object->RecordsCount ? $object->RecordsCount.' / '.$object->NoFilterCount : $object->RecordsCount;
- }
-
- /**
- * Print grid pagination using
- * block names specified
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function PrintPages($params)
- {
- if ($this->Application->Parser->GetParam('no_special')) {
- $params['no_special'] = $this->Application->Parser->GetParam('no_special');
- }
- return parent::PrintPages($params);
- }
-
- function InitCatalog($params)
- {
- $tab_prefixes = $this->Application->GetVar('tp'); // {all, , none}
- if ($tab_prefixes === false) $tab_prefixes = 'all';
- $skip_prefixes = isset($params['skip_prefixes']) && $params['skip_prefixes'] ? explode(',', $params['skip_prefixes']) : Array();
-
- // get all prefixes available
- $prefixes = Array();
- foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
- if ($module_data['Var'] == 'm') continue;
- $prefixes[] = $module_data['Var'];
- }
-
- if ($tab_prefixes == 'none') {
- $skip_prefixes = array_unique(array_merge($skip_prefixes, $prefixes));
- }
- elseif ($tab_prefixes != 'all') {
- // prefix list here
- $tab_prefixes = explode(',', $tab_prefixes); // list of prefixes that should stay
- $skip_prefixes = array_unique(array_merge($skip_prefixes, array_diff($prefixes, $tab_prefixes)));
- }
-
- $params['name'] = $params['render_as'];
- $params['skip_prefixes'] = implode(',', $skip_prefixes);
- return $this->Application->ParseBlock($params, 1);
- }
-}
-
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/categories/categories_item.php
===================================================================
diff -u -N
--- trunk/kernel/units/categories/categories_item.php (revision 6093)
+++ trunk/kernel/units/categories/categories_item.php (revision 0)
@@ -1,179 +0,0 @@
-Validate()) return false;
-
- $this->SetDBField('ResourceId', $this->Application->NextResourceId());
- $this->SetDBField('CreatedById', $this->Application->GetVar('u_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') );
- $ret = parent::Create($force_id, $system_create);
- if ($ret) {
- $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s';
- $parent_path = $this->buildParentPath();
- $this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) );
-
- $this->SetDBField('ParentPath', $parent_path);
- }
- return $ret;
-
- }
-
- function Update($id=null, $system_update=false)
- {
- $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 = '|';
- }
- else {
- $cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName');
- $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s';
- $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) );
- }
-
- return $parent_path.$this->GetID().'|';
- }
-
- /**
- * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
- *
- * @param string $string
- * @return string
- */
- function stripDisallowed($string)
- {
- $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
- '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
- '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
-
- $string = str_replace($not_allowed, '_', $string);
- $string = preg_replace('/(_+)/', '_', $string);
- $string = $this->checkAutoFilename($string);
-
- return $string;
- }
-
- function checkFilename()
- {
- if( !$this->GetDBField('AutomaticFilename') )
- {
- $filename = $this->GetDBField('Filename');
- $this->SetDBField('Filename', $this->stripDisallowed($filename) );
- }
- }
-
- function checkAutoFilename($filename)
- {
- if(!$filename) return $filename;
-
- $item_id = !$this->GetID() ? 0 : $this->GetID();
-
- // check temp table
- $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename);
- $found_temp_ids = $this->Conn->GetCol($sql_temp);
-
- // check live table
- $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename);
- $found_live_ids = $this->Conn->GetCol($sql_live);
-
- $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
-
- $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
-
- $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
- if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
- {
- $append = $duplicates_found ? '_a' : '';
- if($has_page)
- {
- $filename = $rets[1].'_'.$rets[2];
- $append = $rets[3] ? $rets[3] : '_a';
- }
-
- // check live & temp table
- $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
- $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
- while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
- $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
- {
- if (substr($append, -1) == 'z') $append .= 'a';
- $append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
- }
-
- return $filename.$append;
- }
-
- return $filename;
- }
-
- /**
- * Generate item's filename based on it's title field value
- *
- * @return string
- */
- function generateFilename()
- {
- if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) return false;
-
- $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- $name = $this->stripDisallowed( $this->GetDBField( $ml_formatter->LangFieldName('Name', true) ) );
-
- if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name);
- }
-
- /**
- * Allows to detect if root category being edited
- *
- * @param Array $params
- */
- function IsRoot()
- {
- $category_id = $this->Application->GetVar($this->getPrefixSpecial().'_id');
- if (is_numeric($category_id) && $category_id == 0) {
- $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()) {
- $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField');
- $category_name = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') );
- $this->SetDBField($title_field, $category_name);
- return false;
- }
- return parent::IsNewItem();
- }
- }
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/categories/cache_updater.php
===================================================================
diff -u -N
--- trunk/kernel/units/categories/cache_updater.php (revision 6093)
+++ trunk/kernel/units/categories/cache_updater.php (revision 0)
@@ -1,371 +0,0 @@
-Stack = Array();
- }
-
- function Push($values)
- {
- array_push($this->Stack, $values);
- }
-
- function Pop()
- {
- if ($this->Count() > 0) {
- return array_pop($this->Stack);
- }
- else {
- return false;
- }
- }
-
- function Get()
- {
- if ($this->Count() > 0) {
-// return end($this->Stack);
- return $this->Stack[count($this->Stack)-1];
- }
- else {
- return false;
- }
- }
-
- function Update($values)
- {
- $this->Stack[count($this->Stack)-1] = $values;
- }
-
- function Count()
- {
- return count($this->Stack);
- }
-}
-
-
-class clsCachedPermissions
-{
- var $Allow = Array();
- var $Deny = Array();
- var $CatId;
-
- function clsCachedPermissions($CatId)
- {
- $this->CatId = $CatId;
- }
-
- function SetCatId($CatId)
- {
- $this->CatId = $CatId;
- }
-
- function CheckPermArray($Perm)
- {
- if (!isset($this->Allow[$Perm])) {
- $this->Allow[$Perm] = array();
- $this->Deny[$Perm] = array();
- }
- }
-
- function AddAllow($Perm, $GroupId)
- {
- $this->CheckPermArray($Perm);
- if (!in_array($GroupId, $this->Allow[$Perm])) {
- array_push($this->Allow[$Perm], $GroupId);
- $this->RemoveDeny($Perm, $GroupId);
- }
- }
-
- function AddDeny($Perm, $GroupId)
- {
- $this->CheckPermArray($Perm);
- if (!in_array($GroupId, $this->Deny[$Perm])) {
- array_push($this->Deny[$Perm], $GroupId);
- $this->RemoveAllow($Perm, $GroupId);
- }
- }
-
- function RemoveDeny($Perm, $GroupId)
- {
- if (in_array($GroupId, $this->Deny[$Perm])) {
- array_splice($this->Deny[$Perm], array_search($GroupId, $this->Deny[$Perm]), 1);
- }
- }
-
- function RemoveAllow($Perm, $GroupId)
- {
- if (in_array($GroupId, $this->Allow[$Perm])) {
- array_splice($this->Allow[$Perm], array_search($GroupId, $this->Allow[$Perm]), 1);
- }
- }
-
- function GetInsertSQL()
- {
- $values = array();
-
- $has_deny = array();
-
- // don't write DACL at all
- /*foreach ($this->Deny as $perm => $groups) {
- if (count($groups) > 0) {
- $values[] = '('.$this->CatId.', '.$perm.', "", "'.join(',', $groups).'")';
- $has_deny[] = $perm;
- }
- }*/
-
- foreach ($this->Allow as $perm => $groups) {
-// if (in_array($perm, $has_deny)) continue;
- if (count($groups) > 0) {
- $values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
- }
- }
- if (!$values) return '';
- $sql = 'INSERT INTO '.TABLE_PREFIX.'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
- return $sql;
- }
-}
-
-class kPermCacheUpdater extends kHelper
-{
- var $Stack;
- var $iteration;
- var $totalCats;
- var $doneCats;
- var $table;
-
- var $primaryLanguageId = 0;
- var $languageCount = 0;
- var $root_prefixes = Array();
-
- function Init($prefix, $special, $event_params = null)
- {
- parent::Init($prefix, $special, $event_params);
-
- $continuing = $event_params['continue'];
-
- // cache widely used values to speed up process: begin
- $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
- $this->languageCount = $ml_helper->getLanguageCount();
- $this->primaryLanguageId = $this->Application->GetDefaultLanguageId();
- // cache widely used values to speed up process: end
-
- foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
- $this->root_prefixes[ $module_info['RootCat'] ] = $module_info['Var'];
- }
-
- $this->iteration = 0;
- $this->table = $this->Application->GetTempName('permCacheUpdate');
-
- if ($continuing == 1) {
- $this->InitUpdater();
- }
- elseif ($continuing == 2) {
- $this->getData();
- }
- }
-
- function InitUpdater()
- {
- $this->Stack =& new clsRecursionStack();
- $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache';
- $this->Conn->Query($sql);
- $this->initData();
- }
-
- function getDonePercent()
- {
- if(!$this->totalCats)return 0;
- return min(100, intval( round( $this->doneCats / $this->totalCats * 100 ) ));
- }
-
- function getData()
- {
- $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->table);
- if ($tmp) $tmp = unserialize($tmp);
-
- $this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0;
- $this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0;
- if (isset($tmp['stack'])) {
- $this->Stack = $tmp['stack'];
- }
- else {
- $this->Stack = & new clsRecursionStack();
- }
- }
-
- function setData()
- {
- $tmp = Array (
- 'totalCats' => $this->totalCats,
- 'doneCats' => $this->doneCats,
- 'stack' => $this->Stack,
- );
-
- $this->Conn->Query('DELETE FROM '.$this->table);
-
- $fields_hash = Array('data' => serialize($tmp));
- $this->Conn->doInsert($fields_hash, $this->table);
- }
-
- function initData()
- {
- $this->clearData(); // drop table before starting anyway
-
- $this->Conn->Query('CREATE TABLE '.$this->table.'(data LONGTEXT)');
-
- $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category');
- $this->doneCats = 0;
- }
-
- function clearData()
- {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$this->table);
- }
-
- function DoTheJob()
- {
- $data = $this->Stack->Get();
- if ($data === false) { //If Stack is empty
- $data['current_id'] = 0;
- $data['titles'] = Array();
- $data['parent_path'] = Array();
- $data['named_path'] = Array();
- $data['category_template'] = '';
- $data['item_template'] = '';
- $this->Stack->Push($data);
- }
-
- if (!isset($data['queried'])) {
- $this->QueryTitle($data);
- $this->QueryChildren($data);
- $this->QueryPermissions($data);
- $data['queried'] = 1;
-
- if ($sql = $data['perms']->GetInsertSQL()) {
- $this->Conn->Query($sql);
- // $this->doneCats++; // moved to the place where it pops out of the stack by Kostja
- }
- $this->iteration++;
- }
-
- // start with first child if we haven't started yet
- if (!isset($data['current_child'])) $data['current_child'] = 0;
-
- // if we have more children
- if (isset($data['children'][$data['current_child']])) {
- $next_data = Array();
- $next_data['titles'] = $data['titles'];
- $next_data['parent_path'] = $data['parent_path'];
- $next_data['named_path'] = $data['named_path'];
- $next_data['category_template'] = $data['category_template'];
- $next_data['item_template'] = $data['item_template'];
- $next_data['current_id'] = $data['children'][ $data['current_child'] ]; //next iteration should process child
- $next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
- $next_data['perms']->SetCatId($next_data['current_id']);
- $data['current_child']++;
- $this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
- $this->Stack->Push($next_data); //next iteration should process this child
- return true;
- }
- else {
- $this->UpdateCachedPath($data);
- $this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none)
- // we are getting here if we finished with current level, so check if it's first level - then bail out.
-
- $this->doneCats++; // moved by Kostja from above, seems to fix the prob
- return $this->Stack->Count() > 0;
- }
- }
-
- function UpdateCachedPath(&$data)
- {
- $fields_hash = Array (
- 'ParentPath' => '|'.implode('|', $data['parent_path']).'|',
- 'NamedParentPath' => implode('/', $data['named_path'] ),
- 'CachedCategoryTemplate' => $data['category_template'],
- );
-
- $i = 1;
- while ($i <= $this->languageCount) {
- $fields_hash['l'.$i.'_CachedNavbar'] = implode('&|&', $data['titles'][$i]);
- $i++;
- }
-
- $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']);
- }
-
- function QueryTitle(&$data)
- {
- $category_id = $data['current_id'];
- $sql = 'SELECT *
- FROM '.TABLE_PREFIX.'Category
- WHERE CategoryId = '.$category_id;
-
- $record = $this->Conn->GetRow($sql);
- if ($record) {
- $i = 1;
- while ($i <= $this->languageCount) {
- $data['titles'][$i][] = $record['l'.$i.'_Name'] ? $record['l'.$i.'_Name'] : $record['l'.$this->primaryLanguageId.'_Name'];
- $i++;
- }
-
- $data['parent_path'][] = $category_id;
- $data['named_path'][] = $record['Filename'];
-
- // it is one of the modules root category
- $root_prefix = isset($this->root_prefixes[$category_id]) ? $this->root_prefixes[$category_id] : false;
- if ($root_prefix) {
- $fields_hash = Array();
- if (!$record['CategoryTemplate']) {
- $record['CategoryTemplate'] = $this->Application->ConfigValue($root_prefix.'_CategoryTemplate');
- $fields_hash['CategoryTemplate'] = $record['CategoryTemplate'];
- }
-
- $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id);
- }
-
- // if explicitly set, then use it; use parent template otherwise
- if ($record['CategoryTemplate']) {
- $data['category_template'] = $record['CategoryTemplate'];
- }
- }
-
- }
-
- function QueryChildren(&$data)
- {
- $sql = 'SELECT CategoryId
- FROM '.TABLE_PREFIX.'Category
- WHERE ParentId = '.$data['current_id'];
- $data['children'] = $this->Conn->GetCol($sql);
- }
-
- function QueryPermissions(&$data)
- {
- // don't search for section "view" permissions here :)
- $sql = 'SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue
- FROM '.TABLE_PREFIX.'Permissions AS ip
- LEFT JOIN '.TABLE_PREFIX.'PermissionConfig AS ipc ON ipc.PermissionName = ip.Permission
- WHERE (CatId = '.$data['current_id'].') AND (Permission LIKE "%.VIEW") AND (ip.Type = 0)';
-
- $records = $this->Conn->Query($sql);
-
- //create permissions array only if we don't have it yet (set by parent)
- if (!isset($data['perms'])) {
- $data['perms'] = new clsCachedPermissions($data['current_id']);
- }
-
- foreach ($records as $record) {
- if ($record['PermissionValue'] == 1) {
- $data['perms']->AddAllow($record['PermissionConfigId'], $record['GroupId']);
- }
- else {
- $data['perms']->AddDeny($record['PermissionConfigId'], $record['GroupId']);
- }
- }
- }
-}
-?>
\ No newline at end of file
Index: trunk/kernel/units/category_items/category_items_config.php
===================================================================
diff -u -N
--- trunk/kernel/units/category_items/category_items_config.php (revision 6093)
+++ trunk/kernel/units/category_items/category_items_config.php (revision 0)
@@ -1,76 +0,0 @@
- 'ci',
- 'ItemClass' => Array('class'=>'CategoryItems_DBItem','file'=>'category_items_dbitem.php','build_event'=>'OnItemBuild'),
- 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
- 'EventHandlerClass' => Array('class'=>'CategoryItemsEventHander','file'=>'category_items_event_handler.php','build_event'=>'OnBuild'),
- 'TagProcessorClass' => Array('class'=>'CategoryItemsTagProcessor','file'=>'category_items_tag_processor.php','build_event'=>'OnBuild'),
- 'AutoLoad' => true,
-
- 'Clones' => Array(
- 'l-ci' => Array('ParentPrefix' => 'l'),
- 'n-ci' => Array('ParentPrefix' => 'n'),
- 'bb-ci' => Array('ParentPrefix' => 'bb'),
- 'p-ci' => Array('ParentPrefix' => 'p'),
- 'cms-ci'=> Array('ParentPrefix' => 'cms',),
- ),
- 'QueryString' => Array(
- 1 => 'id',
- 2 => 'page',
- 3 => 'event',
- ),
- 'IDField' => 'CategoryId', // in this case idfield doesn't exit in destination table
- 'StatusField' => Array('CategoryStatus'), // field, that is affected by Approve/Decline events
-
- 'TableName' => TABLE_PREFIX.'CategoryItems',
- 'ParentTableKey'=> 'ResourceId',
- 'ForeignKey' => 'ItemResourceId',
-// 'ParentPrefix' => 'p',
- 'AutoDelete' => true,
- 'AutoClone' => false,
-
- 'CalculatedFields' => Array(
- '' => Array (
- 'DummyId' => 'IF(ISNULL(c.CategoryId),0,c.CategoryId)',
- 'CategoryStatus'=> 'c.Status',
- )
- ),
- 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s
- FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'Category AS c ON c.CategoryId = %1$s.CategoryId',
- ), // key - special, value - list select sql
- 'ItemSQLs' => Array( ''=>'SELECT * FROM %s',
- ),
- 'ListSortings' => Array(
- '' => Array(
- 'Sorting' => Array('CategoryName' => 'asc'),
- )
- ),
- 'Fields' => Array(
- 'DummyId' => Array(),
- 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0),
- 'ItemResourceId' => Array('not_null' => 1, 'default' => 0),
- 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'ItemPrefix' => Array('type' => 'string','not_null'=>1,'default'=>''),
- 'Filename' => Array('type' => 'string','not_null'=>1,'default'=>''),
- ),
-
- 'VirtualFields' => Array (
- 'CategoryName' => Array(),
- 'DummyId' => Array(),
- 'CategoryStatus' => Array(),
- ),
-
- 'Grids' => Array(
- 'Default' => Array(
- 'Icons' => Array('default' => 'icon16_cat.gif', 0 => 'icon16_cat_disabled.gif', 1 => 'icon16_cat.gif', 2 => 'icon16_cat_pending.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used
- 'Fields' => Array(
- 'CategoryName' => Array( 'title'=>'la_col_Category', 'data_block' => 'grid_checkbox_category_td'),
- ),
-
- ),
- ),
- );
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/category_items/category_items_event_handler.php
===================================================================
diff -u -N
--- trunk/kernel/units/category_items/category_items_event_handler.php (revision 6625)
+++ trunk/kernel/units/category_items/category_items_event_handler.php (revision 0)
@@ -1,127 +0,0 @@
-getObject();
-
- $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- $object->addCalculatedField('CategoryName', 'c.'.$ml_formatter->LangFieldName('CachedNavbar'));
- }
-
- /**
- * Set's new category as primary for product
- *
- * @param kEvent $event
- */
- function OnSetPrimary(&$event)
- {
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $this->StoreSelectedIDs($event);
- $ids=$this->getSelectedIDs($event);
- if($ids)
- {
- $id = array_shift($ids);
- $table_info = $object->getLinkedInfo();
-
- $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
- $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')');
- }
- $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
- }
-
- /**
- * Apply custom processing to item
- *
- * @param kEvent $event
- */
- function customProcessing(&$event, $type)
- {
- if($event->Name == 'OnMassDelete')
- {
- $object =& $event->getObject();
- $table_info = $object->getLinkedInfo();
-
- switch ($type)
- {
- case 'before':
- $ids = $event->getEventParam('ids');
- if($ids)
- {
- $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')');
- $event->setEventParam('ids',$ids);
- }
- break;
-
- // not needed because 'before' does not allow to delete primary cat!
- /*case 'after':
- // set 1st not deleted category as primary
- $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')');
- if(!$has_primary)
- {
- $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
- $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')');
- }
- break;*/
- }
- }
- }
-
- /**
- * Removes primary mark from cloned category items record
- *
- * @param kEvent $event
- */
- function OnAfterClone(&$event)
- {
- $id = $event->getEventParam('id');
- $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
- $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
- $sql = 'UPDATE %s SET PrimaryCat = 0 WHERE %s = %s';
-
- $this->Conn->Query( sprintf($sql, $table, $id_field, $id) );
- }
-
- /**
- * Deletes items of requested type from requested categories.
- * In case if item is deleted from it's last category, then delete item too.
- *
- * @param kEvent $event
- */
- function OnDeleteFromCategory(&$event)
- {
- $category_ids = $event->getEventParam('category_ids');
- if(!$category_ids) return false;
-
- $item_prefix = $event->getEventParam('item_prefix');
- $item =& $this->Application->recallObject($item_prefix.'.-item', null, Array('skip_autoload' => true));
-
- $ci_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
- $item_table = $this->Application->getUnitOption($item_prefix, 'TableName');
-
- $sql = 'SELECT ItemResourceId, CategoryId FROM %1$s INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) WHERE CategoryId IN (%3$s)';
- $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids) ) );
-
- $item_hash = Array();
- foreach($category_items as $ci_row)
- {
- $item_hash[ $ci_row['ItemResourceId'] ][] = $ci_row['CategoryId'];
- }
-
- foreach($item_hash as $item_resource_id => $delete_category_ids)
- {
- $item->Load($item_resource_id, 'ResourceId');
- $item->DeleteFromCategories($delete_category_ids);
- }
- }
-
- }
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/category_items/category_items_dbitem.php
===================================================================
diff -u -N
--- trunk/kernel/units/category_items/category_items_dbitem.php (revision 1566)
+++ trunk/kernel/units/category_items/category_items_dbitem.php (revision 0)
@@ -1,36 +0,0 @@
-getLinkedInfo();
- return '(CategoryId='.$this->ID.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId'].')';
- }
-
- /**
- * Generate and set new temporary id
- *
- * @access private
- */
- function setTempID()
- {
- // don't set temp id for this item
- }
-
- }
-
-
-?>
\ No newline at end of file
Index: trunk/kernel/units/category_items/category_items_tag_processor.php
===================================================================
diff -u -N
--- trunk/kernel/units/category_items/category_items_tag_processor.php (revision 6093)
+++ trunk/kernel/units/category_items/category_items_tag_processor.php (revision 0)
@@ -1,27 +0,0 @@
-Application->ConfigValue('Root_Name');
- $value = str_replace('&|&', ' > ', $this->Field($params));
- $ret = $this->Application->Phrase($root_phrase).( $value ? ' > ' : '').$value;
- if( $this->Field( Array('field'=> 'PrimaryCat') ) == 1 )
- {
- $label = $params['primary_title'];
- $ret .= ' ('.$this->Application->Phrase($label).')';
- }
- return $ret;
- }
-
- function GetMainID()
- {
- $object =& $this->Application->recallObject( $this->getPrefixSpecial() );
- $table_info = $object->getLinkedInfo();
- return $table_info['ParentId'];
- }
- }
-
-
-?>
\ No newline at end of file