<?php
//include_once(_DIR_TO_CLASS.'/c_page.php');
//class c_page_cab_quiz_theme_card extends c_page
include_once('c_quiz.php') ;
class c_page_cab_quiz_theme_card extends c_page_cab_quiz
{
    public $h1='Контроль знаний - все темы';
    public $title=' - оценка знаний';
    public $rec_section ;


    function __construct($options=array())
    {   if (_CUR_ROOT_DIR_NAME=='frame') $this->body_class='no_menu';
        parent::__construct($options);
    }


    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'] ;
       else if (_CUR_ID) $cur_id=_CUR_ID ;

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

         if (!$this->rec_section['pkey']) $this->result=404 ;
       } else $this->result=404 ;

     }


     function prepare_menu_config()
     {
         $cnt_questions=execSQL_value('select count(pkey) from quiz_questions where parent='.$this->rec_section['pkey']) ;
         $cnt_sections=execSQL_value('select count(pkey) from quiz_themes where parent='.$this->rec_section['pkey'].' and clss=472') ;
         $cnt_knows=execSQL_value('select count(pkey) from quiz_themes where parent='.$this->rec_section['pkey'].' and clss=481') ;

         $menu=[] ; $BASE_URL_THEME_CARD='/'._CUR_ROOT_DIR_NAME.'/quiz/theme/card/'.$this->rec_section['pkey'] ;

         $menu[$BASE_URL_THEME_CARD.'/']='Карточка раздела' ;
         if ($this->rec_section['viewer_name']) $menu[$BASE_URL_THEME_CARD.'/stats/']='Статистика' ;
         if ($this->rec_section['viewer_name']) $menu[$BASE_URL_THEME_CARD.'/graf/']='Оценка знаний' ;
         $menu[$BASE_URL_THEME_CARD.'/learned/']='Усваиваемость' ;
         $menu[$BASE_URL_THEME_CARD.'/rating/']='Рейтинг' ;

         $menu[$BASE_URL_THEME_CARD.'/editor/']='Редактировать' ;
         if ($cnt_questions) $menu[$BASE_URL_THEME_CARD.'/questions/']=['title'=>'Билеты','info_value'=>'<span>'.$cnt_questions.'</span>'] ;
         if ($cnt_sections)  $menu[$BASE_URL_THEME_CARD.'/sections/']=['title'=>'Подразделы','info_value'=>'<span>'.$cnt_sections.'</span>'] ;
         if ($this->rec_section['manual'] or $this->rec_section['json_data'])  $menu[$BASE_URL_THEME_CARD.'/known_doc/']='Редактор знаний' ;
         if ($cnt_knows)  $menu[$BASE_URL_THEME_CARD.'/knows/']=['title'=>'Знания','info_value'=>'<span>'.$cnt_knows.'</span>'] ; ;
         /*if (!$cnt_sections and !$cnt_questions and !$cnt_knows) */$menu[$BASE_URL_THEME_CARD.'/append/']='Добавить...' ;

         //if ($this->rec_section['filter'])
             $menu[$BASE_URL_THEME_CARD.'/personals/']=array('title'=>'Участники') ;
         //if ($this->rec_section['level']<=3 and !$this->rec_section['event_id'])
         $menu[$BASE_URL_THEME_CARD.'/personal_set/[view_event_filter=1]/']=array('title'=>'Выбор участников') ;
         // только для разделов, связанных с мероприятияем КЗ
         //if ($this->rec_section['event_id']) $menu[$BASE_URL_THEME_CARD.'/event/']='Мероприятие' ;
         //if ($this->rec_section['event_id']) $menu[$BASE_URL_THEME_CARD.'/sessions/']='Сеансы КЗ' ;

         $menu[$BASE_URL_THEME_CARD.'/db/']='Исходные данные' ;

         return($menu) ;
     }

    function menu_config()
    {
        if (_CUR_ROOT_DIR_NAME=='window') $this->menu=$this->prepare_menu_config() ;
    }

    function panel_main_menu()
    {
        if (_CUR_ROOT_DIR_NAME!='frame') parent::panel_main_menu() ;
    }

    function second_menu_config()
    {
        if (_CUR_ROOT_DIR_NAME=='frame') $this->second_menu=$this->prepare_menu_config() ;
    }

    function block_main()
    {
      if (_CUR_ROOT_DIR_NAME=='frame')
      { ?><script src="/AddOns/jstree/dist/jstree.min.js"></script>
          <script type="text/javascript">
          $j(document).ready(function () {
              //tree=window.top.frames.fra_tree.document.getElementById('tree') ;
              //item=window.top.frames.fra_tree.document.getElementById('<?echo $this->rec_section['pkey']?>_anchor') ;
              //console.log(tree) ;
              //console.log(item) ;
              //console.log('<?echo $this->rec_section['pkey']?>_anchor') ;
              //207_anchor
              //207_anchor
              sendAppEvent('select_node',{item_id:'<?echo $this->rec_section['pkey']?>_anchor'});

              //$j(tree).jstree("open_node", $j(item));
              //$j(tree).jstree('select_node', $j(item));


            function sendAppEvent (name, data) {
              console.log('out:'+name) ;
              console.log(data) ;
              window.top.frames.fra_tree.postMessage({
               event: name,
               payload: data
              }, '*')
            }


              /*$j(tree).bind("open_node.jstree", function (event, data) {
                if((data.inst._get_parent(data.rslt.obj)).length) {
                  data.inst._get_parent(data.rslt.obj).open_node(this, false);
                }
              });*/



              //$j(tree).jstree(true).refresh();

              //$j(tree).find('#<?echo $this->rec_section['pkey']?>_anchor').click()
              //$j(tree).find('a#<?echo $this->rec_section['pkey']?>_anchor').prev().click() ;
              //$j(tree).find('a#<?echo $this->rec_section['pkey']?>_anchor').click() ;
              //$j(tree).find('#<?echo $this->rec_section['pkey']?>_anchor').remove()
          }) ;

         </script><?
      }
      $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(['quiz_section_tree_id'=>$this->rec_section['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;

      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);
    }


}

?>
