<?php

    // Check Rights
    if(!$parser->getUserId()) die($parser->gt('not_perms'));

    include_once(SYS_BASE_PATH.'main/classes/wreport.class.php');
    $w = new wReport();

    if($w->mode != 'print')
    {
        // Show report filters
        $sec = $w->addSection($parser->gt('main'));
        $w->addReportPar($sec, 'period', $parser->gt('period'), 'period', 0);
        $w->addReportPar($sec, 'grouping', $parser->gt('grouping'), 'select', 1, $parser->gt('sel_no', SYS_BASE_PATH.'main/classes').','.$parser->gt('grobjtype', __FILE__));

        $sec = $w->addSection($parser->gt('more'));
        $w->addSearchField($sec, 'o.name', $parser->gt('name'), array('lang' => 1, 'type' => 'C'));
        $w->addSearchField($sec, 'o.objtype', $parser->gt('objtype'), 'sys_objtypes');
        $w->addSearchField($sec, 'o.isprivate', $parser->gt('isprivate'), 'L');
        $w->addSearchField($sec, 'o.flt1', $parser->gt('total'), 'F');
/*
        $sec = $w->addSection($parser->gt('more'));
        $w->addReportPar($sec, 'currency', 'Page', 'sys_elements_pages', 0);
        $w->addReportPar($sec, 'quantity', 'Quantity', 'C', '');
        $w->addReportPar($sec, 'direction', 'Direction', 'L', 1);
        $w->addReportPar($sec, 'ondate', 'On date', 'D', '');
        $w->addReportPar($sec, 'period', 'Period', 'period', 6);
*/
        $w->show();

        print("<pre class=\"brush:php\">
        include_once(SYS_BASE_PATH.'main/classes/wreport.class.php');
        ".'$'."w = new wReport();

        if(".'$'."w->mode != 'print')
        {
            // Show report filters
            ".'$'."sec = ".'$'."w->addSection(".'$'."parser->gt('main'));
            ".'$'."w->addReportPar(".'$'."sec, 'period', ".'$'."parser->gt('period'), 'period', 0);
            ".'$'."w->addReportPar(".'$'."sec, 'grouping', ".'$'."parser->gt('grouping'), 'select', 1, ".'$'."parser->gt('sel_no', SYS_BASE_PATH.'main/classes').','.".'$'."parser->gt('grobjtype', __FILE__));

            ".'$'."sec = ".'$'."w->addSection(".'$'."parser->gt('more'));
            ".'$'."w->addSearchField(".'$'."sec, 'o.name', ".'$'."parser->gt('name'), array('lang' => 1, 'type' => 'C'));
            ".'$'."w->addSearchField(".'$'."sec, 'o.objtype', ".'$'."parser->gt('objtype'), 'sys_objtypes');
            ".'$'."w->addSearchField(".'$'."sec, 'o.isprivate', ".'$'."parser->gt('isprivate'), 'L');
            ".'$'."w->addSearchField(".'$'."sec, 'o.flt1', ".'$'."parser->gt('total'), 'F');
            ".'$'."w->show();
            return;
        }

        // Print report
        ".'$'."pars = ".'$'."w->getParams();

        ".'$'."from = (".'$'."pars['period1']) ? ".'$'."parser->conn->DBDate(".'$'."parser->utils->dateToISOformat(".'$'."pars['period1'])) : '';
        ".'$'."to = (".'$'."pars['period2']) ? ".'$'."parser->conn->DBDate(".'$'."parser->utils->dateToISOformat(".'$'."pars['period2'])) : '';

        ".'$'."w->q->select('o.objid', ".'$'."parser->gt('id'));
        ".'$'."w->q->lselect('o.name AS oname', ".'$'."parser->gt('name'));
        ".'$'."w->q->lselect('t.name AS tname', ".'$'."parser->gt('objtype'));
        ".'$'."w->q->select('o.avatar', ".'$'."parser->gt('avatar'));
        ".'$'."w->q->select('o.flt1', ".'$'."parser->gt('total'));
        ".'$'."w->q->from('sys_objects o');
        ".'$'."w->q->from('sys_objtypes t');
        ".'$'."w->q->where(\"o.objid<>'0'\");
        ".'$'."w->q->where(\"o.objtype=t.objtype\");
        ".'$'."w->q->extra_where(".'$'."w->getFilters());
        if(".'$'."from) ".'$'."w->q->where(\"o.creaton>=\".".'$'."from);
        if(".'$'."to) ".'$'."w->q->where(\"o.creaton<=\".".'$'."to);

        switch(".'$'."pars['grouping'])
        {
            case 0:

            break;
            case 1:
                ".'$'."w->template = SYS_BASE_PATH.'main/styles/reporter_tpl/tbsgroup1.htm';
                ".'$'."w->q->orderby('tname');
                ".'$'."w->pagelen = 30;
                ".'$'."w->grupfield= 'tname';
            break;
        }

        ".'$'."w->q->orderby('oname');

        ".'$'."w->show();

        </pre>");

        return;
    }

    // Print report
    $pars = $w->getParams();

    $from = ($pars['period1']) ? $parser->conn->DBDate($parser->utils->dateToISOformat($pars['period1'])) : '';
    $to = ($pars['period2']) ? $parser->conn->DBDate($parser->utils->dateToISOformat($pars['period2'])) : '';

    $w->q->select('o.objid', $parser->gt('id'));
    $w->q->lselect('o.name AS oname', $parser->gt('name'));
    $w->q->lselect('t.name AS tname', $parser->gt('objtype'));
    $w->q->select('o.avatar', $parser->gt('avatar'));
    $w->q->select('o.flt1', $parser->gt('total'));
    $w->q->from('sys_objects o');
    $w->q->from('sys_objtypes t');
    $w->q->where("o.objid<>'0'");
    $w->q->where("o.objtype=t.objtype");
    $w->q->extra_where($w->getFilters());
    if($from) $w->q->where("o.creaton>=".$from);
    if($to) $w->q->where("o.creaton<=".$to);

    switch($pars['grouping'])
    {
        case 0:

        break;
        case 1:
            $w->template = SYS_BASE_PATH.'main/styles/reporter_tpl/tbsgroup1.htm';
            $w->q->orderby('tname');
            $w->pagelen = 30;
            $w->grupfield= 'tname';
        break;
    }

    $w->q->orderby('oname');

    $w->show();


?>