<?php
include_once("c_personal_person.php");

class c_page_cab_personal_person_quiz extends c_page_cab_personal_person
{
    public $h1='Карточка сотрудника - статистика по контролю знаний';
    var $use_fusioncharts=1;

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

    function select_obj_info()
    {
        parent::select_obj_info();
        //if ($this->filter['doc_id']) $this->rec_doc=DOCS()->get_doc_by_id($this->filter['doc_id']) ;
    }

    function get_cur_page_meta_tags()
    {
        //if ($this->rec_personal['pkey']) $this->h1='Документы '.$this->rec_personal['obj_name'] ;
        //if ($this->rec_doc['pkey']) $this->h1='Документ "'.$this->rec_doc['obj_name'].'"' ;
        //$this->h1='Документы '.$this->rec_personal['obj_name'] ;
    }

    function second_menu_config()
    {
        $this->second_menu[$this->rec_personal['__href'].'quiz/']=array('title'=>'Статистика КЗ');
        $this->second_menu[$this->rec_personal['__href'].'quiz/rating/']=array('title'=>'Рейтинг сотрудника');
        $this->second_menu[$this->rec_personal['__href'].'quiz/graf/']=array('title'=>'Оценка знаний');
        $this->second_menu[$this->rec_personal['__href'].'quiz/session/']=array('title'=>'Сессии КЗ');
        $this->second_menu[$this->rec_personal['__href'].'quiz/results/']=array('title'=>'Результаты КЗ');
        $this->second_menu[$this->rec_personal['__href'].'quiz/events/']=array('title'=>'Мероприятия КЗ');
        $this->second_menu[$this->rec_personal['__href'].'quiz/plan/']=array('title'=>'План КЗ');
    }

    function block_main()
    { //$this->page_title() ;
        $this->panel_report();
    }

    public $stats_elem_id='stats_chart_div';

    function panel_report()
    {
        include_once(_DIR_EXT.'/quiz/report_quiz_stats2.php');

        //     $report_obj=new report_quiz_stats2(['filter'=>['personal_id'=>$this->rec_personal['pkey']]]) ;
        $report_obj=new report_quiz_stats2();
        $report_obj->personal_id=$this->rec_personal['pkey'];
        $report_obj->init();
        $report_obj->setting();
        //$report_obj->view_as_HTML();

        if(!$this->filter['question_count']) $this->filter['question_count']=10;
        if(!$this->filter['personal_id']) $this->filter['personal_id']=$this->rec_personal['pkey'];

        $report_filter=[];

        //if($this->theme_id) $report_filter['theme_id']=$this->theme_id;
        //if($this->section_id) $report_filter['section_id']=$this->section_id;

        //$report_obj=new report_quiz_stats2(['filter'=>$report_filter]);
        //$report_obj->personal_id=$this->rec_personal['pkey'];

        //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;

        ?>
        <div id="stats_tables"><?
           // damp_array($this->filter);
        $report_obj->view_as_HTML(['stats_elem_id'=>$this->stats_elem_id]);

        ?></div><?

        ?><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>
             <?
    }
}

?>
