<?php
        // Check Rights
        if(!$parser->getUserId()) die($parser->gt('not_perms'));
        $perm = $parser->checkPerms('0');
        if(!$perm['r']) die($parser->gt('not_perms'));
        if(!isset($workframe)) die('');

        include_once(SYS_BASE_PATH.'main/classes/wcatalog.class.php');
        class wcat extends wCatalog
        {
            public $perm = array('c' => 0, 'r' => 0, 'u' => 0, 'd' => 0);
            public function _titleframe()
            {
                global $parser;
                include_once(SYS_BASE_PATH.'ext/wtests/classes/test_uni.class.php');
                $active_tab = (isset($_REQUEST['active_tab'])) ? $_REQUEST['active_tab'] : 0;
                $this->f = new test_uni();
                $this->title = $parser->utils->getFieldFromSql('SELECT name_'.$parser->lang_suff." FROM sys_objtypes WHERE objtype='test_uni'", '');
                $this->addRightRadioButton($parser->gt('card'), '', !$active_tab, '', $parser->makeUrl('fc_test_uni_form'));
                $this->addRightRadioButton($parser->gt('files'), '', ($active_tab == 2), '', $parser->makeUrl('sys_pages_hiddens_file_list', 'objtype=test_uni&autocreatedir=1&startpath=userdata_sl_modules_sl_wtests_sl_test_uni'));
                $this->addRightRadioButton($parser->gt('andmore').'...', '', ($active_tab == 5), '', $parser->makeUrl('fc_test_uni_form_more'));
                $this->extra_from = '';
                $this->extra_where = '';
            }

            public function _gridframe()
            {
                global $parser;
                $cat_id = (isset($_REQUEST['cat_id'])) ? $_REQUEST['cat_id'] : '';
                $active_tab = (isset($_REQUEST['active_tab'])) ? $_REQUEST['active_tab'] : '';
                if(!$this->adding and !$cat_id) return $parser->gt('no_data_found');
                switch($active_tab)
                {
                    case 0:
                        include_once(SYS_BASE_PATH.'ext/wtests/classes/test_uni.class.php');
                        $parser->addScript(SYS_BASE_URL.'main/js/popup.js');

                        $f = new test_uni($this->objtype, $cat_id);
                        $f->id = $cat_id;
                        $f->only_card = true;
                        $f->container = 'test_uni_cat';
                        $form_action = (isset($_POST['form_action'])) ? $_POST['form_action'] : '';
                        switch($form_action)
                        {
                            case 'edit':
                                $f->read();
                                $s = $f->update(true);
                                if($s) print($s);
                            break;
                            case 'insert':
                                $s = $f->insert(true);
                                if($s) $f->error_mess = $s;
                                else  print("<SCRIPT LANGUAGE=\"JavaScript\">parent.titleframe.cancel_adding(".$f->id.");</SCRIPT>");
                            break;
                        }

                        $f->addHidden('cat_id', $cat_id);
                        $f->addHidden('active_tab', $active_tab);
                        if($cat_id)
                        {
                            if($this->perm['u'])
                            {
    	                        $f->addHidden('form_action', 'edit');
    	                        $f->addButton($parser->gt('save'));
                            }
                        } else
                        {
                            if($this->perm['c'])
                            {
    	                        $f->addHidden('form_action', 'insert');
    	                        $f->addButton($parser->gt('insert'));
    	                        $f->addButton($parser->gt('cancel'), "parent_cancel_adding(0)", '', 'button');
                            }
                        }

                        return $f->showForm();
                    break;
                    case 2:
                        if(!$cat_id) die('');

                    break;
                }
            }

        }

        $cat = new wcat('test_uni');
        $cat->notreeframe = true;
        $cat->navigation = true;
        $cat->navibuttons = true;
        $cat->workframe = $workframe;
        $cat->extra_from = '';
        $cat->extra_where = '';
        $cat->adding = $perm['c'];
        $cat->deleting = $perm['d'];
        $cat->perm = $perm;

        $cat->show();

?>