Index: modules/in-commerce/admin_templates/reports/results.tpl =================================================================== --- modules/in-commerce/admin_templates/reports/results.tpl +++ modules/in-commerce/admin_templates/reports/results.tpl @@ -1,5 +1,9 @@ - + + + + + @@ -34,6 +38,9 @@ a_toolbar.AddButton( new ToolBarButton('export', '', function() { submit_event('rep','OnExportReport'); + + set_hidden_field('events[rep]', null); + submitted = false; } ) ); @@ -55,14 +62,16 @@ - +
- + + + - \ No newline at end of file + Index: modules/in-commerce/units/reports/reports_config.php =================================================================== --- modules/in-commerce/units/reports/reports_config.php +++ modules/in-commerce/units/reports/reports_config.php @@ -42,7 +42,7 @@ ), ), - 'IDField' => 'CategoryId', + 'IDField' => '__DYNAMIC__', 'TitlePresets' => Array ( 'default' => Array ( @@ -83,10 +83,11 @@ 'CalculatedFields' => Array ( '' => Array ( - 'CategoryId' => '0', ), ), + 'Fields' => array(), + 'VirtualFields' => Array ( 'ReportType' => array('formatter' => 'kOptionsFormatter', 'options' =>array( 12 => 'la_Overall', @@ -110,7 +111,6 @@ 'options' => Array (0 => 'la_No', 1 => 'la_Yes'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1, ), - 'CategoryId' => Array ('type' => 'int', 'default' => 0), ), 'Grids' => Array ( Index: modules/in-commerce/units/reports/reports_event_handler.php =================================================================== --- modules/in-commerce/units/reports/reports_event_handler.php +++ modules/in-commerce/units/reports/reports_event_handler.php @@ -116,6 +116,8 @@ } if ($field_values['ReportType'] == 1) { // by Category + $field_values['id_field'] = '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 +164,8 @@ $this->Conn->Query($q); } elseif ($field_values['ReportType'] == 2) { // by User + $field_values['id_field'] = '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 +203,8 @@ $this->Conn->Query($q); } elseif ($field_values['ReportType'] == 5) { // by Product + $field_values['id_field'] = '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 +245,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, @@ -340,6 +348,7 @@ } $field_values = unserialize($report); + $grid = $field_values['grid']; $rep_options = $this->Application->getUnitOptions('rep'); $new_options = Array (); @@ -375,12 +384,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 +411,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 +425,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'CategoryName'), + 'options' => $this->GetMetricOptions($new_options, 'CategoryName', $grid), 'use_phrases' => 1, 'default' => 0, ), @@ -439,13 +450,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 +489,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 +517,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 +532,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'ProductName'), + 'options' => $this->GetMetricOptions($new_options, 'ProductName', $grid), 'use_phrases' => 1, 'default' => 0 ), @@ -537,6 +550,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 +560,7 @@ 'default' => 1 ); - $new_options['Grids']['Default'] = Array( + $new_options['Grids'][$grid] = Array( 'Icons' => Array( 'default' => 'icon16_item.png', 'module' => 'core', @@ -569,7 +583,7 @@ 'Metric' => Array ( 'type' => 'int', 'formatter' => 'kOptionsFormatter', - 'options' => $this->GetMetricOptions($new_options, 'Marketplace'), + 'options' => $this->GetMetricOptions($new_options, 'Marketplace', $grid), 'use_phrases' => 1, 'default' => 0 ), @@ -632,17 +646,18 @@ * * @param array $a_config_options * @param string $exclude_field + * @param string $grid */ - function GetMetricOptions(&$a_config_options, $exclude_field) + function GetMetricOptions(&$a_config_options, $exclude_field, $grid) { $a_ret = Array(); - foreach ($a_config_options['Grids']['Default']['Fields'] AS $field => $a_options) + foreach ($a_config_options['Grids'][$grid]['Fields'] AS $field => $a_options) { if ($field == $exclude_field) { 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 +772,10 @@ /** @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']; $ret = ''; foreach ($a_fields AS $field => $a_props) @@ -820,8 +837,6 @@ $ret = str_replace('',',', $ret); $ret = str_replace('',"\r", $ret); - $report_options = unserialize($this->Application->RecallVar('report_options')); - switch ($report_options['ReportType']) { case 1: Index: modules/in-commerce/units/reports/reports_tag_processor.php =================================================================== --- modules/in-commerce/units/reports/reports_tag_processor.php +++ modules/in-commerce/units/reports/reports_tag_processor.php @@ -85,6 +85,35 @@ return ($field_values['ReportType'] == $params['value']); } + /** + * Returns report option value. + * + * @param array $params Tag params. + * + * @return string + */ + protected function ReportOptionValue(array $params) + { + $field_values = unserialize($this->Application->RecallVar('report_options')); + + return $field_values[$params['name']]; + } + + /** + * Replaces "IDField" unit config option to be inline with current report + * + * @param array $params Tag params. + * + * @return string + */ + protected function SyncIDFieldDeclaration(array $params) + { + $field_values = unserialize($this->Application->RecallVar('report_options')); + $this->Application->setUnitOption($this->Prefix, 'IDField', $field_values['id_field']); + + return ''; + } + function CalculateChart($params) { @@ -435,4 +464,4 @@ $curver = explode(".", phpversion()); return ($curver[0] >= $params['version']); } -} \ No newline at end of file +}