<?php
        // Check Rights
        if(!$parser->getUserId()) die($parser->gt('not_perms'));
        $perm = $parser->checkPerms('0');
        if(!$perm['r']) die($parser->gt('not_perms'));
        include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
        $w = new wAjaxGrid();
        $filter_color = (isset($_REQUEST['filter_color'])) ? $_REQUEST['filter_color'] : '';
        $filter_boolfield = (isset($_REQUEST['filter_boolfield'])) ? $_REQUEST['filter_boolfield'] : '';
        $filter_period = (isset($_REQUEST['filter_period'])) ? $_REQUEST['filter_period'] : 1;
        include_once(SYS_BASE_PATH.'ext/wtests/classes/test_uni.class.php');
        $w->f = new test_uni();
        $w->edit_table_alias = 'o';
        //$w->caption = $parser->gt('test_uni', __FILE__);
        $w->caption = $parser->utils->getFieldFromSql('SELECT name_'.$parser->lang_suff." FROM sys_objtypes WHERE objtype='test_uni'", '');

        $w->q->select('o.id',  $parser->gt('id'));
        $w->q->select('o.name', $parser->gt('name'), array('edit' => $perm['u']));
        $w->q->from('test_uni o');
        $w->q->where("o.id<>'0'");
        $w->q->orderby('o.name');
    
        $w->rowclass_col = $w->q->select('o.color', $parser->gt('color'), array('hide' => 1));
        $w->q->select('o.datefield', $parser->gt('createdon'));
        if($filter_period)
        {
             $per = $parser->utils->getPeriod($filter_period, true);
             $w->q->where("o.datefield ".$per);
             $w->f->extra_deleteAll_sql .= "AND (datefield ".$per.")";
        }
        $w->q->select('o.boolfield', $parser->gt('boolfield'));
        switch($filter_boolfield)
        {
            case 1:	 $w->q->where("o.boolfield=1");
                     $w->f->extra_deleteAll_sql .= "AND boolfield=1 ";
            break;
            case 2:	 $w->q->where("o.boolfield=0");
                     $w->f->extra_deleteAll_sql .= "AND boolfield=0 ";
            break;
        }
        if($filter_color)
        {
            $mfilter_color = $parser->utils->addQuots($filter_color);
            $w->q->where("o.color IN(".$mfilter_color.")");
            $w->f->extra_deleteAll_sql .= "AND color IN(".$mfilter_color.") ";
            $w->f->setFieldVal('color', $filter_color);
        }
        $pars = array();
        $pars['onchange'] = $w->container."_postAction('',0)";
        $pars['name'] = 'filter_period';
        $pars['val'] = $filter_period;
        $w->addCell($parser->utils->periodMenu($pars));
    
        $pars = array();
        $pars['onchange'] = $w->container."_postAction('',0)";
        $pars['name'] = 'filter_boolfield';
        $pars['val'] = $filter_boolfield;
        $pars['options'] = array($parser->gt('all'), $parser->gt('mys'), $parser->gt('yesitis'), $parser->gt('noitisnot'));
        $w->addCell($parser->utils->dropdownMenu($pars));
    
        $w->popup_script = true;
        $pars = array();
        $pars['onchange'] = $w->container."_postAction('',0)";
        $pars['name'] = 'filter_color';
        $pars['emptyval'] = 0;
        $pars['tree_btn'] = 0;
        $pars['emptyrefval'] = $parser->gt('all');
        $pars['val'] = $filter_color;
        $pars['objtype'] = 'sys_interface_colors';
        $w->addCell($parser->utils->finder($pars));
    
        $w->addSearchField('o.name', $parser->gt('name'), 'C');

        $w->editing = $perm['u'];
        $w->adding = $perm['c'];
        $w->copying = $perm['c'];
        $w->deleting = $perm['d'];
        $w->multiselect = $perm['d'];

    
        $w->cardurl = $parser->makeUrl('test_uni_card');
    

        $w->show();
?>