if (empty($var['report_params']['filter'][0]) or count($var['report_params']['filter'][0]) < 5) {
            $r['popular'] = '<a href="' . report_lnk($var['report_params'], array('filter_str' => array_merge($var['report_params']['filter_str'], array($r['name'] => _e($r['popular']))))) . '" title="' . _e($r['popular']) . '">' . _e($popular_str) . '</a>';
        } else {
            $r['popular'] = _e($popular_str);
        }
        echo '<tr><td nowrap=""><b><a href="' . report_lnk($var['report_params'], array('mode' => '', 'group_by' => $r['name'])) . '">' . $name . '</a></b></td><td>' . $r['popular'] . '</td>';
    } else {
        echo '<tr><td nowrap=""><a href="' . report_lnk($var['report_params'], array('group_by' => '', 'filter_str' => array_merge($var['report_params']['filter_str'], array($var['report_params']['group_by'] => _e($k))))) . '">' . $k . '</a></td>';
    }
    echo '<td>' . $r['cnt'] . '</td><td>' . round3($r['cnt'] / $r['total'] * 100) . '%</td>';
    if ($var['report_params']['conv'] != 'none') {
        echo '<td class="col_s">' . $r['sale'] . '</td><td class="col_l">' . $r['lead'] . '</td><td class="col_a">' . $r['act'] . '</td><td class="col_s">' . t_conversion($r) . '</td><td class="col_l">' . t_conversion_l($r) . '</td><td class="col_a">' . t_conversion_a($r) . '</td>';
    }
    echo '<td>' . t_price($r) . '</td>';
    if ($var['report_params']['conv'] != 'none') {
        echo '<td class="col_s col_a">' . t_profit($r) . '</td><td>' . t_epc($r) . '</td><td class="col_s col_a">' . t_roi($r) . '</td><td class="col_s">' . t_cps($r) . '</td><td class="col_l">' . t_cpl($r) . '</td><td class="col_a">' . t_cpa($r) . '</td>';
    }
    echo '</tr>';
}
?>
        </tbody>
    </table>
</div>

<script>
    $(document).ready(function() {
        jQuery.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings ){
            oSettings.aaSorting = [[<?php 
if ($var['report_params']['group_by'] == '') {
    ?>
2<?php 
    $name = $r['name'];
    //$name = (empty($r['name'] or $r['name'] == '{empty}') ? $group_types[$group_by][1] : $r['name']);
    // Ограничиваем глубину фильтров
    if (empty($var['report_params']['filter'][0]) or count($var['report_params']['filter'][0]) < 5) {
        $name = '<a href="' . report_lnk($var['report_params'], array('filter_str' => array_merge($var['report_params']['filter_str'], array($var['report_params']['group_by'] => _e($r['id']))))) . '">' . _e($name) . '</a>';
    } else {
        $name = _e($name);
    }
    echo '<tr><td nowrap="" class="report-header">' . $name . '</td><td>' . $r['cnt'] . '</td><td>' . t_repeated($r) . '</td><td>' . t_lpctr($r) . '</td><td>' . $r['out'] . '</td><td class="col_s">' . $r['sale'] . '</td><td class="col_l">' . $r['lead'] . '</td><td class="col_a">' . $r['act'] . '</td><td class="col_s">' . t_conversion($r) . '</td><td class="col_l">' . t_conversion_l($r) . '</td><td class="col_a">' . t_conversion_a($r) . '</td><td>' . t_price($r) . '</td><td class="col_s col_a ' . pos_class($r['income'] - $r['price']) . '">' . t_profit($r) . '</td><td class="col_s">' . t_epc($r) . '</td><td class="col_s">' . t_roi($r) . '</td><td class="col_s">' . t_cps($r) . '</td><td class="col_l">' . t_cpl($r) . '</td><td class="col_a">' . t_cpa($r) . '</td>' . '</tr>';
}
?>
        </tbody>
        <tfoot>
            <tr><td>Итого</td><?php 
$r = $column_total_data;
echo '<td>' . $r['cnt'] . '</td><td>' . t_repeated($r) . '</td><td>' . t_lpctr($r) . '</td><td>' . $r['out'] . '</td><td class="col_s">' . $r['sale'] . '</td><td class="col_l">' . $r['lead'] . '</td><td class="col_a">' . $r['act'] . '</td><td class="col_s">' . t_conversion($r) . '</td><td class="col_l">' . t_conversion_l($r) . '</td><td class="col_a">' . t_conversion_a($r) . '</td><td>' . t_price($r) . '</td><td class="col_s col_a">' . t_profit($r) . '</td><td class="col_s">' . t_epc($r) . '</td><td class="col_s">' . t_roi($r) . '</td><td class="col_s">' . t_cps($r) . '</td><td class="col_l">' . t_cpl($r) . '</td><td class="col_a">' . t_cpa($r) . '</td>';
?>
</tr>
        </tfoot>
    </table>
</div>

<script>
    $(document).ready(function() {
        jQuery.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings ){
            oSettings.aaSorting = [[1, "desc", 0]];
            oSettings.aiDisplay.sort( function (x,y) {
                return x-y;
            } );
            oSettings.aiDisplayMaster.sort( function (x,y) {
                return x-y;