Index: branches/5.2.x/units/reports/reports_event_handler.php =================================================================== diff -u -N -r16516 -r16696 --- branches/5.2.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 16516) +++ branches/5.2.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 16696) @@ -1,6 +1,6 @@ UpdateFormattersMasterFields(); $field_values['offset'] = 0; + $field_values['export_ignore'] = ''; $table_name = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_SaleReport'; $field_values['table_name'] = $table_name; $this->Conn->Query('DROP TABLE IF EXISTS '.$table_name); @@ -116,6 +117,8 @@ } if ($field_values['ReportType'] == 1) { // by Category + $field_values['id_field'] = $field_values['export_ignore'] = 'CategoryId'; + $field_values['grid'] = 'ByCategory'; $q = 'CREATE TABLE '.$table_name.' ( CategoryId int(11) NOT NULL DEFAULT 0, Qty int(11) NOT NULL DEFAULT 0, @@ -162,6 +165,8 @@ $this->Conn->Query($q); } elseif ($field_values['ReportType'] == 2) { // by User + $field_values['id_field'] = $field_values['export_ignore'] = 'PortalUserId'; + $field_values['grid'] = 'ByUser'; $q = 'CREATE TABLE '.$table_name.' ( PortalUserId int(11) NOT NULL DEFAULT 0, Qty int(11) NOT NULL DEFAULT 0, @@ -199,6 +204,8 @@ $this->Conn->Query($q); } elseif ($field_values['ReportType'] == 5) { // by Product + $field_values['id_field'] = $field_values['export_ignore'] = 'ProductId'; + $field_values['grid'] = 'ByProduct'; $q = 'CREATE TABLE '.$table_name.' ( ProductId int(11) NOT NULL DEFAULT 0, Qty int(11) NOT NULL DEFAULT 0, @@ -239,6 +246,8 @@ $this->Conn->Query($q); } elseif ($field_values['ReportType'] == 12) { // Overall + $field_values['id_field'] = 'Marketplace'; + $field_values['grid'] = 'Overall'; $q = 'CREATE TABLE '.$table_name.' ( Marketplace tinyint(1) NOT NULL DEFAULT 0, Qty int(11) NOT NULL DEFAULT 0, @@ -318,10 +327,7 @@ } } - $vars = array('rep_Page', 'rep_Sort1', 'rep_Sort1_Dir', 'rep_Sort2', 'rep_Sort2_Dir'); - foreach ($vars as $var_name) { - $this->Application->RemoveVar($var_name); - } + $event->CallSubEvent('OnResetSorting'); //temporary $event->redirect = $this->Application->GetVar('reports_finish_t'); @@ -340,6 +346,7 @@ } $field_values = unserialize($report); + $grid = $field_values['grid']; $rep_options = $this->Application->getUnitOptions('rep'); $new_options = Array (); @@ -375,12 +382,14 @@ 'SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'Categories AS c ON c.CategoryId = %1$s.CategoryId'; - $new_options['Grids']['Default'] = Array ( + $new_options['Fields']['CategoryId'] = Array ('type' => 'int', 'default' => null); + $new_options['Grids'][$grid] = Array ( 'Icons' => Array ( 'default' => 'icon16_item.png', 'module' => 'core', ), 'Fields' => Array ( + 'CategoryId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter', 'hidden' => 1), 'CategoryName' => Array ('title' => 'la_col_CategoryName', 'filter_block' => 'grid_like_filter'), 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), @@ -400,7 +409,7 @@ ); if (!$this->Application->isModuleEnabled('in-auction')) { - $a_fields =& $new_options['Grids']['Default']['Fields']; + $a_fields =& $new_options['Grids'][$grid]['Fields']; unset($a_fields['StoreQty']); unset($a_fields['eBayQty']); unset($a_fields['StoreAmount']); @@ -414,7 +423,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'CategoryName'), + 'options' => $this->GetMetricOptions($new_options, array('CategoryId', 'CategoryName'), $grid), 'use_phrases' => 1, 'default' => 0, ), @@ -439,13 +448,14 @@ 'SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'Users AS u ON u.PortalUserId = %1$s.PortalUserId'; - - $new_options['Grids']['Default'] = Array ( + $new_options['Fields']['PortalUserId'] = Array ('type' => 'int', 'default' => null); + $new_options['Grids'][$grid] = Array ( 'Icons' => Array ( 'default' => 'icon16_item.png', 'module' => 'core', ), 'Fields' => Array ( + 'PortalUserId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter', 'hidden' => 1), 'Login' => Array ('filter_block' => 'grid_like_filter'), 'FirstName' => Array ('filter_block' => 'grid_like_filter'), 'LastName' => Array ('filter_block' => 'grid_like_filter'), @@ -477,13 +487,14 @@ 'SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'Products AS p ON p.ProductId = %1$s.ProductId'; - - $new_options['Grids']['Default'] = Array ( + $new_options['Fields']['ProductId'] = Array ('type' => 'int', 'default' => null); + $new_options['Grids'][$grid] = Array ( 'Icons' => Array ( 'default' => 'icon16_item.png', 'module' => 'core', ), 'Fields' => Array ( + 'ProductId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter', 'hidden' => 1), 'ProductName' => Array ('title' => 'la_col_ProductName', 'filter_block' => 'grid_like_filter'), 'Qty' => Array ('td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), 'StoreQty' => Array ('title' => 'la_col_StoreQty', 'td_style' => 'text-align: center', 'total' => 'sum', 'filter_block' => 'grid_range_filter'), @@ -504,7 +515,7 @@ if (!$this->Application->isModuleEnabled('in-auction')) { - $a_fields =& $new_options['Grids']['Default']['Fields']; + $a_fields =& $new_options['Grids'][$grid]['Fields']; unset($a_fields['StoreQty']); unset($a_fields['eBayQty']); unset($a_fields['StoreAmount']); @@ -519,7 +530,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'ProductName'), + 'options' => $this->GetMetricOptions($new_options, array('ProductId', 'ProductName'), $grid), 'use_phrases' => 1, 'default' => 0 ), @@ -537,6 +548,7 @@ 'SELECT %1$s.* %2$s FROM %1$s'; $new_options['Fields']['Marketplace'] = Array ( + 'type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array ( 1 => 'la_OnlineStore', @@ -546,7 +558,7 @@ 'default' => 1 ); - $new_options['Grids']['Default'] = Array( + $new_options['Grids'][$grid] = Array( 'Icons' => Array( 'default' => 'icon16_item.png', 'module' => 'core', @@ -569,7 +581,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'Marketplace'), + 'options' => $this->GetMetricOptions($new_options, array('Marketplace'), $grid), 'use_phrases' => 1, 'default' => 0 ), @@ -630,20 +642,24 @@ /** * Generate Metric Field Options * - * @param array $a_config_options - * @param string $exclude_field + * @param array $a_config_options Config options. + * @param array $exclude_fields Exclude fields. + * @param string $grid Grid. + * + * @return array */ - function GetMetricOptions(&$a_config_options, $exclude_field) + function GetMetricOptions(&$a_config_options, array $exclude_fields, $grid) { - $a_ret = Array(); - foreach ($a_config_options['Grids']['Default']['Fields'] AS $field => $a_options) - { - if ($field == $exclude_field) - { + $a_ret = array(); + + foreach ( $a_config_options['Grids'][$grid]['Fields'] as $field => $a_options ) { + if ( in_array($field, $exclude_fields) ) { continue; } - $a_ret[$field] = $a_options['title']; + + $a_ret[$field] = isset($a_options['title']) ? $a_options['title'] : 'column:la_fld_' . $field; } + return $a_ret; } @@ -757,8 +773,15 @@ /** @var kDBItem $ReportItem */ $ReportItem = $this->Application->recallObject('rep.item', 'rep', Array('skip_autoload' => true)); - $a_grids = $this->Application->getUnitOption('rep', 'Grids'); - $a_fields = $a_grids['Default']['Fields']; + $report_options = unserialize($this->Application->RecallVar('report_options')); + + $a_grids = $this->Application->getUnitOption('rep', 'Grids'); + $a_fields = $a_grids[$report_options['grid']]['Fields']; + + if ( $report_options['export_ignore'] ) { + unset($a_fields[$report_options['export_ignore']]); + } + $ret = ''; foreach ($a_fields AS $field => $a_props) @@ -820,8 +843,6 @@ $ret = str_replace('',',', $ret); $ret = str_replace('',"\r", $ret); - $report_options = unserialize($this->Application->RecallVar('report_options')); - switch ($report_options['ReportType']) { case 1: