Conn->qstr( $this->Application->GetVar('cf_type') ); $main_prefix = $this->Conn->GetOne($sql); $section = $this->Application->getUnitOption($main_prefix.'.custom', 'PermSection'); $event->setEventParam('PermSection', $section); return parent::CheckPermission($event); } /** * Apply any custom changes to list's sql query * * @param kEvent $event * @access protected * @see OnListBuild */ function SetCustomQuery(&$event) { $object =& $event->getObject(); $item_type = $this->Application->GetVar('cf_type'); if (!$item_type) { $prefix = $event->getEventParam('SourcePrefix'); $item_type = $this->Application->getUnitOption($prefix, 'ItemType'); } if ($event->Special == 'general') { $object->addFilter('generaltab_filter', '%1$s.OnGeneralTab = 1'); } if ($item_type) { $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); } if (!($this->Application->isDebugMode() && $this->Application->IsAdmin())) { $object->addFilter('user_filter', '%1$s.IsSystem = 0'); } } /** * Prevents from duplicate item creation * * @param kEvent $event */ function OnBeforeItemCreate(&$event) { $object =& $event->getObject(); $live_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $sql = 'SELECT COUNT(*) FROM '.$live_table.' WHERE FieldName = '.$this->Conn->qstr($object->GetDBField('FieldName')).' AND Type = '.$object->GetDBField('Type'); $found = $this->Conn->GetOne($sql); if ($found) { $event->status = erFAIL; $object->SetError('FieldName', 'duplicate', 'la_error_CustomExists'); } } /** * Occurse after deleting item, id of deleted item * is stored as 'id' param of event * * @param kEvent $event * @access public */ function OnAfterItemDelete(&$event) { $object =& $event->getObject(); $main_prefix = $this->getPrefixByItemType($object->GetDBField('Type')); $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); $ml_helper->deleteField($main_prefix.'-cdata', $event->getEventParam('id')); } /** * Get config prefix based on item type * * @param unknown_type $item_type * @return unknown */ function getPrefixByItemType($item_type) { $sql = 'SELECT Prefix FROM '.TABLE_PREFIX.'ItemTypes WHERE ItemType = '.$item_type; return $this->Conn->GetOne($sql); } /** * Enter description here... * * @param kEvent $event */ function OnSaveCustomField(&$event) { if ($event->MasterEvent->status != erSUCCESS) { return false; } $object =& $event->getObject(); $main_prefix = $this->getPrefixByItemType($object->GetDBField('Type')); $this->Application->HandleEvent( new kEvent($main_prefix.'-cdata:OnCreateCustomFields') ); $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); $ml_helper->createFields($main_prefix.'-cdata'); } function OnMassDelete(&$event) { parent::OnMassDelete($event); $event->redirect_params = Array('opener' => 's'); } /** * Prepare temp tables for creating new item * but does not create it. Actual create is * done in OnPreSaveCreated * * @param kEvent $event */ function OnPreCreate(&$event) { parent::OnPreCreate($event); $object =& $event->getObject(); $object->SetDBField('Type', $this->Application->GetVar('cf_type')); } } ?>