Index: branches/5.1.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r12657 -r13086 --- branches/5.1.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 12657) +++ branches/5.1.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 13086) @@ -1,6 +1,6 @@ Application->IsAdmin()) { + if (!$this->Application->isAdmin) { if ($event->Name == 'OnSetSortingDirect') { // allow sorting on front event without view permission return true; @@ -254,6 +254,7 @@ function OnPaste(&$event) { if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) || !$this->_checkPastePermission($event)) { + $event->status = erFAIL; return; } @@ -291,6 +292,7 @@ function OnMassDelete(&$event) { if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + $event->status = erFAIL; return; } @@ -379,29 +381,26 @@ $type_clauses['displayed']['having_filter'] = false; if (in_array('search', $types) || in_array('search', $except_types)) { - $event_mapping = Array( - 'simple' => 'OnSimpleSearch', - 'subsearch' => 'OnSubSearch', - 'advanced' => 'OnAdvancedSearch'); - if($this->Application->GetVar('INPORTAL_ON') && $this->Application->GetVar('Action') == 'm_simple_subsearch') - { - $type = 'subsearch'; - } - else - { - $type = $this->Application->GetVar('search_type') ? $this->Application->GetVar('search_type') : 'simple'; - } + $event_mapping = Array ( + 'simple' => 'OnSimpleSearch', + 'subsearch' => 'OnSubSearch', + 'advanced' => 'OnAdvancedSearch' + ); - if($keywords = $event->getEventParam('keyword_string')) // processing keyword_string param of ListProducts tag - { + $type = $this->Application->GetVar('search_type', 'simple'); + + if ($keywords = $event->getEventParam('keyword_string')) { + // processing keyword_string param of ListProducts tag $this->Application->SetVar('keywords', $keywords); $type = 'simple'; } + $search_event = $event_mapping[$type]; $this->$search_event($event); $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; + if ($this->Conn->Query($sql)) { $search_res_ids = $this->Conn->GetCol('SELECT ResourceId FROM '.$search_table); } @@ -414,6 +413,7 @@ $type_clauses['search']['include'] = '0'; $type_clauses['search']['except'] = '1'; } + $type_clauses['search']['having_filter'] = false; } @@ -675,7 +675,7 @@ } } - /*if ( !$this->Application->IsAdmin() ) { + /*if (!$this->Application->isAdminUser) { $object->addFilter('expire_filter', '%1$s.Expire IS NULL OR %1$s.Expire > UNIX_TIMESTAMP()'); }*/ @@ -724,7 +724,7 @@ // Link1 (before modifications) [Status = 1, OrgId = NULL], Link2 (after modifications) [Status = -2, OrgId = Link1_ID] $pending_editing = $this->Application->getUnitOption($object->Prefix, 'UsePendingEditing'); - if ( !$this->Application->IsAdmin() ) { + if (!$this->Application->isAdminUser) { $types = explode(',', $types); if (in_array('my_items', $types)) { $allow_statuses = Array (STATUS_ACTIVE, STATUS_PENDING, STATUS_PENDING_EDITING); @@ -866,15 +866,15 @@ { parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); + /* @var $object kCatDBItem */ + // update hits field $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); 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) && + if( $this->Application->isAdminUser && ($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').' @@ -955,7 +955,7 @@ $this->setCustomExportColumns($event); } - if (!$this->Application->IsAdmin()) { + if (!$this->Application->isAdminUser) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -989,7 +989,7 @@ $this->setCustomExportColumns($event); } - if (!$this->Application->IsAdmin()) { + if (!$this->Application->isAdminUser) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -1037,19 +1037,13 @@ } /** - * Makes simple search for products + * Makes simple search for category items * based on keywords string * * @param kEvent $event - * @todo Change all hardcoded Products table & In-Commerce module usage to dynamic usage from item config !!! */ function OnSimpleSearch(&$event) { - if($this->Application->GetVar('INPORTAL_ON') && !($this->Application->GetVar('Action') == 'm_simple_search')) - { - return; - } - $event->redirect = false; $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; @@ -1072,12 +1066,8 @@ } $this->Application->StoreVar('keywords', $keywords); - if (!$this->Application->GetVar('INPORTAL_ON')) { - // don't save search log, because in-portal already saved it - $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search - } - $keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_')); + $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search $event->setPseudoClass('_List'); @@ -1227,17 +1217,8 @@ $where_clause = $where_clause.' AND '.$items_table.'.Status=1'; - if($this->Application->GetVar('Action') == 'm_simple_subsearch') // subsearch, In-portal - { - if( $event->getEventParam('ResultIds') ) - { - $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->specificParams['ResultIds']).')'; - } - } - if( $event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild' ) // subsearch, k4 - { - if( $event->MasterEvent->getEventParam('ResultIds') ) - { + if ($event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild') { + if ($event->MasterEvent->getEventParam('ResultIds')) { $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; } } @@ -1249,7 +1230,8 @@ reset($search_config); foreach ($positive_words as $keyword_index => $positive_word) { - $positive_words[$keyword_index] = mysql_real_escape_string($positive_word); + $positive_word = $search_helper->transformWildcards($positive_word); + $positive_words[$keyword_index] = $this->Conn->escape($positive_word); } foreach ($field_list as $field) { @@ -1268,6 +1250,9 @@ $revelance_parts[] = 'IF('.$field.' LIKE "%'.$keyword.'%", '.$weight.', 0)'; } } + + $revelance_parts = array_unique($revelance_parts); + $conf_postfix = $this->Application->getUnitOption($event->Prefix, 'SearchConfigPostfix'); $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_'.$conf_postfix) / 100; $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_'.$conf_postfix) / 100; @@ -1281,7 +1266,7 @@ } // building final search query - if (!$this->Application->GetVar('do_not_drop_search_table') && !$this->Application->GetVar('INPORTAL_ON')) { + if (!$this->Application->GetVar('do_not_drop_search_table')) { $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event $this->Application->SetVar('do_not_drop_search_table', true); } @@ -2199,7 +2184,8 @@ */ function OnBeforeItemCreate(&$event) { - if ($this->Application->IsAdmin()) { + if ($this->Application->isAdminUser) { + // don't set permission-based status, when creating categories in admin return true; } @@ -2261,6 +2247,11 @@ */ function processAdditionalCategories(&$object, $mode) { + if (!array_key_exists('MoreCategories', $object->VirtualFields)) { + // given category item doesn't require such type of processing + return ; + } + $process_categories = $object->GetDBField('MoreCategories'); if ($process_categories === '') { // field was not in submit & have default value (when no categories submitted, then value is null) @@ -2294,7 +2285,7 @@ function OnUpdate(&$event) { $use_pending = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($this->Application->IsAdmin() || !$use_pending) { + if ($this->Application->isAdminUser || !$use_pending) { parent::OnUpdate($event); $this->SetFrontRedirectTemplate($event, 'modify'); return ; @@ -2386,7 +2377,7 @@ */ function SetFrontRedirectTemplate(&$event, $template_key) { - if ($this->Application->IsAdmin() || $event->status != erSUCCESS) { + if ($this->Application->isAdminUser || $event->status != erSUCCESS) { return ; } @@ -2430,6 +2421,7 @@ } if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + $event->status = erFAIL; return; } @@ -2470,7 +2462,7 @@ { parent::OnDelete($event); - if ($event->status == erSUCCESS && !$this->Application->IsAdmin()) { + if ($event->status == erSUCCESS && !$this->Application->isAdmin) { $event->SetRedirectParam('pass', 'm'); $event->SetRedirectParam('m_cat_id', 0); } @@ -2512,7 +2504,7 @@ */ function SetSorting(&$event) { - if (!$this->Application->IsAdmin()) { + if (!$this->Application->isAdmin) { $event->setEventParam('same_special', true); } @@ -2527,7 +2519,7 @@ */ function getPerPage(&$event) { - if (!$this->Application->IsAdmin()) { + if (!$this->Application->isAdmin) { $event->setEventParam('same_special', true); }