<?php

    $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'] : 0;
    include_once(SYS_BASE_PATH.'main/classes/wajaxmindcard.class.php');
    $w = new wAjaxMindCard();
    $w->title = $parser->utils->getFieldFromSql('SELECT name_'.$parser->lang_suff." FROM sys_objtypes WHERE objtype='test_uni'", '');
    $w->caption = $w->title;

    include_once(SYS_BASE_PATH.'ext/wtests/classes/test_uni.class.php');
    $w->f = new test_uni();

    $w->q->select('o.id');
    $w->q->select('o.name');
    $w->q->select('o.isfolder');
    $w->q->select('o.parent');
    $w->rowclass_col = $w->q->select('o.color');
    if($filter_period)
    {
         $per = $parser->utils->getPeriod($filter_period, true);
         $w->q->where("o.datefield ".$per);
         $w->f->extra_deleteAll_sql .= "AND (datefield ".$per.")";
    }
    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('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->q->from('test_uni o');
    $w->q->where("o.id<>'0'");
    $w->q->where("o.parent=:parent:");
    $w->q->orderby('o.name');

    $w->editing = true;
    $w->adding = true;
    $w->copying = true;
    $w->deleting = true;

    $w->card_func = 'card_func';

    $src = "<script type='text/javascript'>
    function card_func(id)
    {
       openWinc('".$parser->makeUrl('test_uni_card')."', 'objid='+id);
    }
    </script>";
    $parser->addScript($src);
    $src = SYS_BASE_URL.'main/js/popup.js';
    $parser->addScript($src);

    $w->show();

    print("<pre class=\"brush:php\">
    ".'$'."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'] : 0;
    include_once(SYS_BASE_PATH.'main/classes/wajaxmindcard.class.php');
    ".'$'."w = new wAjaxMindCard();
    ".'$'."w->title = ".'$'."parser->utils->getFieldFromSql('SELECT name_'.".'$'."parser->lang_suff.\" FROM sys_objtypes WHERE objtype='test_uni'\", '');
    ".'$'."w->caption = ".'$'."w->title;

    include_once(SYS_BASE_PATH.'ext/wtests/classes/test_uni.class.php');
    ".'$'."w->f = new test_uni();

    ".'$'."w->q->select('o.id');
    ".'$'."w->q->select('o.name');
    ".'$'."w->q->select('o.isfolder');
    ".'$'."w->q->select('o.parent');
    ".'$'."w->rowclass_col = ".'$'."w->q->select('o.color');
    if(".'$'."filter_period)
    {
         ".'$'."per = ".'$'."parser->utils->getPeriod(".'$'."filter_period, true);
         ".'$'."w->q->where(\"o.datefield \".".'$'."per);
         ".'$'."w->f->extra_deleteAll_sql .= \"AND (datefield \".".'$'."per.\")\";
    }
    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('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->q->from('test_uni o');
    ".'$'."w->q->where(\"o.id<>'0'\");
    ".'$'."w->q->where(\"o.parent=:parent:\");
    ".'$'."w->q->orderby('o.name');

    ".'$'."w->editing = true;
    ".'$'."w->adding = true;
    ".'$'."w->copying = true;
    ".'$'."w->deleting = true;

    ".'$'."w->card_func = 'card_func';

    ".'$'."src = \"&lt;script type='t e x t / j a v a s c r i p t'&gt;
    f u n c t i o n card_func(id)
    {
       o p e n W i n c('\".".'$'."parser->makeUrl('test_uni_card').\"', 'objid='+id);
    }
    &lt;/script&gt;\";
    ".'$'."parser->addScript(".'$'."src);
    ".'$'."src = SYS_BASE_URL.'main/js/popup.js';
    ".'$'."parser->addScript(".'$'."src);

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

    </pre>");

?>