<?php
include_once(_DIR_TO_CLASS.'/c_page.php');
class c_page_cab_poll_theme_card extends c_page
{
    public $h1='Опрос - карточка темы';
    public $rec_section ;
    var $use_fusioncharts=1 ;

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

    function set_head_tags()
    {   parent::set_head_tags();
        $this->HEAD['css'][]=_PATH_TO_EXT.'/poll/style.css';
    }

    function select_obj_info()
     { if (_CUR_ID)
       { $this->rec_section=POLL()->get_theme_by_id(_CUR_ID) ;
         if ($this->rec_section['pkey'])
         { //$this->h1=$this->rec_theme['obj_name'] ;
           $arr=TREE('view_poll_tree')->get_arr_parents_names($this->rec_section['pkey'],array('from_level'=>2)) ;
           $this->h1=($this->rec_section['level']>1)? implode(' / ',$arr):$this->rec_section['obj_name'] ;
           $this->title=implode(' / ',$arr) ;
           $this->rec_section['__href']='/'._CUR_ROOT_DIR_NAME.'/poll/theme/card/'.$this->rec_section['pkey'].'/' ;

           $_SESSION['cur_obj_page_dir'][_CUR_ROOT_DIR_NAME][$this->rec_section['tkey']][$this->rec_section['clss']]=str_replace(_CUR_ID,'***',_CUR_PAGE_DIR) ;
         }
         if (!$this->rec_section['pkey']) $this->result=404 ;
       } else $this->result=404 ;

     }


     function prepare_menu_config()
     {   $cnt_questions=execSQL_value('select count(pkey) from view_poll_questions where parent='.$this->rec_section['pkey']) ;
         $cnt_sections=execSQL_value('select count(pkey) from view_poll_themes where parent='.$this->rec_section['pkey'].' and clss=572') ;
         $viewer_name=POLL()->get_personal_viewer_name_to_poll_tree_item($this->rec_section) ;
         $cnt_personals=($viewer_name)? execSQL_value('select count(pkey) from '.$viewer_name):0 ;


         $menu=[] ;
         $menu[$this->rec_section['__href']]='Статистика' ;
         $menu[$this->rec_section['__href'].'stats/']='Результат опроса' ;
         $menu[$this->rec_section['__href'].'results/']='Прохождение опроса' ;

         $menu[$this->rec_section['__href'].'editor/']='Редактировать' ;
         if ($cnt_questions) $menu[$this->rec_section['__href'].'questions/']=['title'=>'Вопросы','info_value'=>'<span>'.$cnt_questions.'</span>'] ;
         if ($cnt_sections)  $menu[$this->rec_section['__href'].'sections/']=['title'=>'Подразделы','info_value'=>'<span>'.$cnt_sections.'</span>'] ;
         /*if (!$cnt_sections and !$cnt_questions and !$cnt_knows) */$menu[$this->rec_section['__href'].'append/']='Добавить...' ;

         //if ($this->rec_section['filter'])
         $menu[$this->rec_section['__href'].'personals/']=array('title'=>'Участники','info_value'=>'<span>'.$cnt_personals.'</span>') ;
         //if ($this->rec_section['level']<=3 and !$this->rec_section['event_id'])
         $menu[$this->rec_section['__href'].'personal_set/']=array('title'=>'Выбор участников') ;

         $menu[$this->rec_section['__href'].'db/']='Исходные данные' ;

         return($menu) ;
     }

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

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

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


    function block_main()
    {   /*include_once(_DIR_EXT.'/poll/report_poll_section_stats_pie2d.php');
        include_once(_DIR_EXT.'/poll/report_poll_section_stats_angulargauge.php');
        // результаты опроса в виде радара
        $this->page_title() ;
        $arr_question_ids=execSQL_row('select pkey,answer_type from view_poll_questions where parent'.$this->rec_section['level'].'='.$this->rec_section['pkey']) ;

        ?><div id="reports_chart"><?
			  if (_sizeof($arr_question_ids)) foreach($arr_question_ids as $question_id=>$answer_type)
				{
                // $answer_type=1 - голосование баллами
                if ($answer_type==1)
                { $report_obj=new report_poll_section_stats_angulargauge();
                    $report_obj->no_view_title=1;
                    $report_obj->filter['question_id']=$question_id;
                    $report_obj->view_as_HTML();
                }

                // $answer_type=2 - голосование за ответы
                if ($answer_type==2)
                { $report_obj=new report_poll_section_stats_pie2d();
                    $report_obj->no_view_title=1;
                  $report_obj->filter['question_id']=$question_id;
                  $report_obj->view_as_HTML();
                }

          }
          ?><div class="clear"></div></div>
            <style type="text/css">
                div#reports_chart{}
                div#reports_chart div.radar_chart{float:left;margin-right:20px;margin-bottom:20px;}
                div#reports_chart div.chart_pie2d{float:left;margin-right:20px;margin-bottom:20px;}
            </style>
          <?*/

        // результаты опроса в табличной форме
        // также этот отчет выводится на
        // - карточка темы
        // - карточка темы / статистика
        // - карточка ответа
        include_once(_DIR_EXT.'/poll/report_poll_question_result.php');
        $report_obj=new report_poll_question_result();
        $report_obj->section_id=$this->rec_section['pkey'];
        $report_obj->init();
        $report_obj->no_view_title=1;
        //$report_obj->setting();
        $report_obj->view();

        //execSQL_update('update poll_themes set parent=1,parent2=0,parent3=0,parent4=0,parent5=0,parent6=0,parent7=0,parent8=0,parent9=0,level=0') ;
        //execSQL_update('update poll_questions set parent=1,parent2=0,parent3=0,parent4=0,parent5=0,parent6=0,parent7=0,parent8=0,parent9=0,level=0') ;
        //execSQL_update('update poll_answers set parent=1') ;
        //execSQL_update('update poll_tree set obj_name=""') ;
    }

}
