Index: branches/unlabeled/unlabeled-1.6.2/kernel/units/relationship/relationship_event_handler.php =================================================================== diff -u -r5795 -r6026 --- branches/unlabeled/unlabeled-1.6.2/kernel/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 5795) +++ branches/unlabeled/unlabeled-1.6.2/kernel/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 6026) @@ -23,20 +23,20 @@ function OnNew(&$event) { parent::OnNew(&$event); - + $object =& $event->getObject(); $table_info = $object->getLinkedInfo(); - + $object->SetDBField('SourceId', $table_info['ParentId']); $source_itemtype = $this->Application->getUnitOption($table_info['ParentPrefix'], 'ItemType'); $object->SetDBField('SourceType', $source_itemtype); - + $object->SetDBField('TargetId', $this->Application->GetVar('target_id')); $object->SetDBField('TargetType', $this->Application->GetVar('target_type')); - + $this->OnAfterItemLoad($event); } - + /** * Add new relation * @@ -48,7 +48,7 @@ if ($dst_field == 'TargetId') { // prepare target_id & target_type $object =& $event->getObject( Array('skip_autoload' => true) ); - + $selected_ids = $this->Application->GetVar('selected_ids'); $target_prefix = false; foreach ($selected_ids as $selected_prefix => $target_id) { @@ -57,22 +57,27 @@ break; } } - + + if (!$target_prefix) { + $this->finalizePopup($event); + return; + } + $sql = 'SELECT ResourceId FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' WHERE '.$this->Application->getUnitOption($target_prefix, 'IDField').' = '.$target_id; $target_id = $this->Conn->GetOne($sql); $target_type = $this->Application->getUnitOption($target_prefix, 'ItemType'); - + // don't add same relation twice $table_info = $object->getLinkedInfo(); $sql = 'SELECT TargetId FROM '.$object->TableName.' WHERE (SourceId = '.$table_info['ParentId'].') AND (TargetId = '.$target_id.')'; $duplicate_relation = $this->Conn->GetOne($sql) == $target_id; - + $this->finalizePopup($event); - + if (!$duplicate_relation) { // place correct template in opener stack $source_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); @@ -94,23 +99,23 @@ function OnAfterItemLoad(&$event) { $object =& $event->getObject(); - + $sql = 'SELECT Prefix FROM '.TABLE_PREFIX.'ItemTypes WHERE ItemType = '.$object->GetDBField('TargetType'); $target_prefix = $this->Conn->GetOne($sql); - + $title_field = $this->getTitleField($target_prefix); $title_phrase = $this->Application->getUnitOption($target_prefix, 'TitlePhrase'); - + $sql = 'SELECT '.$title_field.' FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' WHERE ResourceId = '.$object->GetDBField('TargetId'); - + $object->SetDBField('ItemName', $this->Conn->GetOne($sql)); $object->SetDBField('ItemType', $this->Application->Phrase($title_phrase)); } - + /** * Creates needed sql query to load list, * if no query is defined in config for @@ -200,17 +205,17 @@ function getTitleField($prefix) { $lang_prefix = 'l'.$this->Application->GetVar('m_lang').'_'; - + $title_field = $this->Application->getUnitOption($prefix, 'TitleField'); $field_options = $this->Application->getUnitOption($prefix.'.'.$title_field, 'Fields'); - + $formatter_class = isset($field_options['formatter']) ? $field_options['formatter'] : ''; if ($formatter_class == 'kMultiLanguage' && !isset($field_options['master_field'])) { $title_field = $lang_prefix.$title_field; } return $title_field; } - + /** * Get configs from modules installed *