<?php
include_once(_DIR_TO_CLASS.'/c_page.php');
class c_page_cab_quiz extends c_page
{
    public $h1='Контроль знаний - общая статистика';
    var $use_fusioncharts=1;
    var $view_filter=1;

    function second_menu_config()
    {
        //$this->second_menu['/cab/quiz/knowledge/']=array('title'=>'Оценка знаний') ;
        $this->second_menu['/cab/quiz/']=array('title'=>'Оценка знаний') ;
        $this->second_menu['/cab/quiz/stats/']=array('title'=>'Статистика');
//        $this->second_menu['/cab/quiz/graf/']=array('title'=>'Оценка знаний');
        $this->second_menu['/cab/quiz/rating/']=array('title'=>'Рейтинг сотрудников');
        $this->second_menu['/cab/quiz/session/']=array('title'=>'Сессии КЗ');
        $this->second_menu['/cab/quiz/results/']=array('title'=>'Результаты КЗ');
         $this->second_menu['/cab/quiz/themes/']=array('title'=>'Темы КЗ');
        $this->second_menu['/cab/quiz/editor/']=array('title'=>'Темы КЗ - дерево','new_window'=>'quiz_tree');
        $this->second_menu['/cab/quiz/collections/']=array('title'=>'Библиотека тем');
        $this->second_menu['/cab/quiz/setting/']=array('title'=>'Настройки');
        $this->second_menu['/cab/quiz/info/']=array('title'=>'Информация');
        $this->second_menu['/cab/quiz/testings/']=array('title'=>'Тестирование');
    }

    public $stats_elem_id='stats_chart_div';

    function set_head_tags()
    {
       parent::set_head_tags() ;
       $this->HEAD['css'][]=_PATH_TO_EXT.'/quiz/style.css';
       $this->HEAD['css'][] = _PATH_TO_EXT.'/quiz/analyze_style.css?'.time();
       $this->HEAD['js'][] = _PATH_TO_EXT.'/quiz/addition/jquery.loadingIndicator.js';
       $this->HEAD['js'][] = _PATH_TO_EXT.'/quiz/addition/script.js';
    }

    function select_obj_info()
        { $cur_id=0 ;
          if ($this->filter['section_id']) $cur_id=$this->filter['section_id'] ;
          else if ($this->filter['theme_id']) $cur_id=$this->filter['theme_id'] ;

          if ($cur_id)
          { $this->rec_section=QUIZ()->get_theme_by_id($cur_id) ;
            if ($this->rec_section['pkey'])
            { $arr=TREE('quiz_themes')->get_arr_parents_names($this->rec_section['pkey'],array('from_level'=>2)) ;
              $this->title=$this->h1=implode(' / ',$arr).' - оценка знаний' ;
              $base_url=preg_replace('/\[(.+?)\]\//','',_CUR_PAGE_DIR) ;
              $masked_url=str_replace(_CUR_ID,'***',$base_url) ;
              // сохраняем в сессии послений открытую страницу для данного класса
            }
          }

        }


    public $default_rating_order=[
        ['type'=>'question','name'=>'Вопросы'],
        ['type'=>'personal','name'=>'Сотрудники'], //будет основным: ключ 0
        ['type'=>'org','name'=>'Организации'],
        ['type'=>'department','name'=>'Подразделения'],
        ['type'=>'work','name'=>'Должности'],
    ];


    function block_main()
    {
       $this->page_title() ;
       if (!$this->filter['question_count'])  $this->filter['question_count']=10;

       include_once(_DIR_EXT.'/quiz/report_quiz_stats2.php') ;
       $report_obj=new report_quiz_stats2() ;

       if ($this->filter['question_count']) $report_obj->filter['question_count']=$this->filter['question_count'];

       $report_obj->no_view_title=1;
       $report_obj->view_panel_info=0;

       if ($this->view_filter) {?><div class="js-filters-block hidden"><?$report_obj->setting_with_rating();?></div><div class="filters-actions"><div class="filters-actions_item js-filters-state-toggle active"title="Показать фильтры"><i class="fa fa-filter"></i></div></div><?}

       $this->view_graph($report_obj);
       $this->view_rating();

       //damp_array($_SESSION['cur_obj_page_dir'],1,-1);
    }


