Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r4309 -r4314 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4309) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4314) @@ -1649,32 +1649,46 @@ */ function OnSelectItems(&$event) { + $dst_field = $this->Application->RecallVar('dst_field'); $items_info = $this->Application->GetVar('c'); - - if ($items_info) - { - $selected_categories = array_keys($items_info); - $cat_id = array_shift($selected_categories); - - $sql = 'SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ResourceId = '.$cat_id; - $cat_id = $this->Conn->GetOne($sql); + if ($items_info) { + $category_id = array_shift( array_keys($items_info) ); + $sql = 'SELECT CategoryId + FROM '.TABLE_PREFIX.'Category + WHERE ResourceId = '.$category_id; + $category_id = $this->Conn->GetOne($sql); } else { - $cat_id = 0; + $category_id = 0; } - - $this->Application->StoreVar('ImportCategory', $cat_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 == '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); - } /**