Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -r3282 -r3299 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3282) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3299) @@ -109,7 +109,7 @@ function OnPreSaveAndOpenTranslator(&$event) { $this->Application->SetVar('allow_translation', true); - $object =& $event->getObject(); + $object =& $event->getObject(); $this->RemoveRequiredFields($object); $event->CallSubEvent('OnPreSave'); if ($event->status == erSUCCESS) { @@ -127,27 +127,29 @@ } $this->Application->SetVar('cv_id', $cv->getID() ); } - + $event->redirect = $this->Application->GetVar('translator_t'); - $event->redirect_params = Array('pass'=>'all,trans,'.$this->Application->GetVar('translator_prefixes'), + $event->redirect_params = Array('pass'=>'all,trans,'.$this->Application->GetVar('translator_prefixes'), $event->getPrefixSpecial(true).'_id' => $object->GetId(), 'trans_event'=>'OnLoad', 'trans_prefix'=> $this->Application->GetVar('translator_prefixes'), 'trans_field'=>$this->Application->GetVar('translator_field'), + 'trans_multi_line'=>$this->Application->GetVar('translator_multi_line'), ); - // 1. SAVE LAST TEMPLATE TO SESSION + // 1. SAVE LAST TEMPLATE TO SESSION $last_template = $this->Application->RecallVar('last_template'); preg_match('/index4\.php\|'.$this->Application->GetSID().'-(.*):/U', $last_template, $rets); - $this->Application->StoreVar('return_template', $rets[1]); - +// $this->Application->StoreVar('return_template', $rets[1]); + $this->Application->StoreVar('return_template', $this->Application->GetVar('t')); + //$after_script = "openTranslator('".$event->getPrefixSpecial()."', '".$field."', '".$url."', '".$wnd_name."')"; } - + // $this->Application->SetVar('after_script', $after_script); -// $event->redirect = false; +// $event->redirect = false; } - + /** * Apply scope clause * @@ -188,7 +190,7 @@ $view_perm = 1; $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); - + if ( !$this->Application->IsAdmin() ) { $groups = explode( ',', $this->Application->RecallVar('UserGroups') ); @@ -228,7 +230,7 @@ break; } */ } - + /** * Adds calculates fields for item statuses * @@ -237,9 +239,9 @@ */ function PrepareObject(&$object, &$event) { - + $property_mappings = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - + $new_days_var = getArrayValue($property_mappings, 'NewDays'); if($new_days_var) { @@ -250,7 +252,7 @@ %1$s.NewItem )'); } - + $hot_limit_var = getArrayValue($property_mappings, 'HotLimit'); if($hot_limit_var) { @@ -262,10 +264,10 @@ %1$s.HotItem )'); } - + $votes2pop_var = getArrayValue($property_mappings, 'VotesToPop'); $rating2pop_var = getArrayValue($property_mappings, 'RatingToPop'); - + if($votes2pop_var && $rating2pop_var) { $object->addCalculatedField('IsPop', ' IF(%1$s.PopItem = 2, @@ -277,13 +279,13 @@ %1$s.PopItem)'); } } - + function CalculateHotLimit(&$event) { $property_mappings = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); $hot_count_var = getArrayValue($property_mappings, 'HotCount'); $hot_limit_var = getArrayValue($property_mappings, 'HotLimit'); - + if($hot_count_var && $hot_limit_var) { $last_hot = $this->Application->ConfigValue($hot_count_var) - 1; @@ -297,7 +299,7 @@ } return 0; } - + /** * Enter description here... * @@ -315,38 +317,38 @@ $object->SetDBField('Hits', $hits); } } - + function OnAfterItemUpdate(&$event) { $this->CalculateHotLimit($event); } - + /** - * Makes simple search for products + * Makes simple search for products * 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'; - + $keywords = trim($this->Application->GetVar('keywords')); if( !$this->Application->GetVar('INPORTAL_ON') ) { $keywords = unhtmlentities($keywords); } - + $query_object =& $this->Application->recallObject('HTTPQuery'); $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; - + if(!isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql)) @@ -358,68 +360,68 @@ $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); $this->Application->SetVar('keywords_too_short', 1); return; // if no or too short keyword entered, doing nothing - } - + } + $this->Application->StoreVar('keywords', $keywords); - + $keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_')); - + $event->setPseudoClass('_List'); $object =& $event->getObject(); $this->Application->SetVar($event->getPrefixSpecial().'_Page', 1); $lang = $this->Application->GetVar('m_lang'); $product_table = $this->Application->getUnitOption('p', 'TableName'); - + $sql = ' SELECT * FROM '.$this->Application->getUnitOption('confs', 'TableName').' WHERE ModuleName="In-Commerce" AND SimpleSearch=1'; - $search_config = $this->Conn->Query($sql, 'FieldName'); + $search_config = $this->Conn->Query($sql, 'FieldName'); $field_list = array_keys($search_config); - + $join_clauses = Array(); - + // field processing $weight_sum = 0; foreach($field_list as $key => $field) { $options = $object->getFieldOptions($field); $local_table = TABLE_PREFIX.$search_config[$field]['TableName']; $weight_sum += $search_config[$field]['Priority']; // counting weight sum; used when making relevance clause - + // processing multilingual fields if($options['formatter'] == 'kMultiLanguage') { $field_list[$key] = 'l'.$lang.'_'.$field; } - + // processing fields from other tables if($foreign_field = $search_config[$field]['ForeignField']) - { + { $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { unset($field_list[$key]); continue; // ignoring having type clauses in simple search /*$user_object =& $this->Application->recallObject('u'); $user_groups = $user_object->GetDBField('PortalUserId') ? - implode(',', $this->Conn->GetCol(' SELECT GroupId + implode(',', $this->Conn->GetCol(' SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; $having_list[$key] = str_replace('{PREFIX}', TABLE_PREFIX, $exploded[1]); $join_clause = str_replace('{PREFIX}', TABLE_PREFIX, $search_config[$field]['JoinClause']); $join_clause = str_replace('{USER_GROUPS}', $user_groups, $join_clause); $join_clause = ' LEFT JOIN '.$join_clause; $join_clauses[] = $join_clause;*/ } - else + else { $exploded = explode('.', $foreign_field); $foreign_table = TABLE_PREFIX.$exploded[0]; - + $alias_counter++; $alias = 't'.$alias_counter; - - $field_list[$key] = $alias.'.'.$exploded[1]; + + $field_list[$key] = $alias.'.'.$exploded[1]; $join_clause = str_replace('{ForeignTable}', $alias, $search_config[$field]['JoinClause']); $join_clause = str_replace('{LocalTable}', $product_table, $join_clause); if($search_config[$field]['CustomFieldId']) @@ -430,18 +432,18 @@ ON '.$join_clause; } } - else + else { // processing fields from local table $field_list[$key] = $local_table.'.'.$field_list[$key]; } } - - // keyword string processing + + // keyword string processing $normal_keywords = Array(); $plus_keywords = Array(); - $minus_keywords = Array(); - + $minus_keywords = Array(); + for($i = 0; $i < strlen($keywords); $i++) { if(substr($keywords, $i, 1) == ' ') continue; @@ -455,7 +457,7 @@ $keyword_end = strpos($keywords, '"', $i + 2); $extra_skip = 2; } - else + else { $keyword_start = $i + 1; $keyword_end = strpos($keywords, ' ', $i + 1); @@ -470,7 +472,7 @@ $keyword_end = strpos($keywords, '"', $i + 2); $extra_skip = 2; } - else + else { $keyword_start = $i + 1; $keyword_end = strpos($keywords, ' ', $i + 1); @@ -487,24 +489,24 @@ default: $keyword_start = $i; $keyword_end = strpos($keywords, ' ', $i + 1); - $target_array =& $normal_keywords; + $target_array =& $normal_keywords; } - + if($keyword_end === false) { $keyword_end = strlen($keywords); } $keyword_length = $keyword_end - $keyword_start; $keyword = substr($keywords, $keyword_start, $keyword_length); - - if(strlen($keyword) >= $this->Application->ConfigValue('Search_MinKeyword_Length')) + + if(strlen($keyword) >= $this->Application->ConfigValue('Search_MinKeyword_Length')) { $target_array[] = addcslashes($keyword, '"'); } - + $i += $keyword_length + $extra_skip; } - + // preparing conditions $normal_conditions = Array(); $plus_conditions = Array(); @@ -522,16 +524,16 @@ foreach($field_list as $field) { $condition[] = $field.' NOT LIKE "%'.$keyword.'%" OR '.$field.' IS NULL'; - } + } $minus_conditions[] = '('.implode(') AND (', $condition).')'; } - + // building where clause if($normal_conditions) { $where_clause = '('.implode(') OR (', $normal_conditions).')'; } - else + else { $where_clause = '1'; } @@ -546,7 +548,7 @@ $where_clause = $where_clause.' AND '.$product_table.'.Status=1'; if($this->Application->GetVar('Action') == 'm_simple_subsearch') // subsearch, In-portal - { + { if( $event->getEventParam('ResultIds') ) { $where_clause .= ' AND '.$product_table.'.ResourceId IN ('.implode(',', $event->specificParams['ResultIds']).')'; @@ -559,17 +561,17 @@ $where_clause .= ' AND '.$product_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; } } - + // building having clause - - + + // making relevance clause $positive_words = array_merge($normal_keywords, $plus_keywords); $this->Application->StoreVar('highlight_keywords', serialize($positive_words)); $revelance_parts = Array(); reset($search_config); foreach($field_list as $field) - { + { $config_elem = each($search_config); $weight = $search_config[$field]['Priority']; $revelance_parts[] = 'IF('.$field.' LIKE "%'.implode(' ', $positive_words).'%", '.$weight_sum.', 0)'; @@ -580,39 +582,39 @@ } $rel_keywords = $this->Application->ConfigValue('SearchRel_DefaultKeyword_products') / 100; $rel_pop = $this->Application->ConfigValue('SearchRel_DefaultPop_products') / 100; - $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; + $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; $relevance_clause = '('.implode(' + ', $revelance_parts).') / '.$weight_sum.' * '.$rel_keywords; $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; - - // building final search query + + // building final search query if( !$this->Application->GetVar('INPORTAL_ON') ) { $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event } - + if($this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"')) { $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; } - else - { + else + { $select_intro = 'CREATE TABLE '.$search_table.' AS '; } - + $sql = $select_intro.' SELECT '.$relevance_clause.' AS Relevance, '.$product_table.'.ProductId AS ItemId, '.$product_table.'.ResourceId, 11 AS ItemType, '.$product_table.'.EditorsPick AS EdPick - FROM '.$object->TableName.' + FROM '.$object->TableName.' '.implode(' ', $join_clauses).' WHERE '.$where_clause.' GROUP BY '.$product_table.'.ProductId'; - - $res = $this->Conn->Query($sql); + + $res = $this->Conn->Query($sql); } - + /** * Enter description here... * @@ -630,7 +632,7 @@ $event->setEventParam('ResultIds', $ids); $event->CallSubEvent('OnSimpleSearch'); } - + /** * Enter description here... * @@ -644,10 +646,10 @@ { return; // used when navigating by pages or changing sorting in search results } - + $this->Application->RemoveVar('keywords'); $this->Application->RemoveVar('Search_Keywords'); - + $sql = ' SELECT * FROM '.$this->Application->getUnitOption('confs', 'TableName').' WHERE ModuleName="In-Commerce" AND AdvancedSearch=1'; @@ -657,40 +659,40 @@ $object->SetPage(1); $user_object =& $this->Application->recallObject('u'); $product_table = $this->Application->getUnitOption('p', 'TableName'); - + $keywords = $this->Application->GetVar('value'); $verbs = $this->Application->GetVar('verb'); $glues = $this->Application->GetVar('andor'); - + $and_conditions = Array(); $or_conditions = Array(); $and_having_conditions = Array(); $or_having_conditions = Array(); $join_clauses = Array(); $highlight_keywords = Array(); $relevance_parts = Array(); - + $condition_patterns = Array( 'any' => '%s LIKE %s', 'contains' => '%s LIKE %s', 'notcontains' => '(NOT (%1$s LIKE %2$s) OR %1$s IS NULL)', 'is' => '%s = %s', 'isnot' => '(%1$s != %2$s OR %1$s IS NULL)'); - + $alias_counter = 0; $weight_sum = 0; // processing fields and preparing conditions foreach($search_config as $record) { $field = $record['FieldName']; - $join_clause = ''; + $join_clause = ''; $condition_mode = 'WHERE'; - - // field processing - + + // field processing + $options = $object->getFieldOptions($field); $local_table = TABLE_PREFIX.$record['TableName']; $weight_sum += $record['Priority']; // counting weight sum; used when making relevance clause - + // processing multilingual fields if($options['formatter'] == 'kMultiLanguage') { @@ -700,36 +702,36 @@ { $field_name = $field; } - + // processing fields from other tables if($foreign_field = $record['ForeignField']) { $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { $user_groups = $user_object->GetDBField('PortalUserId') ? - implode(',', $this->Conn->GetCol(' SELECT GroupId + implode(',', $this->Conn->GetCol(' SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; $field_name = str_replace('{PREFIX}', TABLE_PREFIX, $exploded[1]); $join_clause = str_replace('{PREFIX}', TABLE_PREFIX, $record['JoinClause']); $join_clause = str_replace('{USER_GROUPS}', $user_groups, $join_clause); $join_clause = ' LEFT JOIN '.$join_clause; - + $condition_mode = 'HAVING'; } - else + else { $exploded = explode('.', $foreign_field); $foreign_table = TABLE_PREFIX.$exploded[0]; - + $alias_counter++; $alias = 't'.$alias_counter; - + $field_name = $alias.'.'.$exploded[1]; $join_clause = str_replace('{ForeignTable}', $alias, $record['JoinClause']); $join_clause = str_replace('{LocalTable}', $product_table, $join_clause); - + if($record['CustomFieldId']) { $join_clause .= ' AND '.$alias.'.CustomFieldId='.$record['CustomFieldId']; @@ -743,7 +745,7 @@ // processing fields from local table $field_name = $local_table.'.'.$field_name; } - + $condition = ''; switch($record['FieldType']) { @@ -752,7 +754,7 @@ { $keywords[$field] = unhtmlentities( $keywords[$field] ); } - + if(strlen($keywords[$field]) >= $this->Application->ConfigValue('Search_MinKeyword_Length')) { $highlight_keywords[] = $keywords[$field]; @@ -808,7 +810,7 @@ case 'EditorsPick': $condition = $product_table.'.EditorsPick = '.$keywords[$field]; break; - } + } } break; case 'range': @@ -836,7 +838,7 @@ $time_mapping = Array('today' => $day_begin, 'yesterday' => ($day_begin - 86400)); $min_time = $time_mapping[$keywords[$field]]; } - else + else { $time_mapping = Array( 'last_week' => 604800, 'last_month' => 2628000, 'last_3_months' => 7884000, 'last_6_months' => 15768000, @@ -848,7 +850,7 @@ } break; } - + if($condition) { if($join_clause) @@ -880,32 +882,32 @@ } } } - + $this->Application->StoreVar('highlight_keywords', serialize($highlight_keywords)); - - // making relevance clause + + // making relevance clause if($relevance_parts) { $rel_keywords = $this->Application->ConfigValue('SearchRel_DefaultKeyword_products') / 100; $rel_pop = $this->Application->ConfigValue('SearchRel_DefaultPop_products') / 100; - $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; + $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; $relevance_clause = '('.implode(' + ', $relevance_parts).') / '.$weight_sum.' * '.$rel_keywords; $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; } - else + else { $relevance_clause = '0'; } - + // building having clause if($or_having_conditions) { $and_having_conditions[] = '('.implode(' OR ', $or_having_conditions).')'; } $having_clause = implode(' AND ', $and_having_conditions); $having_clause = $having_clause ? ' HAVING '.$having_clause : ''; - + // building where clause if($or_conditions) { @@ -919,34 +921,34 @@ { $where_clause = '1'; } - else + else { $where_clause = '0'; $this->Application->SetVar('adv_search_error', 1); } } $where_clause .= ' AND '.$product_table.'.Status = 1'; - + // building final search query $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - + $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); - + $sql = ' CREATE TABLE '.$search_table.' SELECT '.$relevance_clause.' AS Relevance, '.$product_table.'.ProductId AS ItemId, '.$product_table.'.ResourceId AS ResourceId, 11 AS ItemType, '.$product_table.'.EditorsPick AS EdPick - FROM '.$product_table.' + FROM '.$product_table.' '.implode(' ', $join_clauses).' WHERE '.$where_clause.' GROUP BY '.$product_table.'.ProductId'. $having_clause; - + $res = $this->Conn->Query($sql); } - + /** * Set's correct page for list * based on data provided with event @@ -959,17 +961,17 @@ { // get PerPage (forced -> session -> config -> 10) $per_page = $this->getPerPage($event); - + $object =& $event->getObject(); $object->SetPerPage($per_page); $this->Application->StoreVarDefault($event->getPrefixSpecial().'_Page', 1); - + $page = $this->Application->GetVar($event->getPrefixSpecial().'_Page'); if (!$page) { $page = $this->Application->GetVar($event->getPrefixSpecial(true).'_Page'); } - + if (!$page) { if( $this->Application->RewriteURLs() ) @@ -989,7 +991,7 @@ else { $this->Application->StoreVar($event->getPrefixSpecial().'_Page', $page); } - + // $page = $this->Application->GetLinkedVar($event->getPrefixSpecial(true).'_Page', $event->getPrefixSpecial().'_Page'); if( !$event->getEventParam('skip_counting') ) { @@ -1000,7 +1002,7 @@ $page = 1; } } - + $object->SetPage($page); }