Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r14652 -r14674 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14652) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14674) @@ -1,6 +1,6 @@ StoreSelectedIDs($event); $to_delete = Array (); + $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); - if ( $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder') ) { + if ( $recycle_bin ) { $rb =& $this->Application->recallObject('c.recycle', null, array ('skip_autoload' => true)); /* @var $rb CategoriesItem */ @@ -420,9 +421,10 @@ 'advanced' => 'OnAdvancedSearch' ); + $keywords = $event->getEventParam('keyword_string'); $type = $this->Application->GetVar('search_type', 'simple'); - if ($keywords = $event->getEventParam('keyword_string')) { + if ( $keywords ) { // processing keyword_string param of ListProducts tag $this->Application->SetVar('keywords', $keywords); $type = 'simple'; @@ -521,7 +523,7 @@ $related_ids_array = $this->Conn->Query($sql); $related_ids = Array(); - foreach ($related_ids_array as $key => $record) { + foreach ($related_ids_array as $record) { $related_ids[] = $record[ $record['SourceId'] == $p_resource_id ? 'TargetId' : 'SourceId' ]; } @@ -1145,7 +1147,9 @@ } // processing fields from other tables - if ($foreign_field = $search_config[$field]['ForeignField']) { + $foreign_field = $search_config[$field]['ForeignField']; + + if ( $foreign_field ) { $exploded = explode(':', $foreign_field, 2); if ($exploded[0] == 'CALC') { // ignoring having type clauses in simple search @@ -1327,7 +1331,7 @@ WHERE '.$where_clause.' GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' ORDER BY Relevance DESC'; - $res = $this->Conn->Query($sql); + $this->Conn->Query($sql); if ( !$search_table_exists ) { $sql = 'ALTER TABLE ' . $search_table . ' @@ -1344,13 +1348,16 @@ */ function OnSubSearch(&$event) { - $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; - if($this->Conn->Query($sql)) - { - $sql = 'SELECT DISTINCT ResourceId FROM '.$search_table; + $ids = Array (); + $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; + $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; + + if ( $this->Conn->Query($sql) ) { + $sql = 'SELECT DISTINCT ResourceId + FROM ' . $search_table; $ids = $this->Conn->GetCol($sql); } + $event->setEventParam('ResultIds', $ids); $event->CallSubEvent('OnSimpleSearch'); } @@ -1434,7 +1441,9 @@ } // processing fields from other tables - if ($foreign_field = $record['ForeignField']) { + $foreign_field = $record['ForeignField']; + + if ( $foreign_field ) { $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { @@ -1642,7 +1651,7 @@ case 'boolean': if ($keywords[$field] != -1) { $property_mappings = $this->Application->getUnitOption($this->Prefix, 'ItemPropertyMappings'); - $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $items_table = $this->Application->getUnitOption($this->Prefix, 'TableName'); switch ($field) { case 'HotItem': @@ -1904,14 +1913,12 @@ if ($field_values['start_from'] == $field_values['total_records']) { if ($event->Special == 'import') { $this->Application->StoreVar('PermCache_UpdateRequired', 1); - $url_params = Array( - 't' => 'catalog/catalog', - 'm_cat_id' => $this->Application->RecallVar('ImportCategory'), - 'anchor' => 'tab-' . $event->Prefix, - ); - $this->Application->EventManager->openerStackChange($url_params); + $event->SetRedirectParam('m_cat_id', $this->Application->RecallVar('ImportCategory')); + $event->SetRedirectParam('anchor', 'tab-' . $event->Prefix); $event->SetRedirectParam('opener', 'u'); + + $event->redirect = 'catalog/catalog'; } elseif ($event->Special == 'export') { $event->redirect = $export_object->getModuleName($event) . '/' . $event->Special . '_finish'; @@ -2008,7 +2015,14 @@ } } - function isURL($path) + /** + * Detects if image url is specified in a given path (instead of path on disk) + * + * @param string $path + * @return bool + * @access protected + */ + protected function isURL($path) { return preg_match('#(http|https)://(.*)#', $path); } @@ -2055,12 +2069,8 @@ // Tools -> Import -> Item Import -> Select Import Category $this->Application->StoreVar('ImportCategory', $selected_ids['c']); - $url_params = Array ( - $event->getPrefixSpecial() . '_id' => 0, - $event->getPrefixSpecial() . '_event' => 'OnExportBegin', - ); - - $this->Application->EventManager->openerStackChange($url_params); + $event->SetRedirectParam($event->getPrefixSpecial() . '_id', 0); + $event->SetRedirectParam($event->getPrefixSpecial() . '_event', 'OnExportBegin'); } $event->SetRedirectParam('opener', 'u'); @@ -2368,6 +2378,7 @@ * Adds new and removes old additional categories from category item * * @param kCatDBItem $object + * @param int $mode */ function processAdditionalCategories(&$object, $mode) { @@ -2501,35 +2512,37 @@ */ function SetFrontRedirectTemplate(&$event, $template_key) { - if ($this->Application->isAdminUser || $event->status != kEvent::erSUCCESS) { - return ; + if ( $this->Application->isAdminUser || $event->status != kEvent::erSUCCESS ) { + return; } // prepare redirect template $object =& $event->getObject(); + /* @var $object kDBItem */ + $is_active = ($object->GetDBField('Status') == STATUS_ACTIVE); $next_template = $is_active ? 'confirm_template' : 'pending_confirm_template'; - $event->redirect = $this->Application->GetVar($template_key.'_'.$next_template); + $event->redirect = $this->Application->GetVar($template_key . '_' . $next_template); $event->SetRedirectParam('opener', 's'); // send email events $perm_prefix = $this->Application->getUnitOption($event->Prefix, 'PermItemPrefix'); $owner_field = $this->getOwnerField($event->Prefix); $owner_id = $object->GetDBField($owner_field); - switch ($event->Name) { + switch ( $event->Name ) { case 'OnCreate': $event_suffix = $is_active ? 'ADD' : 'ADD.PENDING'; - $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :( - $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $owner_id); + $this->Application->EmailEventAdmin($perm_prefix . '.' . $event_suffix); // there are no ADD.PENDING event for admin :( + $this->Application->EmailEventUser($perm_prefix . '.' . $event_suffix, $owner_id); break; case 'OnUpdate': $event_suffix = $is_active ? 'MODIFY' : 'MODIFY.PENDING'; - $user_id = is_numeric( $object->GetDBField('ModifiedById') ) ? $object->GetDBField('ModifiedById') : $owner_id; - $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :( - $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $user_id); + $user_id = is_numeric($object->GetDBField('ModifiedById')) ? $object->GetDBField('ModifiedById') : $owner_id; + $this->Application->EmailEventAdmin($perm_prefix . '.' . $event_suffix); // there are no ADD.PENDING event for admin :( + $this->Application->EmailEventUser($perm_prefix . '.' . $event_suffix, $user_id); break; } } @@ -2607,7 +2620,9 @@ function checkItemStatus(&$event) { $object =& $event->getObject(); - if (!$object->isLoaded()) { + /* @var $object kDBItem */ + + if ( !$object->isLoaded() ) { $this->_errorNotFound($event); return true; @@ -2617,7 +2632,7 @@ $user_id = $this->Application->RecallVar('user_id'); $owner_field = $this->getOwnerField($event->Prefix); - if (($status == STATUS_PENDING_EDITING || $status == STATUS_PENDING) && ($object->GetDBField($owner_field) == $user_id)) { + if ( ($status == STATUS_PENDING_EDITING || $status == STATUS_PENDING) && ($object->GetDBField($owner_field) == $user_id) ) { return true; } @@ -2656,14 +2671,16 @@ return parent::getPerPage($event); } - function getOwnerField($prefix) + /** + * Returns owner field for given prefix + * + * @param $prefix + * @return string + * @access protected + */ + protected function getOwnerField($prefix) { - $owner_field = $this->Application->getUnitOption($prefix, 'OwnerField'); - if (!$owner_field) { - $owner_field = 'CreatedById'; - } - - return $owner_field; + return $this->Application->getUnitOption($prefix, 'OwnerField', 'CreatedById'); } /**