Index: trunk/kernel/include/advsearch.php =================================================================== diff -u -N -r4084 -r4231 --- trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 4084) +++ trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 4231) @@ -17,6 +17,8 @@ var $PctPop; var $PctRating; + var $SearchLogRecord = Array(); + function clsAdvancedSearchResults($SearchSource,$DataClass, $ItemType = 0) { global $objConfig, $objSearchConfig; @@ -95,6 +97,8 @@ static $x = 0, $customs_joined = Array(); +// echo 'Adding ADVANCED SearchField: ['.$TableName.']; ['.$FieldName.']; ['.$Verb.']; ['.$Value.']; ['.$conj.']
'; + if(!is_object($objSearchConfig)) $objSearchConfig = new clsSeachConfigList(); @@ -127,12 +131,10 @@ $this->AddRelationship($Table.' AS '.$pseudo, $join); // for items that does not have appropriate records in CustomMetaData table - if ($Verb == 'notcontains' || $Verb == 'isnot') - { + if ($Verb == 'notcontains' || $Verb == 'isnot') { $or_not_null = ' OR '.$pseudo.'.'.$Field.' IS NULL'; } - else - { + else { $or_not_null = ''; } @@ -142,8 +144,7 @@ $FieldItem["conjuction"] = $conj; $FieldItem["weight"] = $FieldConfig->Get("Priority"); } - else - { + else { $classes = Array( 'Link' => '_clsLinkList', 'News' => '_clsNewsList', 'Topic' => '_clsTopicList', @@ -158,8 +159,7 @@ $FieldConfig->Set('FieldName', $ml_formatter->LangFieldName('cust_'.$FieldConfig->Get('CustomFieldId'))); } - switch ($FieldName) - { + switch ($FieldName) { case 'HotItem': $cutoff = $objList->GetHotValue(); $Value == 1 ? $not = '' : $not = 'NOT '; @@ -214,11 +214,19 @@ } $this->FieldList[] = $FieldItem; + + // create search record + $this->SearchLogRecord[] = language('la_Field').' "'.$FieldConfig->getHumanField().'" '.$FieldConfig->getHumanVerb($Verb).' '.language('la_Value').' "'.$FieldConfig->getHumanValue($Value).'" '.language('lu_'.$conj); + unset($FieldItem); } - + function getKeywords(&$FieldConfig) + { + $ret = implode('
', $this->SearchLogRecord); + return preg_replace('/(.*) '.preg_quote(language('lu_and'), '/').'|'.preg_quote(language('lu_or'), '/').'$/is', '\\1', $ret); + } /* function AddAdvancedCustomFields() { @@ -284,6 +292,10 @@ static $SelectSQL, $OldItemType; global $objSession, $objItemTypes; + // add recrod to log + $objSearchList = new clsSearchLogList(); + $objSearchList->UpdateKeyword($this->getKeywords(), 1); + $ctype = $objItemTypes->GetItem($ItemType); $idField = $ctype->Get("SourceTable")."Id"; $this->SourceTable = AddTablePrefix($ctype->Get("SourceTable")); Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N -r4228 -r4231 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4228) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4231) @@ -689,10 +689,7 @@ 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 - FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + $user_groups = $this->Application->RecallVar('UserGroups'); $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); @@ -839,7 +836,9 @@ $user_object =& $this->Application->recallObject('u'); $product_table = $this->Application->getUnitOption('p', 'TableName'); - $keywords = $this->Application->GetVar('value'); + $search_keywords = $this->Application->GetVar('value'); // will not be changed + + $keywords = $this->Application->GetVar('value'); // will be changed down there $verbs = $this->Application->GetVar('verb'); $glues = $this->Application->GetVar('andor'); @@ -865,6 +864,7 @@ $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; } + $search_log = ''; $weight_sum = 0; // processing fields and preparing conditions foreach($search_config as $record) @@ -892,10 +892,7 @@ $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { - $user_groups = $user_object->GetDBField('PortalUserId') ? - implode(',', $this->Conn->GetCol(' SELECT GroupId - FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + $user_groups = $this->Application->RecallVar('UserGroups'); $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); @@ -1071,8 +1068,16 @@ $or_having_conditions[] = $condition; } } + + // create search log record + $search_log_data = Array('search_config' => $record, 'verb' => getArrayValue($verbs, $field), 'value' => ($record['FieldType'] == 'range') ? $search_keywords[$field.'_from'].'|'.$search_keywords[$field.'_to'] : $search_keywords[$field]); + $search_log[] = $this->Application->Phrase('la_Field').' "'.$this->getHuman('Field', $search_log_data).'" '.$this->getHuman('Verb', $search_log_data).' '.$this->Application->Phrase('la_Value').' '.$this->getHuman('Value', $search_log_data).' '.$this->Application->Phrase($glues[$field] == 1 ? 'lu_And' : 'lu_Or'); } } + + $search_log = implode('
', $search_log); + $search_log = preg_replace('/(.*) '.preg_quote($this->Application->Phrase('lu_and'), '/').'|'.preg_quote($this->Application->Phrase('lu_or'), '/').'$/is', '\\1', $search_log); + $this->saveToSearchLog($search_log, 1); // advanced search $this->Application->StoreVar('highlight_keywords', serialize($highlight_keywords)); @@ -1140,6 +1145,53 @@ $res = $this->Conn->Query($sql); } + + function getHuman($type, $search_data) + { + $type = ucfirst(strtolower($type)); + extract($search_data); + + switch ($type) { + case 'Field': + return $this->Application->Phrase($search_config['DisplayName']); + break; + + case 'Verb': + return $verb ? $this->Application->Phrase('lu_advsearch_'.$verb) : ''; + break; + + case 'Value': + switch ($search_config['FieldType']) { + case 'date': + $values = Array(0 => 'lu_comm_Any', 'today' => 'lu_comm_Today', + 'yesterday' => 'lu_comm_Yesterday', 'last_week' => 'lu_comm_LastWeek', + 'last_month' => 'lu_comm_LastMonth', 'last_3_months' => 'lu_comm_Last3Months', + 'last_6_months' => 'lu_comm_Last6Months', 'last_year' => 'lu_comm_LastYear'); + $ret = $this->Application->Phrase($values[$value]); + break; + + case 'range': + $value = explode('|', $value); + return $this->Application->Phrase('lu_comm_From').' "'.$value[0].'" '.$this->Application->Phrase('lu_comm_To').' "'.$value[1].'"'; + break; + + case 'boolean': + $values = Array(1 => 'lu_comm_Yes', 0 => 'lu_comm_No', -1 => 'lu_comm_Both'); + $ret = $this->Application->Phrase($values[$value]); + break; + + case 'text': + $ret = $value; + break; + + } + return '"'.$ret.'"'; + break; + } + } + + + /** * Set's correct page for list * based on data provided with event Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r4228 -r4231 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4228) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4231) @@ -689,10 +689,7 @@ 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 - FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + $user_groups = $this->Application->RecallVar('UserGroups'); $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); @@ -839,7 +836,9 @@ $user_object =& $this->Application->recallObject('u'); $product_table = $this->Application->getUnitOption('p', 'TableName'); - $keywords = $this->Application->GetVar('value'); + $search_keywords = $this->Application->GetVar('value'); // will not be changed + + $keywords = $this->Application->GetVar('value'); // will be changed down there $verbs = $this->Application->GetVar('verb'); $glues = $this->Application->GetVar('andor'); @@ -865,6 +864,7 @@ $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; } + $search_log = ''; $weight_sum = 0; // processing fields and preparing conditions foreach($search_config as $record) @@ -892,10 +892,7 @@ $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { - $user_groups = $user_object->GetDBField('PortalUserId') ? - implode(',', $this->Conn->GetCol(' SELECT GroupId - FROM '.TABLE_PREFIX.'UserGroup - WHERE PortalUserId='.$user_object->GetDBField('PortalUserId'))) : 0; + $user_groups = $this->Application->RecallVar('UserGroups'); $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); @@ -1071,8 +1068,16 @@ $or_having_conditions[] = $condition; } } + + // create search log record + $search_log_data = Array('search_config' => $record, 'verb' => getArrayValue($verbs, $field), 'value' => ($record['FieldType'] == 'range') ? $search_keywords[$field.'_from'].'|'.$search_keywords[$field.'_to'] : $search_keywords[$field]); + $search_log[] = $this->Application->Phrase('la_Field').' "'.$this->getHuman('Field', $search_log_data).'" '.$this->getHuman('Verb', $search_log_data).' '.$this->Application->Phrase('la_Value').' '.$this->getHuman('Value', $search_log_data).' '.$this->Application->Phrase($glues[$field] == 1 ? 'lu_And' : 'lu_Or'); } } + + $search_log = implode('
', $search_log); + $search_log = preg_replace('/(.*) '.preg_quote($this->Application->Phrase('lu_and'), '/').'|'.preg_quote($this->Application->Phrase('lu_or'), '/').'$/is', '\\1', $search_log); + $this->saveToSearchLog($search_log, 1); // advanced search $this->Application->StoreVar('highlight_keywords', serialize($highlight_keywords)); @@ -1140,6 +1145,53 @@ $res = $this->Conn->Query($sql); } + + function getHuman($type, $search_data) + { + $type = ucfirst(strtolower($type)); + extract($search_data); + + switch ($type) { + case 'Field': + return $this->Application->Phrase($search_config['DisplayName']); + break; + + case 'Verb': + return $verb ? $this->Application->Phrase('lu_advsearch_'.$verb) : ''; + break; + + case 'Value': + switch ($search_config['FieldType']) { + case 'date': + $values = Array(0 => 'lu_comm_Any', 'today' => 'lu_comm_Today', + 'yesterday' => 'lu_comm_Yesterday', 'last_week' => 'lu_comm_LastWeek', + 'last_month' => 'lu_comm_LastMonth', 'last_3_months' => 'lu_comm_Last3Months', + 'last_6_months' => 'lu_comm_Last6Months', 'last_year' => 'lu_comm_LastYear'); + $ret = $this->Application->Phrase($values[$value]); + break; + + case 'range': + $value = explode('|', $value); + return $this->Application->Phrase('lu_comm_From').' "'.$value[0].'" '.$this->Application->Phrase('lu_comm_To').' "'.$value[1].'"'; + break; + + case 'boolean': + $values = Array(1 => 'lu_comm_Yes', 0 => 'lu_comm_No', -1 => 'lu_comm_Both'); + $ret = $this->Application->Phrase($values[$value]); + break; + + case 'text': + $ret = $value; + break; + + } + return '"'.$ret.'"'; + break; + } + } + + + /** * Set's correct page for list * based on data provided with event Index: trunk/kernel/include/searchconfig.php =================================================================== diff -u -N -r3618 -r4231 --- trunk/kernel/include/searchconfig.php (.../searchconfig.php) (revision 3618) +++ trunk/kernel/include/searchconfig.php (.../searchconfig.php) (revision 4231) @@ -315,6 +315,41 @@ return $ret; } + function getHumanField() + { + return language( $this->Get('DisplayName') ); + } + + function getHumanVerb($verb) + { + return language('lu_advsearch_'.$verb); + } + + function getHumanValue($value) + { + $data_type = $this->Get('FieldType'); + + switch ($data_type) { + case 'text': + case 'textarea': + $ret = $value; + break; + + case 'select': + case 'radio': + case 'checkbox': + $values = $this->parseValuesList(); + $ret = $values[$value]; + break; + + case 'boolean': + $values = Array(-1 => 'lu_advsearch_any', 1 => 'lu_true', 0 => 'lu_false'); + $ret = language($values[$value]); + break; + } + return $ret; + } + /** * If custom field contains values list, then parse it into array * Index: trunk/admin/logs/searchlog.php =================================================================== diff -u -N -r2853 -r4231 --- trunk/admin/logs/searchlog.php (.../searchlog.php) (revision 2853) +++ trunk/admin/logs/searchlog.php (.../searchlog.php) (revision 4231) @@ -107,8 +107,8 @@ $objListView->PageLinkTemplate = $pathtoroot.$admin."/templates/user_page_link.tpl"; $objListView->ColumnHeaders->Add("TextType",admin_language("la_prompt_SearchType"),1,0,$order,"width=\"20%\"","SearchLog_SortField","SearchLog_SortOrder","TextType"); -$objListView->ColumnHeaders->Add("Keyword",admin_language("la_prompt_Keyword"),1,0,$order,"width=\"20%\"","SearchLog_SortField","SearchLog_SortOrder","Keyword"); -$objListView->ColumnHeaders->Add("Indices",admin_language("la_prompt_Frequency"),1,0,$order,"width=\"30%\"","SearchLog_SortField","SearchLog_SortOrder","Indices"); +$objListView->ColumnHeaders->Add("Keyword",admin_language("la_prompt_Keyword"),1,0,$order,"width=\"70%\"","SearchLog_SortField","SearchLog_SortOrder","Keyword"); +$objListView->ColumnHeaders->Add("Indices",admin_language("la_prompt_Frequency"),1,0,$order,"width=\"10%\"","SearchLog_SortField","SearchLog_SortOrder","Indices"); $objListView->ColumnHeaders->SetSort($objConfig->Get("SearchLog_SortField"),$order); $objListView->PrintToolBar = FALSE; Index: trunk/kernel/frontaction.php =================================================================== diff -u -N -r4126 -r4231 --- trunk/kernel/frontaction.php (.../frontaction.php) (revision 4126) +++ trunk/kernel/frontaction.php (.../frontaction.php) (revision 4231) @@ -1019,7 +1019,7 @@ if(strlen($Value) && strlen($Verb)>0 && $Verb!="any") { - //echo "Adding CAT SearchField: [".$field->Get("TableName")."]; [".$field->Get("FieldName")."]; [$Verb]; [$Value]; [$Conjuction]
"; +// echo "Adding CAT SearchField: [".$field->Get("TableName")."]; [".$field->Get("FieldName")."]; [$Verb]; [$Value]; [$Conjuction]
"; $objAdvSearch->AddAdvancedField($field->Get("TableName"),$field->Get("FieldName"),$Verb,$Value,$Conjuction, 'c'); }