    function view_graph($report_obj)
    {
        ?>
        <div id="stats_tables">
        <?
        $report_obj->view_as_HTML(['stats_elem_id'=>$this->stats_elem_id]);
        ?>
        </div>
       <?
    }

    function view_rating()
    {
        ?>
   <!--     <h2>Рейтинг</h2>-->
        <div class="section_tabs main_tabs">
            <label class="analyze_switcher active" analyze_type="knowledge">Уровень знаний</label>
            <label class="analyze_switcher" analyze_type="learned">Усваиваемость</label>
            <?
            foreach ($this->default_rating_order as $order_key=>$rating) {
                ?>
                <label class="rating_type<?if ($order_key===0) echo ' active push_right'?>" get_type="<?=$rating['type']?>"><?=$rating['name']?></label>
                <?
            }
            ?>
        </div>
        <?
        $this->first_render();
        ?>
        <script type="text/javascript">
            $j(document).ready(function () {
                let cur_analyze_type='knowledge';
                let cur_rating_type='<?=$this->default_rating_order[0]['type']?>';
                let cur_page_filter;
                let stats_elem_id='';


                <?if (_sizeof($this->filter)) echo 'cur_page_filter='.json_encode($this->filter).';';?>
                <?if ($this->stats_elem_id) echo 'stats_elem_id=\''.$this->stats_elem_id.'\'';?>

                if (stats_elem_id!=='') {
                    $j('#' + stats_elem_id).loadingIndicator();
                    send_ajax_request({cmd:'quiz/get_snalyze_stats_graph',cur_page_filter:cur_page_filter,stats_elem_id:stats_elem_id}) ;
                    $j('#' + stats_elem_id).loadingIndicator('show');
                }

                $j('#rating_tables').loadingIndicator();
                send_ajax_request({cmd:'quiz/get_rating',analyze_type:cur_analyze_type,get_type:cur_rating_type,cur_page_filter:cur_page_filter}) ;
                $j('#rating_tables').loadingIndicator('show');

                $j('div.section_tabs label.rating_type').on('click',function () {
                    cur_rating_type=$j(this).attr('get_type');
                    $j('div.section_tabs label.rating_type').removeClass('active');
                    $j(this).addClass('active');
                    send_ajax_request({cmd:'quiz/get_rating',analyze_type:cur_analyze_type,get_type:cur_rating_type,cur_page_filter:cur_page_filter}) ;
                    $j('#rating_tables').loadingIndicator('show');
                });

                $j('div.section_tabs label.analyze_switcher').on('click',function () {
                    let new_analyze_type=$j(this).attr('analyze_type');
                    $j('div.section_tabs label.analyze_switcher').removeClass('active');
                    $j(this).addClass('active');
                    if (cur_analyze_type!=new_analyze_type) {
                        cur_analyze_type=new_analyze_type;
                        $j('div.section_tabs label.rating_type button').attr('analyze_type',cur_analyze_type);
                        send_ajax_request({cmd:'quiz/get_rating',analyze_type:cur_analyze_type,get_type:cur_rating_type,cur_page_filter:cur_page_filter}) ;
                        $j('#rating_tables').loadingIndicator('show');
                    }
                    // $j('#rating_tables').loadingIndicator('show');
                });

            })
        </script>
        <?
    }


    function first_render()
    {
        ?>
        <div id="rating_tables" class="js-loading-indicator">
            <div style="width: 100%; height: 400px"></div>
            <?
   //         include_once('addition/panel_rating.php');
   //         panel_rating('report_quiz_question_rating',['filter'=>$this->filter]);
            ?>
        </div>
        <?
    }
}

?>
