Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r5218 -r5219 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5218) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5219) @@ -4,7 +4,7 @@ $application->Factory->includeClassFile('kDBEventHandler'); class kCatDBEventHandler extends InpDBEventHandler { - + /** * Allows to override standart permission mapping * @@ -19,7 +19,7 @@ ); $this->permMapping = array_merge($this->permMapping, $permissions); } - + /** * Checks permissions of user * @@ -33,21 +33,21 @@ return true; } } - + if ($event->Name == 'OnExport') { // save category_id before doing export $this->Application->LinkVar('m_cat_id'); } - + if ($event->Name == 'OnNew' && preg_match('/(.*)\/import$/', $this->Application->GetVar('t'), $rets)) { // redirect to item import template, where permission (import) category will be chosen) $root_category = $this->Application->findModule('Path', $rets[1].'/', 'RootCat'); $this->Application->StoreVar('m_cat_id', $root_category); } - + return parent::CheckPermission($event); } - + function OnCopy(&$event) { $object = $event->getObject(); @@ -91,7 +91,7 @@ } else { // mode == cut $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix, Array('skip_autoload' => true)); - + foreach ($ids_arr as $id) { $object->Load($id); $object->MoveToCat(); @@ -449,15 +449,15 @@ if (!$property_map) { return ; } - + // new items $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. $this->Application->ConfigValue($property_map['NewDays']). '*3600*24), 1, 0), %1$s.NewItem )'); - + // hot items (cache updated every hour) $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache @@ -470,7 +470,7 @@ IF(%1$s.'.$property_map['ClickField'].' >= '.$hot_limit.', 1, 0), %1$s.HotItem )'); - + // popular items $object->addCalculatedField('IsPop', ' IF(%1$s.PopItem = 2, IF(%1$s.CachedVotesQty >= '. @@ -479,14 +479,17 @@ $this->Application->ConfigValue($property_map['MinPopRating']). ', 1, 0), %1$s.PopItem)'); - + } function CalculateHotLimit(&$event) { $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); + if (!$property_map) { + return; + } $click_field = $property_map['ClickField']; - + $last_hot = $this->Application->ConfigValue($property_map['MaxHotNumber']) - 1; $sql = 'SELECT '.$click_field.' FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' ORDER BY '.$click_field.' DESC @@ -495,7 +498,7 @@ $hot_limit = (double)array_shift($res); $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("'.$property_map['HotLimit'].'", "'.$hot_limit.'", '.adodb_mktime().')'); return $hot_limit; - + return 0; } @@ -583,7 +586,7 @@ $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'SearchLog'); } } - + /** * Makes simple search for products * based on keywords string @@ -624,8 +627,8 @@ // 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('%' => '\\%', '_' => '\\_')); $event->setPseudoClass('_List'); @@ -644,23 +647,23 @@ // field processing $weight_sum = 0; - + $alias_counter = 0; - + $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); if ($custom_fields) { $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; } - + // what field in search config becomes what field in sql (key - new field, value - old field (from searchconfig table)) $search_config_map = Array(); - + 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 (getArrayValue($options, 'formatter') == 'kMultiLanguage') { $field_list[$key] = 'l'.$lang.'_'.$field; @@ -686,16 +689,16 @@ { $exploded = explode('.', $foreign_field); // format: table.field_name $foreign_table = TABLE_PREFIX.$exploded[0]; - + $alias_counter++; $alias = 't'.$alias_counter; - + $field_list[$key] = $alias.'.'.$exploded[1]; $search_config_map[ $field_list[$key] ] = $field; - + $join_clause = str_replace('{ForeignTable}', $alias, $search_config[$field]['JoinClause']); $join_clause = str_replace('{LocalTable}', $product_table, $join_clause); - + $join_clauses[] = ' LEFT JOIN '.$foreign_table.' '.$alias.' ON '.$join_clause; } @@ -714,7 +717,7 @@ // keyword string processing $search_helper =& $this->Application->recallObject('SearchHelper'); $where_clause = $search_helper->buildWhereClause($keywords, $field_list); - + $where_clause = $where_clause.' AND '.$product_table.'.Status=1'; if($this->Application->GetVar('Action') == 'm_simple_subsearch') // subsearch, In-portal @@ -823,7 +826,7 @@ $product_table = $this->Application->getUnitOption('p', 'TableName'); $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'); @@ -843,13 +846,13 @@ 'isnot' => '(%1$s != %2$s OR %1$s IS NULL)'); $alias_counter = 0; - + $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); if ($custom_fields) { $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); $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 @@ -872,7 +875,7 @@ else { $field_name = $field; } - + // processing fields from other tables if ($foreign_field = $record['ForeignField']) { $exploded = explode(':', $foreign_field, 2); @@ -916,7 +919,7 @@ $local_table = 'custom_data'; $field_name = 'l'.$lang.'_cust_'.array_search($field_name, $custom_fields); } - + $field_name = $local_table.'.'.$field_name; } @@ -1051,16 +1054,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->saveToSearchLog($search_log, 1); // advanced search $this->Application->StoreVar('highlight_keywords', serialize($highlight_keywords)); @@ -1128,21 +1131,21 @@ $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': @@ -1152,29 +1155,29 @@ '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; - + break; + case 'text': $ret = $value; break; - + } return '"'.$ret.'"'; break; } } - - - + + + /** * Set's correct page for list * based on data provided with event @@ -1314,7 +1317,7 @@ $object =& $event->getObject( Array('skip_autoload' => true) ); $object->SetFieldsFromHash($field_values); $field_values['ImportFilename'] = $object->GetDBField('ImportFilename'); //if upload formatter has renamed the file during moving !!! - + $object->setID($item_id); $this->setRequiredFields($event); @@ -1334,11 +1337,11 @@ $field_values['ExportColumns'] = $field_values['ExportColumns'] ? explode('|', substr($field_values['ExportColumns'], 1, -1) ) : Array(); $field_values['start_from'] = 0; $export_object->saveOptions($event, $field_values); - + if( $export_object->verifyOptions($event) ) { $event->redirect = $this->getModuleFolder($event).'/'.$event->Special.'_progress'; - + } else { @@ -1352,12 +1355,12 @@ $field_values['ImportLocalFilename'] = $filename; $export_object->saveOptions($event, $field_values); } - + $event->status = erFAIL; $event->redirect = false; } } - + /** * Enter description here... * @@ -1367,7 +1370,7 @@ { $this->OnGoBack($event); } - + /** * Sets correct available & export fields * @@ -1450,9 +1453,9 @@ if ($event->Special != 'import') { return false; } - + $object =& $event->getObject(); - + $import_filenames = Array(); if ($folder_handle = opendir(EXPORT_PATH)) { @@ -1464,12 +1467,12 @@ } closedir($folder_handle); } - + $options = $object->GetFieldOptions('ImportLocalFilename'); $options['options'] = $import_filenames; $object->SetFieldOptions('ImportLocalFilename', $options); } - + /** * Returns specific to each item type columns only * @@ -1648,33 +1651,33 @@ else { $category_id = 0; } - + if ($dst_field == 'ImportCategory') { $this->Application->StoreVar('ImportCategory', $category_id); $this->Application->StoreVar($event->getPrefixSpecial().'_ForceNotValid', 1); // not to loose import/export values on form refresh - + $this->Application->SetVar($event->getPrefixSpecial().'_id', 0); $this->Application->SetVar($event->getPrefixSpecial().'_event', 'OnExportBegin'); - + $passed = $this->Application->GetVar('passed'); $this->Application->SetVar('passed', $passed.','.$event->getPrefixSpecial()); $event->setEventParam('pass_events', true); } - + if ($dst_field == 'ItemCategory') { $object =& $event->getObject(); // category item object (e.g. link, product, etc.) - + $ci_prefix = $object->Prefix.'-ci'; $ci_object =& $this->Application->recallObject($ci_prefix, null, Array('skip_autoload' => true)); - + $ci_object->Load($category_id); if (!$ci_object->isLoaded()) { $fields_hash = Array('CategoryId' => $category_id, 'ItemResourceId' => $object->GetDBField('ResourceId')); $ci_object->SetDBFieldsFromHash($fields_hash); $ci_object->Create(true); } } - + $this->finalizePopup($event); } @@ -1689,18 +1692,24 @@ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); if ($items_info) { list($id, $field_values) = each($items_info); - + $object =& $event->getObject( Array('skip_autoload' => true) ); $object->SetFieldsFromHash($field_values); $field_values['ImportFilename'] = $object->GetDBField('ImportFilename'); //if upload formatter has renamed the file during moving !!! $field_values['ImportSource'] = 2; $field_values['ImportLocalFilename'] = $object->GetDBField('ImportFilename'); $items_info[$id] = $field_values; - + $this->Application->StoreVar($event->getPrefixSpecial().'_ItemsInfo', serialize($items_info)); } } + function OnCancelAction(&$event) + { + $event->redirect_params = Array('pass' => 'all,'.$event->GetPrefixSpecial()); + $event->redirect = $this->Application->GetVar('cancel_template'); + } + /* === RELATED TO IMPORT/EXPORT: END === */ }