Index: branches/unlabeled/unlabeled-1.3.4/core/units/config_search/config_search_event_handler.php =================================================================== diff -u -r4367 -r4497 --- branches/unlabeled/unlabeled-1.3.4/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4367) +++ branches/unlabeled/unlabeled-1.3.4/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4497) @@ -13,128 +13,76 @@ { $object =& $event->getObject(); - $module_owner=$this->Application->GetVar('module'); - if ($module_owner===false) { - $module_owner=$this->myUrlDecode($this->Application->GetVar('confs_module')); - $this->Application->SetVar("module", $module_owner); - } + // show only items that belong to selected module + $module = $this->Application->GetVar('module'); + $object->addFilter('module_filter', '%1$s.ModuleName = '.$this->Conn->qstr($module)); - $section=$this->Application->GetVar('section'); - if ($section===false){ - $section=$this->myUrlDecode($this->Application->GetVar('confs_section')); - $this->Application->SetVar("section", $section); - } - - $object->addFilter('module_filter', '%1$s.ModuleName = "'.$module_owner.'"'); - + // don't show disabled search items + $object->addFilter('active_filter', '%1$s.SimpleSearch <> -1'); } + /** + * Enter description here... + * + * @param kEvent $event + */ function OnUpdate(&$event) { if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) { parent::OnUpdate($event); + + $conf_update = new kEvent('conf:OnUpdate'); + $conf_update->redirect = false; + $this->Application->HandleEvent($conf_update); } - $module_owner=$this->Application->GetVar('module'); - $module_section=$this->Application->GetVar('section'); - - $conf_update = new kEvent( ); - $conf_update->Init('conf'); - $conf_update->Name = 'OnUpdate'; - $conf_update->redirect = false; - $this->Application->HandleEvent($conf_update); - $event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay! - + $event->SetRedirectParam('opener', 's'); } function OnCancel(&$event) { parent::OnCancel($event); - $module_owner=$this->Application->GetVar('module'); - $module_section=$this->Application->GetVar('section'); - - $event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay! - - + $event->SetRedirectParam('opener', 's'); } - - function myUrlDecode($str){ - $str=str_replace(';',':', $str); - $str=str_replace('!','-', $str); - return $str; - } - function myUrlEncode($str){ - $str=str_replace('-', '!', $str); - $str=str_replace(':', ';', $str); - return $str; - } - /** * Enter description here... * * @param kEvent $event */ function OnCreateCustomField(&$event) { - $cf_object =& $event->MasterEvent->getObject(); - - $is_new = $event->MasterEvent->getEventParam('IsNew'); + $custom_field =& $event->MasterEvent->getObject(); + if ($custom_field->GetDBField('Type') == 6) { + // user custom fields are not searchable + return false; + } - // TODO: direct access to private attributes of object is prohibited - $cf_search = array(); - $cf_search['DisplayOrder'] = $cf_object->FieldValues['DisplayOrder']; - $cf_search['ElementType'] = $cf_object->FieldValues['ElementType']; - $cf_search['DisplayName'] = $cf_object->FieldValues['FieldLabel']; - $cf_search['FieldName'] = $cf_object->FieldValues['FieldName']; - $cf_search['Description'] = $cf_object->FieldValues['Prompt']; - $cf_search['ConfigHeader'] = 'la_Text_CustomFields'; + $sql = 'SELECT Module + FROM '.TABLE_PREFIX.'ItemTypes + WHERE ItemType = '.$custom_field->GetDBField('Type'); + $module_name = $this->Conn->GetOne($sql); - - $cf_search['TableName'] = "CustomField"; - $cf_search['ModuleName'] = "In-Commerce"; - $cf_search['ForeignField'] = "CustomMetaData.Value"; - $cf_search['JoinClause'] = "{ForeignTable}.ResourceId={LocalTable}.ResourceId"; + $object =& $event->getObject( Array('skip_autoload' => true) ); - if($is_new) - { - - $live_id = $this->Conn->GetOne("SELECT CustomFieldId FROM ".TABLE_PREFIX."CustomField WHERE FieldName='".$cf_search['FieldName']."'"); - - $cf_search['CustomFieldId'] = $live_id; - - $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); - $confs_item = $event->getObject(); - $confs_item->SetFieldsFromHash($cf_search); - $confs_item->Create(); - - }else{ - - - $cf_search['CustomFieldId'] = $cf_object->FieldValues['CustomFieldId']; - - $search_config_id = $this->Conn->GetOne("SELECT SearchConfigId FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId='".$cf_object->FieldValues['CustomFieldId']."'"); - - $cf_search['SearchConfigId'] = $search_config_id; - - $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); - $confs_item = $event->getObject(); - $confs_item->SetFieldsFromHash($cf_search); - $confs_item->Update($search_config_id); - + $custom_id = $custom_field->GetID(); + if ($custom_id) { + $object->Load($custom_id, 'CustomFieldId'); + $object->SetDBField('CustomFieldId', $custom_id); // for cloning only } - } - - /** - * Enter description here... - * - * @param kEvent $event - */ - function OnDeleteCustomField(&$event){ + + $cf_search = Array(); + $cf_search['DisplayOrder'] = $custom_field->GetDBField('DisplayOrder'); + $cf_search['ElementType'] = $custom_field->GetDBField('ElementType'); + $cf_search['DisplayName'] = $custom_field->GetDBField('FieldLabel'); + $cf_search['FieldName'] = $custom_field->GetDBField('FieldName'); + $cf_search['Description'] = $custom_field->GetDBField('Prompt'); + $cf_search['ConfigHeader'] = $custom_field->GetDBField('Heading'); // 'la_Text_CustomFields'; + $cf_search['TableName'] = 'CustomField'; + $cf_search['ModuleName'] = $module_name; + $object->SetFieldsFromHash($cf_search); - $custom_field_id =&$event->MasterEvent->getEventParam('id'); - $this->Conn->Query("DELETE FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId=".$custom_field_id); - + $result = $object->isLoaded() ? $object->Update() : $object->Create(); } }