Factory->includeClassFile('kDBEventHandler'); class kCatDBEventHandler extends InpDBEventHandler { function OnCopy(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'copy'); $this->Application->StoreVar('clipboard', 'COPY-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } function OnCut(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'cut'); $this->Application->StoreVar('clipboard', 'CUT-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } function OnPaste(&$event) { $ids = $this->Application->RecallVar($event->getPrefixSpecial().'_clipboard'); if ($ids == '') { $event->redirect = false; return; } //recalling by different name, because we may get kDBList, if we recall just by prefix $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix); $this->prepareObject($object,$event); if ($this->Application->RecallVar($event->getPrefixSpecial().'_clipboard_mode') == 'copy') { $ids_arr = explode(',', $ids); $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); if($ids_arr) { $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); } } else { // mode == cut $ids_arr = explode(',', $ids); foreach ($ids_arr as $id) { $object->Load($id); $object->MoveToCat(); } } $event->status = erSUCCESS; } /** * Apply scope clause * * @param kEvent $event */ function SetCustomQuery(&$event) { $object =& $event->getObject(); if ($event->Special != 'showall') { if ( $event->getEventParam('parent_cat_id') ) { $parent_cat_id = $event->getEventParam('parent_cat_id'); } else { $parent_cat_id = $this->Application->GetVar('c_id'); if (!$parent_cat_id) { $parent_cat_id = $this->Application->GetVar('m_cat_id'); } if (!$parent_cat_id) { $parent_cat_id = 0; } } if ((string) $parent_cat_id != 'any') { if ($event->getEventParam('recursive')) { $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id); $subcats = $this->Conn->GetCol('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ParentPath LIKE "'.$current_path.'%" '); $object->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.CategoryId IN ('.implode(', ', $subcats).')'); } else { $object->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.CategoryId = '.$parent_cat_id ); } } } else { $object->addFilter('primary_filter', 'PrimaryCat = 1'); } $view_perm = 1; $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); if (!defined('ADMIN')) { $groups = explode(',',$this->Application->RecallVar('UserGroups')); foreach ($groups as $group) { $view_filters[] = 'FIND_IN_SET('.$group.', perm.acl) || ((NOT FIND_IN_SET('.$group.',perm.dacl)) AND perm.acl=\'\')'; } $view_filter = implode(' OR ', $view_filters); $object->addFilter('perm_filter2', $view_filter); } if (!defined('ADMIN')) { $object->addFilter('status_filter', $object->TableName.'.Status = 1'); } /*$list_type = $event->getEventParam('ListType'); switch($list_type) { case 'favorites': $fav_table = $this->Application->getUnitOption('fav','TableName'); $user_id =& $this->Application->GetVar('u_id'); $sql = 'SELECT DISTINCT f.ResourceId FROM '.$fav_table.' f LEFT JOIN '.$object->TableName.' p ON p.ResourceId = f.ResourceId WHERE f.PortalUserId = '.$user_id; $ids = $this->Conn->GetCol($sql); if(!$ids) $ids = Array(-1); $object->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.PrimaryCat = 1'); $object->addFilter('favorites_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')'); break; case 'search': $search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetVar('sid').'_'.TABLE_PREFIX.'Search'; $sql = ' SELECT DISTINCT ResourceId FROM '.$search_results_table.' WHERE ItemType=11'; $ids = $this->Conn->GetCol($sql); if(!$ids) $ids = Array(-1); $object->addFilter('search_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')'); break; } */ } } ?>