Index: trunk/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r6428 -r6583 --- trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 6428) +++ trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 6583) @@ -116,9 +116,10 @@ 'OnPreCreate' => Array('self' => 'add|add.pending'), 'OnEdit' => Array('self' => 'edit|edit.pending'), + 'OnExport' => Array('self' => 'view|advanced:export'), + 'OnExportBegin' => Array('self' => 'view|advanced:export'), - // theese event do not harm, but just in case check them too :) 'OnCancelEdit' => Array('self' => true, 'subitem' => true), 'OnCancel' => Array('self' => true, 'subitem' => true), @@ -1659,6 +1660,23 @@ $this->Application->StoreVar( $event->getPrefixSpecial().'_view_filter', serialize($view_filter) ); } + function OnSetFilterPattern(&$event) + { + $filters = $this->Application->GetVar($event->getPrefixSpecial(true).'_filters'); + if (!$filters) return ; + + $view_filter = $this->Application->RecallVar($event->getPrefixSpecial().'_view_filter'); + $view_filter = $view_filter ? unserialize($view_filter) : Array(); + + $filters = explode(',', $filters); + foreach ($filters as $a_filter) { + list($id, $value) = explode('=', $a_filter); + $view_filter[$id] = $value; + } + $this->Application->StoreVar( $event->getPrefixSpecial().'_view_filter', serialize($view_filter) ); + $event->redirect = false; + } + /** * Add/Remove all filters applied to list from "View" menu * @@ -1778,7 +1796,7 @@ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); // 3. create virtual & calculated fields (for main item) - $calculated_fields = $this->Application->getUnitOption($main_prefix.'.', 'CalculatedFields', Array()); + $calculated_fields = Array(); $virtual_fields = $this->Application->getUnitOption($main_prefix, 'VirtualFields', Array()); $cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper'); @@ -1814,8 +1832,14 @@ $virtual_fields['cust_'.$custom_name] = array_merge_recursive2($field_options, $virtual_fields['cust_'.$custom_name]); $custom_fields[$custom_id] = $custom_name; } + + $config_calculated_fields = $this->Application->getUnitOption($main_prefix, 'CalculatedFields', Array()); + foreach ($config_calculated_fields as $special => $special_fields) { + $config_calculated_fields[$special] = array_merge_recursive2($config_calculated_fields[$special], $calculated_fields); + } + $this->Application->setUnitOption($main_prefix, 'CalculatedFields', $config_calculated_fields); + $this->Application->setUnitOption($main_prefix, 'CustomFields', $custom_fields); - $this->Application->setUnitOption($main_prefix.'.', 'CalculatedFields', $calculated_fields); $this->Application->setUnitOption($main_prefix, 'VirtualFields', $virtual_fields); } @@ -1858,6 +1882,131 @@ $this->finalizePopup($event); } + +/** EXPORT RELATED **/ + + /** + * Shows export dialog + * + * @param kEvent $event + */ + function OnExport(&$event) + { + $this->StoreSelectedIDs($event); + $selected_ids = $this->getSelectedIDs($event); + + if (implode(',', $selected_ids) == '') { + // K4 fix when no ids found bad selected ids array is formed + $selected_ids = false; + } + + $this->Application->StoreVar($event->Prefix.'_export_ids', $selected_ids ? implode(',', $selected_ids) : '' ); + + $export_t = $this->Application->GetVar('export_template'); + $this->Application->LinkVar('export_finish_t'); + $this->Application->LinkVar('export_progress_t'); + $this->Application->StoreVar('export_oroginal_special', $event->Special); + $export_helper =& $this->Application->recallObject('CatItemExportHelper'); + $event->redirect = $export_t ? $export_t : $export_helper->getModuleFolder($event).'/export'; + + $redirect_params = Array( 'm_opener' => 'd', + $this->Prefix.'.export_event' => 'OnNew', + 'pass' => 'all,'.$this->Prefix.'.export'); + + $event->setRedirectParams($redirect_params); + } + + /** + * Apply some special processing to + * object beeing recalled before using + * it in other events that call prepareObject + * + * @param Object $object + * @param kEvent $event + * @access protected + */ + function prepareObject(&$object, &$event) + { + if ($event->Special == 'export' || $event->Special == 'import') + { + $export_helper =& $this->Application->recallObject('CatItemExportHelper'); + $export_helper->prepareExportColumns($event); + } + } + + /** + * Returns specific to each item type columns only + * + * @param kEvent $event + * @return Array + */ + function getCustomExportColumns(&$event) + { + return Array(); + } + + /** + * Export form validation & processing + * + * @param kEvent $event + */ + function OnExportBegin(&$event) + { + $export_helper =& $this->Application->recallObject('CatItemExportHelper'); + $export_helper->OnExportBegin($event); + } + + /** + * Enter description here... + * + * @param kEvent $event + */ + function OnExportCancel(&$event) + { + $this->OnGoBack($event); + } + + /** + * Allows configuring export options + * + * @param kEvent $event + */ + function OnBeforeExportBegin(&$event) + { + + } + + function OnDeleteExportPreset(&$event) + { + $object =& $event->GetObject(); + + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + if($items_info) + { + list($id,$field_values) = each($items_info); + $preset_key = $field_values['ExportPresets']; + + $user =& $this->Application->recallObject('u'); + $export_settings = $user->getPersistantVar('export_settings'); + if (!$export_settings) return ; + $export_settings = unserialize($export_settings); + if (!isset($export_settings[$event->Prefix])) return ; + + $to_delete = ''; + $export_presets = array(''=>''); + foreach ($export_settings[$event->Prefix] as $key => $val) { + if (implode('|', $val['ExportColumns']) == $preset_key) { + $to_delete = $key; + break; + } + } + if ($to_delete) { + unset($export_settings[$event->Prefix][$to_delete]); + $user->setPersistantVar('export_settings', serialize($export_settings)); + } + } + } + }