Application->GetVar('cat_list'), ','); //if(!$cat_list) return true; $cat_id = (int)$this->Conn->GetOne('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ResourceId='.$cat_list); $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); $object =& $event->getObject(); $table_info = $object->getLinkedInfo(); // don't allow duplicate records $already_added = $this->Conn->GetOne('SELECT * FROM '.$object->TableName.' WHERE CategoryId='.$cat_id.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId']); if($already_added === false) { $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); $items_info[0]['CategoryId'] = $cat_id; $items_info[0][ $table_info['ForeignKey'] ] = $table_info['ParentId']; $this->Application->SetVar( $event->getPrefixSpecial(true), $items_info ); $rp_backup = $event->redirect_params; // save opener state $event->setEventParam('ForceCreateId', true); $this->OnCreate($event); $event->redirect_params = $rp_backup; // restore opener state } } /** * Set's new category as primary for product * * @param kEvent $event */ function OnSetPrimary(&$event) { $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); $object =& $event->getObject(); $this->StoreSelectedIDs($event); $ids=$this->getSelectedIDs($event); if($ids) { $id = array_shift($ids); $table_info = $object->getLinkedInfo(); $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')'); } $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay! } /** * Apply custom processing to item * * @param kEvent $event */ function customProcessing(&$event, $type) { if($event->Name == 'onMassDelete') { $object =& $event->getObject(); $table_info = $object->getLinkedInfo(); switch ($type) { case 'before': $ids = $event->getEventParam('ids'); if($ids) { $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')'); $event->setEventParam('ids',$ids); } break; // not needed because 'before' does not allow to delete primary cat! /*case 'after': // set 1st not deleted category as primary $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')'); if(!$has_primary) { $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')'); } break;*/ } } } } ?>